using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
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 ESSupport.Lib;
using ESSupport.Pos;
namespace ConnectPoint
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
///
/// 状态反馈主定时器
///
readonly DispatcherTimer WorkerTimer;
///
/// 数据传输接口地址
///
string WebServiceUrl { get; set; }
///
/// 主支付通道接口地址
///
string PayServiceUrl { get; set; }
public MainWindow()
{
InitializeComponent();
WorkerTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(60)
};
WorkerTimer.Tick += WorkerTimer_Tick;
WorkerTimer.Start();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
new Thread(() =>
{
int _FileCount = 0;
try { FileHelper.DeleteFiles(AppDomain.CurrentDomain.BaseDirectory, new string[] { ".log" }, false, false, 10, ref _FileCount); } catch { }
try { FileHelper.DeleteFiles(AppDomain.CurrentDomain.BaseDirectory + "\\log", new string[] { ".log" }, false, false, 10, ref _FileCount); } catch { }
try { FileHelper.DeleteFiles(AppDomain.CurrentDomain.BaseDirectory + "\\selldata", new string[] { ".log" }, false, false, 60, ref _FileCount); } catch { }
try { DataBaseUpdate.ClearDataBackup(AppDomain.CurrentDomain.BaseDirectory + "\\DataBackup", 60, true); } catch { }
try
{
if (string.IsNullOrWhiteSpace(ConfigHelper.GetAppConfig(AppDomain.CurrentDomain.BaseDirectory + "\\update.xml", "Port")))
{
ConfigHelper.UpdateAppConfig(AppDomain.CurrentDomain.BaseDirectory + "\\update.xml", "Port", "11000");
}
}
catch { }
})
{ IsBackground = true }.Start();
}
private void WorkerTimer_Tick(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(WebServiceUrl))
{
string _ServiceUrl = $"http://{PosConfigInit.ConfigurationValues("server_ip", string.Empty)}:" +
$"{PosConfigInit.ConfigurationValues("DataServicePort", "7080")}/DataServices/Service.asmx";
if (HttpHelper.UrlIsExist(_ServiceUrl))
{
WebServiceUrl = _ServiceUrl;
}
else
{
WebServiceUrl = $"http://{PosConfigInit.ConfigurationValues("server_ip", string.Empty)}:" +
$"{PosConfigInit.ConfigurationValues("service_port", "7080")}/Service.asmx";
}
}
//初始化移动支付交易检测接口地址
if (string.IsNullOrWhiteSpace(PayServiceUrl))
{
PayServiceUrl = $"http://{PosConfigInit.ConfigurationValues("server_ip", string.Empty)}:" +
$"{PosConfigInit.ConfigurationValues("service_port", "7080")}/Service.asmx";
}
if (Common.PosControl.DataCollectionTime == DateTime.MinValue)
{
Common.PosControl.DataCollectionTime = DateTime.Now.AddMilliseconds(-Environment.TickCount);
}
//收银机指令执行线程
if (Common.PosControl.CommodityMachineThread == null ||
!Common.PosControl.CommodityMachineThread.IsAlive)
{
Common.PosControl.CommodityMachineThread = new Thread(() =>
{
ThreadHelper.CommodityMachine(WebServiceUrl);
ThreadHelper.InstructionExecute(WebServiceUrl);
ThreadHelper.License();
})
{
IsBackground = true
};
Common.PosControl.CommodityMachineThread.Start();
}
//启动运行日志记录线程
if (Common.PosControl.RuningLogThread == null ||
!Common.PosControl.RuningLogThread.IsAlive)
{
Common.PosControl.RuningLogThread = new Thread(() =>
{
if (ThreadHelper.RuningLog(Common.PosControl.RuningTime))
{
Common.PosControl.RuningTime = DateTime.Now;
}
})
{
IsBackground = true
};
Common.PosControl.RuningLogThread.Start();
}
//定时启动实时交易统计线程
if (!Common.PosControl.DataCollectionRun &&
(DateTime.Now - Common.PosControl.DataCollectionTime).Minutes % 10 == 0)
{
if (Common.PosControl.DataCollectionThread == null ||
!Common.PosControl.DataCollectionThread.IsAlive)
{
Common.PosControl.DataCollectionThread = new Thread(() =>
{
Common.PosControl.DataCollectionRun = true;
ThreadHelper.DataCollectionUpload(WebServiceUrl);
ThreadHelper.NewSystemConfig();
})
{
IsBackground = true
};
Common.PosControl.DataCollectionThread.Start();
//Common.PosControl.DataCollectionTime = DateTime.Now.AddMinutes(10);
}
}
if (Common.PosControl.DataCollectionRun &&
(DateTime.Now - Common.PosControl.DataCollectionTime).Minutes % 10 != 0)
{
Common.PosControl.DataCollectionRun = false;
}
//定时启动移动支付校验、配置下发线程
if (DateTime.Now > Common.PosControl.MobilePayCheckTime)
{
if (Common.PosControl.MobilePayCheckThread == null ||
!Common.PosControl.MobilePayCheckThread.IsAlive)
{
Common.PosControl.MobilePayCheckThread = new Thread(() =>
{
ThreadHelper.MobilePayCheck(PayServiceUrl, DateTime.Today.AddDays(-3));
ThreadHelper.MobilePayConfigUpdate(PosConfigInit.ConfigurationValues("server_ip", string.Empty));
})
{
IsBackground = true
};
Common.PosControl.MobilePayCheckThread.Start();
Common.PosControl.MobilePayCheckTime = DateTime.Now.AddMinutes(10);
}
}
//定时启动状态反馈线程
if (DateTime.Now > Common.PosControl.StateFeedBackTime)
{
if (Common.PosControl.StateFeedbackThread == null ||
!Common.PosControl.StateFeedbackThread.IsAlive)
{
Common.PosControl.StateFeedbackThread = new Thread(() =>
{
ThreadHelper.StateFeedbackUpload(WebServiceUrl);
})
{
IsBackground = true
};
Common.PosControl.StateFeedbackThread.Start();
Common.PosControl.StateFeedBackTime = DateTime.Now.AddMinutes(5);
}
}
//启动基础数据版本上报线程
if (DateTime.Now > Common.PosControl.BaseInfoFeedbackTime)
{
if (Common.PosControl.BaseInfoFeedbackThread == null ||
!Common.PosControl.BaseInfoFeedbackThread.IsAlive)
{
Common.PosControl.BaseInfoFeedbackThread = new Thread(() =>
{
ThreadHelper.BaseInfoFeedbackUpload(WebServiceUrl);
})
{
IsBackground = true
};
Common.PosControl.BaseInfoFeedbackThread.Start();
Common.PosControl.BaseInfoFeedbackTime = DateTime.Now.AddMinutes(30);
}
}
}
}
}