public void LoadAppBackups(string packagename) { list = new ObservableCollection <Model.BDevice>(); foreach (var module in xmodules) { Model.BDevice bDevice = new Model.BDevice(); bDevice.Device_Name = module.Device.Name; bDevice.Device_Sn = module.Device.Sn; Response res = module.Device.ScriptEngine.GetSlotList(packagename); Response res_current = module.Device.ScriptEngine.GetSlot(packagename); if (res.Json["list"] != null) { foreach (var b in res.Json["list"]) { Model.Backup backup = new Model.Backup(); backup.Name = b.ToString(); if (res_current.Json["name"] != null && res_current.Json["name"].ToString() == backup.Name) { backup.IsCurrent = true; } backup.Device_Sn = module.Device.Sn; bDevice.Backups.Add(backup); } } list.Add(bDevice); } this.Dispatcher.Invoke(new Action(() => { BDeviceListBox.ItemsSource = list; })); }
public void LoadBackups(string packagename) { this.Dispatcher.Invoke(new Action(() => { Label_Backups_Loading.Content = "正在加载现有快照信息,请稍后..."; })); List <Model.Backup> list = new List <Model.Backup>(); Response res = xmodules[0].Device.ScriptEngine.GetSlotList(packagename); Response res_current = xmodules[0].Device.ScriptEngine.GetSlot(packagename); if (res.Json["list"] != null) { foreach (var b in res.Json["list"]) { Model.Backup backup = new Model.Backup(); backup.Name = b["name"].ToString(); if (res_current.Json["name"] != null && res_current.Json["name"].ToString() == backup.Name) { backup.IsCurrent = true; } list.Add(backup); } } this.Dispatcher.Invoke(new Action(() => { BackupListBox.ItemsSource = list; Label_Backups_Loading.Content = "当前设备上存在该APP的" + list.Count + "个快照"; })); }
private void Button_SetSlot_Click(object sender, RoutedEventArgs e) { if (ComboBox_List.SelectedItem != null && ComboBox_List.SelectedItem.ToString() != "请选择APP包名" && ComboBox_List.SelectedItem.ToString() != "正在加载APP列表...") { string packagename = ComboBox_List.SelectedItem.ToString(); Model.Backup backup = (Model.Backup)((MyImageButton)sender).Tag; var device = from m in xmodules where m.Device.Sn == backup.Device_Sn select m.Device; if (device != null) { Device dc = (Device)device.First(); new Thread(() => { ShowLoading("设备[" + dc.Name + "]正在切换到快照[" + backup.Name + "],请稍后..."); Response res = dc.ScriptEngine.SetSlot(packagename, backup.Name); if (res.Result) { Client.ShowToast("设备[" + dc.Name + "]成功切换到快照[" + backup.Name + "]", Color.FromRgb(0, 188, 0)); var dDevice = list.ToList().Find(p => p.Device_Sn == dc.Sn); foreach (var b in dDevice.Backups) { b.IsCurrent = false; } if (dDevice != null) { dDevice.Backups.ToList().Find(p => p.Name == backup.Name).IsCurrent = true; } dDevice.Backups = dDevice.Backups; this.Dispatcher.Invoke(new Action(() => { BDeviceListBox.ItemsSource = null; BDeviceListBox.ItemsSource = list; })); } else { Client.ShowToast("设备[" + dc.Name + "]无法切换到快照[" + backup.Name + "]" + res.Message, Color.FromRgb(239, 34, 7)); } CloseLoading(); }) { IsBackground = true }.Start(); } } }
private void Button_DeleteSlot_Click(object sender, RoutedEventArgs e) { ContentControl_MessageBox.Content = ContentControl_Delete.Content; Grid_MessageBox.Visibility = Visibility.Visible; if (ComboBox_List.SelectedItem != null && ComboBox_List.SelectedItem.ToString() != "请选择APP包名" && ComboBox_List.SelectedItem.ToString() != "正在加载APP列表...") { string packagename = ComboBox_List.SelectedItem.ToString(); backup_delete = (Model.Backup)((MyImageButton)sender).Tag; var device = from m in xmodules where m.Device.Sn == backup_delete.Device_Sn select m.Device; if (device != null) { Device dc = (Device)device.First(); Label_Tip_Delete.Content = "确定要删除设备[" + dc.Name + "]上的快照[" + backup_delete.Name + "]吗?"; } } else { Grid_MessageBox.Visibility = Visibility.Collapsed; } }
private void Button_SetSlot_Click(object sender, RoutedEventArgs e) { if (ComboBox_List.SelectedItem != null && ComboBox_List.SelectedItem.ToString() != "请选择APP包名" && ComboBox_List.SelectedItem.ToString() != "正在加载APP列表...") { string packagename = ComboBox_List.SelectedItem.ToString(); Model.Backup backup = (Model.Backup)((MyImageButton)sender).Tag; var device = from m in xmodules where m.Device.Sn == backup.Device_Sn select m.Device; if (device != null) { Device dc = (Device)device.First(); new Thread(() => { ShowLoading("设备[" + dc.Name + "]正在结束当前APP..."); //结束正在运行的app Response res = dc.ScriptEngine.KillApp(packagename); res = dc.ScriptEngine.ReadBufferFromFile("/data/AppSlot/" + packagename + "/" + backup.Name + "/hardwarekey.txt"); if (res.Result) { ShowLoading("设备[" + dc.Name + "]正在还原硬件信息,请稍后..."); if (res.Json["buffer"] != null) { string hardwarekey = ""; JArray buffer = res.Json["buffer"] as JArray; //如果文件过大可能会分段读取 for (int i = 0; i < buffer.Count; i++) { byte[] bs = (byte[])buffer[i]; hardwarekey += (Encoding.UTF8.GetString(bs)); } if (hardwarekey.Length > 0) { res = dc.ScriptEngine.RestoreHardware(hardwarekey); Console.WriteLine(res.Json.ToString()); if (!res.Result) { Client.ShowToast("设备[" + dc.Name + "]无法还原硬件信息" + res.Message, Color.FromRgb(239, 34, 7)); return; } } } } ShowLoading("设备[" + dc.Name + "]正在切换到快照[" + backup.Name + "],请稍后..."); res = dc.ScriptEngine.SetSlot(packagename, backup.Name); Console.WriteLine(res.Json); if (res.Result) { Client.ShowToast("设备[" + dc.Name + "]成功切换到快照[" + backup.Name + "]", Color.FromRgb(0, 188, 0)); var dDevice = list.ToList().Find(p => p.Device_Sn == dc.Sn); foreach (var b in dDevice.Backups) { b.IsCurrent = false; } if (dDevice != null) { dDevice.Backups.ToList().Find(p => p.Name == backup.Name).IsCurrent = true; } dDevice.Backups = dDevice.Backups; this.Dispatcher.Invoke(new Action(() => { BDeviceListBox.ItemsSource = null; BDeviceListBox.ItemsSource = list; })); } else { Client.ShowToast("设备[" + dc.Name + "]无法切换到快照[" + backup.Name + "]" + res.Message, Color.FromRgb(239, 34, 7)); } CloseLoading(); }) { IsBackground = true }.Start(); } } }