Browse Source

文件上传不加密

合并请求方法
master
张剑 1 year ago
parent
commit
76f4d4cfc2

+ 2
- 2
XHWK.WKTool/App.config View File

@@ -7,8 +7,8 @@
7 7
     <!--0正式 1测试-->
8 8
     <add key="IsDebug" value="1" />
9 9
     <!--版本号-->
10
-    <add key="VersionCode" value="129" />
11
-    <add key="VersionName" value="3.13.2" />
10
+    <add key="VersionCode" value="130" />
11
+    <add key="VersionName" value="3.13.3" />
12 12
     <!--皮肤样式 0白 1蓝 2黑色 -->
13 13
     <add key="SkinStyle" value="0" />
14 14
     <!--是否输出视频记录日志:0否-->

+ 30
- 54
XHWK.WKTool/DAL/DalUpload.cs View File

@@ -40,34 +40,23 @@ namespace XHWK.WKTool.DAL
40 40
             {
41 41
                 try
42 42
                 {
43
-                    JObject jo = ZHttpUtil.PostFunction
44
-                    (
45
-                        _fileRequestAddress + @"/chunkdb/isexist",
46
-                        @"application/x-www-form-urlencoded",
43
+                    string url = new Uri(new Uri(_fileRequestAddress), @"/chunkdb/isexist").AbsoluteUri;
44
+                    ResultVo<ModelResourceAddTwo> resultObj = ZHttpUtil.PostSignle<ResultVo<ModelResourceAddTwo>>(
45
+                        url,
47 46
                         @"md5=" + md5,
48
-                        ""
47
+                        false,
48
+                        contentType: @"application/x-www-form-urlencoded"
49 49
                     );
50
-                    if (jo == null)
50
+                    if (resultObj != null)
51 51
                     {
52
-                        message = "无法访问文件服务器,请检查网络或文件服务器地址。";
53
-                        return false;
54
-                    }
55
-
56
-                    //修改为0为之前上传成功,1为之前未上传成功
57
-                    if (jo["code"]?.ToString() == "0")
58
-                    {
59
-                        message = "";
60
-                        Model.ResultVo<ModelResourceAddTwo> resultObj = JsonHelper.JsonToObj<Model.ResultVo<ModelResourceAddTwo>>(jo.ToString());
61
-                        App.ResourceAddTwo = resultObj.obj;
62
-                        //已存在 不允许上传
63
-                        return false;
64
-                    }
65
-                    else
66
-                    {
67
-                        message = "";
68
-                        //不存在 允许上传
69
-                        return true;
52
+                        if (resultObj.code == 0)
53
+                        {
54
+                            App.ResourceAddTwo = resultObj.obj;
55
+                            //已存在 不允许上传
56
+                            return false;
57
+                        }
70 58
                     }
59
+                    return true;
71 60
                 }
72 61
                 catch (Exception e)
73 62
                 {
@@ -104,32 +93,24 @@ namespace XHWK.WKTool.DAL
104 93
             {
105 94
                 try
106 95
                 {
107
-                    JObject jo = ZHttpUtil.PostFunction
108
-                    (
109
-                        _fileRequestAddress + @"/chunkdb/mergechunk",
110
-                        @"application/x-www-form-urlencoded",
96
+                    string url = new Uri(new Uri(_fileRequestAddress), @"/chunkdb/mergechunk").AbsoluteUri;
97
+                    ResultVo<ModelResourceAddTwo> resultObj = ZHttpUtil.PostSignle<ResultVo<ModelResourceAddTwo>>(
98
+                        url,
111 99
                         @"savefolder=" + savefolder + "&identifier=" + fileCode,
112
-                        ""
100
+                        false,
101
+                        contentType: @"application/x-www-form-urlencoded"
113 102
                     );
114
-                    if (jo == null)
103
+                    if (resultObj != null)
115 104
                     {
116
-                        message = "无法访问文件服务器,请检查网络或文件服务器地址。";
117
-                        return false;
118
-                    }
119
-                    Model.ResultVo<ModelResourceAddTwo> resultObj = JsonHelper.JsonToObj<Model.ResultVo<ModelResourceAddTwo>>(jo.ToString());
120
-                    App.ResourceAddTwo = new ModelResourceAddTwo();
121
-                    //0成功,1失败
122
-                    if (resultObj.code == 0 && resultObj.obj != null)
123
-                    {
124
-                        App.ResourceAddTwo = resultObj.obj;
125
-                        return true;
126
-                    }
127
-                    else
128
-                    {
129
-                        //Message = "上传失败!";
130
-                        message = jo["msg"]?.ToString();
131
-                        return false;
105
+                        if (resultObj.code == 0)
106
+                        {
107
+                            App.ResourceAddTwo = resultObj.obj;
108
+                            return true;
109
+                        }
110
+                        message = resultObj.msg;
132 111
                     }
112
+                    message = "请求失败,请重试!";
113
+                    return false;
133 114
                 }
134 115
                 catch (Exception e)
135 116
                 {
@@ -186,10 +167,7 @@ namespace XHWK.WKTool.DAL
186 167
                     errMessage = "视频已上传";
187 168
                     return false;
188 169
                 }
189
-                else
190
-                {
191
-                    return true;
192
-                }
170
+                return true;
193 171
             }
194 172
             catch (Exception ex)
195 173
             {
@@ -234,8 +212,7 @@ namespace XHWK.WKTool.DAL
234 212
                     errMessage = "未找到课程!";
235 213
                     return false;
236 214
                 }
237
-
238
-                string uploadUrl = _fileRequestAddress + "/chunkdb/upchunk"; //zxyceshi
215
+                string uploadUrl = new Uri(new Uri(_fileRequestAddress), "/chunkdb/upchunk").AbsoluteUri;
239 216
                 if (videoInfo.IsUpload)
240 217
                 {
241 218
                     errMessage = "视频已上传";
@@ -338,8 +315,7 @@ namespace XHWK.WKTool.DAL
338 315
                             //{
339 316
                             //    formFields.Add();
340 317
                             //}
341
-                            JObject jo = ZHttpUtil.UploadRequestflow
342
-                            (
318
+                            JObject jo = ZHttpUtil.UploadFile(
343 319
                                 uploadUrl,
344 320
                                 byteArray,
345 321
                                 fileName,

+ 1
- 1
XHWK.WKTool/DAL/XHApi.cs View File

@@ -145,7 +145,7 @@ namespace XHWK.WKTool.DAL
145 145
         public bool DownloadAvatar(string headPortrait, string savePath)
146 146
         {
147 147
             string url = App.showImageUrl + headPortrait;
148
-            bool result = ZHttpUtil.GetDataGetHtml(url, savePath, "");
148
+            bool result = ZHttpUtil.DownloadFile(url, savePath, "");
149 149
             return result;
150 150
         }
151 151
 

+ 7
- 7
XHWK.WKTool/MainWindow.xaml.cs View File

@@ -2161,7 +2161,7 @@ namespace XHWK.WKTool
2161 2161
         /// <summary>
2162 2162
         /// 视频信息列表
2163 2163
         /// </summary>
2164
-        private readonly List<Uc_VideoItem> _videoControlList = new List<Uc_VideoItem>();
2164
+        private readonly List<UcVideoItem> _videoControlList = new List<UcVideoItem>();
2165 2165
 
2166 2166
         #endregion 初始值
2167 2167
 
@@ -2174,7 +2174,7 @@ namespace XHWK.WKTool
2174 2174
             //隐藏显示的控件
2175 2175
             if (_videoControlList.Count > 0)
2176 2176
             {
2177
-                foreach (Uc_VideoItem item in _videoControlList)
2177
+                foreach (UcVideoItem item in _videoControlList)
2178 2178
                 {
2179 2179
                     if (item.Visibility != Visibility.Hidden)
2180 2180
                     {
@@ -2192,7 +2192,7 @@ namespace XHWK.WKTool
2192 2192
                 {
2193 2193
                     return;
2194 2194
                 }
2195
-                Uc_VideoItem videoItem;
2195
+                UcVideoItem videoItem;
2196 2196
                 if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
2197 2197
                 {
2198 2198
                     videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
@@ -2203,9 +2203,9 @@ namespace XHWK.WKTool
2203 2203
                     {
2204 2204
                         continue;
2205 2205
                     }
2206
-                    videoItem = new Uc_VideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
2207
-                    videoItem.Click_refreshVideoList += LoadUploadInitData;
2208
-                    videoItem.Click_UploadLogin += Login;
2206
+                    videoItem = new UcVideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
2207
+                    videoItem.ClickRefreshVideoList += LoadUploadInitData;
2208
+                    videoItem.ClickUploadLogin += Login;
2209 2209
                     videoItem.Width = _controlWidth;
2210 2210
                     videoItem.Height = _controlHeight;
2211 2211
                     videoItem.HorizontalAlignment = HorizontalAlignment.Left;
@@ -2289,7 +2289,7 @@ namespace XHWK.WKTool
2289 2289
                 //隐藏显示的控件
2290 2290
                 if (_videoControlList.Count > 0)
2291 2291
                 {
2292
-                    foreach (Uc_VideoItem item in _videoControlList)
2292
+                    foreach (UcVideoItem item in _videoControlList)
2293 2293
                     {
2294 2294
                         if (item.Visibility != Visibility.Hidden)
2295 2295
                         {

+ 60
- 177
XHWK.WKTool/Utils/ZHttpUtil.cs View File

@@ -1,6 +1,7 @@
1 1
 namespace Common.system
2 2
 {
3 3
     using Newtonsoft.Json.Linq;
4
+
4 5
     using System;
5 6
     using System.Collections.Specialized;
6 7
     using System.IO;
@@ -18,21 +19,18 @@
18 19
         public static string version = "";
19 20
         public static bool isSt;
20 21
 
21
-        public static void InitRequest(ref System.Net.HttpWebRequest request)
22
-        {
23
-            request.Accept = "text/json,*/*;q=0.5";
24
-            request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
25
-            request.Headers.Add("Accept-Encoding", "gzip, deflate, x-gzip, identity; q=0.9");
26
-            request.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
27
-            request.Timeout = 8000;
28
-        }
29
-
30
-        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
22
+        private static bool CheckValidationResult
23
+        (
24
+            object sender,
25
+            X509Certificate certificate,
26
+            X509Chain chain,
27
+            SslPolicyErrors errors
28
+        )
31 29
         {
32 30
             return true; //总是接受
33 31
         }
34 32
 
35
-        public static System.Net.HttpWebRequest GetHttpWebRequest(string url)
33
+        public static HttpWebRequest GetHttpWebRequest(string url)
36 34
         {
37 35
             HttpWebRequest request;
38 36
             if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
@@ -51,15 +49,21 @@
51 49
             return request;
52 50
         }
53 51
 
54
-        public static WebResponse Download(string downloadUrl, long from, long to, string method)
52
+        public static WebResponse Download
53
+        (
54
+            string downloadUrl,
55
+            long from,
56
+            long to,
57
+            string method
58
+        )
55 59
         {
56 60
             for (int i = 0; i < 10; i++)
57 61
             {
58 62
                 try
59 63
                 {
60 64
                     HttpWebRequest request = GetHttpWebRequest(downloadUrl);
61
-                    InitRequest(ref request);
62 65
                     request.Accept = "text/json,*/*;q=0.5";
66
+                    request.AutomaticDecompression = DecompressionMethods.GZip;
63 67
                     request.AddRange(from, to);
64 68
                     request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
65 69
                     request.Headers.Add("Accept-Encoding", "gzip, deflate, x-gzip, identity; q=0.9");
@@ -78,34 +82,6 @@
78 82
             throw new Exception("已断开网络!请检查网络连接后重试下载!");
79 83
         }
80 84
 
81
-        public static string GetStr(string url)
82
-        {
83
-            try
84
-            {
85
-                HttpWebRequest request = GetHttpWebRequest(url);
86
-                if (request != null)
87
-                {
88
-                    AddHeader(request);
89
-                    string retval;
90
-                    InitRequest(ref request);
91
-                    using (WebResponse response = request.GetResponse())
92
-                    {
93
-                        // ReSharper disable once AssignNullToNotNullAttribute
94
-                        using (StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
95
-                        {
96
-                            retval = reader.ReadToEnd();
97
-                        }
98
-                    }
99
-                    return retval;
100
-                }
101
-            }
102
-            catch (Exception)
103
-            {
104
-                // ignored
105
-            }
106
-            return null;
107
-        }
108
-
109 85
         private static void AddHeader(HttpWebRequest webRequest)
110 86
         {
111 87
             webRequest.Headers.Add("Xh-St", isSt ? "true" : "false");
@@ -126,7 +102,13 @@
126 102
         /// 调用Post接口
127 103
         ///  </summary>
128 104
         ///  <returns></returns>
129
-        public static string PostStr(string url, string postData, bool jm = true)
105
+        public static string PostStr
106
+        (
107
+            string url,
108
+            string postData,
109
+            bool jm = true,
110
+            string contentType = "application/json"
111
+        )
130 112
         {
131 113
             Stream responseStream = null;
132 114
             try
@@ -135,7 +117,7 @@
135 117
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
136 118
                 webRequest.Method = "POST";
137 119
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
138
-                webRequest.ContentType = "application/json";
120
+                webRequest.ContentType = contentType + ";" + "UTF-8";
139 121
                 string aesPostData = postData;
140 122
                 if (jm)
141 123
                 {
@@ -147,15 +129,13 @@
147 129
                 }
148 130
                 byte[] buffer = encoding.GetBytes(aesPostData);
149 131
                 webRequest.ContentLength = buffer.Length;
150
-                webRequest.GetRequestStream()
151
-                .Write
152
-                (
153
-                    buffer,
154
-                    0,
155
-                    buffer.Length
156
-                );
132
+                webRequest.GetRequestStream().Write(buffer, 0, buffer.Length);
157 133
                 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
158
-                isSt = webResponse.GetResponseHeader("Xh-St") == "true";
134
+                //只有可能需要加密的接口的响应头才处理
135
+                if (jm)
136
+                {
137
+                    isSt = webResponse.GetResponseHeader("Xh-St") == "true";
138
+                }
159 139
                 responseStream = webResponse.GetResponseStream();
160 140
                 if (responseStream == null) { return ""; }
161 141
                 using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
@@ -200,7 +180,12 @@
200 180
             {
201 181
                 try
202 182
                 {
203
-                    string respstr = PostStr(url, postData, jm);
183
+                    string respstr = PostStr(
184
+                        url,
185
+                        postData,
186
+                        jm,
187
+                        contentType
188
+                    );
204 189
                     return JsonHelper.JsonToObj<T>(respstr);
205 190
                 }
206 191
                 catch (Exception)
@@ -211,72 +196,6 @@
211 196
             return default;
212 197
         }
213 198
 
214
-        /// <summary>
215
-        /// Cookie
216
-        /// </summary>
217
-        public static CookieContainer cc = new CookieContainer();
218
-
219
-        /// <summary>
220
-        /// Post请求
221
-        /// </summary>
222
-        /// <param name="serviceaddress">请求地址</param>
223
-        /// <param name="contenttype">头 application/x-www-form-urlencoded</param>
224
-        /// <param name="strcontent">参数</param>
225
-        /// <param name="header">token</param>
226
-        /// <param name="timeout"></param>
227
-        /// <returns></returns>
228
-        public static JObject PostFunction
229
-        (
230
-            string serviceaddress,
231
-            string contenttype,
232
-            string strcontent,
233
-            string header,
234
-            int timeout = 5000
235
-        )
236
-        {
237
-            try
238
-            {
239
-                string serviceAddress = serviceaddress;
240
-                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
241
-                WebHeaderCollection myWebHeaderCollection = request.Headers;
242
-
243
-                request.CookieContainer = cc;
244
-                //myWebHeaderCollection.Add("Accept", "*/*");
245
-                if (header != "")
246
-                {
247
-                    myWebHeaderCollection.Add("access_token:" + header);
248
-                }
249
-                request.Timeout = timeout;
250
-                request.Method = "POST";
251
-                request.ContentType = contenttype;
252
-                using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
253
-                {
254
-                    dataStream.Write(strcontent);
255
-                    dataStream.Close();
256
-                }
257
-                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
258
-
259
-                string encoding = response.ContentEncoding;
260
-                if (encoding.Length < 1)
261
-                {
262
-                    encoding = "UTF-8"; //默认编码
263
-                }
264
-                // ReSharper disable once AssignNullToNotNullAttribute
265
-                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
266
-                string retString = reader.ReadToEnd();
267
-                retString = retString.Replace("\\r\\n", "");
268
-
269
-                //解析josn
270
-                JObject jo = JObject.Parse(retString);
271
-                return jo;
272
-            }
273
-            catch (Exception ex)
274
-            {
275
-                LogHelper.Logerror.Error("请求失败(若网络无问题,请重置winsock,解决方法:以管理员方式打开cmd执行 netsh winsock reset 后重启)", ex);
276
-                return null;
277
-            }
278
-        }
279
-
280 199
         /// <summary>
281 200
         /// HttpWebRequest 下载
282 201
         /// </summary>
@@ -284,12 +203,7 @@
284 203
         /// <param name="filePath"></param>
285 204
         /// <param name="header"></param>
286 205
         /// <returns></returns>
287
-        public static bool GetDataGetHtml
288
-        (
289
-            string url,
290
-            string filePath,
291
-            string header
292
-        )
206
+        public static bool DownloadFile(string url, string filePath, string header)
293 207
         {
294 208
             try
295 209
             {
@@ -302,21 +216,24 @@
302 216
                 httpWebRequest.AllowWriteStreamBuffering = false;
303 217
                 //httpWebRequest.Timeout = 300000;
304 218
                 httpWebRequest.ServicePoint.Expect100Continue = false;
305
-
306 219
                 WebHeaderCollection myWebHeaderCollection = httpWebRequest.Headers;
307 220
                 //myWebHeaderCollection.Add("Accept", "*/*");
308 221
                 if (header != "")
309 222
                 {
310 223
                     myWebHeaderCollection.Add("access_token:" + header);
311 224
                 }
312
-
313 225
                 HttpWebResponse webRespon = (HttpWebResponse)httpWebRequest.GetResponse();
314 226
                 Stream webStream = webRespon.GetResponseStream();
315 227
                 if (webStream == null)
316 228
                 {
317 229
                     return false;
318 230
                 }
319
-                Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
231
+                Stream stream = new FileStream(
232
+                    filePath,
233
+                    FileMode.Create,
234
+                    FileAccess.ReadWrite,
235
+                    FileShare.ReadWrite
236
+                );
320 237
                 byte[] bArr = new byte[1024];
321 238
                 int size = webStream.Read(bArr, 0, bArr.Length);
322 239
                 while (size > 0)
@@ -345,7 +262,13 @@
345 262
         /// <param name="databyte">文件数据流</param>
346 263
         /// <param name="filename">文件名</param>
347 264
         /// <param name="formFields">参数 可不传</param>
348
-        public static JObject UploadRequestflow(string url, byte[] databyte, string filename, NameValueCollection formFields = null)
265
+        public static JObject UploadFile
266
+        (
267
+            string url,
268
+            byte[] databyte,
269
+            string filename,
270
+            NameValueCollection formFields = null
271
+        )
349 272
         {
350 273
             // 时间戳,用做boundary
351 274
             string boundary = "-----" + DateTime.Now.Ticks.ToString("x");
@@ -368,66 +291,26 @@
368 291
                 {
369 292
                     foreach (string key in formFields.Keys)
370 293
                     {
371
-                        postStream.Write
372
-                        (
373
-                            boundarybytes,
374
-                            0,
375
-                            boundarybytes.Length
376
-                        );
377
-                        string formitem = string.Format
378
-                        (
379
-                            formdataTemplate,
380
-                            key,
381
-                            formFields[key]
382
-                        );
294
+                        postStream.Write(boundarybytes, 0, boundarybytes.Length);
295
+                        string formitem = string.Format(formdataTemplate, key, formFields[key]);
383 296
                         byte[] formitembytes = Encoding.UTF8.GetBytes(formitem);
384
-                        postStream.Write
385
-                        (
386
-                            formitembytes,
387
-                            0,
388
-                            formitembytes.Length
389
-                        );
297
+                        postStream.Write(formitembytes, 0, formitembytes.Length);
390 298
                     }
391 299
                 }
392
-                postStream.Write
393
-                (
394
-                    boundarybytes,
395
-                    0,
396
-                    boundarybytes.Length
397
-                );
300
+                postStream.Write(boundarybytes, 0, boundarybytes.Length);
398 301
                 const string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";
399 302
 
400 303
                 //文件头
401
-                string header = string.Format
402
-                (
403
-                    headerTemplate,
404
-                    "file",
405
-                    filename
406
-                );
304
+                string header = string.Format(headerTemplate, "file", filename);
407 305
                 byte[] headerbytes = Encoding.UTF8.GetBytes(header);
408
-                postStream.Write
409
-                (
410
-                    headerbytes,
411
-                    0,
412
-                    headerbytes.Length
413
-                );
306
+                postStream.Write(headerbytes, 0, headerbytes.Length);
414 307
 
415 308
                 //文件流
416
-                postStream.Write
417
-                (
418
-                    databyte,
419
-                    0,
420
-                    databyte.Length
421
-                );
309
+                postStream.Write(databyte, 0, databyte.Length);
422 310
 
423 311
                 //结束边界
424 312
                 byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
425
-                postStream.Write
426
-                (
427
-                    boundaryBytes,
428
-                    0,
429
-                    boundaryBytes.Length
430
-                );
313
+                postStream.Write(boundaryBytes, 0, boundaryBytes.Length);
431 314
                 postStream.Close();
432 315
 
433 316
                 //获取服务器端的响应
@@ -497,4 +380,4 @@
497 380
             }
498 381
         }
499 382
     }
500
-}
383
+}

+ 1
- 1
XHWK.WKTool/View/UControl/Uc_VideoItem.xaml View File

@@ -1,5 +1,5 @@
1 1
 <UserControl
2
-    x:Class="XHWK.WKTool.UControl.Uc_VideoItem"
2
+    x:Class="XHWK.WKTool.UControl.UcVideoItem"
3 3
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 4
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 5
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

+ 69
- 81
XHWK.WKTool/View/UControl/Uc_VideoItem.xaml.cs View File

@@ -3,9 +3,7 @@
3 3
 using System;
4 4
 using System.Diagnostics;
5 5
 using System.Windows;
6
-using System.Windows.Controls;
7 6
 using System.Windows.Input;
8
-using System.Windows.Media;
9 7
 
10 8
 using XHWK.Model;
11 9
 using XHWK.WKTool.DAL;
@@ -17,14 +15,14 @@ namespace XHWK.WKTool.UControl
17 15
     /// <summary>
18 16
     /// 视频信息
19 17
     /// </summary>
20
-    public partial class Uc_VideoItem : UserControl
18
+    public partial class UcVideoItem
21 19
     {
22 20
         #region 初始值
23 21
 
24 22
         /// <summary>
25 23
         /// 视频模型
26 24
         /// </summary>
27
-        private ModelVideo VideoModel = new ModelVideo();
25
+        private ModelVideo _videoModel;
28 26
 
29 27
         /// <summary>
30 28
         /// 刷新视频列表
@@ -34,7 +32,7 @@ namespace XHWK.WKTool.UControl
34 32
         /// <summary>
35 33
         /// 刷新视频列表事件
36 34
         /// </summary>
37
-        public event RefreshVideoList Click_refreshVideoList;
35
+        public event RefreshVideoList ClickRefreshVideoList;
38 36
 
39 37
         /// <summary>
40 38
         /// 登录
@@ -44,12 +42,12 @@ namespace XHWK.WKTool.UControl
44 42
         /// <summary>
45 43
         /// 登录事件
46 44
         /// </summary>
47
-        public event UploadLogin Click_UploadLogin;
45
+        public event UploadLogin ClickUploadLogin;
48 46
 
49 47
         /// <summary>
50 48
         /// 上传页面
51 49
         /// </summary>
52
-        private UploadWindow W_UploadWindow = null;
50
+        private UploadWindow _wUploadWindow;
53 51
 
54 52
         #endregion 初始值
55 53
 
@@ -58,24 +56,25 @@ namespace XHWK.WKTool.UControl
58 56
         /// <summary>
59 57
         /// 视频信息
60 58
         /// </summary>
61
-        /// <param name="model_Video"></param>
62
-        public Uc_VideoItem(ModelVideo model_Video)
59
+        /// <param name="modelVideo"></param>
60
+        public UcVideoItem(ModelVideo modelVideo)
63 61
         {
64 62
             InitializeComponent();
65 63
             App.IsUpLoad = false;
66
-            VideoModel = model_Video;
64
+            _videoModel = modelVideo;
67 65
             DataContext = App.PageContextData;
68
-            if (FileToolsCommon.IsExistFile(VideoModel.ThumbnailPath))
66
+            if (FileToolsCommon.IsExistFile(_videoModel.ThumbnailPath))
69 67
             {
70
-                ImgVideo.Source = ImageHelper.ReadBitmapImageFile(VideoModel.ThumbnailPath);// new BitmapImage(new Uri(VideoModel.ThumbnailPath));
68
+                ImgVideo.Source = ImageHelper.ReadBitmapImageFile(_videoModel.ThumbnailPath); // new BitmapImage(new Uri(VideoModel.ThumbnailPath));
71 69
             }
72
-            string videoName = FileToolsCommon.GetIoFileNameNoExtension(VideoModel.VideoPath);
70
+            string videoName = FileToolsCommon.GetIoFileNameNoExtension(_videoModel.VideoPath);
73 71
             TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
74 72
             TbName.ToolTip = videoName;
75
-            LblDateSize.Content = VideoModel.RSTime + " " + VideoModel.VideoSize;
76
-            if (VideoModel.IsUpload)
73
+            LblDateSize.Content = _videoModel.RSTime + " " + _videoModel.VideoSize;
74
+            if (_videoModel.IsUpload)
77 75
             {
78
-                BtnUpload.Visibility = Visibility.Hidden;
76
+                BtnUpload.IsEnabled = false;
77
+                BtnUpload.Background.Opacity = 0.6;
79 78
             }
80 79
         }
81 80
 
@@ -95,7 +94,6 @@ namespace XHWK.WKTool.UControl
95 94
                 TxtModify.Text = TbName.ToolTip.ToString();
96 95
                 TbName.Visibility = Visibility.Hidden;
97 96
                 GridModify.Visibility = Visibility.Visible;
98
-                //BtnNameModifyOK.Visibility = Visibility.Visible;
99 97
             }
100 98
         }
101 99
 
@@ -139,75 +137,66 @@ namespace XHWK.WKTool.UControl
139 137
         {
140 138
             if (TxtModify.Text != TbName.Text)
141 139
             {
142
-                if (ModifyPathName(VideoModel.FileGuid, TxtModify.Text + "." + VideoModel.VideoType, out string ErrMessage))
140
+                if (ModifyPathName(_videoModel.FileGuid, TxtModify.Text + "." + _videoModel.VideoType, out string errMessage))
143 141
                 {
144 142
                     //保存成功
145 143
                     TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
146 144
                     TbName.ToolTip = TxtModify.Text;
147 145
                     TbName.Visibility = Visibility.Visible;
148 146
                     GridModify.Visibility = Visibility.Hidden;
149
-                    //BtnNameModifyOK.Visibility = Visibility.Hidden;
150 147
                 }
151 148
                 else
152 149
                 {
153
-                    MessageWindow.Show(ErrMessage);
150
+                    MessageWindow.Show(errMessage);
154 151
                 }
155 152
             }
156 153
             else
157 154
             {
158 155
                 TbName.Visibility = Visibility.Visible;
159 156
                 GridModify.Visibility = Visibility.Hidden;
160
-                //BtnNameModifyOK.Visibility = Visibility.Hidden;
161 157
             }
162 158
         }
163 159
 
164 160
         /// <summary>
165 161
         /// 修改视频文件名
166 162
         /// </summary>
167
-        /// <param name="Guid">唯一编号</param>
168
-        /// <param name="NewName">新文件名带后缀 不带路径</param>
169
-        /// <param name="Errmessage">错误信息</param>
163
+        /// <param name="fileGuid"></param>
164
+        /// <param name="newName">新文件名带后缀 不带路径</param>
165
+        /// <param name="errmessage">错误信息</param>
170 166
         /// <returns></returns>
171
-        private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
167
+        private bool ModifyPathName(string fileGuid, string newName, out string errmessage)
172 168
         {
173
-            Errmessage = "";
174
-            foreach (ModelWkData WKData in App.WKDataList)
169
+            errmessage = "";
170
+            foreach (ModelWkData wkData in App.WKDataList)
175 171
             {
176
-                if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
172
+                if (wkData.VideoList.Exists(x => x.FileGuid == fileGuid))
177 173
                 {
178
-                    ModelVideo model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
179
-                    string filePathName = model_Video.VideoPath;
174
+                    ModelVideo modelVideo = wkData.VideoList.Find(x => x.FileGuid == fileGuid);
175
+                    string filePathName = modelVideo.VideoPath;
180 176
                     string filePath = FileToolsCommon.GetDirectoryName(filePathName);
181
-                    string newFilePathName = filePath + NewName;
177
+                    string newFilePathName = filePath + newName;
182 178
                     //缩略图
183
-                    string ThumbnailPath = filePath + "ThumbnailPath/";
184
-                    FileToolsCommon.CreateDirectory(ThumbnailPath);
179
+                    string thumbnailPath = filePath + "ThumbnailPath/";
180
+                    FileToolsCommon.CreateDirectory(thumbnailPath);
185 181
                     //缩略图存储位置
186
-                    string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
182
+                    string thumbnailPathName = thumbnailPath + newName.Replace(".", "") + ".JPG";
187 183
                     if (FileToolsCommon.IsExistFile(newFilePathName))
188 184
                     {
189
-                        Errmessage = "文件已存在,请重新修改文件名!";
185
+                        errmessage = "文件已存在,请重新修改文件名!";
190 186
                         return false;
191 187
                     }
192
-                    else
193
-                    {
194
-                        //修改文件名
195
-                        FileToolsCommon.Copy(filePathName, newFilePathName);
196
-                        model_Video.VideoPath = newFilePathName;
197
-                        //修改缩略图名
198
-                        FileToolsCommon.DeleteFile(ThumbnailPathName);
199
-                        FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
200
-                        model_Video.ThumbnailPath = ThumbnailPathName;
201
-                        App.SaveWkData();
202
-                        return true;
203
-                    }
204
-                }
205
-                else
206
-                {
207
-                    continue;
188
+                    //修改文件名
189
+                    FileToolsCommon.Copy(filePathName, newFilePathName);
190
+                    modelVideo.VideoPath = newFilePathName;
191
+                    //修改缩略图名
192
+                    FileToolsCommon.DeleteFile(thumbnailPathName);
193
+                    FileToolsCommon.Copy(modelVideo.ThumbnailPath, thumbnailPathName);
194
+                    modelVideo.ThumbnailPath = thumbnailPathName;
195
+                    App.SaveWkData();
196
+                    return true;
208 197
                 }
209 198
             }
210
-            Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
199
+            errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
211 200
             return false;
212 201
         }
213 202
 
@@ -231,18 +220,21 @@ namespace XHWK.WKTool.UControl
231 220
                     {
232 221
                         continue;
233 222
                     }
234
-                    if (wKData.VideoList.Exists(x => x.FileGuid == VideoModel.FileGuid))
223
+                    if (wKData.VideoList.Exists(x => x.FileGuid == _videoModel.FileGuid))
235 224
                     {
236 225
                         try
237 226
                         {
238
-                            FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid).VideoPath);
239
-                            string ThumbnailPath = wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid).ThumbnailPath;
240
-                            wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == VideoModel.FileGuid));
227
+                            FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).VideoPath);
228
+                            string thumbnailPath = wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid).ThumbnailPath;
229
+                            wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == _videoModel.FileGuid));
241 230
                             //初始化页面  刷新视频列表
242
-                            Click_refreshVideoList();
231
+                            if (ClickRefreshVideoList != null)
232
+                            {
233
+                                ClickRefreshVideoList();
234
+                            }
243 235
                             ImgVideo.Source = null;
244 236
                             GC.Collect();
245
-                            FileToolsCommon.DeleteFile(ThumbnailPath);
237
+                            FileToolsCommon.DeleteFile(thumbnailPath);
246 238
                             Visibility = Visibility.Hidden;
247 239
                             return;
248 240
                         }
@@ -264,7 +256,7 @@ namespace XHWK.WKTool.UControl
264 256
         {
265 257
             try
266 258
             {
267
-                ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
259
+                ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
268 260
                 Process pro = new Process
269 261
                 {
270 262
                     StartInfo = psi
@@ -275,7 +267,6 @@ namespace XHWK.WKTool.UControl
275 267
             {
276 268
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
277 269
                 System.Windows.MessageBox.Show(ex.Message);
278
-                return;
279 270
             }
280 271
         }
281 272
 
@@ -288,7 +279,7 @@ namespace XHWK.WKTool.UControl
288 279
         {
289 280
             try
290 281
             {
291
-                ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
282
+                ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
292 283
                 Process pro = new Process
293 284
                 {
294 285
                     StartInfo = psi
@@ -299,7 +290,6 @@ namespace XHWK.WKTool.UControl
299 290
             {
300 291
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
301 292
                 System.Windows.MessageBox.Show(ex.Message);
302
-                return;
303 293
             }
304 294
         }
305 295
 
@@ -315,7 +305,10 @@ namespace XHWK.WKTool.UControl
315 305
             if (App.IsLoginType == false)
316 306
             {
317 307
                 //登录
318
-                Click_UploadLogin();
308
+                if (ClickUploadLogin != null)
309
+                {
310
+                    ClickUploadLogin();
311
+                }
319 312
                 if (App.IsLoginType == false)
320 313
                 {
321 314
                     return;
@@ -324,35 +317,30 @@ namespace XHWK.WKTool.UControl
324 317
             if (!App.IsUpLoad)
325 318
             {
326 319
                 App.IsUpLoad = true;
327
-                //BtnUpload.IsEnabled = false;
328
-                //BtnUpload.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9EA0A7"));
329
-                //BtnUpload.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999"));
330
-                DalUpload dAL_Upload = new DalUpload();
331
-                if (dAL_Upload.UploadVideo(VideoModel.FileGuid, out string ErrMessage))
320
+                DalUpload dAlUpload = new DalUpload();
321
+                if (dAlUpload.UploadVideo(_videoModel.FileGuid, out string errMessage))
332 322
                 {
333 323
                     App.IsUpLoad = false;
334 324
                     //MessageWindow.Show("视频上传服务器成功!");
335
-                    if (W_UploadWindow == null)
325
+                    if (_wUploadWindow == null)
336 326
                     {
337
-                        W_UploadWindow = new UploadWindow { Owner = App.W_XHMicroLessonSystemWindow };
338
-                        W_UploadWindow.ChangeTextEvents += frm_ChangeTextEvents;
339
-                        ;
327
+                        _wUploadWindow = new UploadWindow { Owner = App.W_XHMicroLessonSystemWindow };
328
+                        _wUploadWindow.ChangeTextEvents += frm_ChangeTextEvents;
340 329
                     }
341 330
 
342 331
                     //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
343
-                    W_UploadWindow.Initialize
344
-                    (
332
+                    _wUploadWindow.Initialize(
345 333
                         TbName.Text,
346
-                        VideoModel.VideoSizebyte,
347
-                        VideoModel.VideoType.ToString(),
348
-                        VideoModel.FileGuid,
334
+                        _videoModel.VideoSizebyte,
335
+                        _videoModel.VideoType.ToString(),
336
+                        _videoModel.FileGuid,
349 337
                         0
350 338
                     );
351 339
                 }
352 340
                 else
353 341
                 {
354 342
                     App.IsUpLoad = false;
355
-                    MessageWindow.Show(ErrMessage);
343
+                    MessageWindow.Show(errMessage);
356 344
                 }
357 345
             }
358 346
         }
@@ -361,12 +349,12 @@ namespace XHWK.WKTool.UControl
361 349
         /// 上传返回事件
362 350
         /// </summary>
363 351
         /// <param name="text"></param>
352
+        /// <param name="i"></param>
364 353
         private void frm_ChangeTextEvents(string text, int i)
365 354
         {
366 355
             if ("上传成功".Equals(text))
367 356
             {
368
-                W_UploadWindow.Close();
369
-                //BorUploadBtn.Visibility = Visibility.Hidden;
357
+                _wUploadWindow.Close();
370 358
                 BtnUpload.IsEnabled = false;
371 359
                 BtnUpload.Background.Opacity = 0.6;
372 360
             }
@@ -383,7 +371,7 @@ namespace XHWK.WKTool.UControl
383 371
             {
384 372
                 App.W_VideoClipWindow = new VideoClipWindow();
385 373
             }
386
-            if (App.W_VideoClipWindow.InitClipVideo(VideoModel.VideoPath))
374
+            if (App.W_VideoClipWindow.InitClipVideo(_videoModel.VideoPath))
387 375
             {
388 376
                 App.W_VideoClipWindow.ShowDialog();
389 377
             }

+ 1
- 1
星火微课/星火微课-测试.iss View File

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课测试版"  
5 5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.13.2"
6
+#define MyAppVersion "3.13.3"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Loading…
Cancel
Save