实现了远程更新的操作,包括上传文件和更新版本号

This commit is contained in:
hsl
2017-03-22 19:50:11 +08:00
parent 8877d91c52
commit 411be01f9c
8 changed files with 391 additions and 39 deletions

View File

@@ -30,6 +30,7 @@ namespace CommonLibrary
public static string { get; } = "A007";
public static string { get; } = "A008";
public static string { get; } = "A009";
public static string { get; } = "A010";

View File

@@ -184,35 +184,7 @@ namespace 软件系统客户端模版
return;
}
//版本验证
if (IsHandleCreated) Invoke(message_show, "正在验证版本...");
else return;
//延时
Thread.Sleep(200);
result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.);
if (result.IsSuccess)
{
//服务器应该返回服务器的版本号
BasicFramework.SystemVersion sv = new BasicFramework.SystemVersion(result.Content);
if (UserClient.CurrentVersion != sv)
{
//保存新版本信息
UserClient.JsonSettings.IsNewVersionRunning = true;
UserClient.JsonSettings.SaveSettings();
//和当前系统版本号不一致,启动更新
if (IsHandleCreated) Invoke(start_update);
return;
}
}
else
{
//访问失败
if (IsHandleCreated) Invoke(message_show, result.Message);
if (IsHandleCreated) Invoke(thread_finish);
return;
}
//检查账户
if (IsHandleCreated) Invoke(message_show, "正在检查账户...");
@@ -258,6 +230,53 @@ namespace 软件系统客户端模版
UserClient.JsonSettings.SaveSettings();
//版本验证
if (IsHandleCreated) Invoke(message_show, "正在验证版本...");
else return;
//延时
Thread.Sleep(200);
result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.);
if (result.IsSuccess)
{
//服务器应该返回服务器的版本号
BasicFramework.SystemVersion sv = new BasicFramework.SystemVersion(result.Content);
//系统账户跳过低版本检测
if (UserClient.UserAccount.UserName != "admin")
{
if (UserClient.CurrentVersion != sv)
{
//保存新版本信息
UserClient.JsonSettings.IsNewVersionRunning = true;
UserClient.JsonSettings.SaveSettings();
//和当前系统版本号不一致,启动更新
if (IsHandleCreated) Invoke(start_update);
return;
}
}
else
{
if (UserClient.CurrentVersion < sv)
{
//保存新版本信息
UserClient.JsonSettings.IsNewVersionRunning = true;
UserClient.JsonSettings.SaveSettings();
//和当前系统版本号不一致,启动更新
if (IsHandleCreated) Invoke(start_update);
return;
}
}
}
else
{
//访问失败
if (IsHandleCreated) Invoke(message_show, result.Message);
if (IsHandleCreated) Invoke(thread_finish);
return;
}
//================================================================================
//验证结束后,根据需要是否下载服务器的数据,或是等到进入主窗口下载也可以
//如果有参数决定主窗口的显示方式,那么必要在下面向服务器请求数据

View File

@@ -195,19 +195,17 @@ namespace 软件系统客户端模版
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
if (UserClient.UserAccount.UserName == "admin")
{
ofd.Multiselect = true;
if(ofd.ShowDialog()==DialogResult.OK)
using (FormUpdateRemote fur = new FormUpdateRemote())
{
using (FormFileOperate fUpload = new FormFileOperate(CommonHeadCode.KeyToken,new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp),CommonLibrary.CommonLibrary.Port_Update_Remote),
ofd.FileNames, "", "", ""))
{
fUpload.ShowDialog();
}
fur.ShowDialog();
}
}
else
{
MessageBox.Show("权限不足!");
}
}
#endregion

View File

@@ -0,0 +1,124 @@
namespace
{
partial class FormUpdateRemote
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.userButton_file = new BasicFramework.UserButton();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.userButton_version = new BasicFramework.UserButton();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(24, 22);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(188, 17);
this.label1.TabIndex = 0;
this.label1.Text = "第一步:更新所有新版本的文件。";
//
// userButton_file
//
this.userButton_file.BackColor = System.Drawing.Color.Transparent;
this.userButton_file.CustomerInformation = "";
this.userButton_file.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190)))));
this.userButton_file.Font = new System.Drawing.Font("微软雅黑", 9F);
this.userButton_file.Location = new System.Drawing.Point(216, 62);
this.userButton_file.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.userButton_file.Name = "userButton_file";
this.userButton_file.Size = new System.Drawing.Size(94, 37);
this.userButton_file.TabIndex = 13;
this.userButton_file.UIText = "选择文件";
this.userButton_file.Click += new System.EventHandler(this.userButton_file_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(141, 181);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(245, 23);
this.textBox1.TabIndex = 14;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(24, 132);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(176, 17);
this.label2.TabIndex = 15;
this.label2.Text = "第二步:更新服务器的版本号。";
//
// userButton_version
//
this.userButton_version.BackColor = System.Drawing.Color.Transparent;
this.userButton_version.CustomerInformation = "";
this.userButton_version.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190)))));
this.userButton_version.Font = new System.Drawing.Font("微软雅黑", 9F);
this.userButton_version.Location = new System.Drawing.Point(216, 236);
this.userButton_version.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.userButton_version.Name = "userButton_version";
this.userButton_version.Size = new System.Drawing.Size(94, 37);
this.userButton_version.TabIndex = 16;
this.userButton_version.UIText = "提交版本号";
this.userButton_version.Click += new System.EventHandler(this.userButton_version_Click);
//
// FormUpdateRemote
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(569, 311);
this.Controls.Add(this.userButton_version);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.userButton_file);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximumSize = new System.Drawing.Size(585, 350);
this.MinimumSize = new System.Drawing.Size(585, 350);
this.Name = "FormUpdateRemote";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "远程更新客户端";
this.Load += new System.EventHandler(this.FormUpdateRemote_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private BasicFramework.UserButton userButton_file;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private BasicFramework.UserButton userButton_version;
}
}

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IndustryEthernet;
using CommonLibrary;
namespace
{
//=====================================================================================
//
// 用途: 本窗口用于实现对本系统的客户端进行全面的远程更新的操作。
// 第一步: 先将新版本的所有客户端传送到服务器端进行覆盖。
// 第二步: 再将版本号传送到服务器进行更新,这样所有的客户端登录后就会自动更新新的版本了
//
//=====================================================================================
public partial class FormUpdateRemote : Form
{
public FormUpdateRemote()
{
InitializeComponent();
}
private void userButton_file_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
using (FormFileOperate fUpload = new FormFileOperate(CommonHeadCode.KeyToken, new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp), CommonLibrary.CommonLibrary.Port_Update_Remote),
ofd.FileNames, "", "", ""))
{
fUpload.ShowDialog();
}
}
}
}
private void userButton_version_Click(object sender, EventArgs e)
{
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode. +
textBox1.Text);
if (result.IsSuccess && result.Content == "1")
{
MessageBox.Show("更新成功!");
}
else
{
MessageBox.Show("更新失败!原因:" + result.ToMessageShowString());
}
}
private void FormUpdateRemote_Load(object sender, EventArgs e)
{
textBox1.Text = UserClient.CurrentVersion.ToString();
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -88,6 +88,12 @@
<Compile Include="FormRegisterAccount.Designer.cs">
<DependentUpon>FormRegisterAccount.cs</DependentUpon>
</Compile>
<Compile Include="FormUpdateRemote.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormUpdateRemote.Designer.cs">
<DependentUpon>FormUpdateRemote.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UserClient.cs" />
@@ -106,6 +112,9 @@
<EmbeddedResource Include="FormRegisterAccount.resx">
<DependentUpon>FormRegisterAccount.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormUpdateRemote.resx">
<DependentUpon>FormUpdateRemote.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@@ -339,6 +339,18 @@ namespace 软件系统服务端模版
UserServer.ServerAccounts.UpdatePassword(name, password);
net_simplify_server.SendMessage(object1, "成功");
}
else if (head_code == CommonHeadCode.SimplifyHeadCode.)
{
try
{
UserServer.ServerSettings.SystemVersion = new SystemVersion(object2.Substring(4));
UserServer.ServerSettings.SaveToFile();
}
catch
{
}
}
else if (head_code == CommonHeadCode.SimplifyHeadCode.)
{
net_simplify_server.SendMessage(object1, net_socket_server.LogReacord.GetLogText());
@@ -507,7 +519,9 @@ namespace 软件系统服务端模版
#endregion
/// <summary>
/// 还未有其他什么用途
/// </summary>
private Log_Record log = new Log_Record();
}
}