Browse Source

文件上传不加密

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

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

7
     <!--0正式 1测试-->
7
     <!--0正式 1测试-->
8
     <add key="IsDebug" value="1" />
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
     <!--皮肤样式 0白 1蓝 2黑色 -->
12
     <!--皮肤样式 0白 1蓝 2黑色 -->
13
     <add key="SkinStyle" value="0" />
13
     <add key="SkinStyle" value="0" />
14
     <!--是否输出视频记录日志:0否-->
14
     <!--是否输出视频记录日志:0否-->

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

40
             {
40
             {
41
                 try
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
                         @"md5=" + md5,
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
                 catch (Exception e)
61
                 catch (Exception e)
73
                 {
62
                 {
104
             {
93
             {
105
                 try
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
                         @"savefolder=" + savefolder + "&identifier=" + fileCode,
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
                 catch (Exception e)
115
                 catch (Exception e)
135
                 {
116
                 {
186
                     errMessage = "视频已上传";
167
                     errMessage = "视频已上传";
187
                     return false;
168
                     return false;
188
                 }
169
                 }
189
-                else
190
-                {
191
-                    return true;
192
-                }
170
+                return true;
193
             }
171
             }
194
             catch (Exception ex)
172
             catch (Exception ex)
195
             {
173
             {
234
                     errMessage = "未找到课程!";
212
                     errMessage = "未找到课程!";
235
                     return false;
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
                 if (videoInfo.IsUpload)
216
                 if (videoInfo.IsUpload)
240
                 {
217
                 {
241
                     errMessage = "视频已上传";
218
                     errMessage = "视频已上传";
338
                             //{
315
                             //{
339
                             //    formFields.Add();
316
                             //    formFields.Add();
340
                             //}
317
                             //}
341
-                            JObject jo = ZHttpUtil.UploadRequestflow
342
-                            (
318
+                            JObject jo = ZHttpUtil.UploadFile(
343
                                 uploadUrl,
319
                                 uploadUrl,
344
                                 byteArray,
320
                                 byteArray,
345
                                 fileName,
321
                                 fileName,

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

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

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

2161
         /// <summary>
2161
         /// <summary>
2162
         /// 视频信息列表
2162
         /// 视频信息列表
2163
         /// </summary>
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
         #endregion 初始值
2166
         #endregion 初始值
2167
 
2167
 
2174
             //隐藏显示的控件
2174
             //隐藏显示的控件
2175
             if (_videoControlList.Count > 0)
2175
             if (_videoControlList.Count > 0)
2176
             {
2176
             {
2177
-                foreach (Uc_VideoItem item in _videoControlList)
2177
+                foreach (UcVideoItem item in _videoControlList)
2178
                 {
2178
                 {
2179
                     if (item.Visibility != Visibility.Hidden)
2179
                     if (item.Visibility != Visibility.Hidden)
2180
                     {
2180
                     {
2192
                 {
2192
                 {
2193
                     return;
2193
                     return;
2194
                 }
2194
                 }
2195
-                Uc_VideoItem videoItem;
2195
+                UcVideoItem videoItem;
2196
                 if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
2196
                 if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
2197
                 {
2197
                 {
2198
                     videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
2198
                     videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
2203
                     {
2203
                     {
2204
                         continue;
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
                     videoItem.Width = _controlWidth;
2209
                     videoItem.Width = _controlWidth;
2210
                     videoItem.Height = _controlHeight;
2210
                     videoItem.Height = _controlHeight;
2211
                     videoItem.HorizontalAlignment = HorizontalAlignment.Left;
2211
                     videoItem.HorizontalAlignment = HorizontalAlignment.Left;
2289
                 //隐藏显示的控件
2289
                 //隐藏显示的控件
2290
                 if (_videoControlList.Count > 0)
2290
                 if (_videoControlList.Count > 0)
2291
                 {
2291
                 {
2292
-                    foreach (Uc_VideoItem item in _videoControlList)
2292
+                    foreach (UcVideoItem item in _videoControlList)
2293
                     {
2293
                     {
2294
                         if (item.Visibility != Visibility.Hidden)
2294
                         if (item.Visibility != Visibility.Hidden)
2295
                         {
2295
                         {

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

1
 namespace Common.system
1
 namespace Common.system
2
 {
2
 {
3
     using Newtonsoft.Json.Linq;
3
     using Newtonsoft.Json.Linq;
4
+
4
     using System;
5
     using System;
5
     using System.Collections.Specialized;
6
     using System.Collections.Specialized;
6
     using System.IO;
7
     using System.IO;
18
         public static string version = "";
19
         public static string version = "";
19
         public static bool isSt;
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
             return true; //总是接受
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
             HttpWebRequest request;
35
             HttpWebRequest request;
38
             if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
36
             if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
51
             return request;
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
             for (int i = 0; i < 10; i++)
60
             for (int i = 0; i < 10; i++)
57
             {
61
             {
58
                 try
62
                 try
59
                 {
63
                 {
60
                     HttpWebRequest request = GetHttpWebRequest(downloadUrl);
64
                     HttpWebRequest request = GetHttpWebRequest(downloadUrl);
61
-                    InitRequest(ref request);
62
                     request.Accept = "text/json,*/*;q=0.5";
65
                     request.Accept = "text/json,*/*;q=0.5";
66
+                    request.AutomaticDecompression = DecompressionMethods.GZip;
63
                     request.AddRange(from, to);
67
                     request.AddRange(from, to);
64
                     request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
68
                     request.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7");
65
                     request.Headers.Add("Accept-Encoding", "gzip, deflate, x-gzip, identity; q=0.9");
69
                     request.Headers.Add("Accept-Encoding", "gzip, deflate, x-gzip, identity; q=0.9");
78
             throw new Exception("已断开网络!请检查网络连接后重试下载!");
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
         private static void AddHeader(HttpWebRequest webRequest)
85
         private static void AddHeader(HttpWebRequest webRequest)
110
         {
86
         {
111
             webRequest.Headers.Add("Xh-St", isSt ? "true" : "false");
87
             webRequest.Headers.Add("Xh-St", isSt ? "true" : "false");
126
         /// 调用Post接口
102
         /// 调用Post接口
127
         ///  </summary>
103
         ///  </summary>
128
         ///  <returns></returns>
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
             Stream responseStream = null;
113
             Stream responseStream = null;
132
             try
114
             try
135
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
117
                 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
136
                 webRequest.Method = "POST";
118
                 webRequest.Method = "POST";
137
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
119
                 webRequest.Accept = "text/html,application/xhtml+xml,*/*";
138
-                webRequest.ContentType = "application/json";
120
+                webRequest.ContentType = contentType + ";" + "UTF-8";
139
                 string aesPostData = postData;
121
                 string aesPostData = postData;
140
                 if (jm)
122
                 if (jm)
141
                 {
123
                 {
147
                 }
129
                 }
148
                 byte[] buffer = encoding.GetBytes(aesPostData);
130
                 byte[] buffer = encoding.GetBytes(aesPostData);
149
                 webRequest.ContentLength = buffer.Length;
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
                 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
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
                 responseStream = webResponse.GetResponseStream();
139
                 responseStream = webResponse.GetResponseStream();
160
                 if (responseStream == null) { return ""; }
140
                 if (responseStream == null) { return ""; }
161
                 using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
141
                 using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
200
             {
180
             {
201
                 try
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
                     return JsonHelper.JsonToObj<T>(respstr);
189
                     return JsonHelper.JsonToObj<T>(respstr);
205
                 }
190
                 }
206
                 catch (Exception)
191
                 catch (Exception)
211
             return default;
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
         /// <summary>
199
         /// <summary>
281
         /// HttpWebRequest 下载
200
         /// HttpWebRequest 下载
282
         /// </summary>
201
         /// </summary>
284
         /// <param name="filePath"></param>
203
         /// <param name="filePath"></param>
285
         /// <param name="header"></param>
204
         /// <param name="header"></param>
286
         /// <returns></returns>
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
             try
208
             try
295
             {
209
             {
302
                 httpWebRequest.AllowWriteStreamBuffering = false;
216
                 httpWebRequest.AllowWriteStreamBuffering = false;
303
                 //httpWebRequest.Timeout = 300000;
217
                 //httpWebRequest.Timeout = 300000;
304
                 httpWebRequest.ServicePoint.Expect100Continue = false;
218
                 httpWebRequest.ServicePoint.Expect100Continue = false;
305
-
306
                 WebHeaderCollection myWebHeaderCollection = httpWebRequest.Headers;
219
                 WebHeaderCollection myWebHeaderCollection = httpWebRequest.Headers;
307
                 //myWebHeaderCollection.Add("Accept", "*/*");
220
                 //myWebHeaderCollection.Add("Accept", "*/*");
308
                 if (header != "")
221
                 if (header != "")
309
                 {
222
                 {
310
                     myWebHeaderCollection.Add("access_token:" + header);
223
                     myWebHeaderCollection.Add("access_token:" + header);
311
                 }
224
                 }
312
-
313
                 HttpWebResponse webRespon = (HttpWebResponse)httpWebRequest.GetResponse();
225
                 HttpWebResponse webRespon = (HttpWebResponse)httpWebRequest.GetResponse();
314
                 Stream webStream = webRespon.GetResponseStream();
226
                 Stream webStream = webRespon.GetResponseStream();
315
                 if (webStream == null)
227
                 if (webStream == null)
316
                 {
228
                 {
317
                     return false;
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
                 byte[] bArr = new byte[1024];
237
                 byte[] bArr = new byte[1024];
321
                 int size = webStream.Read(bArr, 0, bArr.Length);
238
                 int size = webStream.Read(bArr, 0, bArr.Length);
322
                 while (size > 0)
239
                 while (size > 0)
345
         /// <param name="databyte">文件数据流</param>
262
         /// <param name="databyte">文件数据流</param>
346
         /// <param name="filename">文件名</param>
263
         /// <param name="filename">文件名</param>
347
         /// <param name="formFields">参数 可不传</param>
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
             // 时间戳,用做boundary
273
             // 时间戳,用做boundary
351
             string boundary = "-----" + DateTime.Now.Ticks.ToString("x");
274
             string boundary = "-----" + DateTime.Now.Ticks.ToString("x");
368
                 {
291
                 {
369
                     foreach (string key in formFields.Keys)
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
                         byte[] formitembytes = Encoding.UTF8.GetBytes(formitem);
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
                 const string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";
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
                 byte[] headerbytes = Encoding.UTF8.GetBytes(header);
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
                 byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
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
                 postStream.Close();
314
                 postStream.Close();
432
 
315
 
433
                 //获取服务器端的响应
316
                 //获取服务器端的响应
497
             }
380
             }
498
         }
381
         }
499
     }
382
     }
500
-}
383
+}

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

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

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

3
 using System;
3
 using System;
4
 using System.Diagnostics;
4
 using System.Diagnostics;
5
 using System.Windows;
5
 using System.Windows;
6
-using System.Windows.Controls;
7
 using System.Windows.Input;
6
 using System.Windows.Input;
8
-using System.Windows.Media;
9
 
7
 
10
 using XHWK.Model;
8
 using XHWK.Model;
11
 using XHWK.WKTool.DAL;
9
 using XHWK.WKTool.DAL;
17
     /// <summary>
15
     /// <summary>
18
     /// 视频信息
16
     /// 视频信息
19
     /// </summary>
17
     /// </summary>
20
-    public partial class Uc_VideoItem : UserControl
18
+    public partial class UcVideoItem
21
     {
19
     {
22
         #region 初始值
20
         #region 初始值
23
 
21
 
24
         /// <summary>
22
         /// <summary>
25
         /// 视频模型
23
         /// 视频模型
26
         /// </summary>
24
         /// </summary>
27
-        private ModelVideo VideoModel = new ModelVideo();
25
+        private ModelVideo _videoModel;
28
 
26
 
29
         /// <summary>
27
         /// <summary>
30
         /// 刷新视频列表
28
         /// 刷新视频列表
34
         /// <summary>
32
         /// <summary>
35
         /// 刷新视频列表事件
33
         /// 刷新视频列表事件
36
         /// </summary>
34
         /// </summary>
37
-        public event RefreshVideoList Click_refreshVideoList;
35
+        public event RefreshVideoList ClickRefreshVideoList;
38
 
36
 
39
         /// <summary>
37
         /// <summary>
40
         /// 登录
38
         /// 登录
44
         /// <summary>
42
         /// <summary>
45
         /// 登录事件
43
         /// 登录事件
46
         /// </summary>
44
         /// </summary>
47
-        public event UploadLogin Click_UploadLogin;
45
+        public event UploadLogin ClickUploadLogin;
48
 
46
 
49
         /// <summary>
47
         /// <summary>
50
         /// 上传页面
48
         /// 上传页面
51
         /// </summary>
49
         /// </summary>
52
-        private UploadWindow W_UploadWindow = null;
50
+        private UploadWindow _wUploadWindow;
53
 
51
 
54
         #endregion 初始值
52
         #endregion 初始值
55
 
53
 
58
         /// <summary>
56
         /// <summary>
59
         /// 视频信息
57
         /// 视频信息
60
         /// </summary>
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
             InitializeComponent();
62
             InitializeComponent();
65
             App.IsUpLoad = false;
63
             App.IsUpLoad = false;
66
-            VideoModel = model_Video;
64
+            _videoModel = modelVideo;
67
             DataContext = App.PageContextData;
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
             TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
71
             TbName.Text = videoName.Length > 11 ? videoName.Substring(0, 11) + "..." : videoName;
74
             TbName.ToolTip = videoName;
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
                 TxtModify.Text = TbName.ToolTip.ToString();
94
                 TxtModify.Text = TbName.ToolTip.ToString();
96
                 TbName.Visibility = Visibility.Hidden;
95
                 TbName.Visibility = Visibility.Hidden;
97
                 GridModify.Visibility = Visibility.Visible;
96
                 GridModify.Visibility = Visibility.Visible;
98
-                //BtnNameModifyOK.Visibility = Visibility.Visible;
99
             }
97
             }
100
         }
98
         }
101
 
99
 
139
         {
137
         {
140
             if (TxtModify.Text != TbName.Text)
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
                     TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
143
                     TbName.Text = TxtModify.Text.Length > 11 ? TxtModify.Text.Substring(0, 11) + "..." : TxtModify.Text;
146
                     TbName.ToolTip = TxtModify.Text;
144
                     TbName.ToolTip = TxtModify.Text;
147
                     TbName.Visibility = Visibility.Visible;
145
                     TbName.Visibility = Visibility.Visible;
148
                     GridModify.Visibility = Visibility.Hidden;
146
                     GridModify.Visibility = Visibility.Hidden;
149
-                    //BtnNameModifyOK.Visibility = Visibility.Hidden;
150
                 }
147
                 }
151
                 else
148
                 else
152
                 {
149
                 {
153
-                    MessageWindow.Show(ErrMessage);
150
+                    MessageWindow.Show(errMessage);
154
                 }
151
                 }
155
             }
152
             }
156
             else
153
             else
157
             {
154
             {
158
                 TbName.Visibility = Visibility.Visible;
155
                 TbName.Visibility = Visibility.Visible;
159
                 GridModify.Visibility = Visibility.Hidden;
156
                 GridModify.Visibility = Visibility.Hidden;
160
-                //BtnNameModifyOK.Visibility = Visibility.Hidden;
161
             }
157
             }
162
         }
158
         }
163
 
159
 
164
         /// <summary>
160
         /// <summary>
165
         /// 修改视频文件名
161
         /// 修改视频文件名
166
         /// </summary>
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
         /// <returns></returns>
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
                     string filePath = FileToolsCommon.GetDirectoryName(filePathName);
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
                     if (FileToolsCommon.IsExistFile(newFilePathName))
183
                     if (FileToolsCommon.IsExistFile(newFilePathName))
188
                     {
184
                     {
189
-                        Errmessage = "文件已存在,请重新修改文件名!";
185
+                        errmessage = "文件已存在,请重新修改文件名!";
190
                         return false;
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
             return false;
200
             return false;
212
         }
201
         }
213
 
202
 
231
                     {
220
                     {
232
                         continue;
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
                         try
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
                             ImgVideo.Source = null;
235
                             ImgVideo.Source = null;
244
                             GC.Collect();
236
                             GC.Collect();
245
-                            FileToolsCommon.DeleteFile(ThumbnailPath);
237
+                            FileToolsCommon.DeleteFile(thumbnailPath);
246
                             Visibility = Visibility.Hidden;
238
                             Visibility = Visibility.Hidden;
247
                             return;
239
                             return;
248
                         }
240
                         }
264
         {
256
         {
265
             try
257
             try
266
             {
258
             {
267
-                ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
259
+                ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
268
                 Process pro = new Process
260
                 Process pro = new Process
269
                 {
261
                 {
270
                     StartInfo = psi
262
                     StartInfo = psi
275
             {
267
             {
276
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
268
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
277
                 System.Windows.MessageBox.Show(ex.Message);
269
                 System.Windows.MessageBox.Show(ex.Message);
278
-                return;
279
             }
270
             }
280
         }
271
         }
281
 
272
 
288
         {
279
         {
289
             try
280
             try
290
             {
281
             {
291
-                ProcessStartInfo psi = new ProcessStartInfo(VideoModel.VideoPath);
282
+                ProcessStartInfo psi = new ProcessStartInfo(_videoModel.VideoPath);
292
                 Process pro = new Process
283
                 Process pro = new Process
293
                 {
284
                 {
294
                     StartInfo = psi
285
                     StartInfo = psi
299
             {
290
             {
300
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
291
                 LogHelper.Logerror.Error("【视频播放】(BtnVideoPlay_Click)" + ex.Message, ex);
301
                 System.Windows.MessageBox.Show(ex.Message);
292
                 System.Windows.MessageBox.Show(ex.Message);
302
-                return;
303
             }
293
             }
304
         }
294
         }
305
 
295
 
315
             if (App.IsLoginType == false)
305
             if (App.IsLoginType == false)
316
             {
306
             {
317
                 //登录
307
                 //登录
318
-                Click_UploadLogin();
308
+                if (ClickUploadLogin != null)
309
+                {
310
+                    ClickUploadLogin();
311
+                }
319
                 if (App.IsLoginType == false)
312
                 if (App.IsLoginType == false)
320
                 {
313
                 {
321
                     return;
314
                     return;
324
             if (!App.IsUpLoad)
317
             if (!App.IsUpLoad)
325
             {
318
             {
326
                 App.IsUpLoad = true;
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
                     App.IsUpLoad = false;
323
                     App.IsUpLoad = false;
334
                     //MessageWindow.Show("视频上传服务器成功!");
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
                     //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
331
                     //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
343
-                    W_UploadWindow.Initialize
344
-                    (
332
+                    _wUploadWindow.Initialize(
345
                         TbName.Text,
333
                         TbName.Text,
346
-                        VideoModel.VideoSizebyte,
347
-                        VideoModel.VideoType.ToString(),
348
-                        VideoModel.FileGuid,
334
+                        _videoModel.VideoSizebyte,
335
+                        _videoModel.VideoType.ToString(),
336
+                        _videoModel.FileGuid,
349
                         0
337
                         0
350
                     );
338
                     );
351
                 }
339
                 }
352
                 else
340
                 else
353
                 {
341
                 {
354
                     App.IsUpLoad = false;
342
                     App.IsUpLoad = false;
355
-                    MessageWindow.Show(ErrMessage);
343
+                    MessageWindow.Show(errMessage);
356
                 }
344
                 }
357
             }
345
             }
358
         }
346
         }
361
         /// 上传返回事件
349
         /// 上传返回事件
362
         /// </summary>
350
         /// </summary>
363
         /// <param name="text"></param>
351
         /// <param name="text"></param>
352
+        /// <param name="i"></param>
364
         private void frm_ChangeTextEvents(string text, int i)
353
         private void frm_ChangeTextEvents(string text, int i)
365
         {
354
         {
366
             if ("上传成功".Equals(text))
355
             if ("上传成功".Equals(text))
367
             {
356
             {
368
-                W_UploadWindow.Close();
369
-                //BorUploadBtn.Visibility = Visibility.Hidden;
357
+                _wUploadWindow.Close();
370
                 BtnUpload.IsEnabled = false;
358
                 BtnUpload.IsEnabled = false;
371
                 BtnUpload.Background.Opacity = 0.6;
359
                 BtnUpload.Background.Opacity = 0.6;
372
             }
360
             }
383
             {
371
             {
384
                 App.W_VideoClipWindow = new VideoClipWindow();
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
                 App.W_VideoClipWindow.ShowDialog();
376
                 App.W_VideoClipWindow.ShowDialog();
389
             }
377
             }

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

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

Loading…
Cancel
Save