2025-03-28 09:49:56 +08:00

230 lines
9.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// 状态反馈主定时器
/// </summary>
readonly DispatcherTimer WorkerTimer;
/// <summary>
/// 数据传输接口地址
/// </summary>
string WebServiceUrl { get; set; }
/// <summary>
/// 主支付通道接口地址
/// </summary>
string PayServiceUrl { get; set; }
public MainWindow()
{
InitializeComponent();
WorkerTimer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(60)
};
WorkerTimer.Tick += WorkerTimer_Tick;
WorkerTimer.Start();
}
/// <summary>
/// 主程序启动加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
#region
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();
#endregion
}
/// <summary>
/// 主定时器运行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
}
}