From 525d4d5c18ad5f8a7976f1fd20cef7f1d7e82831 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 17 四月 2020 11:22:20 +0800
Subject: [PATCH] 2020-04-17 1.项目引用库更新。 2.备份上传和下载速度优化。

---
 Crabtree/SmartHome/IO/FileUtils.cs |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/Crabtree/SmartHome/IO/FileUtils.cs b/Crabtree/SmartHome/IO/FileUtils.cs
index 559f8b7..ffc8686 100644
--- a/Crabtree/SmartHome/IO/FileUtils.cs
+++ b/Crabtree/SmartHome/IO/FileUtils.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
 using System.IO;
 using System.Collections.Generic;
+using System.Threading;
 
 namespace Shared.IO
 {
@@ -242,13 +243,19 @@
 			WriteFileByBytes (fileName, SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (common)));
 		}
 
-		/// <summary>
-		/// Writes the file by bytes.
-		/// </summary>
-		/// <returns><c>true</c>, if file by bytes was writed, <c>false</c> otherwise.</returns>
-		/// <param name="fileName">File name.</param>
-		/// <param name="bytes">Bytes.</param>
-		public static bool WriteFileByBytes (string fileName, byte [] bytes)
+  		/// <summary>
+        /// 澧炲姞 璇诲啓閿侊紝褰撹祫婧愬浜庡啓鍏ユā寮忔椂锛屽叾浠栫嚎绋嬪啓鍏ラ渶瑕佺瓑寰呮湰娆″啓鍏ョ粨鏉熶箣鍚庢墠鑳界户缁啓鍏�
+        /// 鐢ㄤ簬瑙e喅澶氱嚎绋嬬幆澧冨啓鍏ユ枃浠堕棶棰�
+        /// </summary>
+        static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim ();
+
+	    /// <summary>
+        /// Writes the file by bytes.
+        /// </summary>
+        /// <returns><c>true</c>, if file by bytes was writed, <c>false</c> otherwise.</returns>
+        /// <param name="fileName">File name.</param>
+        /// <param name="bytes">Bytes.</param>
+        public static bool WriteFileByBytes (string fileName, byte [] bytes)
 		{
 			if (fileName == null || (fileName = fileName.Trim ()) == ("")) {
 				return false;
@@ -257,10 +264,13 @@
 			System.IO.FileStream fs = null;
 
 			try {
-				fs = new FileStream (System.IO.Path.Combine (RootPath, fileName), FileMode.Create, FileAccess.Write);
+                //璁剧疆璇诲啓閿佷负鍐欏叆妯″紡鐙崰璧勬簮锛屽叾浠栧啓鍏ヨ姹傞渶瑕佺瓑寰呮湰娆″啓鍏ョ粨鏉熶箣鍚庢墠鑳界户缁啓鍏�
+                LogWriteLock.EnterWriteLock ();
+
+                fs = new FileStream (System.IO.Path.Combine (RootPath, fileName), FileMode.Create, FileAccess.Write);
 				fs.Write (bytes, 0, bytes.Length);
 				fs.Flush ();
-				Utlis.WriteLine ("SaveFile:" + fileName);
+				//Utlis.WriteLine ("SaveFile:" + fileName + " : " + bytes.Length.ToString());
                 //if (!UserConfig.Instance.LocalFiles.Contains (fileName)) {
                 //    UserConfig.Instance.LocalFiles.Add (fileName);
                 //}
@@ -269,8 +279,10 @@
 				Utlis.WriteLine ("FileUtiles Code 113:" + ex.ToString ());
 				return false;
 			} finally {
-				try {
-					if (fs != null) {
+                try {
+                    //閫�鍑哄啓鍏ユā寮忥紝閲婃斁璧勬簮鍗犵敤
+                    LogWriteLock.ExitWriteLock ();
+                    if (fs != null) {
 						fs.Close ();
 					}
 				} catch (Exception ex) {

--
Gitblit v1.8.0