Parcourir la source

zhao:增加视频上传

tags/录制修改前
耀 il y a 4 ans
Parent
révision
357f9eb7c0

+ 1
- 0
Common/Common.csproj Voir le fichier

@@ -134,6 +134,7 @@
134 134
     <Compile Include="system\LogHelper.cs" />
135 135
     <Compile Include="system\PrimaryScreen.cs" />
136 136
     <Compile Include="Properties\AssemblyInfo.cs" />
137
+    <Compile Include="system\QueueSync.cs" />
137 138
     <Compile Include="system\SplashScreen.cs" />
138 139
     <Compile Include="system\XmlUtilHelper.cs" />
139 140
   </ItemGroup>

+ 49
- 0
Common/system/FileToolsCommon.cs Voir le fichier

@@ -562,6 +562,43 @@ namespace Common.system
562 562
                 fs.Close();
563 563
             }
564 564
         }
565
+        /// <summary>
566
+        /// 读取大文件用,读取文件前面指定长度字节数
567
+        /// </summary>
568
+        /// <param name="filePath">文件路径</param>
569
+        /// <param name="Length">读取长度,单位字节</param>
570
+        /// <returns></returns>
571
+        public static byte[] ReadBigFile(string filePath, int Length)
572
+        {
573
+            FileStream stream = new FileStream(filePath, FileMode.Open);
574
+            byte[] buffer = new byte[Length];
575
+            //stream.Position = startIndex;
576
+            stream.Read(buffer, 0, Length);
577
+            stream.Close();
578
+            stream.Dispose();
579
+            return buffer;
580
+        }
581
+        /// <summary>
582
+        /// 读取指定长度的流
583
+        /// </summary>
584
+        /// <param name="filePath">文件位置</param>
585
+        /// <param name="startIndex">开始位置</param>
586
+        /// <param name="Length">长度</param>
587
+        /// <returns></returns>
588
+        public static byte[] ReadBigFileSpecifyLength(string filePath, long startIndex, int Length)
589
+        {
590
+            FileStream stream = new FileStream(filePath, FileMode.Open);
591
+            if (startIndex + Length + 1 > stream.Length)
592
+            {
593
+                Length = (int)(stream.Length - startIndex);
594
+            }
595
+            byte[] buffer = new byte[Length];
596
+            stream.Position = startIndex;
597
+            stream.Read(buffer, 0, Length);
598
+            stream.Close();
599
+            stream.Dispose();
600
+            return buffer;
601
+        }
565 602
         #endregion
566 603
 
567 604
         #region 将文件读取到字符串中
@@ -598,6 +635,18 @@ namespace Common.system
598 635
                 reader.Close();
599 636
             }
600 637
         }
638
+        /// <summary>
639
+        /// 读取大文件用,读取文件前面指定长度字节的字符串
640
+        /// </summary>
641
+        /// <param name="filePath">文件路径</param>
642
+        /// <param name="Length">读取长度,单位字节</param>
643
+        /// <returns></returns>
644
+        public static string ReadBigFileStr(string filePath, int Length)
645
+        {
646
+            byte[] buffer =ReadBigFile(filePath, Length);
647
+            return Encoding.Default.GetString(buffer);
648
+        }
649
+       
601 650
         #endregion
602 651
 
603 652
         #region 从文件的绝对路径中获取文件名( 包含扩展名 )

+ 354
- 17
Common/system/HttpHelper.cs Voir le fichier

@@ -1,5 +1,8 @@
1
-using System;
1
+using Newtonsoft.Json.Linq;
2
+
3
+using System;
2 4
 using System.Collections.Generic;
5
+using System.Collections.Specialized;
3 6
 using System.IO;
4 7
 using System.Net;
5 8
 using System.Net.Security;
@@ -109,7 +112,7 @@ namespace Common.system
109 112
         {
110 113
             try
111 114
             {
112
-                var request = GetHttpWebRequest(url);
115
+                HttpWebRequest request = GetHttpWebRequest(url);
113 116
                 if (request != null)
114 117
                 {
115 118
                     string retval = null;
@@ -117,7 +120,7 @@ namespace Common.system
117 120
                     request.Method = "POST";
118 121
                     request.ServicePoint.Expect100Continue = false;
119 122
                     request.ContentType = "application/json; charset=utf-8";
120
-                    request.Timeout = 800;
123
+                    request.Timeout = 5000;
121 124
                     var bytes = System.Text.UTF8Encoding.UTF8.GetBytes(data);
122 125
                     request.ContentLength = bytes.Length;
123 126
                     using (var stream = request.GetRequestStream())
@@ -163,7 +166,7 @@ namespace Common.system
163 166
                     string respstr = GetStreamReader(url, responseStream, requestStream, streamReader, webResponse, timeout, encode, postData, contentType);
164 167
                     return JsonHelper.JsonToObj<T>(respstr);
165 168
                 }
166
-                catch (Exception)
169
+                catch (Exception ex)
167 170
                 {
168 171
                 }
169 172
                 finally
@@ -193,20 +196,354 @@ namespace Common.system
193 196
         }
194 197
         private static string GetStreamReader(string url, Stream responseStream, Stream requestStream, StreamReader streamReader, WebResponse webResponse, int timeout, string encode, string postData, string contentType)
195 198
         {
196
-            byte[] data = Encoding.GetEncoding(encode).GetBytes(postData);
197
-            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
198
-            webRequest.Method = "POST";
199
-            webRequest.ContentType = contentType + ";" + encode;
200
-            webRequest.ContentLength = data.Length;
201
-            webRequest.Timeout = timeout;
202
-            requestStream = webRequest.GetRequestStream();
203
-            requestStream.Write(data, 0, data.Length);
204
-            webResponse = (HttpWebResponse)webRequest.GetResponse();
205
-            responseStream = webResponse.GetResponseStream();
206
-            if (responseStream == null) { return ""; }
207
-            streamReader = new StreamReader(responseStream, Encoding.GetEncoding(encode));
208
-            return streamReader.ReadToEnd();
199
+            try
200
+            {
201
+                byte[] data = Encoding.GetEncoding(encode).GetBytes(postData);
202
+                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
203
+                webRequest.Method = "POST";
204
+                webRequest.ContentType = contentType + ";" + encode;
205
+                webRequest.ContentLength = data.Length;
206
+                webRequest.Timeout = timeout;
207
+                requestStream = webRequest.GetRequestStream();
208
+                requestStream.Write(data, 0, data.Length);
209
+                webResponse = (HttpWebResponse)webRequest.GetResponse();
210
+                responseStream = webResponse.GetResponseStream();
211
+                if (responseStream == null) { return ""; }
212
+                streamReader = new StreamReader(responseStream, Encoding.GetEncoding(encode));
213
+                return streamReader.ReadToEnd();
214
+            }
215
+            catch (Exception ex)
216
+            {
217
+                return null;
218
+            }
209 219
         }
220
+        /// <summary>
221
+        /// Cookie
222
+        /// </summary>
223
+        public static CookieContainer cc = new CookieContainer();
224
+        /// <summary>
225
+        /// Get请求
226
+        /// </summary>
227
+        /// <param name="serviceaddress">请求地址</param>
228
+        /// <param name="strcontent">头</param>
229
+        /// <param name="contenttype">参数</param>
230
+        /// <param name="header">token</param>
231
+        /// <returns></returns>
232
+        public static JObject GetFunction(string serviceaddress, string strcontent, string contenttype, string header, int Timeout = 5000)
233
+        {
234
+            try
235
+            {
236
+                string serviceAddress = serviceaddress + strcontent;
237
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
238
+                WebHeaderCollection myWebHeaderCollection = request.Headers;
239
+                request.CookieContainer = cc;
240
+                if (header != "")
241
+                {
242
+                    myWebHeaderCollection.Add("access_token:" + header);
243
+                }
244
+
245
+                request.Method = "GET";
246
+                request.ContentType = contenttype;
247
+                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
248
+
249
+                string encoding = response.ContentEncoding;
250
+                if (encoding == null || encoding.Length < 1)
251
+                {
252
+                    encoding = "UTF-8"; //默认编码  
253
+                }
254
+                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
255
+                string retString = reader.ReadToEnd();
210 256
 
257
+                //解析josn
258
+                JObject jo = JObject.Parse(retString);
259
+                return jo;
260
+            }
261
+            catch (Exception)
262
+            {
263
+                return null;
264
+            }
265
+        }
266
+
267
+        /// <summary>
268
+        /// Post请求
269
+        /// </summary>
270
+        /// <param name="serviceaddress">请求地址</param>
271
+        /// <param name="contenttype">头 application/x-www-form-urlencoded</param>
272
+        /// <param name="strcontent">参数</param>
273
+        /// <param name="header">token</param>
274
+        /// <returns></returns>
275
+        public static JObject PostFunction(string serviceaddress, string contenttype, string strcontent, string header, int Timeout = 5000)
276
+        {
277
+            try
278
+            {
279
+                string serviceAddress = serviceaddress;
280
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
281
+                WebHeaderCollection myWebHeaderCollection = request.Headers;
282
+
283
+                request.CookieContainer = cc;
284
+                //myWebHeaderCollection.Add("Accept", "*/*");
285
+                if (header != "")
286
+                {
287
+                    myWebHeaderCollection.Add("access_token:" + header);
288
+                }
289
+                request.Timeout = Timeout;
290
+                request.Method = "POST";
291
+                request.ContentType = contenttype;
292
+
293
+                string strContent = strcontent;
294
+                using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
295
+                {
296
+                    dataStream.Write(strContent);
297
+                    dataStream.Close();
298
+                }
299
+                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
300
+                string encoding = response.ContentEncoding;
301
+                if (encoding == null || encoding.Length < 1)
302
+                {
303
+                    encoding = "UTF-8"; //默认编码  
304
+                }
305
+                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
306
+                string retString = reader.ReadToEnd();
307
+                retString = retString.Replace("\\r\\n", "");
308
+
309
+                //解析josn
310
+                JObject jo = JObject.Parse(retString);
311
+                return jo;
312
+            }
313
+            catch (Exception ex)
314
+            {
315
+                LogHelper.WriteErrLog("请求失败(若网络无问题,请重置winsock,解决方法:以管理员方式打开cmd执行 netsh winsock reset 后重启)", ex);
316
+                return null;
317
+            }
318
+
319
+        }
320
+
321
+        /// <summary>
322
+        ///  上传方法
323
+        /// </summary>
324
+        /// <param name="url">webapi地址</param>
325
+        /// <param name="files">本地文件路径,单文件默认为string[0]</param>
326
+        /// <param name="token"></param>
327
+        /// <param name="formFields">参数可不传</param>
328
+        /// <returns></returns>
329
+        public static JObject UploadFilesToRemoteUrl(string url, string[] files, string token, NameValueCollection formFields = null)
330
+        {
331
+            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
332
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
333
+            request.ContentType = "multipart/form-data; boundary=" +
334
+                                    boundary;
335
+            request.Method = "POST";
336
+            request.KeepAlive = true;
337
+
338
+            Stream memStream = new System.IO.MemoryStream();
339
+
340
+            var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
341
+                                                                    boundary + "\r\n");
342
+            var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
343
+                                                                        boundary + "--");
344
+            WebHeaderCollection myWebHeaderCollection = request.Headers;
345
+            request.CookieContainer = cc;
346
+            if (token != "")
347
+            {
348
+                myWebHeaderCollection.Add("access_token:" + token);
349
+            }
350
+
351
+            string formdataTemplate = "\r\n--" + boundary +
352
+                                        "\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";
353
+            if (formFields != null)
354
+            {
355
+                foreach (string key in formFields.Keys)
356
+                {
357
+                    string formitem = string.Format(formdataTemplate, key, formFields[key]);
358
+                    byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
359
+                    memStream.Write(formitembytes, 0, formitembytes.Length);
360
+                }
361
+            }
362
+
363
+            string headerTemplate =
364
+                "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
365
+                "Content-Type: application/octet-stream\r\n\r\n";
366
+
367
+            for (int i = 0; i < files.Length; i++)
368
+            {
369
+                memStream.Write(boundarybytes, 0, boundarybytes.Length);
370
+                var header = string.Format(headerTemplate, "file", files[i]);
371
+                var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
372
+
373
+                memStream.Write(headerbytes, 0, headerbytes.Length);
374
+
375
+                using (var fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read))
376
+                {
377
+                    var buffer = new byte[1024];
378
+                    var bytesRead = 0;
379
+                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
380
+                    {
381
+                        memStream.Write(buffer, 0, bytesRead);
382
+                    }
383
+                }
384
+            }
385
+
386
+            //memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
387
+            request.ContentLength = memStream.Length;
388
+
389
+            using (Stream requestStream = request.GetRequestStream())
390
+            {
391
+                memStream.Position = 0;
392
+                byte[] tempBuffer = new byte[memStream.Length];
393
+                memStream.Read(tempBuffer, 0, tempBuffer.Length);
394
+                memStream.Close();
395
+                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
396
+            }
397
+
398
+            using (var response = request.GetResponse())
399
+            {
400
+                Stream stream2 = response.GetResponseStream();
401
+                StreamReader reader2 = new StreamReader(stream2);
402
+                JObject a = JObject.Parse(reader2.ReadToEnd());
403
+                return a;
404
+            }
405
+        }
406
+
407
+        /// <summary>
408
+        /// HttpWebRequest 下载
409
+        /// </summary>
410
+        /// <param name="url">URI</param>
411
+        /// <returns></returns>
412
+        public static bool GetDataGetHtml(string url, string filePath, string header)
413
+        {
414
+            try
415
+            {
416
+                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
417
+
418
+                //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
419
+                httpWebRequest.Method = "GET";
420
+                //httpWebRequest.ContentType = "image/jpeg";
421
+                //对发送的数据不使用缓存
422
+                httpWebRequest.AllowWriteStreamBuffering = false;
423
+                //httpWebRequest.Timeout = 300000;
424
+                httpWebRequest.ServicePoint.Expect100Continue = false;
425
+
426
+                WebHeaderCollection myWebHeaderCollection = httpWebRequest.Headers;
427
+                //myWebHeaderCollection.Add("Accept", "*/*");
428
+                if (header != "")
429
+                {
430
+                    myWebHeaderCollection.Add("access_token:" + header);
431
+                }
432
+
433
+                HttpWebResponse webRespon = (HttpWebResponse)httpWebRequest.GetResponse();
434
+                Stream webStream = webRespon.GetResponseStream();
435
+                long length = webRespon.ContentLength;
436
+                if (webStream == null)
437
+                {
438
+                    return false;
439
+                }
440
+                int lengthint = Convert.ToInt32(length);
441
+                //int num = lengthint / 1024;
442
+                //int count = 0;
443
+                //M_DownloadInfo.totalCount = lengthint / 1024;
444
+                //M_DownloadInfo.downloadCount = 0;
445
+
446
+                Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
447
+                byte[] bArr = new byte[1024];
448
+                int size = webStream.Read(bArr, 0, bArr.Length);
449
+                while (size > 0)
450
+                {
451
+                    stream.Write(bArr, 0, size);
452
+                    size = webStream.Read(bArr, 0, bArr.Length);
453
+                    //M_DownloadInfo.downloadCount = M_DownloadInfo.downloadCount + 1;
454
+                }
455
+                webRespon.Close();
456
+                stream.Close();
457
+                webStream.Close();
458
+                return true;
459
+            }
460
+            catch (Exception ex)
461
+            {
462
+                //LogHelper.WriteErrLog("请求失败:" + ex.Message, ex);
463
+                return false;
464
+            }
465
+        }
466
+
467
+        /// <summary>
468
+        /// 上传文件流
469
+        /// 创建人:赵耀
470
+        /// 创建时间:2020年9月5日
471
+        /// </summary>
472
+        /// <param name="url">URL</param>
473
+        /// <param name="databyte">文件数据流</param>
474
+        /// <param name="filename">文件名</param>
475
+        /// <param name="formFields">参数 可不传</param>
476
+        public static JObject UploadRequestflow(string url, byte[] databyte, string filename, NameValueCollection formFields = null)
477
+        {
478
+            JObject jobResult = null;
479
+            // 时间戳,用做boundary
480
+            string boundary = "-----" + DateTime.Now.Ticks.ToString("x");
481
+            byte[] boundarybytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
482
+
483
+            //根据uri创建HttpWebRequest对象
484
+            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(url));
485
+            httpReq.ContentType = "multipart/form-data; boundary=" + boundary;
486
+            httpReq.Method = "POST";
487
+            httpReq.KeepAlive = true;
488
+            //httpReq.Timeout = 300000;
489
+            //httpReq.AllowWriteStreamBuffering = false; //对发送的数据不使用缓存
490
+            httpReq.Credentials = CredentialCache.DefaultCredentials;
491
+
492
+            try
493
+            {
494
+                Stream postStream = httpReq.GetRequestStream();
495
+                //参数
496
+                const string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
497
+                if (formFields != null)
498
+                {
499
+                    foreach (string key in formFields.Keys)
500
+                    {
501
+                        postStream.Write(boundarybytes, 0, boundarybytes.Length);
502
+                        string formitem = string.Format(formdataTemplate, key, formFields[key]);
503
+                        byte[] formitembytes = Encoding.UTF8.GetBytes(formitem);
504
+                        postStream.Write(formitembytes, 0, formitembytes.Length);
505
+                    }
506
+                }
507
+                postStream.Write(boundarybytes, 0, boundarybytes.Length);
508
+
509
+                const string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n";
510
+
511
+                //文件头
512
+                string header = string.Format(headerTemplate, "file", filename);
513
+                byte[] headerbytes = Encoding.UTF8.GetBytes(header);
514
+                postStream.Write(headerbytes, 0, headerbytes.Length);
515
+
516
+                //文件流
517
+                postStream.Write(databyte, 0, databyte.Length);
518
+
519
+                //结束边界
520
+                byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
521
+                postStream.Write(boundaryBytes, 0, boundaryBytes.Length);
522
+                postStream.Close();
523
+
524
+                //获取服务器端的响应
525
+                using (HttpWebResponse response = (HttpWebResponse)httpReq.GetResponse())
526
+                {
527
+                    Stream receiveStream = response.GetResponseStream();
528
+                    StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
529
+                    string returnValue = readStream.ReadToEnd();
530
+                    jobResult = JObject.Parse(returnValue);
531
+                    response.Close();
532
+                    readStream.Close();
533
+                    //MessageBox.Show(returnValue);
534
+                    LogHelper.WriteInfoLog("【文件上传】" + returnValue);
535
+                }
536
+                return jobResult;
537
+            }
538
+            catch (Exception ex)
539
+            {
540
+                LogHelper.WriteErrLog("【文件上传】" + ex.Message, ex);
541
+                return null;
542
+            }
543
+            finally
544
+            {
545
+                httpReq = null;
546
+            }
547
+        }
211 548
     }
212 549
 }

+ 1
- 0
Common/system/ImageHelper.cs Voir le fichier

@@ -364,6 +364,7 @@ namespace Common.system
364 364
             try
365 365
             {
366 366
                 System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
367
+                //在位图中呈现UI元素
367 368
                 RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, 96d, 96d,
368 369
                 PixelFormats.Pbgra32);
369 370
                 bmp.Render(ui);

+ 35
- 2
XHWK.Model/Model_Video.cs Voir le fichier

@@ -1,4 +1,6 @@
1
-namespace XHWK.Model
1
+using System.Collections.Generic;
2
+
3
+namespace XHWK.Model
2 4
 {
3 5
     /// <summary>
4 6
     /// 视频模型
@@ -11,6 +13,12 @@
11 13
         private Enum_WKVidetype _wkType;
12 14
         private string _RSTime;
13 15
         private string _videoSize;
16
+        private bool _IsUpload=false;
17
+        private string _FileGuid;//= System.Guid.NewGuid().ToString()
18
+        private string _FileMD5;
19
+        private string _Savefolder;
20
+        private int _Block;
21
+        private int _Uploaded;
14 22
         /// <summary>
15 23
         /// 视频路径
16 24
         /// </summary>
@@ -32,10 +40,35 @@
32 40
         /// </summary>
33 41
         public string RSTime { get => _RSTime; set => _RSTime = value; }
34 42
         /// <summary>
35
-        /// 视频大小
43
+        /// 视频大小MB
36 44
         /// </summary>
37 45
         public string VideoSize { get => _videoSize; set => _videoSize = value; }
46
+        /// <summary>
47
+        /// 是否已上传
48
+        /// </summary>
49
+        public bool IsUpload { get => _IsUpload; set => _IsUpload = value; }
50
+        /// <summary>
51
+        /// 文件唯一标示
52
+        /// </summary>
53
+        public string FileGuid { get => _FileGuid; set => _FileGuid = value; }
54
+        /// <summary>
55
+        /// 文件MD5
56
+        /// </summary>
57
+        public string FileMD5 { get => _FileMD5; set => _FileMD5 = value; }
58
+        /// <summary>
59
+        /// 文件保存地址 学校id/resource
60
+        /// </summary>
61
+        public string Savefolder { get => _Savefolder; set => _Savefolder = value; }
62
+        /// <summary>
63
+        /// 分块 每块最大5M
64
+        /// </summary>
65
+        public int Block { get => _Block; set => _Block = value; }
66
+        /// <summary>
67
+        /// 当前已上传到第几块
68
+        /// </summary>
69
+        public int Uploaded { get => _Uploaded; set => _Uploaded = value; }
38 70
     }
71
+
39 72
     /// <summary>
40 73
     /// 视频格式类型
41 74
     /// </summary>

+ 10
- 0
XHWK.WKTool/App.config Voir le fichier

@@ -18,5 +18,15 @@
18 18
     <add key="userName" value="" />
19 19
     <!--记住密码-->
20 20
     <add key="isRemind" value="" />
21
+    <!--API请求地址-->
22
+    <add key="APIRequestAddress" value="https://schoolapitest.xhkjedu.com"/>
23
+    <!--文件平台请求地址-->
24
+    <add key="FileRequestAddress" value="https://schoolfiletest.xhkjedu.com"/>
25
+    <!--<add key="FileRequestAddress" value="http://192.168.2.18:8908"/>-->
26
+    <!--展示文件服务器请求地址-->
27
+    <add key="schoolfileRequestAddress" value="https://schoolfiletest.xhkjedu.com"/>
28
+    <!--接口地址: https://schoolapitest.xhkjedu.com/
29
+    文件上传: https://schoolfiletest.xhkjedu.com/
30
+    展示文件:   https://schoolfiletest.xhkjedu.com/-->
21 31
   </appSettings>
22 32
 </configuration>

+ 4
- 0
XHWK.WKTool/App.cs Voir le fichier

@@ -108,6 +108,10 @@ namespace XHWK.WKTool
108 108
         /// 批注
109 109
         /// </summary>
110 110
         public static PracticeWindow W_PracticeWindow = null;
111
+        /// <summary>
112
+        /// 我的视频
113
+        /// </summary>
114
+        public static FileDirectoryWindow fileDirectoryWindow = null;
111 115
         #endregion
112 116
         #endregion
113 117
 

+ 109
- 0
XHWK.WKTool/DAL/DAL_Upload.cs Voir le fichier

@@ -0,0 +1,109 @@
1
+using Common.system;
2
+
3
+using Newtonsoft.Json.Linq;
4
+
5
+using System;
6
+using System.Collections.Generic;
7
+using System.Linq;
8
+using System.Text;
9
+using System.Threading;
10
+using System.Threading.Tasks;
11
+
12
+namespace XHWK.WKTool.DAL
13
+{
14
+    /// <summary>
15
+    /// 上传相关方法
16
+    /// 创建人:赵耀
17
+    /// 创建时间:2020年9月4日
18
+    /// </summary>
19
+    public class DAL_Upload
20
+    {
21
+        string APIRequestAddress = FileToolsCommon.GetConfigValue("APIRequestAddress");
22
+        string FileRequestAddress = FileToolsCommon.GetConfigValue("FileRequestAddress");
23
+        string schoolfileRequestAddress = FileToolsCommon.GetConfigValue("schoolfileRequestAddress");
24
+        /// <summary>
25
+        /// 文件是否允许上传
26
+        /// </summary>
27
+        /// <param name="MD5">MD5</param>
28
+        /// <param name="Message">错误消息</param>
29
+        /// <returns></returns>
30
+        public bool IsAllowUploaded(string MD5, out string Message)
31
+        {
32
+            Exception ex = null;
33
+            Message = "";//请求重试5次 共5秒
34
+            for (int num = 0; num < 5; num++)
35
+            {
36
+                try
37
+                {
38
+                    JObject jo = HttpHelper.PostFunction(FileRequestAddress + @"/chunkdb/isexist", @"application/x-www-form-urlencoded", @"md5=" + MD5, "");
39
+                    //0成功,1失败
40
+                    if(jo["code"].ToString()=="0")
41
+                    {
42
+                        if (string.IsNullOrWhiteSpace(jo["obj"].ToString()))
43
+                        {
44
+                            //不存在 允许上传
45
+                            return true;
46
+                        }
47
+                        else
48
+                        {
49
+                            //已存在 不允许上传
50
+                            return false;
51
+                        }
52
+                    }
53
+                    else
54
+                    {
55
+                        Message=jo["msg"].ToString();
56
+                        return false;
57
+                    }
58
+                }
59
+                catch (Exception e)
60
+                {
61
+                    Message = e.Message;
62
+                    ex = e;
63
+                    Thread.Sleep(1000);
64
+                }
65
+            }
66
+            string ErrMessage = "【文件是否存在】(IsUploaded):请求失败。" + Message;
67
+            LogHelper.WriteErrLog(ErrMessage, ex);
68
+            return false;
69
+        }
70
+        /// <summary>
71
+        /// 上报文件合并指令
72
+        /// </summary>
73
+        /// <param name="Savefolder">保存文件位置  学校id/resource</param>
74
+        /// <param name="FileCode">文件唯一编号 Guid</param>
75
+        /// <param name="Message">错误信息</param>
76
+        /// <returns></returns>
77
+        public bool ReportFileMerge(string Savefolder,string FileCode, out string Message)
78
+        {
79
+            Exception ex = null;
80
+            Message = "";//请求重试5次 共5秒
81
+            for (int num = 0; num < 5; num++)
82
+            {
83
+                try
84
+                {
85
+                    JObject jo = HttpHelper.PostFunction(FileRequestAddress + @"/chunkdb/mergechunk", @"application/x-www-form-urlencoded", @"savefolder=" + Savefolder+ "&identifier="+ FileCode, "");
86
+                    //0成功,1失败
87
+                    if (jo["code"].ToString() == "0")
88
+                    {
89
+                        return true;
90
+                    }
91
+                    else
92
+                    {
93
+                        Message = jo["msg"].ToString();
94
+                        return false;
95
+                    }
96
+                }
97
+                catch (Exception e)
98
+                {
99
+                    Message = e.Message;
100
+                    ex = e;
101
+                    Thread.Sleep(1000);
102
+                }
103
+            }
104
+            string ErrMessage = "【上报合并文件】(ReportFileMerge):请求失败。" + Message;
105
+            LogHelper.WriteErrLog(ErrMessage, ex);
106
+            return false;
107
+        }
108
+    }
109
+}

+ 4
- 2
XHWK.WKTool/DAL/Interface.cs Voir le fichier

@@ -10,7 +10,9 @@ namespace XHWK.WKTool.DAL
10 10
 {
11 11
     public class Interface
12 12
     {
13
- 
13
+        string APIRequestAddress = FileToolsCommon.GetConfigValue("APIRequestAddress");
14
+        string FileRequestAddress = FileToolsCommon.GetConfigValue("FileRequestAddress");
15
+        string schoolfileRequestAddress = FileToolsCommon.GetConfigValue("schoolfileRequestAddress");
14 16
         /// <summary>
15 17
         /// 登陆
16 18
         /// </summary>
@@ -18,7 +20,7 @@ namespace XHWK.WKTool.DAL
18 20
         /// <returns></returns>
19 21
         public int Login(string loginname, string loginpwd)
20 22
         {
21
-            string url = "http://schoolapi.xhkjedu.com/user/login";//地址
23
+            string url = APIRequestAddress + "/user/login";//地址
22 24
             Dictionary<string, object> dic = new Dictionary<string, object>
23 25
             {
24 26
                 { "loginname", loginname},

+ 49
- 1
XHWK.WKTool/FileDirectoryWindow.xaml.cs Voir le fichier

@@ -1,5 +1,8 @@
1
-using System.Windows;
1
+using Org.BouncyCastle.Asn1.Crmf;
2
+using System.Collections.Generic;
3
+using System.Windows;
2 4
 using System.Windows.Input;
5
+using XHWK.Model;
3 6
 
4 7
 namespace XHWK.WKTool
5 8
 {
@@ -8,12 +11,57 @@ namespace XHWK.WKTool
8 11
     /// </summary>
9 12
     public partial class FileDirectoryWindow : Window
10 13
     {
14
+        /// <summary>
15
+        /// 视频模型
16
+        /// </summary>
17
+        List<Model_Video> model_VideoList =null;
11 18
         /// <summary>
12 19
         /// 文件目录
13 20
         /// </summary>
14 21
         public FileDirectoryWindow()
15 22
         {
16 23
             InitializeComponent();
24
+            Initialize();
25
+        } 
26
+        /// <summary>
27
+        /// 初始化
28
+        /// </summary>
29
+        public void Initialize()
30
+        {
31
+            //加载视频列表
32
+            LoadingVideoList();
33
+            //显示视频
34
+            foreach (Model_Video videoinfo in model_VideoList)
35
+            {
36
+                //是否已上传
37
+                //videoinfo.IsUpload;
38
+                //录制时间
39
+                //videoinfo.RSTime;
40
+                //文件大小
41
+                //videoinfo.VideoSize;
42
+                //文件缩略图路径
43
+                //videoinfo.ThumbnailPath;
44
+                //文件唯一标示 上传事件筛选需要上传的视频
45
+                //videoinfo.FileGuid;
46
+                //文件存储路径
47
+                //videoinfo.VidePath;
48
+            }
49
+        }
50
+        /// <summary>
51
+        /// 加载视频列表
52
+        /// </summary>
53
+        public void LoadingVideoList()
54
+        {
55
+            model_VideoList = new List<Model_Video>();
56
+            foreach(Model_WKData Vdata in APP.WKDataList)
57
+            {
58
+                if (Vdata.VideoList == null)
59
+                    continue;
60
+                foreach(Model_Video videoinfo in Vdata.VideoList)
61
+                {
62
+                    model_VideoList.Add(videoinfo);
63
+                }
64
+            }
17 65
         }
18 66
         /// <summary>
19 67
         /// 关闭

+ 76
- 28
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Voir le fichier

@@ -19,6 +19,9 @@ using Aspose.Slides;
19 19
 using static Common.system.PdfTrunImage;
20 20
 using TStudyDigitalPen.HID;
21 21
 using System.Drawing;
22
+using XHWK.WKTool.DAL;
23
+using System.Text;
24
+using System.Collections.Specialized;
22 25
 
23 26
 namespace XHWK.WKTool
24 27
 {
@@ -47,7 +50,7 @@ namespace XHWK.WKTool
47 50
         /// <summary>
48 51
         /// 图片
49 52
         /// </summary>
50
-        string [] ImgPDFPath = new string[300]; 
53
+        string[] ImgPDFPath = new string[300];
51 54
         #endregion
52 55
 
53 56
         #region 初始化
@@ -82,7 +85,6 @@ namespace XHWK.WKTool
82 85
         /// </summary>
83 86
         public void Initialize()
84 87
         {
85
-
86 88
             //创建 DrawingAttributes 类的一个实例  
87 89
             drawingAttributes = new DrawingAttributes();
88 90
             //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用  
@@ -154,7 +156,7 @@ namespace XHWK.WKTool
154 156
                 {
155 157
                     Dispatcher.Invoke(() =>
156 158
                     {
157
-                        if(I>10010)
159
+                        if (I > 10010)
158 160
                         {
159 161
                             long time = Timestamp();
160 162
                             //string FilePathName = ImgPath + RsImgName.Count + ".png";
@@ -185,7 +187,7 @@ namespace XHWK.WKTool
185 187
             imgPlayer.Visibility = Visibility.Hidden;
186 188
             CameraHelper.CloseDevice();
187 189
             I = 9999;
188
-        } 
190
+        }
189 191
         #endregion
190 192
         #endregion
191 193
         /// <summary>
@@ -233,8 +235,54 @@ namespace XHWK.WKTool
233 235
                 Login();
234 236
                 return;
235 237
             }
236
-            FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
237
-            fileDirectoryWindow.Show();
238
+            APP.fileDirectoryWindow = new FileDirectoryWindow();
239
+            APP.fileDirectoryWindow.Show();
240
+
241
+            #region 测试上传
242
+            //string path = "E:/临时文件/test.txt";
243
+            //string newpath = "E:/临时文件/test1.txt";
244
+            //string identifier = Guid.NewGuid().ToString();
245
+            //FileToolsCommon.CreateFile(newpath);
246
+            //DAL_Upload DU = new DAL_Upload();
247
+            //string FileRequestAddress = FileToolsCommon.GetConfigValue("FileRequestAddress");
248
+            //string url = FileRequestAddress+"/chunkdb/upchunk";
249
+            ////是否可以上传
250
+            //if (DU.IsAllowUploaded("TestABC", out string ErrMessage))
251
+            //{
252
+            //    long len = 0;
253
+            //    long filelen = 0;
254
+            //    //文件总长度
255
+            //    using (FileStream stream = new FileStream(path, FileMode.Open))
256
+            //    {
257
+            //        filelen = stream.Length;
258
+            //    }
259
+            //    //分块
260
+            //    for (int i = 0; len + 102400 < filelen; i++)
261
+            //    {
262
+            //        len = i * 102400;
263
+            //        //取指定长度的流
264
+            //        byte[] byteArray = FileToolsCommon.ReadBigFileSpecifyLength(path, len, 102400);
265
+            //        //参数
266
+            //        NameValueCollection formFields = new NameValueCollection();
267
+            //        formFields.Add("identifier", identifier);
268
+            //        formFields.Add("chunkNumber", (i + 1).ToString());
269
+            //        formFields.Add("filename", "test.txt");
270
+            //        formFields.Add("totalchunk", "13");
271
+            //        formFields.Add("md5", "TestABC");
272
+            //        HttpHelper.UploadRequestflow(url, byteArray, "test.txt", formFields);
273
+            //    }
274
+            //    //
275
+            //    bool isres=DU.ReportFileMerge(APP.UserInfo.Schoolid.ToString() + "/resource", identifier, out string Message);
276
+            //    if(!isres)
277
+            //    {
278
+            //        System.Windows.MessageBox.Show(Message);
279
+            //    }
280
+            //}
281
+            //else
282
+            //{
283
+            //    System.Windows.MessageBox.Show(ErrMessage);
284
+            //}
285
+            #endregion
238 286
         }
239 287
         /// <summary>
240 288
         /// 关闭事件
@@ -535,10 +583,10 @@ namespace XHWK.WKTool
535 583
         {
536 584
             if ("关闭窗口".Equals(text))
537 585
             {
538
-                if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
586
+                if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
539 587
                 {
540
-                    APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
541
-                    if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
588
+                    APP.JPaths[APP.pageData.currpage] = APP.ImgPath;
589
+                    if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
542 590
                     {
543 591
                         imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
544 592
                     }
@@ -717,7 +765,7 @@ namespace XHWK.WKTool
717 765
                         }
718 766
                     }
719 767
 
720
-              
768
+
721 769
                 }
722 770
             }
723 771
         }
@@ -819,7 +867,7 @@ namespace XHWK.WKTool
819 867
                     FileToolsCommon.CreateDirectory(AudioPathName);
820 868
                     AudioPathName += APP.WKData.WkName + ".MP3";
821 869
                     VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
822
-                    
870
+
823 871
                     if (FileToolsCommon.IsExistFile(VideoSavePathName))
824 872
                     {
825 873
                         MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
@@ -1083,18 +1131,18 @@ namespace XHWK.WKTool
1083 1131
             int pr = 1;
1084 1132
             string msg = string.Empty;
1085 1133
             string outPut = string.Empty;
1086
-            LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
1087
-            if(pr==0)
1134
+            LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF", out pr, out msg, out outPut);
1135
+            if (pr == 0)
1088 1136
             {
1089
-                outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
1137
+                outPut = outPut.Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
1090 1138
                 APP.OutPut = outPut.Split(',');
1091 1139
                 string defa = string.Empty;
1092
-             List<string>defaList=   LatticeFileHelper.GetPrinterList(out defa);
1140
+                List<string> defaList = LatticeFileHelper.GetPrinterList(out defa);
1093 1141
 
1094 1142
                 int printResult = 1;
1095 1143
                 string standardError = string.Empty;
1096 1144
                 string standardOutput = string.Empty;
1097
-                LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
1145
+                LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF", 1, /*defa*/"导出为WPS PDF", out printResult, out standardError, out standardOutput);
1098 1146
 
1099 1147
             }
1100 1148
         }
@@ -1139,7 +1187,7 @@ namespace XHWK.WKTool
1139 1187
                 myblackboard.changepage(APP.pageData.currpage - 1);
1140 1188
                 if (APP.Paths.Length > 0)
1141 1189
                 {
1142
-                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
1190
+                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length && APP.pageData.currpage > 0)
1143 1191
                     {
1144 1192
                         imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
1145 1193
                     }
@@ -1183,10 +1231,10 @@ namespace XHWK.WKTool
1183 1231
                 myblackboard.changepage(APP.pageData.currpage - 1);
1184 1232
                 if (APP.Paths.Length > 0)
1185 1233
                 {
1186
-                  
1234
+
1187 1235
                     if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
1188 1236
                     {
1189
-                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
1237
+                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
1190 1238
                     }
1191 1239
                     else
1192 1240
                     {
@@ -1502,7 +1550,7 @@ namespace XHWK.WKTool
1502 1550
             {
1503 1551
                 myblackboard.changepages(0, 0, true);
1504 1552
             }));
1505
-          
1553
+
1506 1554
         }
1507 1555
 
1508 1556
         /// <summary>
@@ -1522,7 +1570,7 @@ namespace XHWK.WKTool
1522 1570
             {
1523 1571
                 APP.PenSerial = penSerial;
1524 1572
                 APP.PenStatus = false;
1525
-           
1573
+
1526 1574
                 Dispatcher.Invoke(new Action(() =>
1527 1575
                 {
1528 1576
                     txbNotConnected.Text = "未连接";
@@ -1559,7 +1607,7 @@ namespace XHWK.WKTool
1559 1607
                     txbNotConnected.Text = "已连接";
1560 1608
                     txbNotConnecteds.Text = "已连接";
1561 1609
                 }));
1562
-              
1610
+
1563 1611
             }
1564 1612
         }
1565 1613
         /// <summary>
@@ -1631,16 +1679,16 @@ namespace XHWK.WKTool
1631 1679
                 double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
1632 1680
                 double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
1633 1681
                 //点
1634
-                double testX=(double)cx * PropW;
1635
-                double testY=(double)cy * PropH;
1682
+                double testX = (double)cx * PropW;
1683
+                double testY = (double)cy * PropH;
1636 1684
                 //pageSerial //点阵IP地址  与打印的页面关联
1637 1685
 
1638 1686
                 Dispatcher.Invoke(new Action(() =>
1639 1687
                 {
1640
-                    myblackboard.changepages(testX, testY,false);
1688
+                    myblackboard.changepages(testX, testY, false);
1641 1689
                 }));
1642 1690
 
1643
-             
1691
+
1644 1692
                 ////每3个点画一条曲线
1645 1693
                 //if (stroke.Count % 3 == 0)
1646 1694
                 //{
@@ -1712,8 +1760,8 @@ namespace XHWK.WKTool
1712 1760
         /// <param name="e"></param>
1713 1761
         private void BtnShrink_Click(object sender, RoutedEventArgs e)
1714 1762
         {
1715
-            if(Visibility== Visibility.Hidden)
1716
-            Visibility = Visibility.Visible;
1763
+            if (Visibility == Visibility.Hidden)
1764
+                Visibility = Visibility.Visible;
1717 1765
             else
1718 1766
                 Visibility = Visibility.Hidden;
1719 1767
         }

+ 5
- 0
XHWK.WKTool/XHWK.WKTool.csproj Voir le fichier

@@ -68,6 +68,10 @@
68 68
     <Reference Include="log4net">
69 69
       <HintPath>..\Common\dlls\log4net.dll</HintPath>
70 70
     </Reference>
71
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
72
+      <SpecificVersion>False</SpecificVersion>
73
+      <HintPath>..\Common\dlls\Newtonsoft.Json.dll</HintPath>
74
+    </Reference>
71 75
     <Reference Include="System" />
72 76
     <Reference Include="System.Configuration" />
73 77
     <Reference Include="System.Data" />
@@ -113,6 +117,7 @@
113 117
     <Compile Include="CountdownWindow.xaml.cs">
114 118
       <DependentUpon>CountdownWindow.xaml</DependentUpon>
115 119
     </Compile>
120
+    <Compile Include="DAL\DAL_Upload.cs" />
116 121
     <Compile Include="DAL\Interface.cs" />
117 122
     <Compile Include="DAL\ResultVo.cs" />
118 123
     <Compile Include="FileDirectoryWindow.xaml.cs">

Chargement…
Annuler
Enregistrer