using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class Databackup : FrameLayout
|
{
|
//WebServiceBackup service_backup = new WebServiceBackup ();
|
|
VerticalScrolViewLayout VerticalScrolViewMiddle;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public Databackup ()
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
public void DatabackupShow ()
|
{
|
this.RemoveAll ();
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
X = Application.GetRealWidth (90),
|
Width = Application.GetRealWidth (640 - 180),
|
TextAlignment = TextAlignment.Center,
|
Text = UserConfig.Instance.CurrentRegion.Name + " " + Language.StringByID (R.MyInternationalizationString.Backup),
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
topView.AddChidren (title);
|
title.MouseUpEventHandler += (sdf, asf) => {
|
Dialog dialog = new Dialog ();
|
|
FrameLayout bodyView = new FrameLayout ();
|
dialog.AddChidren (bodyView);
|
bodyView.MouseUpEventHandler += (lkj, oiu) => {
|
dialog.Close ();
|
};
|
|
VerticalScrolViewLayout dialogBodyView = new VerticalScrolViewLayout () {
|
Y = Application.GetRealHeight (126),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (360),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0
|
};
|
bodyView.AddChidren (dialogBodyView);
|
|
foreach (var homeTemp in UserConfig.Instance.HomeLists) {
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (110),
|
};
|
dialogBodyView.AddChidren (rowView);
|
|
Button btnRowLine = new Button () {
|
Y = Application.GetRealHeight (107),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.Black50Transparent
|
};
|
rowView.AddChidren (btnRowLine);
|
|
var btnPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
Visible = homeTemp.Id != UserConfig.Instance.CurrentRegion.Id
|
};
|
rowView.AddChidren (btnPoint);
|
|
var btnName = new Button () {
|
Width = Application.GetRealWidth (550),
|
Text = homeTemp.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (90),
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
rowView.AddChidren (btnName);
|
|
if (homeTemp.Id == UserConfig.Instance.CurrentRegion.Id) {
|
Button btnCheck = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (25),
|
Width = Application.GetRealWidth (72),
|
Height = Application.GetRealHeight (61),
|
UnSelectedImagePath = "Skin/Check.png",
|
};
|
rowView.AddChidren (btnCheck);
|
}
|
|
btnName.MouseUpEventHandler += (ss, ee) => {
|
if (UserConfig.Instance.CurrentRegion == homeTemp) {
|
dialog.Close ();
|
return;
|
}
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var backuplist = IO.FileUtils.ReadFiles ();
|
int index = 0;
|
string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.Id);
|
IO.FileUtils.DeleteRegionFiles (oldRegionRootPath);
|
foreach (var fileName in backuplist) {
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName);
|
if (fileInfo.Exists) {
|
fileInfo.MoveTo (oldRegionRootPath + fileName);
|
Console.WriteLine ("move file : " + fileName);
|
}
|
index++;
|
Application.RunOnMainThread (() => {
|
int pro = (int)(index * 1.0 / backuplist.Count * 50);
|
MainPage.Loading.Text = pro.ToString () + "%";
|
});
|
}
|
IO.FileUtils.DeleteAllFile ();
|
string newRegionRootPath = IO.FileUtils.CreateRegionBackup (homeTemp.Id);
|
IO.FileUtils.RestoreRegionFiles (newRegionRootPath);
|
UserConfig.Instance.RefreshUserConfig ();
|
UserConfig.Instance.CurrentRegion = homeTemp;
|
UserConfig.Instance.SaveUserConfig ();
|
|
Room.InitAllRoom ();
|
//UserConfig.Instance.RefreshUserConfig ();
|
//MainPage.LoginUser.SaveUserInfo ();
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
this.DatabackupShow ();
|
EquipmentPublicClass.CheckLinkRemote (2);
|
});
|
} catch (Exception ex) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
dialog.Close ();
|
});
|
}
|
});
|
};
|
}
|
dialog.Show ();
|
};
|
|
Button ItemButton = new Button () {
|
Width = Application.GetRealWidth (55),
|
Height = Application.GetRealHeight (55),
|
UnSelectedImagePath = "Item/+.png",
|
SelectedImagePath = "Item/+.png",
|
Y = Application.GetRealHeight (15),
|
X = Application.GetRealWidth (640 - 80),
|
};
|
topView.AddChidren (ItemButton);
|
|
ItemButton.MouseUpEventHandler += (sender, e) => {
|
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 = R.MyInternationalizationString.Backup,
|
TextColor = SkinStyle.Current.DialogTextColor
|
};
|
dialogBodyView.AddChidren (btnTitle);
|
|
Button btnackupRemark = new Button () {
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight (100),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (80),
|
TextID = 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 = 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 = R.MyInternationalizationString.SAVE,
|
TextAlignment = TextAlignment.Center
|
};
|
bottomView.AddChidren (btnSave);
|
|
btnSave.MouseUpEventHandler += (sender2, e2) => {
|
if (etBackupRemark.Text.Trim () == "") {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.InputNewBakeUpFilesName),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
if (MainPage.LoginUser == null) {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseLoginSystem),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
userBakeupFile (etBackupRemark.Text.Trim ());
|
dialog.Close ();
|
};
|
dialog.Show ();
|
};
|
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
};
|
#endregion
|
|
var FrameLayoutView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (1136 - 126),
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (FrameLayoutView);
|
|
VerticalScrolViewMiddle = new VerticalScrolViewLayout ();
|
VerticalScrolViewMiddle.RemoveAll ();
|
FrameLayoutView.AddChidren (VerticalScrolViewMiddle);
|
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
});
|
var requestObj = new GetHomeDataBackupPaggerObj () {
|
HomeId = UserConfig.Instance.CurrentRegion.Id,
|
LoginAccessToken = MainPage.LoginUser.LoginTokenString
|
};
|
string urlHead = MainPage.RequestHttpsHost;
|
if (requestObj.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
//GetUserFolderObj requestObj = new GetUserFolderObj () { LevelID = UserConfig.Instance.CurrentRegion.Id };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps (API.GetHomeDataBackupPagger, requestJson, urlHead);
|
if (revertObj.StateCode.ToUpper() == "SUCCESS") {
|
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<GetBackupListResult> (revertObj.ResponseData.ToString ());
|
//var list = new List<BackupListNameInfo> ();
|
//foreach (var data2 in data.PageData) {
|
// if (ZigbeeUniqueId != null && data2.GatewayUniqueId != ZigbeeUniqueId) {
|
// continue;
|
// }
|
// if (getLogBackup == false && data2.BackupName == LogBackupName) {
|
// //不获取Log备份
|
// continue;
|
// }
|
// list.Add (data2);
|
//}
|
|
|
//var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<FolderRes>> (revertObj.ResponseData.ToString ());
|
if (data == null) return;
|
|
Application.RunOnMainThread (() => {
|
foreach(var folder in data.PageData)
|
{
|
addRow (folder.BackupName, folder.Id);
|
}
|
});
|
}
|
//var groupNames = service_backup.GetUserGroup (MainPage.LoginUser.MasterID, 0);
|
//Application.RunOnMainThread (() => {
|
// foreach (UserBackup groupName in groupNames) {
|
// addRow (groupName.UserGroup);
|
// }
|
//});
|
} catch {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
|
void addRow (string groupName, string folderID)
|
{
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (110),
|
};
|
VerticalScrolViewMiddle.AddChidren (rowView);
|
|
Button btnRowLine = new Button () {
|
Y = Application.GetRealHeight (107),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.Black50Transparent
|
};
|
rowView.AddChidren (btnRowLine);
|
|
var btnDelFile = new Button () {
|
TextID = R.MyInternationalizationString.Del,
|
BackgroundColor = SkinStyle.Current.DelColor
|
};
|
btnDelFile.MouseUpEventHandler += (sender, e) => {
|
Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.AreYouSureToDeleteFile), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += ( sender2, e2) => {
|
if (e2) {
|
DeleteFolderData (folderID);
|
}
|
};
|
alert.Show ();
|
};
|
|
if (MainPage.LoginUser.AccountType != 1) {
|
rowView.AddRightView (btnDelFile);
|
}
|
|
var btnPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (25),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
};
|
rowView.AddChidren (btnPoint);
|
|
var btnName = new Button () {
|
Width = Application.GetRealWidth (342),
|
Height = LayoutParams.MatchParent,
|
Text = groupName.Trim (),
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (50),
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
rowView.AddChidren (btnName);
|
|
btnName.MouseLongEventHandler += (sender, e) => {
|
Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.AreYouSureToDeleteFile), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += ( sender2, e2) => {
|
if (e2) {
|
DeleteFolderData (folderID);
|
}
|
};
|
alert.Show ();
|
};
|
|
|
|
var backupIcon = new Button () {
|
Width = Application.GetRealWidth (72),
|
Height = Application.GetRealHeight (57),
|
X = Application.GetRealWidth (452),
|
};
|
rowView.AddChidren (backupIcon);
|
|
var Backup_restores = new Button () {
|
Width = Application.GetRealWidth (56),
|
Height = Application.GetRealHeight (57),
|
X = backupIcon.Right + Application.GetRealWidth (20),
|
UnSelectedImagePath = "Register/Backup_ restores.png",
|
SelectedImagePath = "Register/Backup_ restores_on.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
rowView.AddChidren (Backup_restores);
|
Backup_restores.MouseDownEventHandler += (sender, e) => {
|
Backup_restores.IsSelected = true;
|
};
|
Backup_restores.MouseUpEventHandler += (sender, e) => {
|
Backup_restores.IsSelected = false;
|
UserBakeupFileDetailedInformation (folderID);
|
};
|
}
|
|
/// <summary>
|
/// 删除某个备份
|
/// </summary>
|
/// <param name="folderID"></param>
|
void DeleteFolderData (string folderID)
|
{
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var requestObj = new DelHomeAppGatewayNameObj () {
|
BackupClassId = folderID,
|
HomeId = UserConfig.Instance.CurrentRegion.Id,
|
LoginAccessToken = MainPage.LoginUser.LoginTokenString
|
};
|
string urlHead = MainPage.RequestHttpsHost;
|
if (requestObj.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
//DeleteFolderDataObj requestObj = new DeleteFolderDataObj () { Id = folderID };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps (API.DelHomeAppGatewayName, requestJson, urlHead);
|
if (revertObj.StateCode.ToUpper () == "SUCCESS") {
|
Application.RunOnMainThread (() => {
|
DatabackupShow ();
|
});
|
} else {
|
ShowDelErrorInfo (revertObj.StateCode);
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
|
}
|
|
/// <summary>
|
/// (2)ParameterOrEmpty,则响应字段中[ErrorInfo]为错误信息,ResponseData则为null
|
//3)NoLogin,则响应字段中 [ErrorInfo] 为错误信息为 [无效登录Token!]
|
//(5)NoRecord,则响应字段中 [ErrorInfo] 为错误信息为 [确保您所提交 [项目 (住宅)Id不存在!]
|
//(6)BackupClassIdNoIsYou, 则响应字段中 [ErrorInfo]为错误信息为 [您所备注名主键 = XXXX并不属于您当前住宅:XXXX]
|
//(7)NoPermission, 则响应字段中 [ErrorInfo]为错误信息为 [您并不具有此分享者此住宅的权限!]
|
//(8)InsufficientAuthority, 则响应字段中 [ErrorInfo]为错误信息为 [您并不具有此分享者此住宅的完全控制权限!]
|
//(9)HomeIdAndTokenNoConsistent, 则响应字段中 [ErrorInfo]为错误信息为 [您当前Token与你当前控制的HomeId不一致!]
|
//(10)DeliveryBackNoUpdateDel, 则响应字段中 [ErrorInfo]为错误信息为 [此前提交文件夹Id是属于交付备份, 不能进行更新删除!]
|
/// </summary>
|
/// <param name="stateCodeStr"></param>
|
void ShowDelErrorInfo (string stateCodeStr)
|
{
|
string mes = "";
|
if (stateCodeStr == "HomeIdAndTokenNoConsistent") {
|
//Token 验证失败
|
mes = ErrorCode.HomeIdAndTokenNoConsistent;
|
} else if (stateCodeStr == "DeliveryBackNoUpdateDel") {
|
//交付备份, 不能删除!
|
mes = ErrorCode.DeliveryBackNoUpdateDel;
|
} else if (stateCodeStr == ErrorCode.NetworkError) {
|
mes = ErrorCode.NetworkError;
|
} else {
|
mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
|
|
}
|
if (!string.IsNullOrEmpty (mes)) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
|
|
}
|
|
|
/// <summary>
|
/// 用户备份文件
|
/// </summary>
|
void userBakeupFile (string groupName)
|
{
|
//确定要备份该文件的数据
|
//Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureToBackupYourthisFile), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
|
//alert.ResultEventHandler += (object sender2, bool e2) => {
|
//if (e2) {
|
MainPage.Loading.Start ("Upload...");
|
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
|
//if (string.IsNullOrEmpty (UserConfig.Instance.GatewayMAC)) return;
|
if (!UserConfig.Instance.CheckHomeGateways () || string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) return;
|
|
var requestObj = new AddHomeAppGatewayNameObj () {
|
HomeId = UserConfig.Instance.CurrentRegion.Id,
|
BackupName = groupName,
|
LoginAccessToken = MainPage.LoginUser.LoginTokenString,
|
GatewayUniqueId = UserConfig.Instance.GatewayMAC
|
};
|
string urlHead = MainPage.RequestHttpsHost;
|
if (requestObj.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
requestObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
//AddFolderObj requestObj = new AddFolderObj () { LevelID = UserConfig.Instance.CurrentRegion.Id ,Name = groupName };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps (API.AddHomeAppGatewayName, requestJson, urlHead);
|
if (revertObj.StateCode.ToUpper () == "SUCCESS") {
|
var DATA = Newtonsoft.Json.JsonConvert.DeserializeObject<AddBackupNameResult> (revertObj.ResponseData.ToString());
|
var addFolderID = DATA.BackupClassId;
|
UpLoadBackupFileToDB (addFolderID);
|
|
|
} else {
|
ShowAddHomeAppGatewayNameErrorInfo (revertObj.StateCode);
|
|
}
|
|
} catch (Exception ex) {
|
Shared.Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
Console.WriteLine (ex.Message);
|
});
|
} finally {
|
Shared.Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
DatabackupShow ();
|
});
|
}
|
});
|
// }
|
//};
|
//alert.Show ();
|
}
|
|
/// <summary>
|
/// (1)Success 则[调用此接口操作成功],ResponseData则为null
|
// (2)ParameterOrEmpty,则响应字段中 [ErrorInfo] 为错误信息, ResponseData则为null
|
// (3)NoLogin,则响应字段中 [ErrorInfo] 为错误信息为 [无效登录Token!]
|
|
//(4)NoRecord,则响应字段中 [ErrorInfo] 为错误信息为 [确保您所提交 [项目 (住宅)Id不存在!]
|
//(5)Exist, 则响应字段中 [ErrorInfo]为错误信息为 [您在住宅: XXX, 当前备份名: XXXX已存在, 请换个备份再提交!]
|
|
//(6)NoBind, 则响应字段中 [ErrorInfo]为错误信息为 [网关的唯一Id = XXX,与住宅: XXXX并不存在绑定关系!]
|
//(7)NoPermission, 则响应字段中 [ErrorInfo]为错误信息为 [您并不具有此分享者此住宅的权限!]
|
|
//(8)InsufficientAuthority, 则响应字段中 [ErrorInfo]为错误信息为 [您并不具有此分享者此住宅的完全控制权限!]
|
//(9)HomeIdAndTokenNoConsistent, 则响应字段中 [ErrorInfo]为错误信息为 [您当前Token与你当前控制的HomeId不一致!]
|
/// </summary>
|
/// <param name="stateCodeStr"></param>
|
void ShowAddHomeAppGatewayNameErrorInfo (string stateCodeStr)
|
{
|
string mes = "";
|
if (stateCodeStr == "Exist") {
|
//备份名已存在
|
mes = ErrorCode.NameExist;
|
} else if (stateCodeStr == "HomeIdAndTokenNoConsistent") {
|
//Token 验证失败
|
mes = ErrorCode.HomeIdAndTokenNoConsistent;
|
} else if (stateCodeStr == ErrorCode.NetworkError) {
|
mes = ErrorCode.NetworkError;
|
} else {
|
mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr;
|
|
}
|
if (!string.IsNullOrEmpty (mes)) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
|
|
}
|
|
/// <summary>
|
/// 上传备份文件
|
/// </summary>
|
/// <param name="mBackupClassId"></param>
|
void UpLoadBackupFileToDB (string mBackupClassId)
|
{
|
|
var backuplist = IO.FileUtils.ReadFiles ();
|
int index = 0;
|
foreach (var fileName in backuplist) {
|
//index++;
|
/// <summary>
|
/// 如果是特殊的注册登陆文件,则不需要备份到服务器
|
/// </summary>
|
if (fileName == UserInfo.GlobalRegisterFile) {
|
continue;
|
}
|
//整理数据
|
var datainfo = new FileInfoData ();
|
datainfo.BackupFileName = fileName;
|
datainfo.BackupFileContent = Shared.IO.FileUtils.ReadFile (fileName);
|
|
var list = new List<FileInfoData> ();
|
list.Add (datainfo);
|
|
var upData = new UploadHomeAppGatewaySubFilesObj ();
|
upData.HomeId = UserConfig.Instance.CurrentRegion.Id;
|
upData.BackupClassId = mBackupClassId;
|
upData.UploadSubFileLists = list;
|
//获取控制主人账号的Token
|
upData.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
|
string urlHead = MainPage.RequestHttpsHost;
|
if (upData.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
upData.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
//AddUserBackupObj requestObj2 = new AddUserBackupObj () { LevelID = Convert.ToInt32 (revertObj.ResponseData), Name = fileName, DetailByte = IO.FileUtils.ReadFile (fileName) };
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (upData);
|
var revertObj2 = MainPage.RequestHttps (API.UploadHomeAppGatewaySubFiles, requestJson2, urlHead);
|
if (revertObj2.StateCode.ToUpper () == "SUCCESS") {
|
index++;
|
Application.RunOnMainThread (() => {
|
int pro = (int)(index * 1.0 / backuplist.Count * 100);
|
MainPage.Loading.Text = pro.ToString () + "%";
|
});
|
} else {
|
//提示错误
|
}
|
}
|
|
|
Shared.Application.RunOnMainThread (() => {
|
if (index == 0) {
|
new Alert ("", "Upload failed!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
}
|
|
MainPage.Loading.Hide ();
|
});
|
}
|
|
|
|
|
/// <summary>
|
/// 用户恢复文件
|
/// </summary>
|
public void UserBakeupFileDetailedInformation (string BackupClassId)
|
{
|
//是否确定恢复该文件数据信息
|
Alert alert = new Alert ("", Language.StringByID (R.MyInternationalizationString.SureToRestoreFileInformation), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += ( sender2, e2) => {
|
if (e2) {
|
MainPage.Loading.Start ("Download...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var fileNames = IO.FileUtils.ReadFiles ();
|
foreach (var fileName in fileNames) {
|
if (fileName == UserInfo.GlobalRegisterFile) {
|
continue;
|
}
|
IO.FileUtils.DeleteFile (fileName);
|
}
|
|
var requestObj2 = new GetHomeDataBackupUploadListPaggerObj ();
|
requestObj2.HomeId = UserConfig.Instance.CurrentRegion.Id;
|
requestObj2.BackupClassId = BackupClassId;
|
requestObj2.PageSetting.PageSize = 999999;
|
requestObj2.PageSetting.Page = 1;
|
//获取控制主人账号的Token
|
requestObj2.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
|
string urlHead = MainPage.RequestHttpsHost;
|
if (requestObj2.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
requestObj2.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
//获取所有文件组名
|
//var requestObj2 = new UserBackupListObj () { LevelID = folderID };
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
|
var revertObj2 = MainPage.RequestHttps (API.GetHomeDataBackupUploadListPagger, requestJson2, urlHead);
|
if (revertObj2.StateCode.ToUpper() == "SUCCESS") {
|
var fileListData = Newtonsoft.Json.JsonConvert.DeserializeObject<LoadBackInfoResult> (revertObj2.ResponseData.ToString ());
|
var responseDataObj = fileListData.PageData;
|
////获取文件名字
|
//List<string> listFileName = new List<string> ();
|
//foreach (LoadBackupFileNameInfo file in fileListData.PageData) {
|
// listFileName.Add (file.BackupFileName);
|
//}
|
//var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BackupInfoRes>> (revertObj2.ResponseData.ToString ());
|
|
var mDownLoad = new DownloadSomeDataBackupObj ();
|
mDownLoad.HomeId = UserConfig.Instance.CurrentRegion.Id;
|
mDownLoad.BackupClassId = BackupClassId;
|
//获取控制主人账号的Token
|
mDownLoad.LoginAccessToken = MainPage.LoginUser.LoginTokenString;
|
string mUrlHead = MainPage.RequestHttpsHost;
|
if (mDownLoad.IsOtherAccountCtrl) {
|
urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
|
mDownLoad.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
|
}
|
|
int index = 0;
|
foreach (var file in responseDataObj) {
|
if (file.BackupFileName == "null" || "UserConfig" == file.BackupFileName) {
|
continue;
|
}
|
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);
|
if (revertObj3 != null) {
|
index++;
|
IO.FileUtils.WriteFileByBytes (file.BackupFileName, revertObj3);
|
Application.RunOnMainThread (() => {
|
int pro = (int)(index * 1.0 / responseDataObj.Count * 100);
|
MainPage.Loading.Text = pro.ToString () + "%";
|
});
|
}
|
|
//if (revertObj3.StateCode.ToUpper() == "SUCCESS") {
|
// var jsonBytes = Newtonsoft.Json.JsonConvert.SerializeObject (revertObj3.ResponseData);
|
// var byresss = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]> (jsonBytes);
|
// index++;
|
// //新增加了住宅区域,旧的备份数据没有区域属性,当获取到这个文件时,把当前到住宅信息更到当前备份到数据里面
|
// if ("UserConfig" == file.BackupFileName){
|
// //var regionTemp = UserConfig.Instance.CurrentRegion;
|
// //UserConfig.Instance.RefreshUserConfig ();
|
// //UserConfig.Instance.CurrentRegion = regionTemp;
|
// //UserConfig.Instance.SaveUserConfig ();
|
// ////UserConfig.Instance.GatewayList
|
// continue;
|
// }
|
// IO.FileUtils.WriteFileByBytes (file.BackupFileName, byresss);
|
// Application.RunOnMainThread (() => {
|
// int pro = (int)(index * 1.0 / responseDataObj.Count * 100);
|
// MainPage.Loading.Text = pro.ToString () + "%";
|
// });
|
//} else {
|
// //错误提示
|
|
//}
|
}
|
MainPage.LoginUser.SaveUserInfo ();
|
Room.InitAllRoom ();
|
Application.RunOnMainThread (() => {
|
this.RemoveFromParent ();
|
CommonPage.IsRemote = false;
|
UserMiddle.Init ();
|
EquipmentPublicClass.CheckLinkRemote (2);
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.RestoreFileIsSuccessfull),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo> (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile)));
|
if (MainPage.LoginUser != null) {
|
MainPage.LoginUser.LastTime = System.DateTime.Now;
|
MainPage.LoginUser.SaveUserInfo ();
|
}
|
}
|
} catch (Exception ex) {
|
Shared.Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
Console.WriteLine (ex.ToString());
|
} finally {
|
Shared.Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
};
|
alert.Show ();
|
}
|
}
|
}
|