1051 lines
48 KiB
C#
1051 lines
48 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
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.Xml;
|
|
using Lib = ESSupport.Lib;
|
|
using System.Timers;
|
|
using System.Collections;
|
|
using CL.IO.Zip;
|
|
|
|
namespace RunUpdater
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
#region 参数属性
|
|
/// <summary>
|
|
/// 更新服务地址
|
|
/// </summary>
|
|
string UpdateUri { get; set; }
|
|
|
|
/// <summary>
|
|
/// 更新服务端口
|
|
/// </summary>
|
|
string UpdatePort { get; set; }
|
|
|
|
/// <summary>
|
|
/// 更新模式(省份、服务区、收银机)
|
|
/// </summary>
|
|
string UpdateMode { get; set; }
|
|
|
|
/// <summary>
|
|
/// 模式对应需要上传的值
|
|
/// </summary>
|
|
string UpdateValue { get; set; }
|
|
/// <summary>
|
|
/// 是否正在更新
|
|
/// </summary>
|
|
bool UpdateFlag { get; set; }
|
|
bool UpdateEnd { get; set; } = false;
|
|
bool WebSiteCheckEnd { get; set; } = false;
|
|
/// <summary>
|
|
/// 更新信息数据库地址
|
|
/// </summary>
|
|
string DataBaseIP { get; set; }
|
|
/// <summary>
|
|
/// 数据库端口
|
|
/// </summary>
|
|
string DataBasePort { get; set; }
|
|
/// <summary>
|
|
/// 数据库实例名
|
|
/// </summary>
|
|
string DataBaseInstance { get; set; }
|
|
/// <summary>
|
|
/// 数据库名称
|
|
/// </summary>
|
|
string DataBaseName { get; set; }
|
|
/// <summary>
|
|
/// 数据库登录用户名
|
|
/// </summary>
|
|
string DataBaseUserName { get; set; }
|
|
/// <summary>
|
|
/// 数据库登录密码
|
|
/// </summary>
|
|
string DataBasePassWord { get; set; }
|
|
/// <summary>
|
|
/// 本地更新服务站点端口
|
|
/// </summary>
|
|
string LocalSitePort { get; set; }
|
|
/// <summary>
|
|
/// 本地更新服务站点物理路径
|
|
/// </summary>
|
|
string SiteDir { get; set; }
|
|
/// <summary>
|
|
/// 更新文件下载路径
|
|
/// </summary>
|
|
string DownPath { get; set; }
|
|
/// <summary>
|
|
/// 已下载更新文件数
|
|
/// </summary>
|
|
int DownCount = 0;
|
|
/// <summary>
|
|
/// 总更新文件数
|
|
/// </summary>
|
|
int FilesCount = 0;
|
|
/// <summary>
|
|
/// 程序所在路径
|
|
/// </summary>
|
|
static string AppDir = AppDomain.CurrentDomain.BaseDirectory;
|
|
/// <summary>
|
|
/// 程序配置文件路径
|
|
/// </summary>
|
|
static string XMLPath = AppDir + "Update.config";
|
|
/// <summary>
|
|
/// 站点服务安装/升级包路径
|
|
/// </summary>
|
|
static string ServiceFilesDir = AppDir + "ServicePack";
|
|
DataTable UpdateListTable;
|
|
Timer _Timer = new Timer();
|
|
BackgroundWorker _UpdateWorker;
|
|
Lib.OracleHelper _OracleHelper;
|
|
#endregion
|
|
|
|
private enum Mode
|
|
{
|
|
Province,
|
|
ServerPart,
|
|
Shop,
|
|
Machine
|
|
}
|
|
|
|
private enum Service
|
|
{
|
|
ServiceInstall,
|
|
ServiceUpdate
|
|
}
|
|
private Mode IntConvertToEnumOther(int ModeKey)
|
|
{
|
|
return (Mode)ModeKey;
|
|
}
|
|
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
tbVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
UpdateFlag = false;
|
|
_UpdateWorker = new BackgroundWorker();
|
|
_UpdateWorker.DoWork += BackgroundWorker_DoWork;
|
|
_UpdateWorker.ProgressChanged += BackgroundWorker_ProgressChanged;
|
|
_UpdateWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
|
|
_UpdateWorker.WorkerReportsProgress = true;
|
|
_UpdateWorker.WorkerSupportsCancellation = true;
|
|
_Timer.Elapsed += Timer_Tick;
|
|
_Timer.Interval = 1000;
|
|
_Timer.Start();
|
|
}
|
|
|
|
private void Timer_Tick(object sender, EventArgs e)
|
|
{
|
|
if (!_UpdateWorker.IsBusy && !UpdateFlag)
|
|
{
|
|
UpdateFlag = true;
|
|
_UpdateWorker.RunWorkerAsync();
|
|
}
|
|
if (FilesCount != 0)
|
|
{
|
|
if (DownCount >= FilesCount && UpdateEnd && WebSiteCheckEnd)
|
|
{
|
|
FilesCount = 0;
|
|
DownCount = 0;
|
|
for (int i = 5; i > 0; i--)
|
|
{
|
|
MessageBeginInvoke("系统版本更新检查完成(" + i + ")", "lblMsg", "Label");
|
|
MessageBeginInvoke("100", "downProgress", "ProgressBar");
|
|
}
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|
|
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
{
|
|
|
|
}
|
|
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
MessageBeginInvoke("更新程序正在初始化......", "lblMsg", "Label");
|
|
InitializeAttribute();
|
|
WebSiteCheck(LocalSitePort);
|
|
int.TryParse(UpdateMode, out int _Mode);
|
|
switch (_Mode)
|
|
{
|
|
case 0:
|
|
UpdateValue = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdateValue");
|
|
break;
|
|
case 1:
|
|
UpdateValue = ServerPartList();
|
|
break;
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
break;
|
|
}
|
|
MessageBeginInvoke("正在获取收银系统版本更新信息......", "lblMsg", "Label");
|
|
string _ServiceUri = "http://" + UpdateUri + ":" + UpdatePort + "/Update.asmx";
|
|
object[] _object = { IntConvertToEnumOther(_Mode).ToString(), UpdateValue };
|
|
try
|
|
{
|
|
string _Result = Lib.WSHelper.InvokeWebService(_ServiceUri, "POSUpdate", _object).ToString();
|
|
DataTable _UpdateTable = Lib.JsonHelper.ToDataTable(_Result);
|
|
if (_UpdateTable.Rows.Count > 0)
|
|
{
|
|
UpdateListTable = _UpdateTable;
|
|
//"SOFTUPDATE_ID,PROVINCE_CODE,SERVERPART_CODE,SHOPCODE,MACADDRESS,SOFTUPDATE_DATE,SOFTUPDATE_VERSION"
|
|
DataTable _VersionTable = _UpdateTable.DefaultView.ToTable(true, new string[] { "SOFTUPDATE_VERSION" });
|
|
if (_VersionTable.Rows.Count > 0)
|
|
{
|
|
Dictionary<string, XmlDocument> _UpdateDictionary = new Dictionary<string, XmlDocument>();
|
|
foreach (DataRow _Row in _VersionTable.Rows)
|
|
{
|
|
MessageBeginInvoke("正在获取[" + _Row["SOFTUPDATE_VERSION"].ToString() + "]版本更新文件列表......", "lblMsg", "Label");
|
|
try
|
|
{
|
|
_object = new object[] { "DownLoad", _Row["SOFTUPDATE_VERSION"].ToString() };
|
|
_Result = Lib.WSHelper.InvokeWebService(_ServiceUri, "POSUpdate", _object).ToString();
|
|
XmlDocument _XmlDoc = new XmlDocument();
|
|
_XmlDoc.LoadXml(_Result);
|
|
_UpdateDictionary.Add(_Row["SOFTUPDATE_VERSION"].ToString(), _XmlDoc);
|
|
}
|
|
catch { }
|
|
}
|
|
for (int i = 0; i < _UpdateDictionary.Count; i++)
|
|
{
|
|
FilesCount += _UpdateDictionary[_UpdateDictionary.Keys.ElementAt(i)].SelectNodes("//UpdateFileList//UpdateFile").Count;
|
|
}
|
|
CreateFilesDown(_UpdateDictionary);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
EndUpdate("收银系统版本更新失败," + ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建多版本更新文件下载
|
|
/// </summary>
|
|
/// <param name="UpdateDictionary">版本列表</param>
|
|
private void CreateFilesDown(Dictionary<string, XmlDocument> UpdateDictionary)
|
|
{
|
|
if (UpdateDictionary.Count > 0)
|
|
{
|
|
for (int i = 0; i < UpdateDictionary.Count; i++)
|
|
{
|
|
StartDownLoad(UpdateDictionary[UpdateDictionary.Keys.ElementAt(i)], UpdateDictionary.Keys.ElementAt(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取服务区列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string ServerPartList()
|
|
{
|
|
string _Result = "";
|
|
string _Select = "SELECT SERVERPARTCODE FROM " + DataBaseName + ".T_SYSCODE";
|
|
try
|
|
{
|
|
using (DataTable _Table = _OracleHelper.ExcuteSqlGetDataSet(_Select).Tables[0])
|
|
{
|
|
if (_Table.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow _Row in _Table.Rows)
|
|
{
|
|
_Result += (_Result == "" ? "" : ",") + _Row["SERVERPARTCODE"].ToString();
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdateValue", _Result);
|
|
}
|
|
else
|
|
{
|
|
_Result = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdateValue");
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
_Result = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdateValue");
|
|
}
|
|
return _Result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化属性
|
|
/// </summary>
|
|
private void InitializeAttribute()
|
|
{
|
|
UpdateUri = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdateIP");
|
|
UpdatePort = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdatePort");
|
|
UpdateMode = Lib.ConfigHelper.GetAppConfig(XMLPath, "UpdateMode");
|
|
DataBaseIP = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBaseIP");
|
|
DataBasePort = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBasePort");
|
|
DataBaseInstance = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBaseInstance");
|
|
DataBaseName = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBaseName");
|
|
DataBaseUserName = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBaseUserName");
|
|
DataBasePassWord = Lib.ConfigHelper.GetAppConfig(XMLPath, "DataBasePassWord");
|
|
LocalSitePort = Lib.ConfigHelper.GetAppConfig(XMLPath, "LocalSitePort");
|
|
if (String.IsNullOrWhiteSpace(LocalSitePort))
|
|
{
|
|
LocalSitePort = "11000";
|
|
}
|
|
Hashtable _Hashtable = Lib.IISWorker.GetWebPathAndWebName(LocalSitePort);
|
|
if (_Hashtable.ContainsKey("path"))
|
|
{
|
|
SiteDir = _Hashtable["path"].ToString() + "\\";
|
|
}
|
|
else
|
|
{
|
|
SiteDir = AppDir;
|
|
}
|
|
//Lib.FileHelper.AddpathPower(SiteDir, "Everyone", Lib.FileHelper.FilePower.FullControl.ToString());
|
|
Lib.FileHelper.AddSecurityControll2Folder(SiteDir);
|
|
DownPath = SiteDir + "UpdateServer";
|
|
if (String.IsNullOrWhiteSpace(UpdateUri) || String.IsNullOrWhiteSpace(UpdatePort) ||
|
|
String.IsNullOrWhiteSpace(UpdateMode) || String.IsNullOrWhiteSpace(LocalSitePort))
|
|
{
|
|
InitializeConfigFile();
|
|
}
|
|
//if (UpdateUri != "cloud.eshangtech.com")
|
|
//{
|
|
// UpdateUri = "cloud.eshangtech.com";
|
|
// UpdatePort = "11000";
|
|
// try
|
|
// {
|
|
// Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdateIP", UpdateUri);
|
|
// Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdatePort", UpdatePort);
|
|
// }
|
|
// catch { }
|
|
//}
|
|
_OracleHelper = new Lib.OracleHelper(DataBaseIP, DataBasePort, DataBaseInstance, DataBaseUserName, DataBasePassWord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 程序配置文件初始化
|
|
/// </summary>
|
|
private void InitializeConfigFile()
|
|
{
|
|
try
|
|
{
|
|
if (String.IsNullOrWhiteSpace(DataBaseIP))
|
|
{
|
|
DataBaseIP = "localhost";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBaseIP", DataBaseIP);
|
|
if (String.IsNullOrWhiteSpace(DataBasePort))
|
|
{
|
|
DataBasePort = "1521";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBasePort", DataBasePort);
|
|
if (String.IsNullOrWhiteSpace(DataBaseUserName))
|
|
{
|
|
DataBaseUserName = "highway_exchange";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBaseUserName", DataBaseUserName);
|
|
if (String.IsNullOrWhiteSpace(DataBasePassWord))
|
|
{
|
|
DataBasePassWord = "qrwl";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBasePassWord", DataBasePassWord);
|
|
if (String.IsNullOrWhiteSpace(DataBaseInstance))
|
|
{
|
|
DataBaseInstance = "orcl";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBaseInstance", DataBaseInstance);
|
|
if (String.IsNullOrWhiteSpace(DataBaseName))
|
|
{
|
|
DataBaseName = "highway_exchange";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "DataBaseName", DataBaseName);
|
|
if (String.IsNullOrWhiteSpace(LocalSitePort))
|
|
{
|
|
LocalSitePort = "11000";
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "LocalSitePort", LocalSitePort);
|
|
|
|
if (String.IsNullOrWhiteSpace(UpdatePort))
|
|
{
|
|
string _UpdatePort = Lib.ConfigHelper.GetAppConfig(System.IO.Path.Combine(DownPath, "update.xml"), "Port");
|
|
if (String.IsNullOrWhiteSpace(_UpdatePort))
|
|
{
|
|
UpdatePort = "11000";
|
|
}
|
|
else
|
|
{
|
|
UpdatePort = _UpdatePort;
|
|
}
|
|
}
|
|
if (String.IsNullOrWhiteSpace(UpdateUri))
|
|
{
|
|
string _UpdateUrl = Lib.ConfigHelper.GetAppConfig(System.IO.Path.Combine(DownPath, "update.xml"), "IP");
|
|
if (!Lib.HttpHelper.UrlIsExist("http://" + _UpdateUrl + ":" + UpdatePort + "/Update.asmx"))
|
|
{
|
|
UpdateUri = "cloud.eshangtech.com";
|
|
}
|
|
else
|
|
{
|
|
UpdateUri = _UpdateUrl;
|
|
}
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdateIP", UpdateUri);
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdatePort", UpdatePort);
|
|
|
|
if (String.IsNullOrWhiteSpace(UpdateMode))
|
|
{
|
|
if (File.Exists(System.IO.Path.Combine(DownPath, "ProvinceUpdateExe.exe")))
|
|
{
|
|
UpdateMode = "0";
|
|
}
|
|
else
|
|
{
|
|
UpdateMode = "1";
|
|
}
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdateMode", UpdateMode);
|
|
if (String.IsNullOrWhiteSpace(UpdateValue))
|
|
{
|
|
string _UpdateValue = Lib.ConfigHelper.GetAppConfig(System.IO.Path.Combine(DownPath, "update.xml"), "Province");
|
|
if (String.IsNullOrWhiteSpace(_UpdateValue))
|
|
{
|
|
UpdateValue = "330000";
|
|
}
|
|
else
|
|
{
|
|
UpdateValue = _UpdateValue;
|
|
}
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpdateValue", UpdateValue);
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "UpDate")))
|
|
|
|
{
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "UpDate", "2018/03/09 20:33:00");
|
|
}
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "SoftVersion")))
|
|
{
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "SoftVersion", "");
|
|
}
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "SoftName")))
|
|
{
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "SoftName", "驿商统一收银系统");
|
|
}
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "KillApp")))
|
|
{
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "KillApp", "");
|
|
}
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "StartApp")))
|
|
{
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "StartApp", "");
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 本地自动更新站点检测
|
|
/// </summary>
|
|
/// <param name="SitePort"></param>
|
|
private void WebSiteCheck(string SitePort)
|
|
{
|
|
string _LocalWebUri = "http://localhost:" + SitePort + "/Update.asmx";
|
|
MessageBeginInvoke("正在检查更新服务站点......", "lblMsg", "Label");
|
|
Hashtable _Hashtable = Lib.IISWorker.GetWebPathAndWebName(SitePort);
|
|
if (_Hashtable.ContainsKey("name"))
|
|
{
|
|
SiteDir = _Hashtable["path"].ToString() + "\\";
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("正在创建更新服务站点......", "lblMsg", "Label");
|
|
if (!int.TryParse(SitePort, out int SiteID))
|
|
{
|
|
SiteID = Lib.IISWorker.SiteId();
|
|
}
|
|
SiteDir = AppDir;
|
|
Lib.IISWorker.CreateAppPool7("DefaultAppPool", 1, 1000, "0");
|
|
Lib.IISWorker.CreateSite("[" + SitePort + "]自动更新", SiteID, SitePort,
|
|
"", "Default.aspx,Index.Html,index.asp", AppDir, "DefaultAppPool");
|
|
}
|
|
if (String.IsNullOrWhiteSpace(Lib.ConfigHelper.GetAppConfig(XMLPath, "ServiceVersion")))
|
|
{
|
|
WebSiteInstall(SiteDir);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
HttpWebRequest _HttpWebRequest = (HttpWebRequest)WebRequest.Create(_LocalWebUri);
|
|
// 有些网站会阻止程序访问,需要加入下面这句
|
|
_HttpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
|
_HttpWebRequest.Method = "GET";
|
|
// Sends the HttpWebRequest and waits for a response.
|
|
HttpWebResponse _HttpWebResponse = (HttpWebResponse)_HttpWebRequest.GetResponse();
|
|
if (_HttpWebResponse.StatusCode == HttpStatusCode.OK)
|
|
{
|
|
WebSiteUpdate(SiteDir, Lib.ConfigHelper.GetAppConfig(XMLPath, "ServiceVersion"));
|
|
}
|
|
else
|
|
{
|
|
if (File.Exists(SiteDir + "Update.asmx"))
|
|
{
|
|
WebSiteUpdate(SiteDir, Lib.ConfigHelper.GetAppConfig(XMLPath, "ServiceVersion"));
|
|
}
|
|
else
|
|
{
|
|
WebSiteInstall(SiteDir);
|
|
}
|
|
}
|
|
_HttpWebResponse.Close();
|
|
}
|
|
catch
|
|
{
|
|
WebSiteInstall(SiteDir);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装更新服务
|
|
/// </summary>
|
|
/// <param name="InstallDir">更新服务安装路径</param>
|
|
private void WebSiteInstall(string InstallDir)
|
|
{
|
|
string _FileUri = "http://" + UpdateUri + ":" + UpdatePort + "/ServicePack/ServiceInstall.zip";
|
|
string _SaveFileName = ServiceFilesDir + "\\ServiceInstall.zip";
|
|
string _ServiceUri = "http://" + UpdateUri + ":" + UpdatePort + "/Update.asmx";
|
|
if (!Directory.Exists(ServiceFilesDir))
|
|
{
|
|
Directory.CreateDirectory(ServiceFilesDir);
|
|
}
|
|
if (File.Exists(_SaveFileName))
|
|
{
|
|
string _InstallFileMd5 = Lib.FileHelper.GetMD5ByMD5CryptoService(_SaveFileName);
|
|
object[] _object = { Service.ServiceInstall.ToString(), _InstallFileMd5 };
|
|
try
|
|
{
|
|
string _Result = Lib.WSHelper.InvokeWebService(_ServiceUri, "ServiceUpdate", _object).ToString();
|
|
if (!String.IsNullOrWhiteSpace(_Result))
|
|
{
|
|
Dictionary<string, string> _Dictionary = Lib.JsonHelper.JsonDeserializeBySingleData<Dictionary<string, string>>(_Result);
|
|
if (_Dictionary.ContainsKey("Md5"))
|
|
{
|
|
if (_Dictionary["Md5"] == _InstallFileMd5)
|
|
{
|
|
UnpackService(_SaveFileName, InstallDir, false);
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
else
|
|
{
|
|
WebClient _ServiceWebClient = new WebClient();
|
|
_ServiceWebClient.DownloadProgressChanged += delegate (object _sender, DownloadProgressChangedEventArgs Event)
|
|
{
|
|
//显示下载进度
|
|
MessageBeginInvoke("正在下载更新服务安装包......(" + Lib.FileHelper.ConvertSize(Event.BytesReceived) +
|
|
"/" + Lib.FileHelper.ConvertSize(Event.TotalBytesToReceive) + ")", "lblMsg", "Label");
|
|
MessageBeginInvoke(Event.ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
};
|
|
_ServiceWebClient.DownloadFileCompleted += delegate (object _sender, AsyncCompletedEventArgs Event)
|
|
{
|
|
if (Event.Error != null)
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载完成", "lblMsg", "Label");
|
|
MessageBeginInvoke("正在校验安装包完整性......", "lblMsg", "Label");
|
|
if (Lib.FileHelper.GetMD5ByMD5CryptoService(_SaveFileName) == _Dictionary["Md5"])
|
|
{
|
|
UnpackService(_SaveFileName, InstallDir, false);
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
WebSiteCheckEnd = true;
|
|
};
|
|
//创建文件下载线程
|
|
_ServiceWebClient.DownloadFileAsync(new Uri(_FileUri), _SaveFileName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
MessageBeginInvoke("更新服务安装失败,原因:" + ex.Message, "lblMsg", "Label");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WebClient _ServiceWebClient = new WebClient();
|
|
_ServiceWebClient.DownloadProgressChanged += delegate (object _sender, DownloadProgressChangedEventArgs Event)
|
|
{
|
|
//显示下载进度
|
|
MessageBeginInvoke("正在下载更新服务安装包......(" + Lib.FileHelper.ConvertSize(Event.BytesReceived) +
|
|
"/" + Lib.FileHelper.ConvertSize(Event.TotalBytesToReceive) + ")", "lblMsg", "Label");
|
|
MessageBeginInvoke(Event.ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
};
|
|
_ServiceWebClient.DownloadFileCompleted += delegate (object _sender, AsyncCompletedEventArgs Event)
|
|
{
|
|
if (Event.Error != null)
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载完成", "lblMsg", "Label");
|
|
MessageBeginInvoke("正在校验更新文件完整性......", "lblMsg", "Label");
|
|
string _InstallFileMd5 = Lib.FileHelper.GetMD5ByMD5CryptoService(_SaveFileName);
|
|
object[] _object = { Service.ServiceInstall.ToString(), _InstallFileMd5 };
|
|
try
|
|
{
|
|
string _Result = Lib.WSHelper.InvokeWebService(_ServiceUri, "ServiceUpdate", _object).ToString();
|
|
if (!String.IsNullOrWhiteSpace(_Result))
|
|
{
|
|
Dictionary<string, string> _Dictionary = Lib.JsonHelper.JsonDeserializeBySingleData<Dictionary<string, string>>(_Result);
|
|
if (_Dictionary.ContainsKey("Md5"))
|
|
{
|
|
if (_Dictionary["Md5"] == _InstallFileMd5)
|
|
{
|
|
UnpackService(_SaveFileName, InstallDir, false);
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
MessageBeginInvoke("更新服务安装包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
WebSiteCheckEnd = true;
|
|
};
|
|
//创建文件下载线程
|
|
_ServiceWebClient.DownloadFileAsync(new Uri(_FileUri), _SaveFileName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新服务升级检查
|
|
/// </summary>
|
|
/// <param name="ServiceVersion">本地版本号</param>
|
|
private void WebSiteUpdate(string UpdateDir, string ServiceVersion)
|
|
{
|
|
//服务升级包下载地址
|
|
string _FileUri = "http://" + UpdateUri + ":" + UpdatePort + "/ServicePack/ServiceUpdate.zip";
|
|
//服务升级包保存地址
|
|
string _SaveFileName = ServiceFilesDir + "\\ServiceUpdate.zip";
|
|
//服务升级检查WebService接口地址
|
|
string _ServiceUri = "http://" + UpdateUri + ":" + UpdatePort + "/Update.asmx";
|
|
object[] _object = { Service.ServiceUpdate.ToString(), ServiceVersion };
|
|
try
|
|
{
|
|
string _Result = Lib.WSHelper.InvokeWebService(_ServiceUri, "ServiceUpdate", _object).ToString();
|
|
if (!String.IsNullOrWhiteSpace(_Result))
|
|
{
|
|
Dictionary<string, string> _Dictionary = Lib.JsonHelper.JsonDeserializeBySingleData<Dictionary<string, string>>(_Result);
|
|
if (_Dictionary.ContainsKey("Version"))
|
|
{
|
|
if (String.Compare(_Dictionary["Version"], ServiceVersion) > 0)
|
|
{
|
|
WebClient _ServiceWebClient = new WebClient();
|
|
_ServiceWebClient.DownloadProgressChanged += delegate (object _sender, DownloadProgressChangedEventArgs Event)
|
|
{
|
|
//显示下载进度
|
|
MessageBeginInvoke("正在下载更新服务升级包......(" + Lib.FileHelper.ConvertSize(Event.BytesReceived) +
|
|
"/" + Lib.FileHelper.ConvertSize(Event.TotalBytesToReceive) + ")", "lblMsg", "Label");
|
|
MessageBeginInvoke(Event.ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
};
|
|
_ServiceWebClient.DownloadFileCompleted += delegate (object _sender, AsyncCompletedEventArgs Event)
|
|
{
|
|
if (Event.Error != null)
|
|
{
|
|
MessageBeginInvoke("更新服务升级包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务升级包下载完成", "lblMsg", "Label");
|
|
MessageBeginInvoke("正在校验更新服务升级文件完整性......", "lblMsg", "Label");
|
|
if (Lib.FileHelper.GetMD5ByMD5CryptoService(_SaveFileName) == _Dictionary["Md5"])
|
|
{
|
|
UnpackService(_SaveFileName, UpdateDir, true);
|
|
}
|
|
else
|
|
{
|
|
MessageBeginInvoke("更新服务升级包下载失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
WebSiteCheckEnd = true;
|
|
};
|
|
//创建文件下载线程
|
|
_ServiceWebClient.DownloadFileAsync(new Uri(_FileUri), _SaveFileName);
|
|
}
|
|
else
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
WebSiteCheckEnd = true;
|
|
MessageBeginInvoke("更新服务升级失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 解压安装/升级包
|
|
/// </summary>
|
|
/// <param name="ZipPath"></param>
|
|
/// <param name="unzipPath"></param>
|
|
/// <param name="IsUpdate"></param>
|
|
private void UnpackService(string ZipPath, string unzipPath, bool IsUpdate)
|
|
{
|
|
try
|
|
{
|
|
ZipHandler _ZipHandler = ZipHandler.GetInstance();
|
|
//获取压缩包密码
|
|
MessageBeginInvoke("正在解密自动更新服务" + (IsUpdate ? "升级" : "安装") + "包......", "lblMsg", "Label");
|
|
MessageBeginInvoke("100", "downProgress", "ProgressBar");
|
|
string _Password = _ZipHandler.GetZipExtensionFileName(ZipPath, ".pw");
|
|
if (String.IsNullOrWhiteSpace(_Password))
|
|
{
|
|
_ZipHandler.UnpackAll(ZipPath, unzipPath, (ProgressPercentage) =>
|
|
{
|
|
MessageBeginInvoke("正在" + (IsUpdate ? "升级" : "安装") + "自动更新服务......" + ProgressPercentage.ToString("F0") + "%", "lblMsg", "Label");
|
|
MessageBeginInvoke(ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
});
|
|
}
|
|
else
|
|
{
|
|
_ZipHandler.UnpackAll(ZipPath, unzipPath, _Password, (ProgressPercentage) =>
|
|
{
|
|
MessageBeginInvoke("正在" + (IsUpdate ? "升级" : "安装") + "自动更新服务......" + ProgressPercentage.ToString("F0") + "%", "lblMsg", "Label");
|
|
MessageBeginInvoke(ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
});
|
|
}
|
|
Lib.ConfigHelper.UpdateAppConfig(XMLPath, "ServiceVersion", _Password);
|
|
}
|
|
catch
|
|
{
|
|
MessageBeginInvoke("更新服务" + (IsUpdate ? "升级" : "安装") + "失败,程序将在下次启动时重试。", "lblMsg", "Label");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 程序更新文件校验
|
|
/// </summary>
|
|
/// <param name="FileList">文件列表</param>
|
|
/// <param name="APPVersion">主程序版本号</param>
|
|
/// <param name="UpdateDate">程序更新时间</param>
|
|
/// <returns>返回更新结果</returns>
|
|
private bool StartCheckUpdate(Dictionary<string, string> FileList, string APPVersion)
|
|
{
|
|
string[] _Files = Directory.GetFiles(DownPath + "\\" + APPVersion + "\\UpdateFiles");
|
|
for (int i = 0; i < FileList.Count; i++)
|
|
{
|
|
decimal _Progress = (decimal)(i + 1) / FileList.Count * 100;
|
|
MessageBeginInvoke("正在校验更新文件完整性......(" + _Progress.ToString("F0") + "%)", "lblMsg", "Label");
|
|
MessageBeginInvoke(_Progress.ToString("F2"), "downProgress", "ProgressBar");
|
|
string _FileMd5 = Lib.FileHelper.GetMD5ByMD5CryptoService(DownPath + "\\" + APPVersion + "\\UpdateFiles" + FileList.Keys.ElementAt(i));
|
|
if (_FileMd5 != FileList[FileList.Keys.ElementAt(i)])
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#region 创建并开始更新文件线程
|
|
/// <summary>
|
|
/// 下载更新文件
|
|
/// </summary>
|
|
/// <param name="XMLDoc">更新文件列表</param>
|
|
/// <param name="APPVersion">程序版本</param>
|
|
private void StartDownLoad(XmlDocument XMLDoc, string APPVersion)
|
|
{
|
|
bool _FinishFlag = true;
|
|
int _DownCount = 0;
|
|
Dictionary<string, string> _FileList = new Dictionary<string, string>();
|
|
XmlNodeList xmlNodeList = XMLDoc.SelectNodes("//UpdateFileList//UpdateFile");
|
|
for (int i = 0; i < xmlNodeList.Count; i++)
|
|
{
|
|
_FileList.Add(xmlNodeList[i].InnerXml, xmlNodeList[i].Attributes["Md5"].Value);
|
|
}
|
|
int _DownEndCount = 0;
|
|
if (!String.IsNullOrEmpty(APPVersion))
|
|
{
|
|
//创建版本目录
|
|
if (!Directory.Exists(DownPath + "\\" + APPVersion + "\\UpdateFiles"))
|
|
{
|
|
Directory.CreateDirectory(DownPath + "\\" + APPVersion + "\\UpdateFiles");
|
|
}
|
|
//else
|
|
//{
|
|
// //清空已下载同版本文件
|
|
// Lib.FileHelper.DeleteDir(DownPath + "\\" + Version + "\\UpdateFiles");
|
|
//}
|
|
}
|
|
//创建更新文件下载进程
|
|
for (int i = 0; i < _FileList.Count; i++)
|
|
{
|
|
decimal _Progress = (decimal)(i + 1) / _FileList.Count * 100;
|
|
MessageBeginInvoke("正在创建[" + APPVersion + "]更新文件下载任务......(" + _Progress.ToString("F0") + "%)", "lblMsg", "Label");
|
|
MessageBeginInvoke(_Progress.ToString("F2"), "downProgress", "ProgressBar");
|
|
bool _FileFlag = false;
|
|
string _FileName = _FileList.Keys.ElementAt(i);
|
|
//文件Uri路径
|
|
string _FileUri = "http://" + UpdateUri + ":" + UpdatePort + "/UpdateServer" +
|
|
(XMLDoc.SelectNodes("//UpdateInfo//Version") == null ? "" : "/" + APPVersion) +
|
|
"/UpdateFiles" + _FileName.Replace('\\', '/');
|
|
//文件保存位置
|
|
string _SaveFileName = DownPath + (APPVersion == null ? "" : "\\" + APPVersion) + "\\UpdateFiles" + _FileName;
|
|
if (File.Exists(_SaveFileName))
|
|
{
|
|
string _FileMd5 = Lib.FileHelper.GetMD5ByMD5CryptoService(_SaveFileName);
|
|
if (_FileMd5 == _FileList[_FileName])
|
|
{
|
|
_DownEndCount += 1;
|
|
DownCount += 1;
|
|
_FileFlag = true;
|
|
}
|
|
}
|
|
if (!_FileFlag)
|
|
{
|
|
WebClient webClient = new WebClient();
|
|
webClient.DownloadProgressChanged += delegate (object _sender, DownloadProgressChangedEventArgs Event)
|
|
{
|
|
//显示下载进度
|
|
MessageBeginInvoke("正在下载更新:" + _FileName.Substring(_FileName.LastIndexOf("\\") + 1,
|
|
_FileName.LastIndexOf(".rar") - 1).Replace("_", "__") + "(" + Lib.FileHelper.ConvertSize(Event.BytesReceived) +
|
|
"/" + Lib.FileHelper.ConvertSize(Event.TotalBytesToReceive) + ")", "lblMsg", "Label");
|
|
MessageBeginInvoke(Event.ProgressPercentage.ToString(), "downProgress", "ProgressBar");
|
|
};
|
|
webClient.DownloadFileCompleted += delegate (object _sender, AsyncCompletedEventArgs Event)
|
|
{
|
|
if (Event.Error != null)
|
|
{
|
|
_FinishFlag = false;
|
|
}
|
|
_DownEndCount += 1;
|
|
DownCount += 1;
|
|
if (_DownEndCount >= xmlNodeList.Count)
|
|
{
|
|
MessageBeginInvoke("更新文件下载完成", "lblMsg", "Label");
|
|
MessageBeginInvoke("正在校验更新文件完整性......", "lblMsg", "Label");
|
|
if (StartCheckUpdate(_FileList, APPVersion))
|
|
{
|
|
//保存更新列表文件
|
|
XMLDoc.Save(DownPath + (APPVersion == null ? "" : "\\" + APPVersion) + "\\UpdateList-" + APPVersion + ".xml");
|
|
SaveUpdate(APPVersion);
|
|
}
|
|
if (DownCount == FilesCount)
|
|
{
|
|
UpdateEnd = true;
|
|
}
|
|
}
|
|
};
|
|
//创建文件下载线程
|
|
webClient.DownloadFileAsync(new Uri(_FileUri), _SaveFileName);
|
|
}
|
|
System.Threading.Thread.Sleep(100);
|
|
}
|
|
if (_DownEndCount >= xmlNodeList.Count)
|
|
{
|
|
MessageBeginInvoke("更新文件下载完成", "lblMsg", "Label");
|
|
MessageBeginInvoke("正在校验更新文件完整性......", "lblMsg", "Label");
|
|
if (StartCheckUpdate(_FileList, APPVersion))
|
|
{
|
|
//保存更新列表文件
|
|
XMLDoc.Save(DownPath + (APPVersion == null ? "" : "\\" + APPVersion) + "\\UpdateList-" + APPVersion + ".xml");
|
|
SaveUpdate(APPVersion);
|
|
DeleteScratchFile();
|
|
}
|
|
if (DownCount == FilesCount)
|
|
{
|
|
UpdateEnd = true;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 删除无效更新文件
|
|
/// </summary>
|
|
private void DeleteScratchFile()
|
|
{
|
|
DataTable _VersionTable = UpdateListTable.DefaultView.ToTable(true, new string[] { "SOFTUPDATE_VERSION" });
|
|
string[] _strDir = Directory.GetDirectories(DownPath);
|
|
for (int i = 0; i < _strDir.Count(); i++)
|
|
{
|
|
MessageBeginInvoke("正在清除过期更新文件......", "lblMsg", "Label");
|
|
MessageBeginInvoke(((decimal)(i + 1) / _strDir.Count() * 100).ToString("F0"), "downProgress", "ProgressBar");
|
|
if (Version.TryParse(_strDir[i].Substring(_strDir[i].LastIndexOf('\\') + 1), out Version _Version))
|
|
{
|
|
if (_VersionTable.Select("SOFTUPDATE_VERSION = '" + _strDir[i].Substring(_strDir[i].LastIndexOf('\\') + 1) + "'").Count() == 0)
|
|
{
|
|
Lib.FileHelper.DeleteDir(_strDir[i], false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存版本更新信息
|
|
/// </summary>
|
|
/// <param name="APPVersion">版本号</param>
|
|
/// <returns></returns>
|
|
private bool SaveUpdate(string APPVersion)
|
|
{
|
|
//"SOFTUPDATE_ID,PROVINCE_CODE,SERVERPART_CODE,SHOPCODE,MACADDRESS,SOFTUPDATE_DATE,SOFTUPDATE_VERSION"
|
|
DataRow[] _DataRow = UpdateListTable.Select(string.Format("SOFTUPDATE_VERSION = '{0}'", APPVersion));
|
|
bool _SaveFlag = true;
|
|
for (int i = 0; i < _DataRow.Count(); i++)
|
|
{
|
|
try
|
|
{
|
|
MessageBeginInvoke("正在保存[" + APPVersion + "]版本更新信息......", "lblMsg", "Label");
|
|
MessageBeginInvoke(((decimal)(i + 1) / _DataRow.Count() * 100).ToString("F0"), "downProgress", "ProgressBar");
|
|
string _SelectString = $@"SELECT 1 FROM {DataBaseName}.T_SOFTUPDATE
|
|
WHERE MACADDRESS = '{_DataRow[i]["MACADDRESS"].ToString()}' AND
|
|
SERVERPART_CODE = '{_DataRow[i]["SERVERPART_CODE"].ToString()}' AND
|
|
SHOPCODE = '{_DataRow[i]["SHOPCODE"].ToString()}'";
|
|
//string _SelectString = string.Format("SELECT 1 FROM {0}.T_SOFTUPDATE WHERE MACADDRESS = '{1}'", DataBaseName, "00");
|
|
if (_OracleHelper.ExcuteSqlGetDataSet(_SelectString).Tables[0].Rows.Count > 0)
|
|
{
|
|
string _UpdateString = $@"UPDATE {DataBaseName}.T_SOFTUPDATE
|
|
SET SOFTUPDATE_VERSION = '{_DataRow[i]["SOFTUPDATE_VERSION"].ToString()}',
|
|
SOFTUPDATE_DATE = TO_DATE('{_DataRow[i]["SOFTUPDATE_DATE"].ToString()}','YYYY/MM/DD HH24:MI:SS'),
|
|
SOFTUPDATE_DESC = '{_DataRow[i]["SOFTUPDATE_DESC"].ToString()}',
|
|
WHERE MACADDRESS = '{_DataRow[i]["MACADDRESS"].ToString()}' AND
|
|
SERVERPART_CODE = '{_DataRow[i]["SERVERPART_CODE"].ToString()}' AND
|
|
SHOPCODE = '{_DataRow[i]["SHOPCODE"].ToString()}' ";
|
|
_OracleHelper.ExecuteSqlTran(_UpdateString);
|
|
}
|
|
else
|
|
{
|
|
string _InsertString = $@"INSERT INTO {DataBaseName}.T_SOFTUPDATE (
|
|
SOFTUPDATE_ID,PROVINCE_CODE,SERVERPART_CODE,SHOPCODE,
|
|
MACADDRESS,SOFTUPDATE_DATE,SOFTUPDATE_VERSION,SOFTUPDATE_DESC)
|
|
VALUES ({_DataRow[i]["SOFTUPDATE_ID"].ToString()},'{_DataRow[i]["PROVINCE_CODE"].ToString()}',
|
|
'{_DataRow[i]["SERVERPART_CODE"].ToString()}','{_DataRow[i]["SHOPCODE"].ToString()}',
|
|
'{_DataRow[i]["MACADDRESS"].ToString()}',TO_DATE('{_DataRow[i]["SOFTUPDATE_DATE"].ToString()}','YYYY/MM/DD HH24:MI:SS'),
|
|
'{_DataRow[i]["SOFTUPDATE_VERSION"].ToString()}','{_DataRow[i]["SOFTUPDATE_DESC"].ToString()}')";
|
|
_OracleHelper.ExecuteSqlTran(_InsertString);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Lib.LogHelper.WriteServiceLog("系统更新保存失败:" + ex.Message);
|
|
_SaveFlag = false;
|
|
}
|
|
}
|
|
return _SaveFlag;
|
|
}
|
|
/// <summary>
|
|
/// 更新完成启动程序
|
|
/// </summary>
|
|
/// <param name="Msg">更新结果消息</param>
|
|
private void EndUpdate(string Msg)
|
|
{
|
|
MessageBeginInvoke(Msg, "lblMsg", "Label");
|
|
//StartSetupAPP(Msg);
|
|
System.Threading.Thread.Sleep(500);
|
|
Environment.Exit(0);
|
|
}
|
|
#region 控件操作委托
|
|
/// <summary>
|
|
/// 控件线程委托
|
|
/// </summary>
|
|
/// <param name="Msg">消息内容</param>
|
|
/// <param name="ControlName">控件名称</param>
|
|
/// <param name="ControlType">控件类型</param>
|
|
delegate void DelegateMessage(string Msg, string ControlName, string ControlType);
|
|
|
|
/// <summary>
|
|
/// 线程委托操作事件
|
|
/// </summary>
|
|
/// <param name="Msg">消息内容</param>
|
|
/// <param name="ControlName">控件名称</param>
|
|
/// <param name="ControlType">控件类型</param>
|
|
private void MessageBeginInvoke(string Msg, string ControlName, string ControlType)
|
|
{
|
|
Dispatcher.BeginInvoke(new DelegateMessage(MessageHandle), new object[] { Msg, ControlName, ControlType });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 线程消息操作
|
|
/// </summary>
|
|
/// <param name="Msg">消息内容</param>
|
|
/// <param name="ControlName">控件名称</param>
|
|
/// <param name="ControlsType">控件类型</param>
|
|
private void MessageHandle(string Msg, string ControlName, string ControlsType)
|
|
{
|
|
switch (ControlsType)
|
|
{
|
|
case "ProgressBar":
|
|
if (double.TryParse(Msg, out double _Value))
|
|
{
|
|
ProgressBar _ProgressBar = (ProgressBar)FindName(ControlName);
|
|
_ProgressBar.Value = _Value;
|
|
}
|
|
break;
|
|
case "Label":
|
|
Label _Label = (Label)FindName(ControlName);
|
|
_Label.Content = Msg;
|
|
break;
|
|
case "Image":
|
|
Image _Image = (Image)FindName(ControlName);
|
|
_Image.Source = new BitmapImage(new Uri(Msg, UriKind.Relative));
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|