UpLoadFileRequest.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /* ==============================================================================
  2. * 功能描述:UpLoadFileRequest
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/3/23 15:19:52
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Text;
  13. using System.Windows;
  14. using SAGA.MBI.Common;
  15. using Utilities;
  16. using Aliyun.OSS;
  17. using Aliyun.OSS.Common;
  18. using Newtonsoft.Json.Linq;
  19. using SAGA.DotNetUtils;
  20. using SAGA.DotNetUtils.Encrypt;
  21. using SAGA.DotNetUtils.Extend;
  22. using SAGA.DotNetUtils.FileOperate;
  23. using SAGA.DotNetUtils.Http;
  24. using SAGA.DotNetUtils.Logger;
  25. using SAGA.DotNetUtils.Others;
  26. using SAGA.MBI.DataArrange;
  27. using SAGA.MBI.FileStream;
  28. using SAGA.MBI.JsonConvert;
  29. using SAGA.MBI.Login;
  30. using SAGA.MBI.Tools;
  31. using SAGA.RevitUtils;
  32. namespace SAGA.MBI.RequestData
  33. {
  34. /// <summary>
  35. /// UpLoadFileRequest
  36. /// </summary>
  37. public class UpLoadFileRequest
  38. {
  39. #region Download
  40. /// <summary>
  41. /// 下载指定文件到指定
  42. /// </summary>
  43. /// <param name="downPath"></param>
  44. /// <param name="fileName"></param>
  45. /// <returns></returns>
  46. public static bool DownLoadRevitFile(string downPath, string fileName)
  47. {
  48. try
  49. {
  50. if (!Directory.Exists(downPath))
  51. Directory.CreateDirectory(downPath);
  52. var filePath = Path.Combine(downPath, fileName);
  53. //如果文件存在,删除重新下载
  54. File.Delete(filePath);
  55. //文件下载
  56. var url =
  57. $"{MBIConst.ImageServiceLocalHost}image-service/common/file_get/{fileName}?systemId={MBIConst.RevitServiceId}";
  58. WebClient wc = new WebClient();
  59. wc.Headers.Add("postman-token", "8efb60cb-a34c-592e-6e61-5412b1dfc1bb");
  60. wc.Headers.Add("cache-control", "no-cache");
  61. wc.DownloadFile(new Uri(url), filePath);
  62. wc.Dispose();
  63. }
  64. catch (Exception e)
  65. {
  66. Console.WriteLine(e);
  67. return false;
  68. }
  69. finally
  70. {
  71. }
  72. return true;
  73. }
  74. #endregion
  75. #region DownLoadAsync
  76. private static WinMFMDownloadProcress windown = null;
  77. /// <summary>
  78. /// 显示下载窗体
  79. /// </summary>
  80. public static void ShowDownloadWindow(string floorName, string fullPath, int count, int cur)
  81. {
  82. if (windown == null)
  83. {
  84. windown = new WinMFMDownloadProcress();
  85. windown.Show();
  86. }
  87. windown.LabelFloorName = $"正在下载{floorName}层模型文件,请稍后。。。";
  88. windown.LabelPath = fullPath;
  89. windown.Count = count;
  90. windown.Cur = cur;
  91. }
  92. /// <summary>
  93. /// 下载指定文件到指定
  94. /// </summary>
  95. /// <param name="downPath"></param>
  96. /// <param name="fileName"></param>
  97. /// <returns></returns>
  98. public static bool DownLoadFileAsync(Tuple<string, int, string> tuple, int count, int cur)
  99. {
  100. bool result = true;
  101. string fullPath = tuple.Item1;
  102. string floorName = tuple.Item3;
  103. string cloudName = CommonTool.GetCloudRevitName(fullPath);
  104. int state = tuple.Item2;
  105. if (state == 2)
  106. FloorFileOperate.BakFile(fullPath);
  107. string key = $"{MBIConst.OssClientFileKey}{cloudName}";
  108. OssClient client = new OssClient(MBIConst.Endpoint, MBIConst.AccessKeyId, MBIConst.AccessKeySecret);
  109. int timeoutNum = 20;
  110. long totalLength = 0;
  111. try
  112. {
  113. string bucketName = MBIConst.BucketName;
  114. ShowDownloadWindow(tuple.Item3, fullPath, count, cur);
  115. var getObjectRequest = new GetObjectRequest(bucketName, key);
  116. //getObjectRequest.StreamTransferProgress += DownStreamProgressCallback;
  117. var buffer = new byte[1024 * 1024];
  118. long stargIndex = 0;
  119. getObjectRequest.StreamTransferProgress += (s, args) =>
  120. {
  121. var tempTrans = stargIndex + args.TransferredBytes;
  122. var tempTotal = stargIndex + args.TotalBytes;
  123. var currentData = Math.Round(((double)tempTrans)/ tempTotal *100d, 3);
  124. Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
  125. Math.Round(tempTotal / 1024d / 1024,3), Math.Round(tempTrans / 1024d / 1024,3), currentData);
  126. windown?.Update(currentData);
  127. if (currentData >= 100d && windown.Count == windown.Cur)
  128. {
  129. //MessageBox.Show("数据上传完毕!");
  130. CloseDownloadWin(true, false);
  131. }
  132. };
  133. using (var fs = new MemoryStream())
  134. {
  135. ReDownload:
  136. getObjectRequest.SetRange(stargIndex, -1);
  137. OssObject ossObject = client.GetObject(getObjectRequest);
  138. //设置下载超时时间
  139. ossObject.ResponseStream.ReadTimeout = 60 * 1000;//*20;
  140. if (totalLength == 0)
  141. {
  142. totalLength = ossObject.ContentLength;
  143. }
  144. using (var stream = ossObject.Content)
  145. {
  146. var bytesRead = 0;
  147. try
  148. {
  149. while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
  150. {
  151. fs.Write(buffer, 0, bytesRead);
  152. }
  153. }
  154. catch (WebException e)
  155. {
  156. #region 超时重试
  157. timeoutNum--;
  158. if (0 < timeoutNum && e.Message.Contains("超时"))
  159. {
  160. stargIndex = fs.Length;
  161. goto ReDownload;
  162. }
  163. throw;
  164. #endregion
  165. }
  166. if (fs.Length < totalLength)
  167. {
  168. stargIndex = fs.Length;
  169. goto ReDownload;
  170. }
  171. }
  172. FileStreamOperate.WriteFile(fs.ToArray(), fullPath);
  173. #region 下载后Md5较验
  174. string md5 = MD5Tools.GetMD5HashFromFileByBase64(fullPath);
  175. //下载后的文件md5校验
  176. if (client.GetObjectMetadata(bucketName, key).ContentMd5 != md5)
  177. {
  178. string per =Math.Round((fs.Length / (double)totalLength) * 100,3) + "%";
  179. string errorMessage = ($"楼层 {floorName} MD5校验失败,本地与服务器不一致!下载进度{per}");
  180. MailLog.Log("下载MD5异常", errorMessage);
  181. MessageShowBase.Infomation(errorMessage);
  182. result = false;
  183. }
  184. #endregion
  185. }
  186. Log4Net.Debug($"Get object:{key} succeeded");
  187. }
  188. catch (Exception ex)
  189. {
  190. MessageShowBase.Infomation("Revit文件下载失败!\r\n"+ex.Message+"\r\n"+ex.StackTrace);
  191. result = false;
  192. CloseDownloadWin(result,false);
  193. }
  194. return result;
  195. }
  196. /// <summary>
  197. /// 下载进度条
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="args"></param>
  201. private static void DownStreamProgressCallback(object sender, StreamTransferProgressArgs args)
  202. {
  203. try
  204. {
  205. var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
  206. Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
  207. args.TotalBytes / 1024 / 1024, args.TransferredBytes / 1024 / 1024, currentData);
  208. windown?.Update(currentData);
  209. if (currentData >= 100d && windown.Count == windown.Cur)
  210. {
  211. //MessageBox.Show("数据上传完毕!");
  212. CloseDownloadWin(true, false);
  213. }
  214. }
  215. catch (Exception ex)
  216. {
  217. throw;
  218. }
  219. }
  220. /// <summary>
  221. /// 关闭下载窗口
  222. /// </summary>
  223. public static void CloseDownloadWin(bool issucess, bool hasTip = true)
  224. {
  225. if (windown != null)
  226. {
  227. windown?.Close();
  228. windown = null;
  229. }
  230. if (hasTip)
  231. MessageShowBase.Infomation(issucess ? "Revit模型文件下载成功!" : "Revit模型文件下载失败!");
  232. }
  233. #endregion
  234. #region Upload
  235. /// <summary>
  236. /// 将本地文件上传到指定的服务器(HttpWebRequest方法)
  237. /// </summary>
  238. /// <returns></returns>
  239. public static string UpLoadFile(string downPath, string fileName, string url)
  240. {
  241. var responseValue = string.Empty;
  242. var filePath = downPath;
  243. if (!File.Exists(downPath))
  244. filePath = Path.Combine(downPath, fileName);
  245. try
  246. {
  247. var request = (HttpWebRequest)WebRequest.Create(url);
  248. request.Timeout = 60000;
  249. request.Method = "POST";
  250. //每次上传4k
  251. int bufferLength = 40960;
  252. byte[] buffer = new byte[bufferLength];
  253. // 要上传的文件
  254. System.IO.FileStream fs = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read);
  255. BinaryReader r = new BinaryReader(fs);
  256. int size = r.Read(buffer, 0, bufferLength);
  257. //request.ContentLength = bufferLength;
  258. Stream postStream = null;
  259. try
  260. {
  261. while (size > 0)
  262. {
  263. postStream = request.GetRequestStream();
  264. postStream.Write(buffer, 0, bufferLength);
  265. size = r.Read(buffer, 0, bufferLength);
  266. }
  267. }
  268. catch (Exception e)
  269. {
  270. Console.WriteLine(e);
  271. throw;
  272. }
  273. finally
  274. {
  275. fs.Close();
  276. postStream?.Close();
  277. r.Close();
  278. }
  279. //返回数据
  280. using (var response = (HttpWebResponse)request.GetResponse())
  281. {
  282. if (response.StatusCode != HttpStatusCode.OK)
  283. {
  284. var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
  285. throw new ApplicationException(message);
  286. }
  287. // grab the response
  288. using (var responseStream = response.GetResponseStream())
  289. {
  290. if (responseStream != null)
  291. using (var reader = new StreamReader(responseStream))
  292. {
  293. responseValue = reader.ReadToEnd();
  294. }
  295. }
  296. }
  297. }
  298. catch (Exception e)
  299. {
  300. MessageShowBase.Show(e);
  301. }
  302. return responseValue;
  303. }
  304. /// <summary>
  305. /// 上传到文件服务器的Revit目录中
  306. /// </summary>
  307. /// <returns></returns>
  308. public static string UpLoadRevitFile(string downPath, string fileName)
  309. {
  310. string systemId = MBIConst.RevitServiceId;
  311. string secret = MBIConst.RevitServiceSecret;
  312. //文件下载
  313. string url =
  314. $"{MBIConst.ImageServiceLocalHost}image-service/common/file_upload?systemId={systemId}&secret={secret}&key={fileName}&overwrite=true";
  315. return UpLoadFile(downPath, fileName, url);
  316. }
  317. /// <summary>
  318. /// 上传到文件服务器的Dev目录中
  319. /// </summary>
  320. /// <returns></returns>
  321. public static string UpLoadDevFile(string downPath, string fileName)
  322. {
  323. string systemId = MBIConst.DevServiceId;
  324. string secret = MBIConst.DevServiceSecret;
  325. //文件下载
  326. string url =
  327. $"{MBIConst.ImageServiceLocalHost}image-service/common/file_upload?systemId={systemId}&secret={secret}&key={fileName}&overwrite=true";
  328. return UpLoadFile(downPath, fileName, url);
  329. }
  330. /// <summary>
  331. /// 上传到图片服务器的Dev目录中
  332. /// </summary>
  333. /// <returns></returns>
  334. public static string UpLoadDevImage(string downPath, string fileName)
  335. {
  336. string systemId = MBIConst.DevServiceId;
  337. string secret = MBIConst.DevServiceSecret;
  338. //文件下载
  339. string url =
  340. $"{MBIConst.ImageServiceLocalHost}image-service/common/image_upload?systemId={systemId}&secret={secret}&key={fileName}&overwrite=true";
  341. return UpLoadFile(downPath, fileName, url);
  342. }
  343. #endregion
  344. #region UploadAsync
  345. private static WinMFMUploadProcress win = null;
  346. /// <summary>
  347. /// 显示上传窗体
  348. /// </summary>
  349. /// <param name="filePath"></param>
  350. public static void ShowUploadWindow(string floorName, string filePath, int count, int cur)
  351. {
  352. if (win == null)
  353. {
  354. win = new WinMFMUploadProcress();
  355. win.Show();
  356. }
  357. win.FloorName = $"正在上传{floorName}层模型文件,请稍后。。。";
  358. win.LabelPath = filePath;
  359. win.Count = count;
  360. win.Cur = cur;
  361. }
  362. /// <summary>
  363. /// 关闭上传窗体
  364. /// </summary>
  365. public static void CloseUploadWindow(bool issucess, bool hasTip = false)
  366. {
  367. if (win != null)
  368. {
  369. win?.Close();
  370. win = null;
  371. }
  372. if (hasTip)
  373. MessageBox.Show(issucess ? "Revit模型文件上传成功!" : "Revit文件上传失败!");
  374. }
  375. /// <summary>
  376. /// 上传Revit文件到服务器
  377. /// </summary>
  378. /// <param name="filePath"></param>
  379. /// <param name="fileName"></param>
  380. /// <returns></returns>
  381. public static bool UpLoadRevitAsync(string floorName, string filePath, string fileName, int count, int cur)
  382. {
  383. bool result = true;
  384. string key = $"{MBIConst.OssClientFileKey}{fileName}";
  385. OssClient client = new OssClient(MBIConst.Endpoint, MBIConst.AccessKeyId, MBIConst.AccessKeySecret);
  386. try
  387. {
  388. using (var fs = new MemoryStream(FileStreamOperate.ReadFile(filePath)))
  389. {
  390. string bucketName = MBIConst.BucketName;
  391. var putObjectRequest = new PutObjectRequest(bucketName, key, fs);
  392. ShowUploadWindow(floorName, filePath, count, cur);
  393. putObjectRequest.StreamTransferProgress += StreamProgressCallback;
  394. client.PutObject(putObjectRequest);
  395. #region 上传后MD5较验
  396. string md5 = MD5Tools.GetMD5HashFromFileByBase64(filePath);
  397. //上传后的文件md5校验
  398. if (client.GetObjectMetadata(bucketName, key).ContentMd5 != md5)
  399. {
  400. string errorMessage = ($"楼层 {floorName} MD5校验失败,本地与服务器不一致!");
  401. MailLog.Log("上传MD5异常", errorMessage);
  402. MessageShowBase.Infomation(errorMessage);
  403. //不关闭窗体
  404. // throw new Exception(errorMessage);
  405. }
  406. #endregion
  407. }
  408. Console.WriteLine("Put object:{0} succeeded", key);
  409. }
  410. catch (Exception ex)
  411. {
  412. MessageShowBase.Infomation("Revit文件上传载失败!\r\n" + ex.Message + "\r\n" + ex.StackTrace);
  413. result = false;
  414. CloseUploadWindow(result,false);
  415. }
  416. return result;
  417. }
  418. /// <summary>
  419. /// 上传进度条
  420. /// </summary>
  421. /// <param name="sender"></param>
  422. /// <param name="args"></param>
  423. private static void StreamProgressCallback(object sender, StreamTransferProgressArgs args)
  424. {
  425. var currentData = Math.Round(args.TransferredBytes * 100d / args.TotalBytes, 3);
  426. Debug.WriteLine("ProgressCallback - TotalBytes:{0}M, TransferredBytes:{1}M,上传百分比:{2}%",
  427. args.TotalBytes / 1024 / 1024, args.TransferredBytes / 1024 / 1024, currentData);
  428. win?.Update(currentData);
  429. if (currentData >= 100d)
  430. {
  431. CloseUploadWindow(true, false);
  432. }
  433. }
  434. #endregion
  435. #region Del
  436. /// <summary>
  437. /// 删除服务器文件
  438. /// </summary>
  439. /// <returns></returns>
  440. public static string DeleteFile(string url, string key)
  441. {
  442. //文件下载
  443. try
  444. {
  445. JObject jObject = new JObject();
  446. JArray keyArray = new JArray();
  447. keyArray.Add(key);
  448. jObject.Add("keys", keyArray);
  449. string postData = jObject.ToString();
  450. RestClient client = new RestClient(url, HttpVerb.POST, postData);
  451. string request = client.PostRequest();
  452. return request;
  453. }
  454. catch (Exception e)
  455. {
  456. MessageShowBase.Show(e);
  457. }
  458. return null;
  459. }
  460. /// <summary>
  461. /// 删除文件服务器Revit目录下的数据
  462. /// </summary>
  463. /// <param name="key"></param>
  464. /// <returns></returns>
  465. public static string DeleteRevitFile(string key)
  466. {
  467. string systemId = MBIConst.RevitServiceId;
  468. string secret = MBIConst.RevitServiceSecret;
  469. string url =
  470. $"{MBIConst.ImageServiceLocalHost}image-service/common/files_delete?systemId={systemId}&secret={secret}";
  471. return DeleteFile(url, key);
  472. }
  473. /// <summary>
  474. /// 删除文件服务器Dev目录下的数据
  475. /// </summary>
  476. /// <param name="key"></param>
  477. /// <returns></returns>
  478. public static string DeleteDevFile(string key)
  479. {
  480. string systemId = MBIConst.DevServiceId;
  481. string secret = MBIConst.DevServiceSecret;
  482. string url =
  483. $"{MBIConst.ImageServiceLocalHost}image-service/common/files_delete?systemId={systemId}&secret={secret}";
  484. return DeleteFile(url, key);
  485. }
  486. /// <summary>
  487. /// 删除图片服务器Dev目录的图片
  488. /// </summary>
  489. /// <param name="key"></param>
  490. /// <returns></returns>
  491. public static string DeleteDevImage(string key)
  492. {
  493. string systemId = MBIConst.DevServiceId;
  494. string secret = MBIConst.DevServiceSecret;
  495. string url =
  496. $"{MBIConst.ImageServiceLocalHost}image-service/common/images_delete?systemId={systemId}&secret={secret}";
  497. return DeleteFile(url, key);
  498. }
  499. #endregion
  500. #region 一级底层封装
  501. /*
  502. * 1、上传接口:URL,(传路径|传bytes) 系统及Id
  503. * 2、下载接口:URL,(传路径|返回bytes)
  504. * 3、返回文件列表:前缀,数量默认
  505. * 4、删除文件:(列表|单独文件)
  506. */
  507. public static bool UploadFile(FileServiceSetting setting, string key, Byte[] bytes)
  508. {
  509. try
  510. {
  511. string url =
  512. $"{MBIConst.ImageServiceLocalHost}image-service/common/file_upload?systemId={setting.SystemId}&secret={setting.Secret}&key={key}&overwrite=true";
  513. MemoryStream stream = new MemoryStream(bytes);
  514. var result = RequestClient.UploadFile(url, stream);
  515. JObject rj = JObject.Parse(result);
  516. if (rj["Result"].ToString() == "success")
  517. {
  518. return true;
  519. }
  520. //结果暂时不处理
  521. throw new Exception(rj["ResultMsg"].ToString());
  522. return false;
  523. }
  524. catch (Exception e)
  525. {
  526. throw;
  527. }
  528. }
  529. public static bool UploadFile(FileServiceSetting setting, string key, string filePath)
  530. {
  531. try
  532. {
  533. var bytes = File.ReadAllBytes(filePath);
  534. var result = UploadFile(setting, key, bytes);
  535. //结果暂时不处理
  536. return true;
  537. }
  538. catch (Exception)
  539. {
  540. throw;
  541. }
  542. }
  543. public static byte[] DownloadFile(FileServiceSetting setting, string key)
  544. {
  545. var url =
  546. $"{MBIConst.ImageServiceLocalHost}image-service/common/file_get/{key}?systemId={setting.SystemId}";
  547. try
  548. {
  549. return RequestClient.DownloadFile(url);
  550. }
  551. catch (Exception e)
  552. {
  553. throw;
  554. }
  555. return null;
  556. }
  557. public static bool DownloadFile(FileServiceSetting setting, string key, string filePath)
  558. {
  559. try
  560. {
  561. string parentPath = Directory.GetParent(filePath).FullName;
  562. if (!Directory.Exists(parentPath))
  563. Directory.CreateDirectory(parentPath);
  564. //if (!File.Exists(filePath))
  565. // File.Create(filePath);
  566. var reuslt = DownloadFile(setting, key);
  567. if (reuslt == null)
  568. throw new Exception("下载文件失败");
  569. File.WriteAllBytes(filePath, reuslt);
  570. return true;
  571. }
  572. catch (Exception)
  573. {
  574. throw;
  575. }
  576. }
  577. /// <summary>
  578. /// 根据指定前缀获取文件列表
  579. /// </summary>
  580. /// <param name="prefix"></param>
  581. /// <returns></returns>
  582. public static List<string> GetFiles(FileServiceSetting setting, string prefix)
  583. {
  584. List<string> files = new List<string>();
  585. string url = $"{MBIConst.ImageServiceLocalHost}image-service/common/files_list?systemId={setting.SystemId}&secret={setting.Secret}";
  586. JObject jObject = new JObject();
  587. jObject.Add("prefix", prefix);
  588. var result = RequestClient.Post(url, jObject);
  589. JObject resultJson = JObject.Parse(result);
  590. files = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(resultJson["Content"].ToString()) ?? new List<string>();
  591. return files;
  592. }
  593. /// <summary>
  594. /// 删除传入文件信息
  595. /// </summary>
  596. /// <param name="setting"></param>
  597. /// <param name="inputFiles"></param>
  598. /// <returns>成功删除的文件</returns>
  599. public static List<string> DeleteFiles(FileServiceSetting setting, List<string> inputFiles)
  600. {
  601. List<string> delFiles = new List<string>();
  602. if (inputFiles.IsNullOrEmptyExt())
  603. return delFiles;
  604. string url = $"{MBIConst.ImageServiceLocalHost}image-service/common/files_delete?systemId={setting.SystemId}&secret={setting.Secret}";
  605. JObject jObject = new JObject();
  606. JArray array = new JArray();
  607. inputFiles.ForEach(s => array.Add(s));
  608. jObject.Add("keys", array);
  609. var result = RequestClient.Post(url, jObject);
  610. JObject resultJson = JObject.Parse(result);
  611. delFiles = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(resultJson["Content"].ToString()) ?? new List<string>();
  612. return delFiles;
  613. }
  614. public static bool DeleteFile(FileServiceSetting setting, string file)
  615. {
  616. var delFile = DeleteFiles(setting, new List<string>() { file })?.FirstOrDefault();
  617. return delFile == file;
  618. }
  619. #endregion
  620. }
  621. /// <summary>
  622. /// 文件服务设置
  623. /// </summary>
  624. public class FileServiceSetting
  625. {
  626. static FileServiceSetting()
  627. {
  628. RevitSetting = new FileServiceSetting() { SystemId = MBIConst.RevitServiceId, Secret = MBIConst.RevitServiceSecret };
  629. DevSetting = new FileServiceSetting() { SystemId = MBIConst.DevServiceId, Secret = MBIConst.DevServiceSecret };
  630. }
  631. /// <summary>
  632. /// 系统ID
  633. /// </summary>
  634. public string SystemId { get; set; } = "";
  635. /// <summary>
  636. /// 系统密码
  637. /// </summary>
  638. public string Secret { get; set; } = "";
  639. public static FileServiceSetting RevitSetting { get; private set; }
  640. public static FileServiceSetting DevSetting { get; private set; }
  641. }
  642. }