星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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