Ejemplo n.º 1
0
        public ConditionGroupsEditorViewModel(Func <IHistoryManager> historyCreator, IConditionDataProvider conditionDataProvider, IWindowManager windowManager,
                                              IMessageBoxService messageBoxService, ITaskRunner taskRunner)
        {
            this.conditionDataProvider = conditionDataProvider;
            this.windowManager         = windowManager;
            this.messageBoxService     = messageBoxService;

            SourceItems = new ObservableCollection <ConditionGroupsEditorData>();

            foreach (var item in conditionDataProvider.GetConditionGroups())
            {
                SourceItems.Add(new ConditionGroupsEditorData(in item));
            }

            Save = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Saving condition groups", SaveGroupsToFile);
            }, () => IsModified);
            AddGroup   = new AsyncCommand(AddGroupToSource);
            DeleteItem = new DelegateCommand <object>(DeleteItemFromSource);
            AddMember  = new AsyncCommand <ConditionGroupsEditorData>(AddItemToGroup);
            EditItem   = new AsyncCommand <ConditionGroupsEditorData>(EditSourceItem);
            // history setup
            historyHandler           = new ConditionGroupsEditorHistoryHandler(SourceItems !);
            History                  = historyCreator();
            undoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
            redoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
            History.PropertyChanged += (sender, args) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                IsModified = !History.IsSaved;
            };
            History.AddHandler(historyHandler);
        }
Ejemplo n.º 2
0
        public ConditionsDefinitionEditorViewModel(Func <IHistoryManager> historyCreator, IConditionDataProvider conditionDataProvider, IWindowManager windowManager,
                                                   ITaskRunner taskRunner, IParameterFactory parameterFactory)
        {
            this.conditionDataProvider = conditionDataProvider;
            SourceItems           = new ObservableCollection <ConditionJsonData>(conditionDataProvider.GetConditions().ToList());
            this.windowManager    = windowManager;
            this.parameterFactory = parameterFactory;
            SelectedIndex         = -1;

            Save = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Saving conditions definition list", SaveConditions);
            }, () => IsModified);
            Delete   = new DelegateCommand(DeleteItem);
            AddItem  = new AsyncCommand(AddNewItem);
            EditItem = new AsyncCommand <ConditionJsonData?>(EditCondition);
            // history setup
            historyHandler           = new ConditionsEditorHistoryHandler(SourceItems);
            History                  = historyCreator();
            undoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
            redoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
            History.PropertyChanged += (sender, args) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                IsModified = !History.IsSaved;
            };
            History.AddHandler(historyHandler);
        }
Ejemplo n.º 3
0
 public SmartDataGroupsEditorViewModel(ISmartRawDataProvider smartDataProvider, ITaskRunner taskRunner, IMessageBoxService messageBoxService,
                                       IWindowManager windowManager, Func <IHistoryManager> historyCreator, SmartDataSourceMode dataSourceMode)
 {
     this.smartDataProvider = smartDataProvider;
     this.messageBoxService = messageBoxService;
     this.windowManager     = windowManager;
     this.dataSourceMode    = dataSourceMode;
     SourceItems            = new ObservableCollection <SmartDataGroupsEditorData>();
     MakeItems();
     AddGroup = new AsyncAutoCommand(AddGroupToSource);
     Save     = new DelegateCommand(() =>
     {
         taskRunner.ScheduleTask("Saving Group Definitions to file", SaveGroupsToFile);
     });
     DeleteItem = new DelegateCommand <object>(DeleteItemFromSource);
     AddMember  = new AsyncAutoCommand <SmartDataGroupsEditorData>(AddItemToGroup);
     EditItem   = new AsyncAutoCommand <SmartDataGroupsEditorData>(EditSourceItem);
     // history setup
     History                  = historyCreator();
     historyHandler           = new SmartDataGroupsHistory(SourceItems);
     UndoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
     RedoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
     History.PropertyChanged += (sender, args) =>
     {
         UndoCommand.RaiseCanExecuteChanged();
         RedoCommand.RaiseCanExecuteChanged();
         IsModified = !History.IsSaved;
         RaisePropertyChanged(nameof(IsModified));
     };
     History.AddHandler(historyHandler);
 }
        public SessionServiceViewModel(ISessionService sessionService,
                                       IInputBoxService inputBoxService,
                                       IMessageBoxService messageBoxService,
                                       IWindowManager windowManager,
                                       Lazy <IDocumentManager> documentManager,
                                       ITextDocumentService textDocumentService,
                                       IHistoryManager historyManager)
        {
            this.SessionService    = sessionService;
            this.inputBoxService   = inputBoxService;
            this.messageBoxService = messageBoxService;
            this.windowManager     = windowManager;
            this.History           = historyManager;
            History.AddHandler(this);

            Undo = new DelegateCommand(() => History.Undo(), () => History.CanUndo).ObservesProperty(() =>
                                                                                                     History.CanUndo);
            Redo = new DelegateCommand(() => History.Redo(), () => History.CanRedo).ObservesProperty(() =>
                                                                                                     History.CanRedo);

            NewSessionCommand = new AsyncAutoCommand(NewSession);

            var save = new AsyncAutoCommand(SaveCurrent, _ => sessionService.IsNonEmpty);

            SaveCurrentCurrent = save;

            var forget = new AsyncAutoCommand(ForgetCurrent, _ => sessionService.IsOpened);

            ForgetCurrentCurrent = forget;

            DeleteItem = new DelegateCommand <ISolutionItem>(sessionService.RemoveItem, _ => sessionService.IsOpened).ObservesProperty(() => this.SessionService.IsOpened);

            var preview = new DelegateCommand(() =>
            {
                var sql = sessionService.GenerateCurrentQuery();
                if (sql == null)
                {
                    return;
                }
                documentManager.Value.OpenDocument(textDocumentService.CreateDocument($"Preview of " + sessionService.CurrentSession !.Name, sql, "sql"));
            }, () => sessionService.IsNonEmpty);

            PreviewCurrentCommand = preview;

            sessionService.ToObservable(o => o.IsNonEmpty)
            .SubscribeAction(_ =>
            {
                preview.RaiseCanExecuteChanged();
                forget.RaiseCanExecuteChanged();
                save.RaiseCanExecuteChanged();
            });

            History.ToObservable(h => h.IsSaved)
            .SubscribeAction(_ =>
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsModified)));
            });
        }
        public SmartDataDefinesListViewModel(ISmartRawDataProvider smartDataProvider, ISmartDataManager smartDataManager, IParameterFactory parameterFactory,
                                             ITaskRunner taskRunner, IMessageBoxService messageBoxService, IWindowManager windowManager, Func <IHistoryManager> historyCreator, SmartDataSourceMode dataSourceMode)
        {
            this.smartDataProvider = smartDataProvider;
            this.parameterFactory  = parameterFactory;
            this.smartDataManager  = smartDataManager;
            this.dataSourceMode    = dataSourceMode;
            this.messageBoxService = messageBoxService;
            this.windowManager     = windowManager;
            switch (dataSourceMode)
            {
            case SmartDataSourceMode.SD_SOURCE_EVENTS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetEvents());
                break;

            case SmartDataSourceMode.SD_SOURCE_ACTIONS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetActions());
                break;

            case SmartDataSourceMode.SD_SOURCE_TARGETS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetTargets());
                break;

            default:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>();
                break;
            }

            OnItemSelected = new DelegateCommand <SmartGenericJsonData?>(ShowEditorWindow);
            CreateNew      = new DelegateCommand(CreateNewItem);
            DeleteItem     = new DelegateCommand(DeleteSelectedItem);
            Save           = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Saving modified SmartData defines", SaveDataToFile);
            }, () => IsModified);
            SelectedItemIndex = -1;
            // history setup
            History                  = historyCreator();
            historyHandler           = new SmartDataListHistoryHandler(DefinesItems);
            UndoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
            RedoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
            History.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
                IsModified = !History.IsSaved;
                RaisePropertyChanged(nameof(IsModified));
            };
            History.AddHandler(historyHandler);
        }