JLChen
2020-11-16 64b5d3b0eab77341795cc7d6634ffa7cf60848e2
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/Databackup.cs
@@ -890,7 +890,7 @@
            mDownLoad.BackupFileName = file.BackupFileName;
            //var requestObj3 = new BackupDetailObj () { Id = file.Id };
            var requestJson3 = Newtonsoft.Json.JsonConvert.SerializeObject (mDownLoad);
            var revertObj3 = MainPage.RequestHttpsReturnByte (API.DownloadSomeDataBackup, requestJson3, false, mUrlHead);
            var revertObj3 = MainPage.RequestHttpsReturnByteNew (API.DownloadSomeDataBackup, requestJson3, mUrlHead);
            if (revertObj3 != null) {
                IO.FileUtils.WriteFileByBytes (file.BackupFileName, revertObj3);
@@ -915,6 +915,9 @@
            }
        }
        private readonly object SendLocker = new object ();
        private readonly object DownloadLocker = new object ();
        /// <summary>
        /// 多线程下载
@@ -954,16 +957,44 @@
                new System.Threading.Thread (() => {
                    for (var j = startIndex1; j <= endIndex1; j++) {
                        try {
                            //如果失败重新下载,重复3次
                            int errorCount = 0;
                            while (errorCount < 3) {
                        var result = DownloadSomeDataBackup (mDownLoad, mUrlHead, mFileList [j]);
                        if (result) {
                                    lock (DownloadLocker) {
                            index++;
                                    }
                            Application.RunOnMainThread (() => {
                                int pro = (int)(index * 1.0 / mFileList.Count * 100);
                                MainPage.Loading.Text = pro.ToString () + "%";
                            });
                                    errorCount = 3;
                                } else {
                                    errorCount++;
                                    Utlis.WriteLine ($"下载失败: {mFileList [j].BackupFileName} 次数:{errorCount}");
                        }
                            }
                        } catch { } finally {
                            lock (SendLocker) {
                        indexCount++;
                            }
                        }
                        //var t1 = DateTime.Now.Second;
                        //var result = DownloadSomeDataBackup (mDownLoad, mUrlHead, mFileList [j]);
                        //if (result) {
                        //    index++;
                        //    Application.RunOnMainThread (() => {
                        //        int pro = (int)(index * 1.0 / mFileList.Count * 100);
                        //        MainPage.Loading.Text = pro.ToString () + "%";
                        //    });
                        //} else {
                        //    Utlis.WriteLine ($"下载失败: {mFileList [j].BackupFileName} 时间:{DateTime.Now.Second - t1}S");
                        //}
                        //indexCount++;
                        //Utlis.WriteLine ($"下载线程:{id}  完成index:{j}  indexCount: {indexCount}");
                    }
@@ -1160,14 +1191,30 @@
                UploadHomeAppGatewaySubFilesObj mUpData = upData;
                mUpData.UploadSubFileLists = list;
                //var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData);
                //var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead);
                //if (revertObj2.StateCode.ToUpper () == "SUCCESS") {
                //    return true;
                //} else {
                //    //提示错误
                //    return false;
                //}
                //2020-11-16 如果失败重新上传,重复3次
                int errorCount = 0;
                var result = false;
                while (errorCount < 3) {
                var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (mUpData);
                var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead);
                    var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, mUrlHead, MainPage.TIME_OUT_20);
                if (revertObj2.StateCode.ToUpper () == "SUCCESS") {
                    return true;
                        result = true;
                        errorCount = 3;
                } else {
                    //提示错误
                    return false;
                        errorCount++;
                        //Utlis.WriteLine ($"上传失败({startIndex1}-{endIndex1}),次数:{errorCount}");
                }
                }
                return result;
            } catch {
                return false;
            }