From 9b44e30275621a48335fbea7b32b5065a2859c9c Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 16 三月 2021 16:54:33 +0800
Subject: [PATCH] Merge branch 'WJC' into temp-wxr
---
HDL_ON/Common/FileUtlis.cs | 84 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/HDL_ON/Common/FileUtlis.cs b/HDL_ON/Common/FileUtlis.cs
index 62136bd..63a3e07 100644
--- a/HDL_ON/Common/FileUtlis.cs
+++ b/HDL_ON/Common/FileUtlis.cs
@@ -1,6 +1,7 @@
锘縰sing System;
using System.Collections.Generic;
using System.IO;
+using System.Net;
using HDL_ON.Entity;
namespace HDL_ON.Common
@@ -47,6 +48,10 @@
{
get
{
+ if(DB_ResidenceData.Instance.CurrentRegion == null || DB_ResidenceData.Instance.CurrentRegion.RegionID == null)
+ {
+ return AccountPath;
+ }
if (string.IsNullOrEmpty(regionPath) || !regionPath.Contains(DB_ResidenceData.Instance.CurrentRegion.RegionID ))
{
regionPath = Path.Combine(AccountPath, DB_ResidenceData.Instance.CurrentRegion.RegionID);
@@ -269,5 +274,84 @@
}
}
}
+
+
+
+ /// <summary>
+ /// 涓嬭浇缃戠粶鍥剧墖
+ /// </summary>
+ /// <param name="fileName"></param>
+ /// <param name="url"></param>
+ public void DownLoadImage(string fileName, string url,Action action)
+ {
+ if (!File.Exists(fileName))
+ {
+ System.Threading.Tasks.Task.Run(() => {
+ FileStream fs = null;
+ try
+ {
+ MyWebClient webClient = new MyWebClient();
+ byte[] recevieBytes = webClient.DownloadData(new Uri(url));
+ fs = new FileStream(Path.Combine(RootPath, fileName), FileMode.Create, FileAccess.Write);
+ //fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
+ fs.Write(recevieBytes, 0, recevieBytes.Length);
+ fs.Flush();
+ }
+ catch (Exception ex) {
+ MainPage.Log($"down image : {ex.Message}");
+ }
+ finally
+ {
+ if (fs != null)
+ {
+ fs.Close();
+ action?.Invoke();
+ }
+ }
+ });
+ }else
+ {
+ action?.Invoke();
+ }
+ }
+
}
+
+
+ public class MyWebClient : WebClient
+ {
+ int _timeout = 10000;
+
+ /// <summary>
+ /// 瓒呮椂鏃堕棿(姣)
+ /// </summary>
+ public int Timeout
+ {
+ get
+ {
+ return _timeout;
+ }
+ set
+ {
+ _timeout = value;
+ }
+ }
+ public MyWebClient()
+ {
+
+ }
+
+ public MyWebClient(int timeout)
+ {
+ this._timeout = timeout;
+ }
+
+ protected override WebRequest GetWebRequest(Uri address)
+ {
+ var result = base.GetWebRequest(address);
+ result.Timeout = this._timeout;
+ return result;
+ }
+ }
+
}
--
Gitblit v1.8.0