UpdateSvc.cs
5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.EnterpriseServices;
using System.Reflection;
using System.IO;
using Comm;
using System.Windows.Forms;
/// <summary>
/// UpdateSvc 的摘要说明
/// </summary>
[Transaction(TransactionOption.Required)]
[WebServiceAttribute(Namespace = BaseSvc.strNameSpace)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class UpdateSvc : BaseSvc
{
public UpdateSvc()
{
//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}
#region Component Designer generated code
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod(Description = "获得最新客户端的版本信息", EnableSession = true, TransactionOption = TransactionOption.RequiresNew)]
public string GetClientVersion()
{
string strVer = "";
try
{
string strClientPath = Configuration.ClientPath;
if (!strClientPath.EndsWith(@"\")) //若路径不是以\结尾,则追加之
strClientPath += @"\";
strClientPath += "App.exe";
Assembly Asm = Assembly.LoadFrom(strClientPath);
AssemblyName AsmName = Asm.GetName();
//this._LocalMainVersion = AsmName.Version.ToString();
//this._LocalMainCulture = AsmName.CultureInfo.ToString();
//this._LocalMainPublicKey = Convert.ToString(AsmName.GetPublicKeyToken());
strVer = AsmName.Version.ToString();
}
catch (Exception e)
{
throw e;
}
return strVer;
}
[WebMethod(Description = "获得最新客户端的升级文件列表", EnableSession = true, TransactionOption = TransactionOption.RequiresNew)]
public DataSet GetClientFileList()
{
return ReadClientFileList();
}
[WebMethod(Description = "获得最新客户端的升级文件", EnableSession = true, TransactionOption = TransactionOption.RequiresNew)]
public byte[] GetClientFile(string FileName)
{
return ReadClientFile(FileName);
}
[WebMethod(Description = "获得自动升级开关值", EnableSession = true, TransactionOption = TransactionOption.RequiresNew)]
public string GetUpdateSwitch()
{
string f_UpdateSwitch = Configuration.MyCMMIUpdateSwitch;
return f_UpdateSwitch;
}
private DataSet ReadClientFileList()
{
string strClientPath;
DataSet UpdateFileInfo = new DataSet("UpdateFileInfo");
try
{
strClientPath = Configuration.ClientPath;
}
catch
{
return UpdateFileInfo;
}
DataTable UpdateFileTab = UpdateFileInfo.Tables.Add("UpdateFileTab");
UpdateFileTab.Columns.Add("FileName", typeof(string));
UpdateFileTab.Columns.Add("FileLength", typeof(string));
UpdateFileTab.Columns.Add("FileDateTime", typeof(string));
//todo modify by colbert liveupdate multiple Directories Files
string[] FilePaths = Directory.GetFiles(strClientPath, "*.*", SearchOption.AllDirectories);
for (int i = 0; i < FilePaths.Length; i++)
{
FileInfo fileinfo = new FileInfo(FilePaths[i]);
DataRow UpdateFileRow = UpdateFileTab.NewRow();
UpdateFileRow["FileName"] = fileinfo.FullName.Replace(strClientPath, "");
UpdateFileRow["FileLength"] = fileinfo.Length.ToString();
UpdateFileRow["FileDateTime"] = fileinfo.LastWriteTime.ToString();
UpdateFileTab.Rows.Add(UpdateFileRow);
}
return UpdateFileInfo;
}
private byte[] ReadClientFile(string FileName)
{
byte[] mbyte;
FileStream fstr;
try
{
string strClientPath = Configuration.ClientPath;
}
catch
{
return mbyte = new byte[0];
}
string FileFullName = Configuration.ClientPath;
if (!FileFullName.EndsWith(@"\")) //若路径不是以\结尾,则追加之
FileFullName += @"\";
FileFullName = FileFullName + FileName;
try
{
fstr = new FileStream(FileFullName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
}
catch
{
return mbyte = new byte[0];
}
mbyte = new byte[fstr.Length];
int mbyteLength = mbyte.Length;
int m = 0;
do
{
m = fstr.Read(mbyte, 0, mbyteLength);
}
while (m > 0);
fstr.Close();
return mbyte;
}
}