From 3d7673c7b4aa0dc886d4816fe2d0ab400702e6e1 Mon Sep 17 00:00:00 2001
From: lss <lsc@hdlchina.com.cn>
Date: 星期四, 25 三月 2021 19:11:13 +0800
Subject: [PATCH] 2021-03-25  集成丰林可视对讲

---
 HDL_ON/Common/FileUtlis.cs |   58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/HDL_ON/Common/FileUtlis.cs b/HDL_ON/Common/FileUtlis.cs
index 63a3e07..a77e0ae 100644
--- a/HDL_ON/Common/FileUtlis.cs
+++ b/HDL_ON/Common/FileUtlis.cs
@@ -6,7 +6,7 @@
 
 namespace HDL_ON.Common
 {
-    public  class FileUtlis
+    public class FileUtlis
     {
         static Common.FileUtlis _temp;
         public static Common.FileUtlis Files
@@ -26,7 +26,8 @@
         string RootPath = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/";
 
         string accountPath;
-        string AccountPath {
+        string AccountPath
+        {
             get
             {
                 if (string.IsNullOrEmpty(accountPath) || !accountPath.Contains(UserInfo.Current.ID))
@@ -48,11 +49,11 @@
         {
             get
             {
-                if(DB_ResidenceData.Instance.CurrentRegion == null || DB_ResidenceData.Instance.CurrentRegion.RegionID == null)
+                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 ))
+                if (string.IsNullOrEmpty(regionPath) || !regionPath.Contains(DB_ResidenceData.Instance.CurrentRegion.RegionID))
                 {
                     regionPath = Path.Combine(AccountPath, DB_ResidenceData.Instance.CurrentRegion.RegionID);
                     if (!Directory.Exists(regionPath))
@@ -232,8 +233,6 @@
             }
         }
 
-
-
         public byte[] ReadFile(string fileName)
         {
             FileStream fs = null;
@@ -275,18 +274,55 @@
             }
         }
 
+        // 璇诲彇鎸囧畾璺緞鏂囦欢鍐呭
+        public byte[] ReadFileForPath(string path)
+        {
+            FileStream fs = null;
+            try
+            {
+                if (File.Exists(path))
+                {
+                    fs = new FileStream(path, FileMode.Open, FileAccess.Read);
+                }
+                else
+                {
+                    return new byte[0];
+                }
+                byte[] bytes = new byte[fs.Length];
+                fs.Read(bytes, 0, bytes.Length);
+                return bytes;
+            }
+            catch
+            {
+                return new byte[0];
+            }
+            finally
+            {
+                try
+                {
+                    if (fs != null)
+                    {
+                        fs.Close();
+                    }
+                }
+                catch
+                {
 
+                }
+            }
+        }
 
         /// <summary>
         /// 涓嬭浇缃戠粶鍥剧墖
         /// </summary>
         /// <param name="fileName"></param>
         /// <param name="url"></param>
-        public void DownLoadImage(string fileName, string url,Action action)
+        public void DownLoadImage(string fileName, string url, Action action)
         {
             if (!File.Exists(fileName))
             {
-                System.Threading.Tasks.Task.Run(() => {
+                System.Threading.Tasks.Task.Run(() =>
+                {
                     FileStream fs = null;
                     try
                     {
@@ -297,7 +333,8 @@
                         fs.Write(recevieBytes, 0, recevieBytes.Length);
                         fs.Flush();
                     }
-                    catch (Exception ex) {
+                    catch (Exception ex)
+                    {
                         MainPage.Log($"down image : {ex.Message}");
                     }
                     finally
@@ -309,7 +346,8 @@
                         }
                     }
                 });
-            }else
+            }
+            else
             {
                 action?.Invoke();
             }

--
Gitblit v1.8.0