private void AddWorkerCommand(object parameter)
        {
            var workerIndex = Workers.WorkerList.IndexOf((Worker)parameter);

            Workers.WorkerIndex = workerIndex;
            if (workerIndex != -1)
            {
                var newWorker = Workers.WorkerList[workerIndex].Clone();
                Workers.WorkerListInsert(workerIndex, newWorker);
            }
        }
        private void CopyWorkerCommand(object obj)
        {
            var itemToCopy = obj as WorkerCopy;

            if (itemToCopy != null)
            {
                var newIndex = Workers.WorkerList.IndexOf(itemToCopy.DestinationWorker);
                if (newIndex != -1)
                {
                    Workers.WorkerListInsert(newIndex, itemToCopy.SourceWorker);
                }
            }
        }
        private void NewWorkerCommand(object parameter)
        {
            var workerIndex = Workers.WorkerList.IndexOf((Worker)parameter);

            Workers.WorkerIndex = workerIndex;
            if (workerIndex != -1)
            {
                var index = workerIndex + 1;
                if (index < Workers.WorkerList.Count)
                {
                    Workers.WorkerListInsert(index, Worker.DefaultWorker());
                }
                else
                {
                    Workers.WorkerListAdd(Worker.DefaultWorker());
                }
            }
        }
Beispiel #4
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;
            }
        }