Beispiel #1
0
        private void RestoreState(UndoObject undoObject)
        {
            switch (undoObject.OperationType)
            {
            case UndoOperationType.WorkerEdit:
                Workers.WorkerListReplaceItem(undoObject.Index, ((Worker)undoObject.Data).Clone());
                break;

            case UndoOperationType.WorkersPowerCost:
                Workers.PowerCost = (double)undoObject.Data;
                break;

            case UndoOperationType.WorkersCoinType:
                Workers.CoinType = (string)undoObject.Data;
                break;

            case UndoOperationType.WorkersDisplayCoinAs:
                Workers.DisplayCoinAs = (string)undoObject.Data;
                break;

            case UndoOperationType.WorkerAdd:
                Workers.WorkerListRemoveAt(Workers.WorkerList.Count - 1);
                break;

            case UndoOperationType.WorkerAddRange:
                Workers.WorkerListRemoveRangeAt(undoObject.Index, (int)undoObject.Data);
                break;

            case UndoOperationType.WorkerInsert:
                Workers.WorkerListRemoveAt(undoObject.Index);
                break;

            case UndoOperationType.WorkerRemove:
                Workers.WorkerListInsert(undoObject.Index, ((Worker)undoObject.Data).Clone());
                break;

            case UndoOperationType.WorkerRemoveRange:
                Workers.WorkerListAddRangeAt((ObservableCollection <Worker>)undoObject.Data, undoObject.Index);
                break;

            case UndoOperationType.WorkerMove:
                Workers.WorkerListMove((int)undoObject.Data, undoObject.Index);
                break;

            case UndoOperationType.SettingsEdit:
                UnHookUpWmtSettingsPropertyChangeEvents();
                SaveUndoRedo("WtmSettings");
                var  wtms = ((WtmSettingsObject)undoObject.Data).Clone();
                bool switchTimeFromEqual    = WtmSwitchTimeFromStored.Equals(wtms.SwitchTimeFrom);
                bool switchTimeToEqual      = WtmSwitchTimeToStored.Equals(wtms.SwitchTimeTo);
                bool historicalAverageEqual = WtmHistoricalAveragePeriodStored == wtms.HistoricalAveragePeriod;
                bool historyTimeFromEqual   = WtmHistoryTimeFromStored.Equals(wtms.HistoryTimeFrom);
                bool historyTimeToEqual     = WtmHistoryTimeToStored.Equals(wtms.HistoryTimeTo);
                WtmSettings = wtms;
                HookUpWmtSettingsPropertyChangeEvents();
                if (WtmSettings.AutoSwitch)
                {
                    SwitchTimeIsUpdated = false;
                }
                if (WtmSettings.BackupHistoricalPrices)
                {
                    HistoryTimeIsUpdated = false;
                }
                WtmSettings.ServerSettingsAreUpdated = true;
                break;

            case UndoOperationType.WorkersAll:
                SaveUndoRedo("WorkersAll");
                var allWorkers = undoObject.Data as ObservableCollection <Worker>;
                Workers.WorkerList.Clear();
                foreach (var worker in allWorkers)
                {
                    Workers.WorkerList.Add(worker.Clone());
                }
                break;
            }
        }