123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using Common.system;
-
- using Newtonsoft.Json.Linq;
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace XHWK.WKTool.DAL
- {
- /// <summary>
- /// 上传相关方法
- /// 创建人:赵耀
- /// 创建时间:2020年9月4日
- /// </summary>
- public class DAL_Upload
- {
- string APIRequestAddress = FileToolsCommon.GetConfigValue("APIRequestAddress");
- string FileRequestAddress = FileToolsCommon.GetConfigValue("FileRequestAddress");
- string schoolfileRequestAddress = FileToolsCommon.GetConfigValue("schoolfileRequestAddress");
- /// <summary>
- /// 文件是否允许上传
- /// </summary>
- /// <param name="MD5">MD5</param>
- /// <param name="Message">错误消息</param>
- /// <returns></returns>
- public bool IsAllowUploaded(string MD5, out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- for (int num = 0; num < 5; num++)
- {
- try
- {
- JObject jo = HttpHelper.PostFunction(FileRequestAddress + @"/chunkdb/isexist", @"application/x-www-form-urlencoded", @"md5=" + MD5, "");
- //0成功,1失败
- if(jo["code"].ToString()=="0")
- {
- if (string.IsNullOrWhiteSpace(jo["obj"].ToString()))
- {
- //不存在 允许上传
- return true;
- }
- else
- {
- //已存在 不允许上传
- return false;
- }
- }
- else
- {
- Message=jo["msg"].ToString();
- return false;
- }
- }
- catch (Exception e)
- {
- Message = e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【文件是否存在】(IsUploaded):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return false;
- }
- /// <summary>
- /// 上报文件合并指令
- /// </summary>
- /// <param name="Savefolder">保存文件位置 学校id/resource</param>
- /// <param name="FileCode">文件唯一编号 Guid</param>
- /// <param name="Message">错误信息</param>
- /// <returns></returns>
- public bool ReportFileMerge(string Savefolder,string FileCode, out string Message)
- {
- Exception ex = null;
- Message = "";//请求重试5次 共5秒
- for (int num = 0; num < 5; num++)
- {
- try
- {
- JObject jo = HttpHelper.PostFunction(FileRequestAddress + @"/chunkdb/mergechunk", @"application/x-www-form-urlencoded", @"savefolder=" + Savefolder+ "&identifier="+ FileCode, "");
- //0成功,1失败
- if (jo["code"].ToString() == "0")
- {
- return true;
- }
- else
- {
- Message = jo["msg"].ToString();
- return false;
- }
- }
- catch (Exception e)
- {
- Message = e.Message;
- ex = e;
- Thread.Sleep(1000);
- }
- }
- string ErrMessage = "【上报合并文件】(ReportFileMerge):请求失败。" + Message;
- LogHelper.WriteErrLog(ErrMessage, ex);
- return false;
- }
- }
- }
|