You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1340 lines
57 KiB
1340 lines
57 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using PCScreenSavers.Common;
|
|
using System.Windows.Interop;
|
|
using PCScreenSavers.Model;
|
|
using Transitionals;
|
|
using PCScreenSavers.Business;
|
|
using System.Threading;
|
|
using System.Runtime.InteropServices;
|
|
using System.Diagnostics;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Net.Sockets;
|
|
using System.Configuration;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows.Media.Animation;
|
|
using System.Net;
|
|
using Newtonsoft.Json;
|
|
using WebSocket4Net;
|
|
using Vlc.DotNet.Wpf;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PCScreenSavers.Win
|
|
{
|
|
/// <summary>
|
|
/// WindowView.xaml 的交互逻辑 优化闪屏问题还需4K视频测试
|
|
/// </summary>
|
|
public partial class WindowView : Window
|
|
{
|
|
Class_Config config = new Class_Config();
|
|
private Socket clentSocket;
|
|
//创建接收客户端发送消息的线程
|
|
Thread threadReceive;
|
|
DispatcherTimer VCDTimer = new DispatcherTimer();//停止播放视频的定时器
|
|
DispatcherTimer NavTimer = new DispatcherTimer();//接地导航隐藏
|
|
DispatcherTimer GCTimer = new DispatcherTimer();
|
|
DispatcherTimer SubTitleTime = new DispatcherTimer();
|
|
DispatcherTimer dateTime = new DispatcherTimer();
|
|
private Thread th1;//播放屏保的线程
|
|
private Thread thCheckTimer;//校时线程
|
|
//private VlcPlayer vlc_player_;
|
|
private List<Tuple<UserControl, Transition, ResInfo, bool>> ucList = new List<Tuple<UserControl, Transition, ResInfo, bool>>();//记录最新的屏保列表
|
|
// List<Tuple<UserControl, Transition, ResInfo, bool>> ucListbeifen = new List<Tuple<UserControl, Transition, ResInfo, bool>>();//备份屏保列表
|
|
PlayBackManage pbm;
|
|
private bool isStop = false;//是否关闭线程
|
|
private bool isMedia = false;//当前播放的是否是视频
|
|
private bool isCheckStop = 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();
|
|
WebSocketForFaceManage webForFace = new WebSocketForFaceManage();
|
|
private List<DateTime> navDateList = new List<DateTime>();
|
|
JService jService = new JService();
|
|
string outLinePath;
|
|
private readonly DirectoryInfo vlcLibDirectory;
|
|
private VlcControl control;
|
|
|
|
double beginX = 0;
|
|
double endX = 0;
|
|
double beginY = 0;
|
|
double endY = 0;
|
|
//GifImageLib.GifImage GgifImage;
|
|
|
|
/// <summary>
|
|
/// 鼠标位置数组
|
|
/// </summary>
|
|
ArrayList Points = new ArrayList();//
|
|
public ObservableCollection<NavGuide> ItemsList { get; set; } = new ObservableCollection<NavGuide>();
|
|
public WindowView(PlayBackManage pbm1)
|
|
{
|
|
InitializeComponent();
|
|
this.Width = SystemParameters.PrimaryScreenWidth-1;
|
|
this.Height = SystemParameters.PrimaryScreenHeight-1;
|
|
mainp.Height = this.Height;
|
|
mainp.Width = this.Width;
|
|
pbm = pbm1;
|
|
//this.MouseLeftButtonUp += new MouseButtonEventHandler(this_MouseLeftButtonDown);
|
|
outLinePath = Environment.CurrentDirectory + "/OutlineFiles";
|
|
mh.SetHook();
|
|
mh.MouseClickEvent += this_MouseClickDown;
|
|
var currentAssembly = Assembly.GetEntryAssembly();
|
|
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
|
|
// Default installation path of VideoLAN.LibVLC.Windows
|
|
vlcLibDirectory = new DirectoryInfo(currentDirectory);
|
|
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 LoadGif()
|
|
{
|
|
endX = touch.Width- 630;
|
|
Random ran = new Random();
|
|
endY = ran.Next(0, Convert.ToInt32(touch.Height- 630)); ;
|
|
ss();
|
|
}
|
|
void ss_Completed(object sender, EventArgs e)
|
|
{
|
|
Random ran = new Random();
|
|
beginX = endX;
|
|
beginY = endY;
|
|
if (endX >= (touch.Width- 630))
|
|
{
|
|
if (endY >= (touch.Height- 630 ) / 2)
|
|
{
|
|
endX = ran.Next(0, Convert.ToInt32((touch.Width- 630) / 2));
|
|
endY = (touch.Height - 630 );
|
|
}
|
|
else
|
|
{
|
|
endX = ran.Next(0, Convert.ToInt32((touch.Width - 630) / 2));
|
|
endY = 0;
|
|
}
|
|
}
|
|
else if (endX == 0)
|
|
{
|
|
if (endY >= (touch.Height - 630 ) / 2)
|
|
{
|
|
endX = ran.Next(Convert.ToInt32((touch.Width - 630) / 2), Convert.ToInt32((touch.Width - 630)));
|
|
endY = (touch.Height - 630);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
endX = ran.Next(Convert.ToInt32((touch.Width - 630) / 2), Convert.ToInt32((touch.Width - 630)));
|
|
endY = 0;
|
|
|
|
}
|
|
}else
|
|
if (endY == (touch.Height - 630 ))
|
|
{
|
|
if (endX >= (touch.Width - 630) / 2)
|
|
{
|
|
endY = ran.Next(0, Convert.ToInt32((touch.Height - 630 ) / 2));
|
|
endX = (touch.Width - 630);
|
|
}
|
|
else
|
|
{
|
|
endY = ran.Next(0, Convert.ToInt32((touch.Height - 630 ) / 2));
|
|
endX = 0;
|
|
}
|
|
}
|
|
else if (endY == 0)
|
|
{
|
|
if (endX >= (touch.Width - 630) / 2)
|
|
{
|
|
endY = ran.Next(Convert.ToInt32((touch.Height - 630 ) / 2), Convert.ToInt32((touch.Height - 630 )));
|
|
|
|
endX = (touch.Width - 630);
|
|
}
|
|
else
|
|
{
|
|
endY = ran.Next(Convert.ToInt32((touch.Height - 630 ) / 2), Convert.ToInt32((touch.Height - 630 )));
|
|
|
|
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));//时间
|
|
|
|
DoubleAnimation DAnimation1 = new DoubleAnimation();
|
|
DAnimation1.From = beginY;//起点
|
|
DAnimation1.To = endY;//终点
|
|
DAnimation1.Duration = new Duration(TimeSpan.FromSeconds(time));//时间
|
|
|
|
Storyboard.SetTarget(DAnimation, GgifImage2);
|
|
Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
|
|
|
|
|
|
Storyboard.SetTarget(DAnimation1, GgifImage2);
|
|
Storyboard.SetTargetProperty(DAnimation1, new PropertyPath(Canvas.TopProperty));
|
|
Storyboard story = new Storyboard();
|
|
|
|
story.Completed += new EventHandler(ss_Completed);//完成后要做的事
|
|
//story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上
|
|
story.Children.Add(DAnimation);
|
|
story.Children.Add(DAnimation1);
|
|
story.Begin();
|
|
}
|
|
|
|
private void BindWeather()
|
|
{
|
|
JService jService = new JService();
|
|
string imgUrl = "";
|
|
Weathers weather = jService.GetWeather();
|
|
if (weather == null || string.IsNullOrEmpty(weather.Status))
|
|
{
|
|
imgWeather.Visibility = Visibility.Hidden;
|
|
txtTemp.Visibility = Visibility.Hidden;
|
|
gridSplitter.Visibility = Visibility.Hidden;
|
|
return;
|
|
}
|
|
else {
|
|
imgWeather.Visibility = Visibility.Visible;
|
|
txtTemp.Visibility = Visibility.Visible;
|
|
gridSplitter.Visibility = Visibility.Visible;
|
|
}
|
|
if (weather.Status.Contains("阴"))
|
|
{
|
|
imgUrl = "sun_cloudy.png";
|
|
}
|
|
else if (weather.Status.Contains("云"))
|
|
{
|
|
imgUrl = "sun_cloudy.png";
|
|
}
|
|
else if (weather.Status.Contains("雨"))
|
|
{
|
|
imgUrl = "rain.png";
|
|
}
|
|
else if (weather.Status.Contains("雪"))
|
|
{
|
|
imgUrl = "snow.png";
|
|
}
|
|
else
|
|
{
|
|
imgUrl = "sun.png";
|
|
}
|
|
Uri uri = new Uri("pack://application:,,,/PCScreenSavers;component/Images/" + imgUrl, UriKind.RelativeOrAbsolute);
|
|
ImageBrush ib = new ImageBrush();
|
|
ib.ImageSource = new BitmapImage(uri);
|
|
this.imgWeather.Source = ib.ImageSource;
|
|
if (!string.IsNullOrEmpty(weather.Temperature_High))
|
|
{
|
|
txtTemp.Text = weather.Temperature_High + "°";
|
|
}
|
|
//string pm = jService.GetPM();
|
|
//if (string.IsNullOrEmpty(pm)) {
|
|
//lblPM.Text = "PM2.5:" + pm;
|
|
//message.ColumnDefinitions[4].Width = 0;
|
|
//}
|
|
}
|
|
|
|
private void WindowView_Load(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//touch.Width = SystemParameters.PrimaryScreenWidth;
|
|
//touch.Height = SystemParameters.PrimaryScreenHeight;
|
|
app.TouchType = "2";
|
|
if (string.IsNullOrEmpty(app.TouchType) || app.TouchType.Equals("0"))
|
|
{
|
|
touch.Visibility = Visibility.Hidden;
|
|
}
|
|
else
|
|
{
|
|
touch.Visibility = Visibility.Visible;
|
|
//if (app.TouchType.Equals("1"))
|
|
//{
|
|
// //GgifImage1.Source = "/PCScreenSavers;component/Images/touch1.gif";
|
|
// //GgifImage1.Visibility = Visibility;
|
|
// //GgifImage = GgifImage1;
|
|
// LoadGif();
|
|
//}
|
|
//else
|
|
//{
|
|
// // GgifImage1.SetBinding(DependencyProperty.);
|
|
// //GgifImage1.Visibility = Visibility;
|
|
// GgifImage2.Visibility = Visibility;
|
|
// GgifImage = GgifImage2;
|
|
// LoadGif();
|
|
//}
|
|
LoadGif();
|
|
}
|
|
LoadRectBtn();
|
|
//string pluginPath = System.Environment.CurrentDirectory + "\\plugins\\";
|
|
//vlc_player_ = new VlcPlayer(pluginPath, false);
|
|
VCDTimer.Interval = TimeSpan.FromSeconds(1);//每秒刷新一次
|
|
StartPlay();
|
|
myControl.Width = this.Width;
|
|
myControl.Height = this.Height;
|
|
MyUc.Width = mainp.Width;
|
|
MyUc.Height = mainp.Height;
|
|
Color color = (Color)ColorConverter.ConvertFromString("Black");
|
|
MyUc.Background = new SolidColorBrush(color);
|
|
|
|
subtitleTop.Width = SystemParameters.PrimaryScreenWidth;
|
|
//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 = ViewModel.MarqueeType.Left;
|
|
scrollingTextControlTop.SubTitleType = 1;
|
|
//scrollingTextControlTop.Margin = new Thickness(100, 0, 100, 0);
|
|
scrollingTextControlTop.ItemsSource = new List<string>() { };
|
|
|
|
subtitleBottom.Width = SystemParameters.PrimaryScreenWidth;
|
|
//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 = ViewModel.MarqueeType.Left;
|
|
scrollingTextControlBottom.SubTitleType = 2;
|
|
//scrollingTextControlBottom.Margin = new Thickness(100, 0, 100, 0);
|
|
scrollingTextControlBottom.ItemsSource = new List<string>() { };
|
|
|
|
this.GCTimer.Interval = TimeSpan.FromMinutes(30); //垃圾释放定时器 我定为每十分钟释放一次,大家可根据需要修改
|
|
this.GCTimer.Start();
|
|
|
|
this.SubTitleTime.Interval = TimeSpan.FromSeconds(5);
|
|
GetSubtitle();
|
|
this.SubTitleTime.Start();
|
|
|
|
this.EventsRegistion(); // 注册事件
|
|
|
|
NavTimer.Tick += new EventHandler(NavTimer_Tick);
|
|
NavTimer.Interval = TimeSpan.FromSeconds(1);//每秒刷新一次
|
|
//jService.SetPlayRecord();
|
|
if (app.isSameScreen && thCheckTimer == null)
|
|
{
|
|
thCheckTimer = new Thread(new ThreadStart(() =>
|
|
{
|
|
|
|
while (!isCheckStop)//停止播放
|
|
{
|
|
try
|
|
{
|
|
|
|
if (app.StartTime != "")
|
|
{
|
|
if (!app.isGotoStart)
|
|
{
|
|
string timenow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
if (timenow.Equals(app.StartTime))
|
|
{
|
|
|
|
app.isGotoStart = true;
|
|
app.StartTime = "";
|
|
}
|
|
log.WriteLogFile("app.isGotoStart:" + app.isGotoStart.ToString(), "starttime");
|
|
|
|
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!app.isGotoStart)
|
|
{
|
|
if (!isGetStart)
|
|
{
|
|
if ((DateTime.Now.Minute) % 3 == 0)
|
|
{
|
|
if (app.StartTime == "")
|
|
{
|
|
//调用接口 要不要判断是否正在下载??
|
|
app.StartTime = pbm.GetStartTime();
|
|
log.WriteLogFile(app.StartTime, "starttime");
|
|
isGetStart = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((DateTime.Now.Minute) % 3 != 0)
|
|
{
|
|
isGetStart = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
|
|
}
|
|
|
|
Thread.Sleep(50);
|
|
}
|
|
|
|
}));
|
|
thCheckTimer.IsBackground = true;
|
|
thCheckTimer.Start();
|
|
}
|
|
//初始化配置,指定引用库
|
|
myControl.SourceProvider.CreatePlayer(this.vlcLibDirectory);
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
BindWeather();
|
|
lblDate.Text = dtNow.ToString("yyyy-MM-dd");
|
|
lblWeek.Text = dtNow.DayOfWeek.ToString();
|
|
lblTime.Text = dtNow.ToShortTimeString().ToString();
|
|
//dateTime.Tick += new EventHandler(dateTime_Tick);
|
|
//dateTime.Interval = TimeSpan.FromSeconds(10);//每秒刷新一次
|
|
//dateTime.Start();
|
|
|
|
//NavGuide ucimg = new NavGuide(SystemParameters.PrimaryScreenWidth, 220, "http://192.168.1.173:8001//Files/b18e0ede-35cc-403f-9658-097f197d57a7/%E7%94%BB%E6%9D%BF%201%20%E5%89%AF%E6%9C%AC%2030.png", "KOYO", "店铺位于L1", 60);
|
|
//DoubleAnimation heightAnimation = new DoubleAnimation(0, 120, new Duration(TimeSpan.FromSeconds(1)));
|
|
//ucimg.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
|
|
//stackPanel1.Children.Insert(0, ucimg);
|
|
//navDateList.Add(DateTime.Now);
|
|
|
|
//RichAD richAD = new RichAD(1080, 210, "/Files/b18e0ede-35cc-403f-9658-097f197d57a7/%E7%94%BB%E6%9D%BF%201%20%E5%89%AF%E6%9C%AC%2030.png", "KOYO", "L1", 60);
|
|
//DoubleAnimation heightAnimation1 = new DoubleAnimation(0, 230, new Duration(TimeSpan.FromSeconds(1)));
|
|
//richAD.BeginAnimation(Border.HeightProperty, heightAnimation1, HandoffBehavior.Compose);
|
|
//this.stackPanelAD.Children.Insert(0, richAD);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
|
|
}
|
|
WebSocketManage.WebSocketReceiveEvent += new WebSocketManage.WebSocketReceiveDelegate(WebSocketManage_WebSocketReceiveEvent);
|
|
web.OpenWebSocket();
|
|
WebSocketForFaceManage.WebSocketReceiveEvent += new WebSocketForFaceManage.WebSocketReceiveDelegate(WebSocketManage_WebSocketReceiveEvent);
|
|
webForFace.OpenWebSocket();
|
|
log.WriteLogFile(app.websocket.State.ToString(), "1111");
|
|
//app.websocket.Send("首页");
|
|
//if (app.websocket != null && app.websocket.State == WebSocketState.Open)
|
|
//{
|
|
|
|
//}
|
|
//openSocket();
|
|
}
|
|
public void LoadRectBtn()
|
|
{
|
|
try
|
|
{
|
|
Storyboard storyboard = new Storyboard();
|
|
for (int i = 0; i < 95; i++)
|
|
{
|
|
ObjectAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
|
|
BitmapImage bitmapImage = new BitmapImage();
|
|
bitmapImage.BeginInit();
|
|
string text = i.ToString().PadLeft(5, '0');
|
|
bitmapImage.UriSource = new Uri("pack://application:,,,/PCScreenSavers;component/Images/TouchMeNew/touth05_" + text + ".png");
|
|
bitmapImage.CacheOption = BitmapCacheOption.Default;
|
|
bitmapImage.EndInit();
|
|
bitmapImage.Freeze();
|
|
ImageBrush imageBrush = new ImageBrush(bitmapImage);
|
|
DiscreteObjectKeyFrame discreteObjectKeyFrame = new DiscreteObjectKeyFrame();
|
|
discreteObjectKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30));
|
|
discreteObjectKeyFrame.Value = imageBrush;
|
|
imageBrush.Freeze();
|
|
objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);
|
|
discreteObjectKeyFrame.Freeze();
|
|
Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, new PropertyPath("(Rectangle.Fill)"));
|
|
Storyboard.SetTarget(objectAnimationUsingKeyFrames, RectBtn);
|
|
storyboard.Children.Add(objectAnimationUsingKeyFrames);
|
|
}
|
|
storyboard.RepeatBehavior = RepeatBehavior.Forever;
|
|
storyboard.Begin();
|
|
storyboard.Freeze();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile("悬浮按钮加载失败:" + ex.Message);
|
|
}
|
|
}
|
|
private void dateTime_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime dtNow = DateTime.Now;
|
|
lblDate.Text = dtNow.ToString("yyyy-MM-dd");
|
|
lblWeek.Text = dtNow.DayOfWeek.ToString();
|
|
lblTime.Text = dtNow.ToShortTimeString().ToString();
|
|
if (dtNow.ToString("mm").LastIndexOf("3") == 1)
|
|
{
|
|
BindWeather();
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
bool isGetStart = false;
|
|
private void CheckTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (app.StartTime != "")
|
|
{
|
|
if (!app.isGotoStart)
|
|
{
|
|
string timenow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
if (timenow.Equals(app.StartTime))
|
|
{
|
|
|
|
app.isGotoStart = true;
|
|
app.StartTime = "";
|
|
}
|
|
log.WriteLogFile("app.isGotoStart:" + app.isGotoStart.ToString(), "starttime");
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!app.isGotoStart)
|
|
{
|
|
if (!isGetStart)
|
|
{
|
|
if ((DateTime.Now.Minute) % 10 == 0)
|
|
{
|
|
//调用接口 要不要判断是否正在下载??
|
|
app.StartTime = pbm.GetStartTime();
|
|
log.WriteLogFile(app.StartTime, "starttime");
|
|
isGetStart = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((DateTime.Now.Minute) % 10 != 0)
|
|
{
|
|
isGetStart = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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;
|
|
scrollingTextControlBottom.ItemsSource = app.BottomSubTitle;
|
|
}
|
|
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++;
|
|
if (currentTime >= duration)
|
|
{
|
|
isMedia = false;
|
|
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
|
|
|
|
}
|
|
else
|
|
currentTime++;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.Message, "error");
|
|
}
|
|
}
|
|
private void TCPSocketClose()
|
|
{
|
|
try
|
|
{
|
|
TcpClient tcp = new TcpClient();
|
|
string AddressIP = "127.0.0.1";
|
|
int port = 8888;
|
|
string portstring = ConfigurationManager.AppSettings["ClientSettingsProvider.ServiceUri"];
|
|
if (string.IsNullOrEmpty(portstring))
|
|
portstring = "8888";
|
|
else
|
|
{
|
|
try
|
|
{
|
|
port = int.Parse(portstring);
|
|
}
|
|
catch
|
|
{
|
|
port = 8888;
|
|
}
|
|
}
|
|
if (!tcp.Connected)
|
|
tcp.Connect(AddressIP, port);//根据服务器的IP地址和侦听的端口连接
|
|
|
|
if (tcp.Connected)
|
|
{
|
|
|
|
//连接成功的消息机制 详细见DEMO
|
|
|
|
NetworkStream streamToServer = tcp.GetStream();
|
|
string msg = "0";
|
|
//int BufferSize = 600;
|
|
byte[] buffer = Encoding.ASCII.GetBytes(msg); //msg为发送的字符串
|
|
lock (streamToServer)
|
|
{
|
|
streamToServer.Write(buffer, 0, buffer.Length); // 发往服务器
|
|
}
|
|
//
|
|
|
|
}
|
|
tcp.Close();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "TCPLog");
|
|
}
|
|
}
|
|
private void WindowView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (isMedia)
|
|
{
|
|
app.PlayTime = currentTime;
|
|
}
|
|
else {
|
|
app.PlayTime = ImageShowTime;
|
|
}
|
|
config.WriteToProgramConfig();
|
|
if (VCDTimer != null)
|
|
VCDTimer.Stop();
|
|
isStop = true;
|
|
if (th1 != null)
|
|
th1.Abort();
|
|
//if (vlc_player_ != null)
|
|
// vlc_player_.Stop();
|
|
//vlc_player_ = null;
|
|
if (isplay) {
|
|
StopVideo();
|
|
}
|
|
app.websocket.Send("close");
|
|
webForFace.CloseWebSocket();
|
|
|
|
mh.UnHook();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
|
|
}
|
|
try
|
|
{
|
|
|
|
log.WriteLogFile("程序关闭 isclose" + isclose.ToString() + " Mainclose" + Mainclose.ToString(), "WindowViewErrorlog");
|
|
if (!isclose && !Mainclose)
|
|
{
|
|
TCPSocketClose();
|
|
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 { }
|
|
}
|
|
/// <summary>
|
|
/// 根据获取到的信息生成UseControl
|
|
/// </summary>
|
|
private void GetUControl(bool isLoad=true)
|
|
{
|
|
try
|
|
{
|
|
|
|
//foreach (var item in ucList)
|
|
//{
|
|
//}
|
|
ucList.Clear();
|
|
FulshMemor();
|
|
//mainp.Visibility = Visibility.Hidden;
|
|
//waiting.Visibility = Visibility.Visible;
|
|
List<Tuple<ResInfo, Transition>> result = pbm.GetResource(isLoad);
|
|
if (result == null|| result.Count==0)
|
|
{
|
|
|
|
mainp.Visibility = Visibility.Hidden;
|
|
myControl.Visibility = Visibility.Hidden;
|
|
waiting.Visibility = Visibility.Visible;
|
|
if (isplay)
|
|
{
|
|
isplay = false;
|
|
StopVideo();
|
|
// vlc_player_.Stop();
|
|
VCDTimer.Stop();
|
|
isMedia = false;
|
|
}
|
|
return;
|
|
}
|
|
mainp.Visibility = Visibility.Visible;
|
|
myControl.Visibility = Visibility.Hidden;
|
|
waiting.Visibility = Visibility.Hidden;
|
|
//生成useControl,并记录相对应的效果
|
|
foreach (var item in result)
|
|
{
|
|
|
|
//waiting.Visibility = Visibility.Hidden;
|
|
try
|
|
{
|
|
|
|
|
|
string fileExtension = System.IO.Path.GetExtension(item.Item1.img);
|
|
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))
|
|
{
|
|
ucList.Add(new Tuple<UserControl, Transition, ResInfo, bool>(uc, item.Item2, item.Item1, true));
|
|
//ucListbeifen.Add(new Tuple<UserControl, Transition, ResInfo, bool>(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);
|
|
ucList.Add(new Tuple<UserControl, Transition, ResInfo, bool>(ucimg, item.Item2, item.Item1, false));
|
|
//ucListbeifen.Add(new Tuple<UserControl, Transition, ResInfo, bool>(ucimg, item.Item2, item.Item1, false));
|
|
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) { log.WriteLogFile(ex.ToString(), "AddimgError"); }
|
|
|
|
}
|
|
if (ucList.Count > 0)
|
|
{
|
|
mainp.Visibility = Visibility.Visible;
|
|
myControl.Visibility = Visibility.Hidden;
|
|
waiting.Visibility = Visibility.Hidden;
|
|
/*最新
|
|
app.currentIndex = 0;
|
|
*/
|
|
}
|
|
//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);
|
|
/// <summary>
|
|
/// 开始播放
|
|
/// </summary>
|
|
private void StartPlay()
|
|
{
|
|
isStop = false;
|
|
app.view = this;
|
|
|
|
GetUControl(false);
|
|
if (app.isSameScreen)
|
|
{
|
|
app.StartTime = pbm.GetStartTime();
|
|
}
|
|
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);
|
|
if (th1 == null)
|
|
{
|
|
th1 = new Thread(new ThreadStart(() =>
|
|
{
|
|
|
|
while (!isStop)//停止播放
|
|
{
|
|
try
|
|
{
|
|
if (app.isGotoStart)
|
|
{
|
|
app.isGotoStart = false;
|
|
if (isMedia)
|
|
{
|
|
isMedia = false;
|
|
}
|
|
app.currentIndex = 0; //改成0还是重新获取列表?
|
|
ImageShowTime = 0;
|
|
log.WriteLogFile("同步校时", "starttime");
|
|
}
|
|
if (isMedia)//正在播放视频
|
|
{
|
|
Thread.Sleep(500);
|
|
continue;
|
|
}
|
|
if (ImageShowTime > 1)
|
|
{
|
|
ImageShowTime--;
|
|
Thread.Sleep(500);
|
|
continue;
|
|
}
|
|
//播放完后重新获取最新屏保
|
|
if (app.currentIndex >= ucList.Count || app.currentIndex < 0)
|
|
{
|
|
this.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
GetUControl();
|
|
}));
|
|
app.currentIndex = 0;
|
|
}
|
|
//if (app.currentIndex == ucList.Count)
|
|
//{
|
|
// app.currentIndex = 0;
|
|
//}
|
|
this.stackPanelAD.Dispatcher.Invoke(new Action(delegate
|
|
{
|
|
this.stackPanelAD.Children.Clear();
|
|
}));
|
|
if (ucList.Count > 0)
|
|
{
|
|
//log.WriteLogFile(app.currentIndex.ToString(), "currentIndexlog");
|
|
if (ucList[app.currentIndex].Item4 == false)//如果是播放的图片
|
|
{
|
|
if (isplay)
|
|
{
|
|
isplay = false;
|
|
StopVideo();
|
|
//vlc_player_.Stop();
|
|
VCDTimer.Stop();
|
|
}
|
|
|
|
this.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
try
|
|
{
|
|
mainp.Transition = ucList[app.currentIndex].Item2;
|
|
mainp.Content = ucList[app.currentIndex].Item1;
|
|
myControl.Visibility = Visibility.Hidden;
|
|
mainp.Visibility = Visibility.Visible;
|
|
app.currentIndex++;
|
|
isMedia = false;
|
|
}
|
|
catch { }
|
|
}));
|
|
if (app.PlayTime > 0)
|
|
{
|
|
ImageShowTime = app.PlayTime;
|
|
app.PlayTime = 0;
|
|
}
|
|
else {
|
|
ImageShowTime = Convert.ToInt32(ucList[app.currentIndex - 1].Item3.time) * 2;
|
|
}
|
|
|
|
log.WriteRecordToFile(ucList[app.currentIndex - 1].Item3.code, ucList[app.currentIndex - 1].Item3.time);
|
|
//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:")|| ucList[app.currentIndex].Item3.img.StartsWith("https:"))
|
|
// vlc_player_.PlayStream(ucList[app.currentIndex].Item3.img);
|
|
//else
|
|
// vlc_player_.PlayFile(ucList[app.currentIndex].Item3.img);
|
|
|
|
// duration = (int)vlc_player_.Duration();
|
|
//log.WriteLogFile("-----"+app.PlayTime,"222");
|
|
//if (app.PlayTime > 0)
|
|
//{
|
|
// currentTime = app.PlayTime;
|
|
// duration = Convert.ToInt32(ucList[app.currentIndex].Item3.duration) / 1000 - currentTime;
|
|
|
|
// //vlc_player_.SetPlayTime(currentTime);
|
|
// app.PlayTime = 0;
|
|
//}
|
|
//else
|
|
//{
|
|
currentTime = 0;
|
|
duration = Convert.ToInt32(ucList[app.currentIndex].Item3.duration) / 1000;
|
|
//}
|
|
StartVideo(ucList[app.currentIndex].Item3.img, currentTime * 1000);
|
|
//log.WriteLogFile("currentTime"+ currentTime,"222");
|
|
VCDTimer.Start();
|
|
app.currentIndex++;
|
|
isMedia = true;
|
|
isplay = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
|
|
}
|
|
}));
|
|
//Thread.Sleep(Convert.ToInt32(ucList[app.currentIndex-1].Item3.time) * 1000);//
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Thread.Sleep(10000);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
|
|
}
|
|
}
|
|
|
|
|
|
}));
|
|
//app.view.WindowState = WindowState.Maximized;
|
|
}
|
|
th1.IsBackground = true;
|
|
th1.Start();
|
|
}
|
|
|
|
private void StartVideo(string videoPath,long duration)
|
|
{
|
|
try
|
|
{
|
|
//this.control?.Dispose();
|
|
//this.control = new VlcControl();
|
|
//this.mainp.Content = this.control;
|
|
//Task.Factory.StartNew(() =>
|
|
//{
|
|
// this.Dispatcher.Invoke(() =>
|
|
// {
|
|
// this.control.SourceProvider.CreatePlayer(this.vlcLibDirectory);
|
|
// control.SourceProvider.MediaPlayer.Play(new Uri(videoPath));
|
|
// if (duration > 0)
|
|
// {
|
|
// control.SourceProvider.MediaPlayer.Time = duration;
|
|
// }
|
|
// });
|
|
//});
|
|
|
|
myControl.SourceProvider.MediaPlayer.Play(new Uri(videoPath));
|
|
myControl.Visibility = Visibility.Visible;
|
|
|
|
mainp.Visibility = Visibility.Hidden;
|
|
//// This can also be called before EndInit
|
|
//this.control.SourceProvider.MediaPlayer.Log += (_, args) =>
|
|
//{
|
|
// string message = $"libVlc : {args.Level} {args.Message} @ {args.Module}";
|
|
// System.Diagnostics.Debug.WriteLine(message);
|
|
//};
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void StopVideo()
|
|
{
|
|
myControl.SourceProvider.MediaPlayer.Stop();
|
|
//myControl.Visibility = Visibility.Hidden;
|
|
//this.control?.Dispose();
|
|
//this.control = null;
|
|
}
|
|
|
|
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, 220, 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, 120, 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 - 1;
|
|
if (!string.IsNullOrEmpty(ucList[curIndex].Item3.shopName))
|
|
{
|
|
log.WriteLogFile(Convert.ToDouble(ucList[curIndex].Item3.angle).ToString(), "socket");
|
|
RichAD richAD = new RichAD(2180, 690, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), ucList[curIndex].Item3.shopCode);
|
|
DoubleAnimation heightAnimation = new DoubleAnimation(0, 690, new Duration(TimeSpan.FromSeconds(1)));
|
|
richAD.BeginAnimation(Border.HeightProperty, heightAnimation, HandoffBehavior.Compose);
|
|
this.stackPanelAD.Children.Insert(0, richAD);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.Message, "richerror");
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
}
|
|
else if (type == "syndata")
|
|
{
|
|
this.Dispatcher.Invoke(new Action(() =>
|
|
{
|
|
GetUControl();
|
|
}));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.Message, "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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 接口服务器发送的消息
|
|
/// </summary>
|
|
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(2180, 690, ucList[curIndex].Item3.logoPath, ucList[curIndex].Item3.shopName, ucList[curIndex].Item3.floorName, Convert.ToDouble(ucList[curIndex].Item3.angle), ucList[curIndex].Item3.shopCode);
|
|
DoubleAnimation heightAnimation = new DoubleAnimation(0, 690, 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(), "socket");
|
|
log.WriteLogFile(ex.Message, "socket");
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile("-------" + ex.Message, "socket");
|
|
}
|
|
}
|
|
|
|
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
|