| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text.RegularExpressions; |
| | | using Shared.SimpleControl; |
| | | |
| | | namespace Shared |
| | | { |
| | |
| | | alert.Show (); |
| | | } |
| | | |
| | | #region ■ 通用Dialog_______________________ |
| | | /// <summary> |
| | | /// 通用编辑Dialog |
| | | /// </summary> |
| | | /// <param name="nameStr"></param> |
| | | /// <param name="titleStr"></param> |
| | | public void ShowEditTextDialog (string nameStr, Action<string> saveAction, string titleStr = "") |
| | | { |
| | | Dialog dialog = new Dialog (); |
| | | |
| | | FrameLayout dialogBodyView = new FrameLayout () { |
| | | Gravity = Gravity.Center, |
| | | Width = Application.GetRealWidth (500), |
| | | Height = Application.GetRealHeight (330), |
| | | Radius = 5, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | BorderWidth = 0, |
| | | BackgroundColor = SkinStyle.Current.DialogColor, |
| | | }; |
| | | dialog.AddChidren (dialogBodyView); |
| | | |
| | | Button btnTitle = new Button () { |
| | | Height = Application.GetRealHeight (80), |
| | | TextAlignment = TextAlignment.Center, |
| | | Text = titleStr, |
| | | TextColor = SkinStyle.Current.DialogTextColor, |
| | | BackgroundColor = SkinStyle.Current.DialogTitle, |
| | | }; |
| | | dialogBodyView.AddChidren (btnTitle); |
| | | |
| | | EditText etZoneName = new EditText () { |
| | | X = Application.GetRealWidth (50), |
| | | Y = Application.GetRealHeight (120), |
| | | Width = Application.GetRealWidth (400), |
| | | Height = Application.GetRealHeight (80), |
| | | TextColor = SkinStyle.Current.TextColor, |
| | | TextAlignment = TextAlignment.Center, |
| | | Radius = 5, |
| | | BorderColor = SkinStyle.Current.BorderColor, |
| | | BorderWidth = 2, |
| | | Text = nameStr, |
| | | }; |
| | | dialogBodyView.AddChidren (etZoneName); |
| | | |
| | | FrameLayout BottomView = new FrameLayout () { |
| | | Y = dialogBodyView.Height - Application.GetRealHeight (88), |
| | | Height = Application.GetRealHeight (90), |
| | | BackgroundColor = SkinStyle.Current.Black50Transparent, |
| | | }; |
| | | dialogBodyView.AddChidren (BottomView); |
| | | |
| | | Button btnClose = new Button () { |
| | | Width = Application.GetRealWidth (250), |
| | | TextID = SimpleControl.R.MyInternationalizationString.Close, |
| | | TextColor = SkinStyle.Current.DialogTextColor, |
| | | BackgroundColor = SkinStyle.Current.DialogTitle, |
| | | }; |
| | | BottomView.AddChidren (btnClose); |
| | | btnClose.MouseUpEventHandler += (sdf, fds) => { |
| | | dialog.Close (); |
| | | }; |
| | | |
| | | Button btnOption = new Button () { |
| | | X = btnClose.Right + Application.GetRealWidth (2), |
| | | Width = Application.GetRealWidth (250), |
| | | TextID = SimpleControl.R.MyInternationalizationString.SAVE, |
| | | TextColor = SkinStyle.Current.DialogTextColor, |
| | | BackgroundColor = SkinStyle.Current.DialogTitle, |
| | | }; |
| | | BottomView.AddChidren (btnOption); |
| | | |
| | | btnOption.MouseUpEventHandler += (sdf, fds) => { |
| | | //修改名称 |
| | | var newStr = etZoneName.Text.Trim (); |
| | | if (nameStr != newStr) { |
| | | saveAction?.Invoke (newStr); |
| | | } |
| | | dialog.Close (); |
| | | }; |
| | | dialog.Show (); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region ■ 共用上传备份操作_______________________ |
| | | /// <summary> |
| | | /// 将当前本地数据上传到自动备份 |
| | | /// </summary> |
| | | /// <param name="finishAction">上传结束事件</param> |
| | | public void ShowUploadToAutomaticBackupDialog (Action finishAction) |
| | | { |
| | | Dialog dialog = new Dialog (); |
| | | |
| | | FrameLayout dialogBodyView = new FrameLayout () { |
| | | Gravity = Gravity.Center, |
| | | Width = Application.GetRealWidth (500), |
| | | Height = Application.GetRealHeight (500), |
| | | BackgroundColor = SkinStyle.Current.DialogColor, |
| | | Radius = 5, |
| | | BorderColor = SkinStyle.Current.Transparent, |
| | | BorderWidth = 0, |
| | | }; |
| | | dialog.AddChidren (dialogBodyView); |
| | | |
| | | Button btnTitle = new Button () { |
| | | Height = Application.GetRealHeight (80), |
| | | BackgroundColor = SkinStyle.Current.DialogTitle, |
| | | TextAlignment = TextAlignment.Center, |
| | | TextID = SimpleControl.R.MyInternationalizationString.Backup, |
| | | TextColor = SkinStyle.Current.DialogTextColor |
| | | }; |
| | | dialogBodyView.AddChidren (btnTitle); |
| | | //Button btnGoDownTip = new Button () { |
| | | // Gravity = Gravity.CenterHorizontal, |
| | | // Y = Application.GetRealHeight (90 - 26), |
| | | // Width = Application.GetRealWidth (53), |
| | | // Height = Application.GetRealHeight (26), |
| | | // UnSelectedImagePath = "Room/godown.png", |
| | | //}; |
| | | //dialogBodyView.AddChidren (btnGoDownTip); |
| | | |
| | | Button btnackupRemark = new Button () { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Y = Application.GetRealHeight (100), |
| | | Width = Application.GetRealWidth (400), |
| | | Height = Application.GetRealHeight (80), |
| | | TextID = SimpleControl.R.MyInternationalizationString.Remark, |
| | | TextAlignment = TextAlignment.CenterLeft, |
| | | TextColor = SkinStyle.Current.TextColor, |
| | | }; |
| | | dialogBodyView.AddChidren (btnackupRemark); |
| | | |
| | | EditText etBackupRemark = new EditText () { |
| | | Gravity = Gravity.CenterHorizontal, |
| | | Y = btnackupRemark.Bottom, |
| | | Width = Application.GetRealWidth (400), |
| | | Height = Application.GetRealHeight (80), |
| | | TextAlignment = TextAlignment.Center, |
| | | Radius = 5, |
| | | BorderColor = SkinStyle.Current.BorderColor, |
| | | BorderWidth = 1, |
| | | TextColor = SkinStyle.Current.TextColor, |
| | | }; |
| | | dialogBodyView.AddChidren (etBackupRemark); |
| | | etBackupRemark.EditorEnterAction += (obj) => { |
| | | Application.HideSoftInput (); |
| | | }; |
| | | FrameLayout bottomView = new FrameLayout () { |
| | | Y = Application.GetRealHeight (420), |
| | | Height = Application.GetRealHeight (85), |
| | | BackgroundColor = SkinStyle.Current.DialogTitle |
| | | }; |
| | | dialogBodyView.AddChidren (bottomView); |
| | | |
| | | Button btnClose = new Button () { |
| | | Width = Application.GetRealWidth (249), |
| | | TextID = SimpleControl.R.MyInternationalizationString.Close, |
| | | TextAlignment = TextAlignment.Center |
| | | }; |
| | | bottomView.AddChidren (btnClose); |
| | | btnClose.MouseUpEventHandler += (send2er, e2) => { |
| | | dialog.Close (); |
| | | }; |
| | | |
| | | Button btnBottomLine = new Button () { |
| | | X = btnClose.Right, |
| | | Width = 1, |
| | | BackgroundColor = SkinStyle.Current.Black50Transparent, |
| | | }; |
| | | bottomView.AddChidren (btnBottomLine); |
| | | |
| | | Button btnSave = new Button () { |
| | | X = btnBottomLine.Right, |
| | | Width = Application.GetRealWidth (249), |
| | | TextID = SimpleControl.R.MyInternationalizationString.SAVE, |
| | | TextAlignment = TextAlignment.Center |
| | | }; |
| | | bottomView.AddChidren (btnSave); |
| | | |
| | | btnSave.MouseUpEventHandler += (sender2, e2) => { |
| | | if (etBackupRemark.Text.Trim () == "") { |
| | | new Alert (Language.StringByID (SimpleControl.R.MyInternationalizationString.Tip), Language.StringByID (SimpleControl.R.MyInternationalizationString.InputNewBakeUpFilesName), |
| | | Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show (); |
| | | return; |
| | | } |
| | | if (MainPage.LoginUser == null) { |
| | | new Alert (Language.StringByID (SimpleControl.R.MyInternationalizationString.Tip), Language.StringByID (SimpleControl.R.MyInternationalizationString.PleaseLoginSystem), |
| | | Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show (); |
| | | return; |
| | | } |
| | | userBakeupFile (etBackupRemark.Text.Trim (), finishAction); |
| | | dialog.Close (); |
| | | }; |
| | | dialog.Show (); |
| | | |
| | | } |
| | | |
| | | |
| | | ///// <summary> |
| | | ///// 交互备份 |
| | | ///// </summary> |
| | | //int InteractiveBackup = 0; |
| | | ///// <summary> |
| | | ///// 自定义工程备份 |
| | | ///// </summary> |
| | | //int CustomProjectBackup = 1; |
| | | ///// <summary> |
| | | ///// 用户自动备份 |
| | | ///// </summary> |
| | | //int UserAutoBackup = 2; |
| | | ///// <summary> |
| | | ///// 用户自定义备份 |
| | | ///// </summary> |
| | | //int UserCustomizedBackup = 3; |
| | | /// <summary> |
| | | /// 用户备份文件 |
| | | /// </summary> |
| | | void userBakeupFile (string folderName, Action finishAction) |
| | | { |
| | | MainPage.Loading.Start ("Upload..."); |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | try { |
| | | var revertObj = HttpServerRequest.Current.CreateBackupFolder(folderName); |
| | | if (revertObj.Code == StateCode.SUCCESS) { |
| | | var mBackupFolderCreateRes = Newtonsoft.Json.JsonConvert.DeserializeObject<BackupFolderCreateRes> (revertObj.Data.ToString ()); |
| | | //UpLoadBackupFileNEW (mBackupFolderCreateRes.id); |
| | | UpLoadBackupFileOne (mBackupFolderCreateRes.id); |
| | | } else { |
| | | IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); |
| | | } |
| | | } catch (Exception ex) { |
| | | Shared.Application.RunOnMainThread (() => { |
| | | new Alert (Language.StringByID (SimpleControl.R.MyInternationalizationString.Tip), Language.StringByID (SimpleControl.R.MyInternationalizationString.CheckInternet), |
| | | Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show (); |
| | | Shared.Utlis.WriteLine (ex.Message); |
| | | }); |
| | | } finally { |
| | | Shared.Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | //结束事件 |
| | | finishAction?.Invoke (); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //2020-01-11 |
| | | /// <summary> |
| | | /// 删除某个备份 |
| | | /// </summary> |
| | | /// <param name="folderID"></param> |
| | | void DeleteFolderDataAfterUploadFailed (string folderID) |
| | | { |
| | | try { |
| | | var revertObj = HttpServerRequest.Current.DeleteBackupFolder (folderID); |
| | | if (revertObj.Code == StateCode.SUCCESS) { |
| | | //GetHomeDataBackupList (); |
| | | } else { |
| | | //IMessageCommon.Current.ShowErrorInfoAlter (API.API_DELETE_Folder_Delete, revertObj.StateCode); |
| | | } |
| | | } catch { } finally { |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Hide (); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 上传备份文件 |
| | | /// 多次上传多个文件 |
| | | /// </summary> |
| | | /// <param name="mBackupClassId"></param> |
| | | public void UpLoadBackupFileOne (string folderId) |
| | | { |
| | | var backuplist = IO.FileUtils.ReadFiles (); |
| | | var mFileList = backuplist.FindAll ((obj) => obj != "null" && obj != UserConfig.configFile && obj != UserInfo.GlobalRegisterFile && obj != "AccountListDB" && obj != CommonConfig.ConfigFile && (!obj.Contains (".json"))); |
| | | |
| | | if (mFileList.Count <= 0) return; |
| | | |
| | | int resultCount = mFileList.Count; |
| | | int index = 0; |
| | | foreach (var fileName in mFileList) { |
| | | byte [] fileBytes = IO.FileUtils.ReadFile (fileName); |
| | | var result = UploadDataBackupByOne (folderId, fileName, fileBytes); |
| | | if (result) { |
| | | index++; |
| | | Application.RunOnMainThread (() => { |
| | | int pro = (int)(index * 1.0 / resultCount * 100); |
| | | MainPage.Loading.Text = pro.ToString () + "%"; |
| | | }); |
| | | } else { |
| | | Console.WriteLine ("上传失败:" + fileName); |
| | | } |
| | | } |
| | | |
| | | |
| | | Utlis.WriteLine ($"上传完成"); |
| | | |
| | | if (index != resultCount) { |
| | | //2020-01-11 备份失败 |
| | | DeleteFolderDataAfterUploadFailed (folderId); |
| | | Shared.Application.RunOnMainThread (() => { |
| | | new Alert ("", Language.StringByID (SimpleControl.R.MyInternationalizationString.FailedToBackupFile), Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show (); |
| | | MainPage.Loading.Hide (); |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | Application.RunOnMainThread (() => { |
| | | //MainPage.Loading.Text = "100%"; |
| | | new Alert ("", Language.StringByID (SimpleControl.R.MyInternationalizationString.BackupFileIsSuccessful), Language.StringByID (SimpleControl.R.MyInternationalizationString.Close)).Show (); |
| | | }); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="folderId"></param> |
| | | /// <param name="fileName"></param> |
| | | /// <param name="fileBytes"></param> |
| | | /// <returns></returns> |
| | | bool UploadDataBackupByOne (string folderId, string fileName, byte [] fileBytes) |
| | | { |
| | | try { |
| | | var queryDic = new Dictionary<string, object> (); |
| | | queryDic.Add ("folderId", folderId); |
| | | queryDic.Add ("fileName", fileName); |
| | | queryDic.Add ("homeId", UserConfig.Instance.CurrentRegion.Id); |
| | | |
| | | var revertObj = HttpUtil.RequestHttpsUpload (RestSharp.Method.POST, NewAPI.API_POST_File_Create, fileBytes, queryDic, null, UserConfig.Instance.CurrentRegion.regionUrl); |
| | | if (revertObj.Code == StateCode.SUCCESS) { |
| | | return true; |
| | | } else { |
| | | //提示错误 |
| | | return false; |
| | | } |
| | | } catch { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | //#region ■ 文件操作_______________________ |
| | | ///// <summary> |
| | | ///// 删除本地文件 |
| | | ///// </summary> |
| | | //public void ReadFilesAndDelete () |
| | | //{ |
| | | // var fileNames = IO.FileUtils.ReadFiles (); |
| | | // foreach (var fileName in fileNames) { |
| | | // if (fileName == UserInfo.GlobalRegisterFile || fileName == UserConfig.configFile || fileName == MqttInfoConfig.ConfigFile || fileName == APIInfoConfig.ConfigFile) { |
| | | // continue; |
| | | // } |
| | | // IO.FileUtils.DeleteFile (fileName); |
| | | // } |
| | | |
| | | //} |
| | | //#endregion |
| | | |
| | | |
| | | } |
| | | } |