using Container.Business;
using Container.Common;
using Container.Model;
using Container.Services;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Transitionals;
namespace Container.Win
{
///
/// WindowView.xaml 的交互逻辑 优化闪屏问题还需4K视频测试
///
public partial class WindowView : Window
{
private Socket clentSocket;
double beginX = 0;
double endX = 0;
double beginY = 0;
double endY = 0;
bool isSysProg = true;
//创建接收客户端发送消息的线程
Thread threadReceive;
DispatcherTimer VCDTimer = new DispatcherTimer();//停止播放视频的定时器
DispatcherTimer NavTimer = new DispatcherTimer();//接地导航隐藏
DispatcherTimer GCTimer = new DispatcherTimer();
DispatcherTimer SubTitleTime = new DispatcherTimer();
DispatcherTimer ProgramSyncTimer = new DispatcherTimer();//停止播放视频的定时器
private Thread th1;//播放屏保的线程
private VlcPlayer vlc_player_;
private List> ucListSys = new List>();//记录最新的屏保列表
private List> ucNewsList = new List>(); //记录插播列表
private List> ucList = new List>(); //记录插播列表
PlayBackManage pbm;
private bool isStop = false;//是否关闭线程
private bool isMedia = false;//当前播放的是否是视频
private int duration = 0;//视频总时长;
int currentTime = 0;
int ImageShowTime = 0;
App app = ((App)Application.Current);
Class_Log log = new Class_Log();
UserControl MyUc = new UserControl();
bool isplay = false;
public bool isclose = false;
public bool Mainclose = false;
MouseHook mh = new MouseHook();
// WebSocketManage web = new WebSocketManage();
private List navDateList = new List();
WebSocketForFaceManage webForFace = new WebSocketForFaceManage();
WebSocketForProgram webForProgram = new WebSocketForProgram();
JService jService = new JService();
string outLinePath;
private double percentHeight = 1;
int isShowCountDown = 0;
bool isStartRunProg = false;
private Socket _socket;
///
/// 鼠标位置数组
///
ArrayList Points = new ArrayList();//
public ObservableCollection ItemsList { get; set; } = new ObservableCollection();
public WindowView(int type=1)
{
InitializeComponent();
isShowCountDown = type;
this.Width = app.ScreenWidth-1;
this.Height = app.ScreenHeight-1;
pbm = new PlayBackManage();
//this.MouseLeftButtonUp += new MouseButtonEventHandler(this_MouseLeftButtonDown);
outLinePath = Environment.CurrentDirectory + "/OutlineFiles";
mh.SetHook();
mh.MouseClickEvent += this_MouseClickDown;
try
{
//Application.ExecutablePathSystem.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/"))
string strImages = System.Environment.CurrentDirectory + "\\pic\\bg.png";//AppDomain.CurrentDomain.BaseDirectory + "pic\\common\\bg.png";
if (File.Exists(strImages) == true)
{
Uri uri = new Uri(strImages, UriKind.Absolute);
ImageBrush ib = new ImageBrush();
ib.ImageSource = new BitmapImage(uri);
this.waiting.Background = ib;
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
private void LoadPics()
{
try
{
Storyboard _storyboard = new Storyboard();
for (int i = 0; i < 220; i++)
{
ObjectAnimationUsingKeyFrames oauf = new ObjectAnimationUsingKeyFrames();
//ObjectAnimationUsingKeyFrames 可以对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
string name = i.ToString().PadLeft(5, '0');
bitmap.UriSource = new Uri("pack://application:,,,/Container;component/image/CountDowmImage/倒计时透明度_" + name + ".png");
bitmap.CacheOption = BitmapCacheOption.Default;
bitmap.EndInit();
ImageBrush imgBrush = new ImageBrush(bitmap);
//读取图片文件
DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame();
//DiscreteObjectKeyFrame 通过使用离散内插,可以在前一个关键帧的 Object 值及其自己的 Value 之间进行动画处理。
dokf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30));
//KeyTime 获取或设置应到达关键帧的目标 Value 的时间
//这里每隔40毫秒设置一张图片,也就是每秒1000/40=25帧
dokf.Value = imgBrush;
oauf.KeyFrames.Add(dokf);
Storyboard.SetTargetProperty(oauf, new PropertyPath("(Rectangle.Fill)"));
//把动画应用到窗体的Rectangle中
Storyboard.SetTarget(oauf, RectDisImage);
//RectDis是Rectangle的名称
_storyboard.Children.Add(oauf);
//把ObjectAnimationUsingKeyFrames动画添加到Storyboard中
}
_storyboard.Completed += new EventHandler(time_Completed);
//_storyboard.RepeatBehavior = RepeatBehavior.Forever;
_storyboard.Begin();
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "error");
}
}
void time_Completed(object sender, EventArgs e)
{
timeGrid.Visibility = Visibility.Hidden;
gridMain.Visibility = Visibility.Visible;
LoadData();
}
private void LoadData() {
try
{
this.GCTimer.Interval = TimeSpan.FromMinutes(30); //垃圾释放定时器 我定为每十分钟释放一次,大家可根据需要修改
this.GCTimer.Start();
this.SubTitleTime.Interval = TimeSpan.FromSeconds(5);
GetSubtitle();
this.SubTitleTime.Start();
jService.SetPlayRecord();
this.EventsRegistion(); // 注册事件
this.ProgramSyncTimer.Start();
NavTimer.Tick += new EventHandler(NavTimer_Tick);
NavTimer.Interval = TimeSpan.FromSeconds(1);//每秒刷新一次
if (app.screensaver.ScreenType == 0 || (app.AppList.Count == 0 && string.IsNullOrEmpty(app.configstartexe)))
{
_canvas.Visibility = Visibility.Hidden;
}
else if (app.screensaver.ScreenType < 5)
{
_canvas.Visibility = Visibility.Visible;
RectDis.Visibility = Visibility.Visible;
gridImage.Visibility = Visibility.Hidden;
LoadPics(app.screensaver.ScreenType);
}
else if (!string.IsNullOrEmpty(app.screensaver.ScreenFile))
{
string fileExtension = System.IO.Path.GetExtension(app.screensaver.ScreenFile);
if (fileExtension.ToLower() == ".gif")
{
_canvas.Visibility = Visibility.Visible;
RectDis.Visibility = Visibility.Hidden;
gridImage.Visibility = Visibility.Hidden;
GifImageLib.GifImage image = new GifImageLib.GifImage();
image.Source = app.screensaver.ScreenFile;
image.Width = 300;
image.Height = 300;
image.Background = new SolidColorBrush(Colors.Transparent);
gridmove.Children.Add(image);
}
else
{
_canvas.Visibility = Visibility.Visible;
RectDis.Visibility = Visibility.Hidden;
gridImage.Visibility = Visibility.Visible;
Uri uri = new Uri(app.screensaver.ScreenFile, UriKind.Absolute);
gridImage.Source = new BitmapImage(uri);
}
}
if (app.screensaver.ScreenEffect == 1)
{
LoadGif();
if (app.screensaver.EffectType == 0)
{
gridmove.Margin = new Thickness(0, (_canvas.Height - gridmove.Height) / 2, 0, (_canvas.Height - gridmove.Height) / 2);
}
}
else
{
if (app.screensaver.EffectType == 0)
{
gridmove.Margin = new Thickness((_canvas.Width - gridmove.Width), (_canvas.Height - gridmove.Height), 0, 0);
}
else
{
gridmove.Margin = new Thickness((_canvas.Width - gridmove.Width) / 2, (_canvas.Height - gridmove.Height) / 2, (_canvas.Width - gridmove.Width) / 2, (_canvas.Height - gridmove.Height) / 2);
}
}
jService.GetSyncDev();
StartPlay();
WebSocketForFaceManage.WebSocketReceiveEvent += new WebSocketForFaceManage.WebSocketReceiveDelegate(WebSocketManage_WebSocketReceiveEvent);
webForFace.OpenWebSocket();
WebSocketForKiosk.allSocketsForKiosk.ToList().ForEach(s => s.Send("首页"));
}
catch (Exception e)
{
log.WriteLogFile(e.ToString(), "WindowViewErrorlog");
}
}
private void WindowView_Load(object sender, RoutedEventArgs e)
{
try
{
//LoadScoket();
this.Width = SystemParameters.PrimaryScreenWidth-1;
this.Height = SystemParameters.PrimaryScreenHeight-1;
percentHeight = SystemParameters.PrimaryScreenHeight / 3840;
tbMessage.FontSize = 30 * percentHeight;
_canvas.Height = 2000 * percentHeight;
_canvas.Width = SystemParameters.PrimaryScreenWidth-1;
gridmove.Width = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
gridmove.Height = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
gridImage.Width = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
gridImage.Height = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
RectDis.Width = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
RectDis.Height = SystemParameters.PrimaryScreenWidth > 1920 ? 600 : 300;
string pluginPath = System.Environment.CurrentDirectory + "\\plugins\\";
log.WriteLogFile(pluginPath, "plugins");
vlc_player_ = new VlcPlayer(pluginPath, false);
VCDTimer.Interval = TimeSpan.FromSeconds(1);//每秒刷新一次
ProgramSyncTimer.Interval = TimeSpan.FromMinutes(1);
ShowCursor(0);
MyUc.Width = mainp.Width;
MyUc.Height = mainp.Height;
Color color = (Color)ColorConverter.ConvertFromString("Black");
MyUc.Background = new SolidColorBrush(color);
subtitleTop.Width = SystemParameters.PrimaryScreenWidth-1;
//subtitleTop.Margin = new Thickness(100, 10, 100, 10);
//subtitle.VerticalAlignment = VerticalAlignment.Bottom;
scrollingTextControlTop.Width = subtitleTop.Width;
scrollingTextControlTop.Height = subtitleTop.Height;
scrollingTextControlTop.Speed = 150;
scrollingTextControlTop.ShowType = SaversViewModel.MarqueeType.Left;
scrollingTextControlTop.SubTitleType = 1;
//scrollingTextControlTop.Margin = new Thickness(100, 0, 100, 0);
scrollingTextControlTop.ItemsSource = new List() { };
subtitleBottom.Width = SystemParameters.PrimaryScreenWidth-1;
//subtitleBottom.Margin = new Thickness(100, 10, 100, 10);
//subtitle.VerticalAlignment = VerticalAlignment.Bottom;
scrollingTextControlBottom.Width = subtitleTop.Width;
scrollingTextControlBottom.Height = subtitleTop.Height;
scrollingTextControlBottom.Speed = 150;
scrollingTextControlBottom.ShowType = SaversViewModel.MarqueeType.Left;
scrollingTextControlBottom.SubTitleType = 2;
//scrollingTextControlBottom.Margin = new Thickness(100, 0, 100, 0);
scrollingTextControlBottom.ItemsSource = new List() { };
WebSocketForProgram.WebSocketReceiveEvent += new WebSocketForProgram.WebSocketReceiveDelegate(WebSocketManage_WebSocketReceiveEvent);
if (isShowCountDown == 1)
{
LoadPics();
}
else
{
timeGrid.Visibility = Visibility.Hidden;
gridMain.Visibility = Visibility.Visible;
LoadData();
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
//private void LoadScoket()
//{
// //1、创建Socket对象
// Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// _socket = socket;
// //2、连接服务器,绑定IP 与 端口
// IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
// try
// {
// socket.Connect(iPEndPoint);
// }
// catch (Exception)
// {
// //MessageBox.Show("连接失败,请重新连接!", "提示");
// //return;
// }
// //3、接收消息
// ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveServerMsg), socket);
//}
/////
///// 不断接收客户端信息子线程方法
/////
///// 参数Socke对象
//private void ReceiveServerMsg(object obj)
//{
// var proxSocket = obj as Socket;
// //创建缓存内存,存储接收的信息 ,不能放到while中,这块内存可以循环利用
// byte[] data = new byte[1020 * 1024];
// while (true)
// {
// int len;
// try
// {
// //接收消息,返回字节长度
// len = proxSocket.Receive(data, 0, data.Length, SocketFlags.None);
// }
// catch (Exception ex)
// {
// return;//让方法结束,终结当前客户端数据的异步线程,方法退出,即线程结束
// }
// if (len > 0)//判断接收的字节数
// {
// ////将消息显示到TxtLog
// string msgStr = Encoding.Default.GetString(data, 0, len);
// Dictionary Commands = JsonConvert.DeserializeObject>(msgStr);
// var type = Commands["Type"].ToString();
// if (type == "playprog")
// {
// isStartRunProg = true;
// if (app.isProgramServer)
// {
// app.websocketForProgramServer.CloasSocket();
// app.isProgramServer = false;
// }
// if (app.isProgramSync) {
// app.webSocketForProgram.CloseWebSocket();
// app.isProgramSync = false;
// }
// this.ProgramSyncTimer.Stop();
// if (isplay)
// {
// isplay = false;
// vlc_player_.Stop();
// VCDTimer.Stop();
// }
// }
// else if (type == "shutdownprog")
// {
// this.ProgramSyncTimer.Start();
// }
// }
// }
//}
[DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]
public static extern void ShowCursor(int status);
void OnGarbageCollection(object sender, EventArgs e)
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
public void EventsRegistion()
{
this.GCTimer.Tick += new EventHandler(OnGarbageCollection);
this.SubTitleTime.Tick += new EventHandler(GetSubTitle);
this.VCDTimer.Tick += new EventHandler(VCDTimer_Tick);
this.ProgramSyncTimer.Tick += new EventHandler(ProgramSyncTimer_Tick);
}
void GetSubTitle(object sender, EventArgs e)
{
GetSubtitle();
}
private void GetSubtitle()
{
if (app.TopSubTitle.Count == 0 && app.BottomSubTitle.Count == 0)
{
jService.GetSubTitle();
scrollingTextControlTop.ItemsSource = app.TopSubTitle.Select(i => i.text).ToList();
scrollingTextControlBottom.ItemsSource = app.BottomSubTitle.Select(i => i.text).ToList();
}
if (app.TopSubTitle.Count > 0 && subtitleTop.Visibility == Visibility.Hidden)
{
subtitleTop.Visibility = Visibility.Visible;
//scrollingTextControlTop.ItemsSource = app.TopSubTitle;
}
if (app.TopSubTitle == null || app.TopSubTitle.Count == 0 && subtitleTop.Visibility == Visibility.Visible)
{
subtitleTop.Visibility = Visibility.Hidden;
}
if (app.BottomSubTitle.Count > 0 && subtitleBottom.Visibility == Visibility.Hidden)
{
subtitleBottom.Visibility = Visibility.Visible;
//scrollingTextControlBottom.ItemsSource = app.BottomSubTitle;
}
if (app.BottomSubTitle == null || app.BottomSubTitle.Count == 0 && subtitleBottom.Visibility == Visibility.Visible)
{
subtitleBottom.Visibility = Visibility.Hidden;
}
}
private void NavTimer_Tick(object sender, EventArgs e)
{
try
{
if (navDateList.Count > 0)
{
if (navDateList[0].AddSeconds(15) <= DateTime.Now)
{
this.stackPanel1.Dispatcher.Invoke(
new Action(
delegate
{
stackPanel1.Children.RemoveAt(navDateList.Count - 1);
navDateList.RemoveAt(0);
if (navDateList.Count == 0)
{
NavTimer.Stop();
}
}
));
}
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "error");
}
}
private void VCDTimer_Tick(object sender, EventArgs e)
{
try
{
//if (currentTime >= duration - 5)
//{
// isMedia = false;
// SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
//}
//else
// currentTime++;
log.WriteLogFile(currentTime + " " + duration, "1111");
if (currentTime >= duration)
{
isMedia = false;
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
//if (isplay)
//{
// isplay = false;
// vlc_player_.Stop();
// VCDTimer.Stop();
//}
}
else
currentTime++;
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "error");
}
}
private void ProgramSyncTimer_Tick(object sender, EventArgs e)
{
try
{
jService.GetSyncDev();
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "error");
}
}
private void WindowView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
if (VCDTimer != null)
VCDTimer.Stop();
if (NavTimer != null)
NavTimer.Stop();
if (SubTitleTime != null)
SubTitleTime.Stop();
if (GCTimer != null)
GCTimer.Stop();
if (ProgramSyncTimer != null)
ProgramSyncTimer.Stop();
isStop = true;
//if (th1 != null)
// th1.Abort();
if (vlc_player_ != null)
vlc_player_.Stop();
vlc_player_ = null;
mh.UnHook();
//webForFace.CloseWebSocket();
}
catch (Exception ex)
{
log.WriteLogFile("--------" + ex.ToString(), "WindowViewErrorlog");
}
try
{
log.WriteLogFile("程序关闭 isclose" + isclose.ToString() + " Mainclose" + Mainclose.ToString(), "WindowViewErrorlog");
//if (!isclose && !Mainclose)
//{
// Process[] process = Process.GetProcesses();
// foreach (Process prc in process)
// {
// if (prc.ProcessName.Equals(System.Diagnostics.Process.GetCurrentProcess().ProcessName))
// prc.Kill();
// }
//}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
public void FulshMemor()
{
try
{
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
GC.Collect();
//Mouse.OverrideCursor = Cursors.None;
}
catch { }
}
///
/// 根据获取到的信息生成UseControl
///
private void GetUControl()
{
try
{
//foreach (var item in ucList)
//{
//}
ucListSys.Clear();
ucNewsList.Clear();
ucList.Clear();
FulshMemor();
//mainp.Visibility = Visibility.Hidden;
//waiting.Visibility = Visibility.Visible;
//List> result = pbm.GetResource();
List> result =null;
if (result == null || result.Count == 0)
{
if (isplay)
{
isplay = false;
vlc_player_.Stop();
VCDTimer.Stop();
}
mainp.Visibility = Visibility.Hidden;
waiting.Visibility = Visibility.Visible;
return;
}
mainp.Visibility = Visibility.Visible;
waiting.Visibility = Visibility.Hidden;
//生成useControl,并记录相对应的效果
foreach (var item in result)
{
//waiting.Visibility = Visibility.Hidden;
try
{
string fileExtension = System.IO.Path.GetExtension(item.Item1.img).ToLower();
FileTypeJudgment fvdo = new FileTypeJudgment() { TypeTarget = new TypeVideo() };
var ext = fileExtension.Split('.').Last();//文件类型
//if (fileExtension != ".mp4"&&fileExtension != ".mov" && fileExtension != ".avi")
if (fvdo.Judge(ext))
{
UserControl uc = new UserControl();
uc.Width = mainp.Width;
uc.Height = mainp.Height;
Color color = (Color)ColorConverter.ConvertFromString("Black");
uc.Background = new SolidColorBrush(color);
if (File.Exists(item.Item1.img))
{
if (item.Item1.protype == "1")
{
ucListSys.Add(new Tuple(uc, item.Item2, item.Item1, true));
}
else
{
ucNewsList.Add(new Tuple(uc, item.Item2, item.Item1, true));
}
//ucList.Add(new Tuple(uc, item.Item2, item.Item1, true));
//ucListbeifen.Add(new Tuple(uc, item.Item2, item.Item1, false));
}
}
else
{
if (File.Exists(item.Item1.img))
{
UCImageText ucimg = new UCImageText(item.Item1.img, item.Item1.text, item.Item1.screenmatch);
ucimg.Width = mainp.Width;
ucimg.Height = mainp.Height;
Color colorimg = (Color)ColorConverter.ConvertFromString("Black");
ucimg.Background = new SolidColorBrush(colorimg);
if (item.Item1.protype == "1")
{
ucListSys.Add(new Tuple(ucimg, item.Item2, item.Item1, false));
}
else
{
ucNewsList.Add(new Tuple(ucimg, item.Item2, item.Item1, false));
}
//ucListbeifen.Add(new Tuple(ucimg, item.Item2, item.Item1, false));
}
}
}
catch (Exception ex) { log.WriteLogFile(ex.ToString(), "AddimgError"); }
}
ucList = ucNewsList.Where(i => Convert.ToDateTime(i.Item3.launchtime) < DateTime.Now && Convert.ToDateTime(i.Item3.expirydate) > DateTime.Now).ToList();
isSysProg = false;
if (ucList == null || ucList.Count == 0)
{
ucList = ucListSys;
isSysProg = true;
}
else
{
ucListSys.Clear();
}
if (ucList.Count > 0)
{
mainp.Visibility = Visibility.Visible;
waiting.Visibility = Visibility.Hidden;
app.currentIndex = 0;
}
else {
if (isplay)
{
isplay = false;
vlc_player_.Stop();
VCDTimer.Stop();
}
mainp.Visibility = Visibility.Hidden;
waiting.Visibility = Visibility.Visible;
}
//else if (ucListbeifen.Count > 0)
//{
// foreach (var uc in ucListbeifen)
// {
// ucList.Add(uc);
// }
//}
if (!File.Exists(outLinePath + "/temp.xml"))
{
log.WriteLogFile("未找到temp.xml文件", "WindowViewErrorlog");
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
///
/// 开始播放
///
private void StartPlay()
{
isStop = false;
//app.view = this;
//Thread.Sleep(1000);
GetUControl();
stackPanelAD.Children.Clear();
MyUc.Width = mainp.Width;
MyUc.Height = mainp.Height;
Color color = (Color)ColorConverter.ConvertFromString("Black");
MyUc.Background = new SolidColorBrush(color);
this.Background = new SolidColorBrush(color);
this.main.Background = new SolidColorBrush(color);
try
{
if (th1 == null)
{
th1 = new Thread(new ThreadStart(() =>
{
while (!isStop)//停止播放
{
try
{
if (app.isSendSync)
{
Thread.Sleep(1000);
continue;
}
if (isMedia)//正在播放视频
{
Thread.Sleep(1000);
continue;
}
if (ImageShowTime > 1)
{
ImageShowTime--;
Thread.Sleep(1000);
continue;
}
//播放完后重新获取最新屏保
if (app.currentIndex >= ucList.Count || app.currentIndex < 0)
{
this.Dispatcher.Invoke(new Action(() =>
{
GetUControl();
}));
app.currentIndex = 0;
}
if (app.isProgramSync && !app.isProgramServer)
{
Thread.Sleep(1000);
continue;
}
//if (app.currentIndex == ucList.Count)
//{
// app.currentIndex = 0;
//}
this.stackPanelAD.Dispatcher.Invoke(new Action(delegate
{
this.stackPanelAD.Children.Clear();
}));
if (ucList.Count > 0)
{
if (app.isProgramServer)
{
SendPlay();
}
else if (!app.isProgramSync)
{
Play();
}
}
else
{
Thread.Sleep(10000);
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
}));
//app.view.WindowState = WindowState.Maximized;
}
th1.IsBackground = true;
th1.Start();
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
private void SendPlay()
{
app.isSendSync = true;
try
{
WebsocketForProgramServer.allSockets.ToList().ForEach(s => s.Send(ucList[app.currentIndex].Item3.code));
}
catch (Exception e)
{
log.WriteLogFile(e.ToString(), "StartPlayerror");
}
}
private void Play()
{
try
{
this.stackPanelAD.Dispatcher.Invoke(new Action(delegate
{
this.stackPanelAD.Children.Clear();
}));
log.WriteLogFile(app.currentIndex.ToString(), "currentIndexlog");
log.WriteLogFile(ucList.Count.ToString()+"-----", "currentIndexlog");
if (ucList[app.currentIndex].Item4 == false)//如果是播放的图片
{
if (isplay)
{
isplay = false;
vlc_player_.Stop();
VCDTimer.Stop();
}
this.Dispatcher.Invoke(new Action(() =>
{
try
{
string fileExtension = System.IO.Path.GetExtension(ucList[app.currentIndex].Item3.img).ToLower();
if (fileExtension == ".gif")
{
GifImageLib.GifImage gifImage = new GifImageLib.GifImage();
gifImage.Width = mainp.Width;
gifImage.Height = mainp.Height;
gifImage.Source = ucList[app.currentIndex].Item3.img;
string ScreenMatch = ucList[app.currentIndex].Item3.screenmatch;
if (!string.IsNullOrEmpty(ScreenMatch))
{
if (ScreenMatch.Trim().Equals("拉伸"))
{
gifImage.Stretch = Stretch.Fill;
}
else if (ScreenMatch.Trim().Equals("适应"))
{
gifImage.Stretch = Stretch.Uniform;
}
else if (ScreenMatch.Trim().Equals("填充"))
{
gifImage.Stretch = Stretch.UniformToFill;
}
else if (ScreenMatch.Trim().Equals("居中"))
{
gifImage.Stretch = Stretch.None;
}
else
{
gifImage.Stretch = Stretch.Uniform;
}
}
mainp.Transition = ucList[app.currentIndex].Item2;
mainp.Content = gifImage;
}
else
{
mainp.Transition = ucList[app.currentIndex].Item2;
mainp.Content = ucList[app.currentIndex].Item1;
}
app.isSendSync = false;
isMedia = false;
ImageShowTime = Convert.ToInt32(ucList[app.currentIndex].Item3.time);
app.currentIndex++;
if (isSysProg)
{
var ucNews = ucNewsList.Where(i => Convert.ToDateTime(i.Item3.launchtime) < DateTime.Now.AddSeconds(ImageShowTime) && Convert.ToDateTime(i.Item3.expirydate) > DateTime.Now.AddSeconds(ImageShowTime)).ToList();
if (ucNews.Count > 0)
{
ucList = ucNews;
app.currentIndex = 0;
isSysProg = false;
}
else
{
log.WriteRecordToFile(ucList[app.currentIndex - 1].Item3.code, ucList[app.currentIndex - 1].Item3.time);
}
}
//var curIndex = app.currentIndex - 1;
//if (!string.IsNullOrEmpty(ucList[curIndex].Item3.shopName))
//{
// //log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
// //RichAD richAD = new RichAD(((SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) ? SystemParameters.PrimaryScreenWidth / 2 : SystemParameters.PrimaryScreenWidth), 420 * percentHeight, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), percentHeight);
// RichAD richAD = new RichAD( ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.devNum, ucList[curIndex].Item3.floorName, ucList[curIndex].Item3.floorOrder, ucList[curIndex].Item3.houseNum, ucList[curIndex].Item3.xaxis, ucList[curIndex].Item3.shopFormatName, ucList[curIndex].Item3.shopFormatIcon, ucList[curIndex].Item3.applets);
// DoubleAnimation heightAnimation = new DoubleAnimation(0, 620 , new Duration(TimeSpan.FromSeconds(1)));
// richAD.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
// this.stackPanelAD.Children.Insert(0, richAD);
//}
}
catch { }
}));
//try
//{
// SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
// GC.Collect();
//}
//catch { }
//Thread.Sleep(Convert.ToInt32(ucList[app.currentIndex - 1].Item3.time) * 1000);
}
else//如果是播放的视频
{
this.Dispatcher.Invoke(new Action(() =>
{
try
{
//mainp.Transition = ucList[app.currentIndex].Item2;
mainp.Content = MyUc;
if (!isplay)
{
isplay = false;
var hwndSource = (System.Windows.Interop.HwndSource)PresentationSource.FromDependencyObject(main);
IntPtr render_wnd = hwndSource.Handle;
vlc_player_.SetRenderWindow((int)render_wnd);
}
if (ucList[app.currentIndex].Item3.img.StartsWith("http:"))
vlc_player_.PlayStream(ucList[app.currentIndex].Item3.img);
else
vlc_player_.PlayFile(ucList[app.currentIndex].Item3.img);
duration = (int)vlc_player_.Duration();
app.isSendSync = false;
log.WriteLogFile(ucList[app.currentIndex].Item3.img + " " + duration.ToString(), "duration");
currentTime = 0;
ImageShowTime = 0;
VCDTimer.Start();
app.currentIndex++;
isMedia = true;
isplay = true;
if (isSysProg)
{
var ucNews = ucNewsList.Where(i => Convert.ToDateTime(i.Item3.launchtime) < DateTime.Now.AddSeconds(duration) && Convert.ToDateTime(i.Item3.expirydate) > DateTime.Now.AddSeconds(duration)).ToList();
if (ucNews.Count > 0)
{
ucList = ucNews;
app.currentIndex = 0;
isSysProg = false;
}
else
{
log.WriteRecordToFile(ucList[app.currentIndex - 1].Item3.code, ucList[app.currentIndex - 1].Item3.time);
}
}
//var curIndex = app.currentIndex - 1;
//if (!string.IsNullOrEmpty(ucList[curIndex].Item3.shopName))
//{
// log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
// RichAD richAD = new RichAD(((SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) ? SystemParameters.PrimaryScreenWidth / 2 : SystemParameters.PrimaryScreenWidth), 420 * percentHeight, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), percentHeight);
// DoubleAnimation heightAnimation = new DoubleAnimation(0, 460 * percentHeight, new Duration(TimeSpan.FromSeconds(1)));
// richAD.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
// this.stackPanelAD.Children.Insert(0, richAD);
//}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}));
//Thread.Sleep(Convert.ToInt32(ucList[app.currentIndex-1].Item3.time) * 1000);//
}
}
catch (Exception e)
{
log.WriteLogFile(e.ToString(), "currentIndexlog");
}
}
private void this_MouseClickDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
if (e.Button == System.Windows.Forms.MouseButtons.Left) //|| e.Button == System.Windows.Forms.MouseButtons.Right
{
//点击翻页
//Point p = new Point(e.Location.X, e.Location.Y);
//if (p.X < this.Width / 2)
//{
// app.currentIndex -= 2;
// while (app.currentIndex < 0)
// {
// app.currentIndex = ucList.Count + app.currentIndex;
// }
//}
//if (isMedia)
//{
// isMedia = false;
// SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
//}
//else
//{
// ImageShowTime = 0;
//}
//------------------
//点击关闭
Point p = new Point(e.Location.X, e.Location.Y);
Points.Add(p);
if (Points.Count == 5)
Points.Remove(Points[0]);
if (Points.Count > 4)
Points.Clear();
else if (Points.Count == 4 && p.X < 100 && p.Y > this.Height - 100)
{
p = (Point)Points[2];
if (p.X < 100 && p.Y > this.Height - 100)
{
p = (Point)Points[1];
if (p.X < 100 && p.Y > this.Height - 100)
{
p = (Point)Points[0];
if (p.X < 100 && p.Y > this.Height - 100)
{
this.Close();
}
}
}
}
//------------------
}
//Mouse.OverrideCursor = Cursors.Arrow;
}
catch (Exception ex)
{
Class_Log log = new Class_Log();
log.WriteLogFile("记录鼠标位置异常" + ex.ToString(), "MainWindowErrorLog");
}
}
private void WebSocketManage_WebSocketReceiveEvent(string type, string message)
{
try
{
if (type == "relay")//开始下载
{
this.stackPanel1.Dispatcher.Invoke(
new Action(
delegate
{
if (this.stackPanel1.Children.Count >= 3)
{
stackPanel1.Children.RemoveAt(2);
navDateList.RemoveAt(0);
if (navDateList.Count == 0)
{
NavTimer.Stop();
}
}
if (navDateList.Count == 0)
{
NavTimer.Start();
}
NavGuide ucimg = new NavGuide(SystemParameters.PrimaryScreenWidth-1, 440, app.navModel.LogoPath, app.navModel.ShopName, string.IsNullOrEmpty(app.navModel.FloorName) ? "距离您还有" + app.navModel.Distance + "m" : ("店铺位于" + app.navModel.FloorName), app.navModel.Angle);
DoubleAnimation heightAnimation = new DoubleAnimation(0, 440, new Duration(TimeSpan.FromSeconds(1)));
ucimg.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
stackPanel1.Children.Insert(0, ucimg);
navDateList.Add(DateTime.Now);
}
));
}
if (type == "richad")//开始下载
{
this.stackPanelAD.Dispatcher.InvokeAsync(
new Action(
delegate
{
try
{
log.WriteLogFile(this.stackPanelAD.Children.Count.ToString(), "socket");
//判断发送的数据的类型
if (this.stackPanelAD.Children.Count <= 0)
{
var curIndex = app.currentIndex > 0 ? app.currentIndex - 1 : 0;
if (!string.IsNullOrEmpty(ucList[curIndex].Item3.shopName))
{
//log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
//RichAD richAD = new RichAD(((SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) ? SystemParameters.PrimaryScreenWidth / 2 : SystemParameters.PrimaryScreenWidth), 420 * percentHeight, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), percentHeight);
//log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
RichAD richAD = new RichAD(ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.devNum, ucList[curIndex].Item3.floorName, ucList[curIndex].Item3.floorOrder, ucList[curIndex].Item3.houseNum, ucList[curIndex].Item3.xaxis, ucList[curIndex].Item3.shopFormatName, ucList[curIndex].Item3.shopFormatIcon, ucList[curIndex].Item3.applets);
DoubleAnimation heightAnimation = new DoubleAnimation(0, 620, new Duration(TimeSpan.FromSeconds(1)));
richAD.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
this.stackPanelAD.Children.Insert(0, richAD);
if (!isMedia)
{
ImageShowTime = Convert.ToInt32(ucList[curIndex].Item3.time);
}
}
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "richaderror");
}
})
);
}
else if (type == "syndata")
{
this.Dispatcher.Invoke(new Action(() =>
{
GetUControl();
}));
}
else if (type == "play")
{
//this.Dispatcher.Invoke(new Action(() =>
//{
List imageList = ucList.Select(i => i.Item3.code).ToList();
var imageIndex = imageList.IndexOf(message);
//log.WriteLogFile(message, "play");
//log.WriteLogFile(imageIndex.ToString(), "play");
//if (imageIndex < 0)
//{
// imageList = ucListSys.Select(i => i.Item3.code).ToList();
// imageIndex = imageList.IndexOf(message);
//}
if (imageIndex >= 0)
{
app.currentIndex = imageIndex;
currentTime = 0;
ImageShowTime = 0;
isMedia = false;
if (isplay)
{
isplay = false;
vlc_player_.Stop();
VCDTimer.Stop();
}
//app.isSendSync = false;
Play();
}
else
{
app.currentIndex = app.currentIndex > 0 ? app.currentIndex - 1 : 0;
//app.isSendSync = false;
Play();
}
// }));
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "errorsocket");
}
}
public void openSocket()
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
clentSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clentSocket.Connect(ip, 9001);
//开启一个新的线程不停的接收服务器发送消息的线程
threadReceive = new Thread(new ThreadStart(Receive));
//设置为后台线程
threadReceive.IsBackground = true;
threadReceive.Start();
}
///
/// 接口服务器发送的消息
///
private void Receive()
{
try
{
while (true)
{
byte[] buffer = new byte[2048];
//实际接收到的字节数
int r = clentSocket.Receive(buffer);
if (r == 0)
{
break;
}
else
{
this.stackPanelAD.Dispatcher.InvokeAsync(
new Action(
delegate
{
try
{
log.WriteLogFile(this.stackPanelAD.Children.Count.ToString(), "socket");
//判断发送的数据的类型
if (this.stackPanelAD.Children.Count <= 0)
{
var curIndex = app.currentIndex - 1;
if (!string.IsNullOrEmpty(ucList[curIndex].Item3.shopName))
{
//log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
//RichAD richAD = new RichAD(((SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight) ? SystemParameters.PrimaryScreenWidth / 2 : SystemParameters.PrimaryScreenWidth), 420 * percentHeight, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), percentHeight);
RichAD richAD = new RichAD(ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.devNum, ucList[curIndex].Item3.floorName, ucList[curIndex].Item3.floorOrder, ucList[curIndex].Item3.houseNum, ucList[curIndex].Item3.xaxis, ucList[curIndex].Item3.shopFormatName, ucList[curIndex].Item3.shopFormatIcon, ucList[curIndex].Item3.applets);
DoubleAnimation heightAnimation = new DoubleAnimation(0, 620, new Duration(TimeSpan.FromSeconds(1)));
richAD.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
this.stackPanelAD.Children.Insert(0, richAD);
}
}
}
catch (Exception ex)
{
log.WriteLogFile(app.currentIndex.ToString(), "123");
log.WriteLogFile(ex.Message, "123");
}
})
);
}
}
}
catch (Exception ex)
{
log.WriteLogFile("-------" + ex.Message, "socket");
}
}
private void LoadPics(int type)
{
try
{
Storyboard _storyboard = new Storyboard();
int count = 99;
if (type < 3)
{
count = 68;
}
for (int i = 0; i < count; i++)
{
ObjectAnimationUsingKeyFrames oauf = new ObjectAnimationUsingKeyFrames();
//ObjectAnimationUsingKeyFrames 可以对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
string name = i.ToString().PadLeft(5, '0');
bitmap.UriSource = new Uri("pack://application:,,,/Container;component/touch/touch" + type + "/touch_" + name + ".png");
log.WriteLogFile(bitmap.UriSource.AbsolutePath, "file");
bitmap.CacheOption = BitmapCacheOption.Default;
bitmap.EndInit();
ImageBrush imgBrush = new ImageBrush(bitmap);
//读取图片文件
DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame();
//DiscreteObjectKeyFrame 通过使用离散内插,可以在前一个关键帧的 Object 值及其自己的 Value 之间进行动画处理。
dokf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30));
//KeyTime 获取或设置应到达关键帧的目标 Value 的时间
//这里每隔40毫秒设置一张图片,也就是每秒1000/40=25帧
dokf.Value = imgBrush;
oauf.KeyFrames.Add(dokf);
Storyboard.SetTargetProperty(oauf, new PropertyPath("(Rectangle.Fill)"));
//把动画应用到窗体的Rectangle中
Storyboard.SetTarget(oauf, RectDis);
//RectDis是Rectangle的名称
_storyboard.Children.Add(oauf);
//把ObjectAnimationUsingKeyFrames动画添加到Storyboard中
}
_storyboard.RepeatBehavior = RepeatBehavior.Forever;
_storyboard.Begin();
}
catch (Exception ex)
{
log.WriteLogFile(ex.Message, "error");
}
}
private void LoadGif()
{
endX = _canvas.Width - gridmove.Width;
Random ran = new Random();
endY = ran.Next(0, Convert.ToInt32(_canvas.Height - gridmove.Height)); ;
ss();
//if (app.screensaver.ScreenEffect == 1 && app.screensaver.EffectType == 0)
//{
// endX = 0;
// endX = _canvas.Width - gridmove.Width;
// beginY = (_canvas.Height - gridmove.Height) / 2;
// endY = (_canvas.Height - gridmove.Height) / 2;
//}
//else {
// endX = _canvas.Width - gridmove.Width;
// Random ran = new Random();
// endY = ran.Next(0, Convert.ToInt32(_canvas.Height - gridmove.Height)); ;
//}
//ss();
}
void ss_Completed(object sender, EventArgs e)
{
Random ran = new Random();
beginX = endX;
beginY = endY;
if (app.screensaver.EffectType == 1)
{
if (endX >= _canvas.Width - gridmove.Width)
{
if (endY >= (_canvas.Height - gridmove.Width) / 2)
{
endX = ran.Next(0, Convert.ToInt32((_canvas.Width - gridmove.Width) / 2));
endY = _canvas.Height - gridmove.Height;
}
else
{
endX = ran.Next(0, Convert.ToInt32((_canvas.Width - gridmove.Width) / 2));
endY = 0;
}
}
else if (endX == 0)
{
if (endY >= (_canvas.Height - gridmove.Height) / 2)
{
endX = ran.Next(Convert.ToInt32((_canvas.Width - gridmove.Width) / 2), Convert.ToInt32(_canvas.Width - gridmove.Width));
endY = 0;
}
else
{
endX = ran.Next(Convert.ToInt32((_canvas.Width - gridmove.Width) / 2), Convert.ToInt32(_canvas.Width - gridmove.Width));
endY = _canvas.Height - gridmove.Height;
}
}
else
if (endY == _canvas.Height - gridmove.Height)
{
if (endX >= (_canvas.Width - gridmove.Width) / 2)
{
endY = ran.Next(0, Convert.ToInt32((_canvas.Height - gridmove.Height) / 2));
endX = _canvas.Width - gridmove.Width;
}
else
{
endY = ran.Next(0, Convert.ToInt32((_canvas.Height - gridmove.Height) / 2));
endX = 0;
}
}
else if (endY == 0)
{
if (endX >= (_canvas.Width - gridmove.Width) / 2)
{
endY = ran.Next(Convert.ToInt32((_canvas.Height - gridmove.Height) / 2), Convert.ToInt32(_canvas.Height - gridmove.Height));
endX = _canvas.Width - gridmove.Width;
}
else
{
endY = ran.Next(Convert.ToInt32((_canvas.Height - gridmove.Height) / 2), Convert.ToInt32(_canvas.Height - gridmove.Height));
endX = 0;
}
}
}
else
{
if (beginX == 0)
{
endX = _canvas.Width - gridmove.Width;
}
else
{
endX = 0;
}
}
ss();
}
void ss()
{
var x = endX - beginX;
var y = endY - beginY;
var z = Math.Sqrt(x * x + y * y);
var time = z / 200;
DoubleAnimation DAnimation = new DoubleAnimation();
DAnimation.From = beginX;//起点
DAnimation.To = endX;//终点
DAnimation.Duration = new Duration(TimeSpan.FromSeconds(time));//时间
Storyboard.SetTarget(DAnimation, gridmove);
Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
Storyboard story = new Storyboard();
story.Completed += new EventHandler(ss_Completed);//完成后要做的事
//story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上
if (app.screensaver.EffectType == 1)
{
DoubleAnimation DAnimation1 = new DoubleAnimation();
DAnimation1.From = beginY;//起点
DAnimation1.To = endY;//终点
DAnimation1.Duration = new Duration(TimeSpan.FromSeconds(time));//时间
Storyboard.SetTarget(DAnimation1, gridmove);
Storyboard.SetTargetProperty(DAnimation1, new PropertyPath(Canvas.TopProperty));
story.Children.Add(DAnimation1);
}
story.Children.Add(DAnimation);
story.Begin();
}
}
}