Beispiel #1
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 SmartDataEditorsProvider(ISmartRawDataProvider smartDataProvider, IParameterFactory parameterFactory, ISmartDataManager smartDataManager,
                                        ITaskRunner taskRunner, IMessageBoxService messageBoxService, IWindowManager windowManager, Func <IHistoryManager> historyCreator)
        {
            var editors = new List <IMenuItem> {
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Events", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                               taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_EVENTS }),
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Actions", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                                taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_ACTIONS }),
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Targets", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                                taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_TARGETS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Event Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                      messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_EVENTS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Action Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                       messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_ACTIONS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Target Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                       messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_TARGETS }),
            };

            var saiCategory = new List <IMenuItem> {
                new SmartDataCategoryItem("Smart Scripts", editors)
            };
            IMenuCategoryItem obj = new SmartDataCategoryItem("Smart Data", saiCategory);

            SubItems = new List <IMenuItem>()
            {
                obj
            };
        }
        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);
        }
        public SmartDataProvider(ISmartRawDataProvider smartRawDataProvider,
                                 ICurrentCoreVersion coreVersion)
        {
            this.coreVersion = coreVersion;

            actions = smartRawDataProvider.GetActions().Where(IsSmartValidForCore).ToList();
            events  = smartRawDataProvider.GetEvents().Where(IsSmartValidForCore).ToList();
            targets = smartRawDataProvider.GetTargets().Where(IsSmartValidForCore).ToList();

            var actionKeys = actions.Select(g => g.Name).ToHashSet();
            var eventKeys  = events.Select(g => g.Name).ToHashSet();
            var targetKeys = targets.Select(g => g.Name).ToHashSet();

            eventsGroups = smartRawDataProvider.GetEventsGroups().Select(group =>
                                                                         new SmartGroupsJsonData()
            {
                Name    = group.Name,
                Members = group.Members.Where(name => eventKeys.Contains(name)).ToList()
            })
                           .ToList();

            actionsGroups = smartRawDataProvider.GetActionsGroups().Select(group =>
                                                                           new SmartGroupsJsonData()
            {
                Name    = group.Name,
                Members = group.Members.Where(name => actionKeys.Contains(name)).ToList()
            })
                            .ToList();

            targetsGroups = smartRawDataProvider.GetTargetsGroups().Select(group =>
                                                                           new SmartGroupsJsonData()
            {
                Name    = group.Name,
                Members = group.Members.Where(name => targetKeys.Contains(name)).ToList()
            })
                            .ToList();
        }