using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Caliburn.Micro.Core; using Caliburn.Micro; using FurnaceUI.Models; using FurnaceUI.Views.Maintenances; using Aitex.Core.RT.IOCore; using MECF.Framework.Common.OperationCenter; using Aitex.Core.Util; using OpenSEMI.ClientBase; using MECF.Framework.Common.DataCenter; using System.Globalization; using MECF.Framework.UI.Client.ClientBase; using System.Collections.ObjectModel; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using FurnaceUI.DataModule; using System.Windows.Data; using System.Threading; using System.IO; using System.Diagnostics; using FurnaceUI.Views.Editors; using System.Windows.Input; using FurnaceUI.Controls.Common; namespace FurnaceUI.Views.Parameter { public class BackUpViewModel : FurnaceUIViewModelBase { [Subscription("Rt.Status")] public string RtStatus { get; set; } [Subscription("PM1.Status")] public string PM1EntityStatus { get; set; } private Visibility _gridHistoryVisibility = Visibility.Visible; public Visibility GridHistoryVisibility { get { return _gridHistoryVisibility; } set { _gridHistoryVisibility = value; this.NotifyOfPropertyChange(nameof(GridHistoryVisibility)); } } [Subscription("System.BackUpFileData")] public Dictionary> AllFilesDatas { get; set; } private ObservableCollection _historyTableDatas = new ObservableCollection(); public ObservableCollection HistoryTableDatas { get { return _historyTableDatas; } set { _historyTableDatas = value; this.NotifyOfPropertyChange(nameof(HistoryTableDatas)); } } public PageDataView SelectedItemHistory { get; set; } private bool _busyIndicatorVisibility = false; public bool BusyIndicatorVisibility { get { return _busyIndicatorVisibility; } set { _busyIndicatorVisibility = value; this.NotifyOfPropertyChange(nameof(BusyIndicatorVisibility)); } } private bool _isAllEnable = true; public bool IsAllEnable { get { return _isAllEnable; } set { _isAllEnable = value; this.NotifyOfPropertyChange(nameof(IsAllEnable)); } } RelayCommand _compareCommand; public ICommand CompareCommand { get { if (_compareCommand == null) { _compareCommand = new RelayCommand(param => this.CompareClick(), param => this.CanCompareClick()); } return _compareCommand; } } RelayCommand _rollBackCommand; public ICommand RollBackCommand { get { if (_rollBackCommand == null) { _rollBackCommand = new RelayCommand(param => this.RollBackClick(), param => this.CanRollBackClick()); } return _rollBackCommand; } } protected override void OnActivate() { base.OnActivate(); DelayData(); } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); } protected override void OnDeactivate(bool close) { base.OnDeactivate(close); } public void CreateZIP() { var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Are you sure you want to CreateZIP?"); if (selection == DialogButton.No) return; BusyIndicatorVisibility = true; InvokeClient.Instance.Service.DoOperation($"System.CreateZIP"); DelayData(); } public void BackUpClick() { var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Are you sure you want to BackUp?"); if (selection == DialogButton.No) return; BusyIndicatorVisibility = true; InvokeClient.Instance.Service.DoOperation($"System.BackUpFileData"); DelayData(1500); } async void DelayData(int delayTime = 1000) { await WaitForResultsAsync(delayTime); GetDataOfConfigItems(); BusyIndicatorVisibility = false; } private async Task WaitForResultsAsync(int delayTime) { // Simulate waiting for results using a delay // In a real-world scenario, you might wait for an event or a specific condition await Task.Delay(delayTime); // Here you can add logic to check if the results are ready // For example, polling or using a completion source } private void RollBackClick() { var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.WARNING, $"If you want to RollBack, you must restart after RollBack!"); if (selection == DialogButton.No) return; var selectItem = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}@{a.Name}").FirstOrDefault(); if (selectItem == null) { DialogBox.ShowWarning("Please select at least one"); return; } InvokeClient.Instance.Service.DoOperation($"System.RollBackFileData", selectItem); DelayData(); } private void CompareClick() { var selection = DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, $"Are you sure you want to Compare?"); if (selection == DialogButton.No) return; var selectItems = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}@{a.Name}").ToList(); InvokeClient.Instance.Service.DoOperation($"System.CompareFileData", string.Join(",", selectItems.ToArray())); var windowManager = IoC.Get(); BackUpCompareViewModel backUpCompareViewModel = new BackUpCompareViewModel(); backUpCompareViewModel.SelectItemNames = HistoryTableDatas.Where(a => a.IsSelect == true).Select(a => $"{a.ValueStr}").ToList(); var rtn = (windowManager as WindowManager)?.ShowDialogWithTitle(backUpCompareViewModel, null, $"Compare View"); } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); //System位于AutoIdle/Idle/Init/ PM位于 IsAllEnable = (RtStatus == "Idle" || RtStatus == "AutoIdle" || RtStatus == "Init" || RtStatus == "Error") && (PM1EntityStatus == "Idle"); } private bool CanRollBackClick() { bool isEnable = false; if (HistoryTableDatas != null) { int count = HistoryTableDatas.Count(p => p.IsSelect == true); if (count == 1) { isEnable = true; } } return isEnable; } private bool CanCompareClick() { bool isEnable = false; if (HistoryTableDatas != null) { int count = HistoryTableDatas.Count(p => p.IsSelect == true); if (0 < count && count <= 2) { isEnable = true; } } return isEnable; } private void GetDataOfConfigItems() { HistoryTableDatas.Clear(); if (AllFilesDatas == null || AllFilesDatas.Count == 0) { return; } foreach (var item in AllFilesDatas["SC"]) { var nameStr = item.Split('@'); var time = nameStr[0]; var name = nameStr[1]; HistoryTableDatas.Add(new PageDataView() { Name = name, ValueStr = time }); } } } }