protected ViewModelBase(IHistoryManager history,
                                DatabaseTableSolutionItem solutionItem,
                                ISolutionItemNameRegistry solutionItemName,
                                ISolutionManager solutionManager,
                                ISolutionTasksService solutionTasksService,
                                IEventAggregator eventAggregator,
                                IQueryGenerator queryGenerator,
                                IDatabaseTableDataProvider databaseTableDataProvider,
                                IMessageBoxService messageBoxService,
                                ITaskRunner taskRunner,
                                IParameterFactory parameterFactory,
                                ITableDefinitionProvider tableDefinitionProvider,
                                IItemFromListProvider itemFromListProvider,
                                ISolutionItemIconRegistry iconRegistry,
                                ISessionService sessionService,
                                IDatabaseTableCommandService commandService,
                                IParameterPickerService parameterPickerService,
                                IStatusBar statusBar,
                                IMySqlExecutor mySqlExecutor)
        {
            this.solutionItemName          = solutionItemName;
            this.solutionManager           = solutionManager;
            this.solutionTasksService      = solutionTasksService;
            this.queryGenerator            = queryGenerator;
            this.databaseTableDataProvider = databaseTableDataProvider;
            this.messageBoxService         = messageBoxService;
            this.taskRunner              = taskRunner;
            this.parameterFactory        = parameterFactory;
            this.tableDefinitionProvider = tableDefinitionProvider;
            this.itemFromListProvider    = itemFromListProvider;
            this.sessionService          = sessionService;
            this.commandService          = commandService;
            this.parameterPickerService  = parameterPickerService;
            this.statusBar     = statusBar;
            this.mySqlExecutor = mySqlExecutor;
            this.solutionItem  = solutionItem;
            History            = history;

            undoCommand            = new DelegateCommand(History.Undo, CanUndo);
            redoCommand            = new DelegateCommand(History.Redo, CanRedo);
            Save                   = new AsyncAutoCommand(SaveSolutionItem);
            title                  = solutionItemName.GetName(solutionItem);
            Icon                   = iconRegistry.GetIcon(solutionItem);
            nameGeneratorParameter = parameterFactory.Factory("Parameter");

            History.PropertyChanged += (_, _) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(IsModified));
            };

            tableDefinition = tableDefinitionProvider.GetDefinition(solutionItem.DefinitionId) !;
            LoadAndCreateCommands();
            nameGeneratorParameter = parameterFactory.Factory(tableDefinition.Picker);
        }
示例#2
0
 public SmartScriptBaseFindAnywhereSource(ISmartDataManager smartDataManager,
                                          ISmartScriptDatabaseProvider databaseProvider,
                                          IEditorFeatures editorFeatures,
                                          ISolutionItemNameRegistry nameRegistry,
                                          ISolutionItemIconRegistry iconRegistry)
 {
     this.smartDataManager = smartDataManager;
     this.databaseProvider = databaseProvider;
     this.editorFeatures   = editorFeatures;
     this.nameRegistry     = nameRegistry;
     this.iconRegistry     = iconRegistry;
 }
 public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       ICurrentCoreVersion currentCoreVersion,
                                       ISolutionItemNameRegistry nameRegistry,
                                       IConditionQueryGenerator conditionQueryGenerator)
 {
     this.smartFactory            = smartFactory;
     this.smartDataManager        = smartDataManager;
     this.currentCoreVersion      = currentCoreVersion;
     this.nameRegistry            = nameRegistry;
     this.conditionQueryGenerator = conditionQueryGenerator;
 }
        public SmartScriptEditorViewModel(SmartScriptSolutionItem item, IHistoryManager history, IDatabaseProvider database, IEventAggregator eventAggregator, ISmartDataManager smartDataManager, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, ISmartTypeListProvider smartTypeListProvider, ISolutionItemNameRegistry itemNameRegistry)
        {
            _item                      = item;
            _history                   = history;
            this.database              = database;
            this.smartDataManager      = smartDataManager;
            this.smartFactory          = smartFactory;
            this.itemFromListProvider  = itemFromListProvider;
            this.smartTypeListProvider = smartTypeListProvider;
            this.itemNameRegistry      = itemNameRegistry;
            var lines = database.GetScriptFor(_item.Entry, _item.SmartType);

            script = new SmartScript(_item, smartFactory);
            script.Load(lines);

            EditEvent  = new DelegateCommand(EditEventCommand);
            EditAction = new DelegateCommand <SmartAction>(EditActionCommand);
            AddEvent   = new DelegateCommand(AddEventCommand);
            AddAction  = new DelegateCommand <SmartEvent>(AddActionCommand);

            SaveCommand = new DelegateCommand(SaveAllToDb);

            DeleteAction = new DelegateCommand <SmartAction>(DeleteActionCommand);
            DeleteEvent  = new DelegateCommand(DeleteEventCommand);

            _history.AddHandler(new SaiHistoryHandler(script));

            UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo);
            RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo);

            _history.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            };

            eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) =>
            {
                if (args.Item is SmartScriptSolutionItem)
                {
                    var itemm = args.Item as SmartScriptSolutionItem;
                    if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType)
                    {
                        args.Sql = new SmartScriptExporter(script, smartFactory).GetSql();
                    }
                }
            });
        }
 public ExporterHelper(SmartScript script,
                       IDatabaseProvider databaseProvider,
                       ISmartScriptSolutionItem item,
                       ISmartScriptExporter scriptExporter,
                       ICurrentCoreVersion currentCoreVersion,
                       ISolutionItemNameRegistry nameProvider,
                       IConditionQueryGenerator conditionQueryGenerator)
 {
     this.script                  = script;
     this.databaseProvider        = databaseProvider;
     this.item                    = item;
     this.scriptExporter          = scriptExporter;
     this.currentCoreVersion      = currentCoreVersion;
     this.conditionQueryGenerator = conditionQueryGenerator;
     this.nameProvider            = nameProvider;
 }
示例#6
0
 public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       ICurrentCoreVersion currentCoreVersion,
                                       ISolutionItemNameRegistry nameRegistry,
                                       IDatabaseProvider databaseProvider,
                                       IMessageBoxService messageBoxService,
                                       IConditionQueryGenerator conditionQueryGenerator)
 {
     this.smartFactory            = smartFactory;
     this.smartDataManager        = smartDataManager;
     this.currentCoreVersion      = currentCoreVersion;
     this.nameRegistry            = nameRegistry;
     this.databaseProvider        = databaseProvider;
     this.messageBoxService       = messageBoxService;
     this.conditionQueryGenerator = conditionQueryGenerator;
 }
示例#7
0
        protected ViewModelBase(IHistoryManager history,
                                DatabaseTableSolutionItem solutionItem,
                                ISolutionItemNameRegistry solutionItemName,
                                ISolutionManager solutionManager,
                                ISolutionTasksService solutionTasksService,
                                IEventAggregator eventAggregator,
                                IQueryGenerator queryGenerator,
                                IDatabaseTableDataProvider databaseTableDataProvider,
                                IMessageBoxService messageBoxService,
                                ITaskRunner taskRunner,
                                IParameterFactory parameterFactory,
                                ITableDefinitionProvider tableDefinitionProvider,
                                IItemFromListProvider itemFromListProvider,
                                ISolutionItemIconRegistry iconRegistry)
        {
            this.solutionItemName          = solutionItemName;
            this.solutionManager           = solutionManager;
            this.solutionTasksService      = solutionTasksService;
            this.queryGenerator            = queryGenerator;
            this.databaseTableDataProvider = databaseTableDataProvider;
            this.messageBoxService         = messageBoxService;
            this.taskRunner           = taskRunner;
            this.parameterFactory     = parameterFactory;
            this.itemFromListProvider = itemFromListProvider;
            this.solutionItem         = solutionItem;
            History = history;

            undoCommand            = new DelegateCommand(History.Undo, CanUndo);
            redoCommand            = new DelegateCommand(History.Redo, CanRedo);
            Save                   = new DelegateCommand(SaveSolutionItem);
            title                  = solutionItemName.GetName(solutionItem);
            Icon                   = iconRegistry.GetIcon(solutionItem);
            nameGeneratorParameter = parameterFactory.Factory("Parameter");

            History.PropertyChanged += (_, _) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(IsModified));
            };

            tableDefinition        = tableDefinitionProvider.GetDefinition(solutionItem.DefinitionId) !;
            nameGeneratorParameter = parameterFactory.Factory(tableDefinition.Picker);

            AutoDispose(eventAggregator.GetEvent <EventRequestGenerateSql>()
                        .Subscribe(ExecuteSql));
        }
 public SolutionTasksService(ITaskRunner taskRunner,
                             ISolutionItemSqlGeneratorRegistry sqlGenerator,
                             ISolutionItemRemoteCommandGeneratorRegistry remoteCommandGenerator,
                             IMySqlExecutor sqlExecutor,
                             ISolutionItemNameRegistry solutionItemNameRegistry,
                             IRemoteConnectorService remoteConnectorService,
                             IDatabaseProvider databaseProvider,
                             IStatusBar statusBar)
 {
     this.taskRunner               = taskRunner;
     this.sqlGenerator             = sqlGenerator;
     this.remoteCommandGenerator   = remoteCommandGenerator;
     this.sqlExecutor              = sqlExecutor;
     this.solutionItemNameRegistry = solutionItemNameRegistry;
     this.remoteConnectorService   = remoteConnectorService;
     this.databaseProvider         = databaseProvider;
     this.statusBar = statusBar;
 }
示例#9
0
 public SmartScriptEditorProvider(
     ISolutionItemNameRegistry solutionItemNameRegistry,
     IHistoryManager historyManager,
     IDatabaseProvider databaseProvider,
     IEventAggregator eventAggregator,
     ISmartFactory smartFactory,
     IItemFromListProvider itemFromListProvider,
     SmartTypeListProvider smartTypeListProvider
     )
 {
     this.solutionItemNameRegistry = solutionItemNameRegistry;
     this.historyManager           = historyManager;
     this.databaseProvider         = databaseProvider;
     this.eventAggregator          = eventAggregator;
     this.smartFactory             = smartFactory;
     this.itemFromListProvider     = itemFromListProvider;
     this.smartTypeListProvider    = smartTypeListProvider;
 }
示例#10
0
        public SolutionItemViewModel(ISolutionItemIconRegistry iconRegistry, ISolutionItemNameRegistry itemNameRegistry, ISolutionItem item, SolutionItemViewModel?parent)
        {
            this.iconRegistry     = iconRegistry;
            this.itemNameRegistry = itemNameRegistry;
            Item   = item;
            Parent = parent;
            Icon   = iconRegistry.GetIcon(item);

            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            if (item.Items != null)
            {
                Children = new ObservableCollection <SolutionItemViewModel>();

                foreach (ISolutionItem obj in item.Items)
                {
                    AddItem(obj);
                }

                item.Items.CollectionChanged += (sender, args) =>
                {
                    if (args.NewItems != null)
                    {
                        var i = 0;
                        foreach (ISolutionItem obj in args.NewItems)
                        {
                            AddItem(obj, args.NewStartingIndex + i);
                        }
                    }

                    if (args.OldItems != null)
                    {
                        foreach (ISolutionItem obj in args.OldItems)
                        {
                            ISolutionItem solutionItem = obj;
                            Children.Remove(itemToViewmodel[solutionItem]);
                            itemToViewmodel.Remove(solutionItem);
                        }
                    }
                };
            }
        }
示例#11
0
        public SolutionItemViewModel(ISolutionItemNameRegistry itemNameRegistry, ISolutionItem item, SolutionItemViewModel parent)
        {
            this.itemNameRegistry = itemNameRegistry;
            _item   = item;
            _parent = parent;

            _itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            if (item.Items != null)
            {
                _children = new ObservableCollection <SolutionItemViewModel>();

                foreach (object obj in item.Items)
                {
                    AddItem(obj as ISolutionItem);
                }

                item.Items.CollectionChanged += (sender, args) =>
                {
                    if (args.NewItems != null)
                    {
                        foreach (object obj in args.NewItems)
                        {
                            AddItem(obj as ISolutionItem);
                        }
                    }

                    if (args.OldItems != null)
                    {
                        foreach (object obj in args.OldItems)
                        {
                            var solutionItem = obj as ISolutionItem;
                            _children.Remove(_itemToViewmodel[solutionItem]);
                            _itemToViewmodel.Remove(solutionItem);
                        }
                    }
                };
            }
        }
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         ISolutionSqlService solutionSqlService,
                                         INewItemService newItemService,
                                         ISolutionTasksService solutionTasksService,
                                         IStatusBar statusBar,
                                         ISolutionItemIconRegistry solutionItemIconRegistry,
                                         ISolutionItemProvideService provider,
                                         IInputBoxService inputBoxService,
                                         IMessageBoxService messageBoxService)
        {
            this.itemNameRegistry = itemNameRegistry;
            this.solutionManager  = solutionManager;
            this.ea        = ea;
            this.statusBar = statusBar;
            this.solutionItemIconRegistry = solutionItemIconRegistry;
            this.inputBoxService          = inputBoxService;

            Root            = new ObservableCollection <SolutionItemViewModel>();
            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (ISolutionItem item in this.solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            this.solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    var i = 0;
                    foreach (ISolutionItem obj in args.NewItems)
                    {
                        AddItemToRoot(obj, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (ISolutionItem obj in args.OldItems)
                    {
                        ISolutionItem solutionItem = obj;
                        Root.Remove(itemToViewmodel[solutionItem]);
                        itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            solutionManager.RefreshRequest += item =>
            {
                foreach (var root in Root)
                {
                    root.Refresh();
                }
            };

            Dictionary <string, AddItemCategoryMenuViewModel> byNameCategories = new();
            Func <ISolutionItemProvider, Task> insertItemCommand = async provider =>
            {
                ISolutionItem?item = null;
                if (provider is INamedSolutionItemProvider namedProvider)
                {
                    var name = await this.inputBoxService.GetString("New",
                                                                    "Please provide a name for " + namedProvider.GetName(), "");

                    if (name == null || name.Length < 3)
                    {
                        await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                           .SetTitle("New")
                                                           .SetMainInstruction("Name is too short")
                                                           .SetContent("Name can't be shorter than 3 characters")
                                                           .WithOkButton(true)
                                                           .Build());

                        return;
                    }

                    item = await namedProvider.CreateSolutionItem(name);
                }
                else
                {
                    item = await provider.CreateSolutionItem();
                }
                if (item != null)
                {
                    DoAddItem(item);
                }
            };

            foreach (var item in provider.AllCompatible)
            {
                if (!byNameCategories.TryGetValue(item.GetGroupName(), out var category))
                {
                    category = new AddItemCategoryMenuViewModel(item.GetGroupName());
                    byNameCategories.Add(category.Name, category);
                    AddItems.Add(category);
                }

                category.Items.Add(new SolutionItemMenuViewModel(item, insertItemCommand));
            }

            AddItem = new DelegateCommand(async() =>
            {
                ISolutionItem?item = await newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    DoAddItem(item);
                }
            }, () => (SelectedItem == null || SelectedItem.IsContainer) && SelectedItems.Count <= 1)
                      .ObservesProperty(() => SelectedItem)
                      .ObservesProperty(() => SelectedItems.Count);

            RemoveItem = new DelegateCommand <SolutionItemViewModel>(vm =>
            {
                if (SelectedItems.Count > 0)
                {
                    foreach (var item in SelectedItems.ToList())
                    {
                        DeleteSolutionItem(item);
                    }
                    SelectedItems.Clear();
                }
                else if (vm != null)
                {
                    DeleteSolutionItem(vm);
                }
            }, vm => vm != null || SelectedItems.Count > 0)
                         .ObservesProperty(() => SelectedItems.Count);

            RenameItem = new AsyncAutoCommand <SolutionItemViewModel>(async vm =>
            {
                if (vm.Item is IRenameableSolutionItem renameable)
                {
                    var newName = await inputBoxService.GetString("Rename", "Please provide a new name", vm.Name);
                    if (newName != null)
                    {
                        if (newName.Length < 3)
                        {
                            await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                               .SetTitle("Rename")
                                                               .SetMainInstruction("Name too short")
                                                               .SetContent("The name can't be shorter than 3 characters")
                                                               .SetIcon(MessageBoxIcon.Warning)
                                                               .WithOkButton(true)
                                                               .Build());
                            return;
                        }
                        renameable.Rename(newName);
                        solutionManager.Refresh(vm.Item);
                    }
                }
            }, o => o is SolutionItemViewModel vm && vm.Item is IRenameableSolutionItem);

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>(ob => { selected = ob; });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>(item =>
            {
                if (item != null && !item.IsContainer)
                {
                    this.ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand <SolutionItemViewModel>(vm =>
            {
                if (vm != null)
                {
                    solutionSqlService.OpenDocumentWithSqlFor(vm.Item);
                }
            }, vm => vm != null);

            UpdateDatabase = new DelegateCommand <SolutionItemViewModel>(vm =>
            {
                if (vm != null)
                {
                    solutionTasksService.SaveSolutionToDatabaseTask(vm.Item);
                }
            }, vm => vm != null && solutionTasksService.CanSaveToDatabase);

            ExportToServer = new DelegateCommand <SolutionItemViewModel>(vm =>
            {
                if (vm != null)
                {
                    solutionTasksService.SaveAndReloadSolutionTask(vm.Item);
                }
            }, vm => vm != null && solutionTasksService.CanSaveAndReloadRemotely);

            ExportToServerItem = new DelegateCommand <object>(item =>
            {
                if (item is SolutionItemViewModel si)
                {
                    solutionTasksService.SaveAndReloadSolutionTask(si.Item);
                }
            }, item => solutionTasksService.CanSaveAndReloadRemotely);
        }
示例#13
0
 public SmartScriptEditorProvider(ISolutionItemNameRegistry solutionItemNameRegistry, IContainerProvider containerProvider)
 {
     this.solutionItemNameRegistry = solutionItemNameRegistry;
     this.containerProvider        = containerProvider;
 }
示例#14
0
 public SolutionItemViewModel(ISolutionItemNameRegistry itemNameRegistry, ISolutionItem item) : this(itemNameRegistry,
                                                                                                     item,
                                                                                                     null)
 {
 }
示例#15
0
 public TrinitySmartScriptFindAnywhereSource(ISmartDataManager smartDataManager, ISmartScriptDatabaseProvider databaseProvider, IEditorFeatures editorFeatures, ISolutionItemNameRegistry nameRegistry, ISolutionItemIconRegistry iconRegistry) : base(smartDataManager, databaseProvider, editorFeatures, nameRegistry, iconRegistry)
 {
 }
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         ISolutionSqlService solutionSqlService,
                                         INewItemService newItemService,
                                         ISolutionTasksService solutionTasksService,
                                         IStatusBar statusBar,
                                         ISolutionItemIconRegistry solutionItemIconRegistry,
                                         ISolutionItemProvideService provider)
        {
            this.itemNameRegistry = itemNameRegistry;
            this.solutionManager  = solutionManager;
            this.ea        = ea;
            this.statusBar = statusBar;
            this.solutionItemIconRegistry = solutionItemIconRegistry;

            Root            = new ObservableCollection <SolutionItemViewModel>();
            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (ISolutionItem item in this.solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            this.solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    var i = 0;
                    foreach (ISolutionItem obj in args.NewItems)
                    {
                        AddItemToRoot(obj, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (ISolutionItem obj in args.OldItems)
                    {
                        ISolutionItem solutionItem = obj;
                        Root.Remove(itemToViewmodel[solutionItem]);
                        itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            solutionManager.RefreshRequest += item =>
            {
                foreach (var root in Root)
                {
                    root.Refresh();
                }
            };

            Dictionary <string, AddItemCategoryMenuViewModel> byNameCategories = new();
            Func <ISolutionItemProvider, Task> insertItemCommand = async provider =>
            {
                var item = await provider.CreateSolutionItem();

                if (item != null)
                {
                    DoAddItem(item);
                }
            };

            foreach (var item in provider.AllCompatible)
            {
                if (item is INamedSolutionItemProvider)
                {
                    continue;
                }

                if (!byNameCategories.TryGetValue(item.GetGroupName(), out var category))
                {
                    category = new AddItemCategoryMenuViewModel(item.GetGroupName());
                    byNameCategories.Add(category.Name, category);
                    AddItems.Add(category);
                }

                category.Items.Add(new SolutionItemMenuViewModel(item, insertItemCommand));
            }

            AddItem = new DelegateCommand(async() =>
            {
                ISolutionItem?item = await newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    DoAddItem(item);
                }
            }, () => (SelectedItem == null || SelectedItem.IsContainer) && SelectedItems.Count <= 1)
                      .ObservesProperty(() => SelectedItem)
                      .ObservesProperty(() => SelectedItems.Count);

            RemoveItem = new DelegateCommand(() =>
            {
                if (SelectedItems.Count > 0)
                {
                    foreach (var item in SelectedItems.ToList())
                    {
                        DeleteSolutionItem(item);
                    }
                    SelectedItems.Clear();
                }
                else if (selected != null)
                {
                    DeleteSolutionItem(selected);
                }
            }, () => SelectedItem != null || SelectedItems.Count > 0)
                         .ObservesProperty(() => SelectedItem)
                         .ObservesProperty(() => SelectedItems.Count);

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>(ob => { selected = ob; });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>(item =>
            {
                if (item != null && !item.IsContainer)
                {
                    this.ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    solutionSqlService.OpenDocumentWithSqlFor(selected.Item);
                }
            });

            UpdateDatabase = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    solutionTasksService.SaveSolutionToDatabaseTask(selected.Item);
                }
            }, () => solutionTasksService.CanSaveToDatabase);

            ExportToServer = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    solutionTasksService.SaveAndReloadSolutionTask(selected.Item);
                }
            }, () => solutionTasksService.CanSaveAndReloadRemotely);

            ExportToServerItem = new DelegateCommand <SolutionItemViewModel>(item =>
            {
                if (item != null)
                {
                    solutionTasksService.SaveAndReloadSolutionTask(item.Item);
                }
            }, item => solutionTasksService.CanSaveAndReloadRemotely);
        }
示例#17
0
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         INewItemService newItemService,
                                         IStatusBar statusBar,
                                         ISolutionItemSqlGeneratorRegistry sqlGeneratorRegistry)
        {
            this.itemNameRegistry = itemNameRegistry;
            _solutionManager      = solutionManager;
            _ea        = ea;
            _statusBar = statusBar;

            _firstGeneration = new ObservableCollection <SolutionItemViewModel>();
            _itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (var item in _solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            _solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    int i = 0;
                    foreach (var obj in args.NewItems)
                    {
                        AddItemToRoot(obj as ISolutionItem, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (var obj in args.OldItems)
                    {
                        var solutionItem = obj as ISolutionItem;
                        Root.Remove(_itemToViewmodel[solutionItem]);
                        _itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            AddItem = new DelegateCommand(() =>
            {
                ISolutionItem item = newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    if (_selected == null)
                    {
                        solutionManager.Items.Add(item);
                    }
                    else
                    {
                        _selected.Item.Items.Add(item);
                    }
                }
            });

            RemoveItem = new DelegateCommand(() =>
            {
                if (_selected != null)
                {
                    if (_selected.Parent == null)
                    {
                        _solutionManager.Items.Remove(_selected.Item);
                    }
                    else
                    {
                        _selected.Parent.Item.Items.Remove(_selected.Item);
                    }
                }
            });

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>((ob) =>
            {
                _selected = ob;
            });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>((item) =>
            {
                if (item != null && !item.IsContainer)
                {
                    _ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (_selected != null)
                {
                    MetaSolutionSQL solution = new MetaSolutionSQL(sqlGeneratorRegistry.GenerateSql(_selected.Item));
                    _ea.GetEvent <EventRequestOpenItem>().Publish(solution);
                }
            });
        }
        public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry,
                                         ISolutionManager solutionManager,
                                         IEventAggregator ea,
                                         ISolutionSqlService solutionSqlService,
                                         INewItemService newItemService,
                                         IStatusBar statusBar)
        {
            this.itemNameRegistry = itemNameRegistry;
            this.solutionManager  = solutionManager;
            this.ea        = ea;
            this.statusBar = statusBar;

            Root            = new ObservableCollection <SolutionItemViewModel>();
            itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>();

            foreach (ISolutionItem item in this.solutionManager.Items)
            {
                AddItemToRoot(item);
            }

            this.solutionManager.Items.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    var i = 0;
                    foreach (object obj in args.NewItems)
                    {
                        AddItemToRoot(obj as ISolutionItem, args.NewStartingIndex + i);
                        i++;
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (object obj in args.OldItems)
                    {
                        ISolutionItem solutionItem = obj as ISolutionItem;
                        Root.Remove(itemToViewmodel[solutionItem]);
                        itemToViewmodel.Remove(solutionItem);
                    }
                }
            };

            AddItem = new DelegateCommand(async() =>
            {
                ISolutionItem item = await newItemService.GetNewSolutionItem();
                if (item != null)
                {
                    if (selected == null || selected.Item.Items == null)
                    {
                        solutionManager.Items.Add(item);
                    }
                    else
                    {
                        selected.Item.Items.Add(item);
                    }
                }
            });

            RemoveItem = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    if (selected.Parent == null)
                    {
                        this.solutionManager.Items.Remove(selected.Item);
                    }
                    else
                    {
                        selected.Parent.Item.Items.Remove(selected.Item);
                    }
                }
            });

            SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>(ob => { selected = ob; });

            RequestOpenItem = new DelegateCommand <SolutionItemViewModel>(item =>
            {
                if (item != null && !item.IsContainer)
                {
                    this.ea.GetEvent <EventRequestOpenItem>().Publish(item.Item);
                }
            });

            GenerateSQL = new DelegateCommand(() =>
            {
                if (selected != null)
                {
                    solutionSqlService.OpenDocumentWithSqlFor(selected.Item);
                }
            });
        }
示例#19
0
        public SmartScriptEditorViewModel(IHistoryManager history,
                                          IDatabaseProvider database,
                                          IEventAggregator eventAggregator,
                                          ISmartDataManager smartDataManager,
                                          ISmartFactory smartFactory,
                                          IItemFromListProvider itemFromListProvider,
                                          ISmartTypeListProvider smartTypeListProvider,
                                          IStatusBar statusbar,
                                          ISolutionItemNameRegistry itemNameRegistry)
        {
            this.history               = history;
            this.database              = database;
            this.smartDataManager      = smartDataManager;
            this.smartFactory          = smartFactory;
            this.itemFromListProvider  = itemFromListProvider;
            this.smartTypeListProvider = smartTypeListProvider;
            this.statusbar             = statusbar;
            this.itemNameRegistry      = itemNameRegistry;

            EditEvent       = new DelegateCommand(EditEventCommand);
            DeselectActions = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    if (!e.IsSelected)
                    {
                        foreach (var a in e.Actions)
                        {
                            a.IsSelected = false;
                        }
                    }
                }
            });
            DeselectAll = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    foreach (var a in e.Actions)
                    {
                        a.IsSelected = false;
                    }
                    e.IsSelected = false;
                }
            });
            DeselectAllEvents = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    e.IsSelected = false;
                }
            });
            OnDropItems = new DelegateCommand <int?>(destIndex =>
            {
                using (script.BulkEdit("Reorder events"))
                {
                    var selected = new List <SmartEvent>();
                    int d        = destIndex.Value;
                    for (int i = Events.Count - 1; i >= 0; --i)
                    {
                        if (Events[i].IsSelected)
                        {
                            if (i <= destIndex)
                            {
                                d--;
                            }
                            selected.Add(Events[i]);
                            script.Events.RemoveAt(i);
                        }
                    }
                    if (d == -1)
                    {
                        d = 0;
                    }
                    selected.Reverse();
                    foreach (var s in selected)
                    {
                        script.Events.Insert(d++, s);
                    }
                }
            });
            OnDropActions = new DelegateCommand <DropActionsArgs>(data =>
            {
                using (script.BulkEdit("Reorder actions"))
                {
                    var selected = new List <SmartAction>();
                    var d        = data.ActionIndex;
                    for (var eventIndex = 0; eventIndex < Events.Count; eventIndex++)
                    {
                        var e = Events[eventIndex];
                        for (int i = e.Actions.Count - 1; i >= 0; --i)
                        {
                            if (e.Actions[i].IsSelected)
                            {
                                if (eventIndex == data.EventIndex && i < data.ActionIndex)
                                {
                                    d--;
                                }
                                selected.Add(e.Actions[i]);
                                e.Actions.RemoveAt(i);
                            }
                        }
                    }
                    selected.Reverse();
                    foreach (var s in selected)
                    {
                        Events[data.EventIndex].Actions.Insert(d++, s);
                    }
                }
            });
            EditAction = new DelegateCommand <SmartAction>(action => EditActionCommand(action));
            AddEvent   = new DelegateCommand(AddEventCommand);
            AddAction  = new DelegateCommand <NewActionViewModel>(AddActionCommand);

            SaveCommand = new AsyncAutoCommand(SaveAllToDb, null, e =>
            {
                statusbar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while saving script to the database: " + e.Message));
            });

            DeleteAction   = new DelegateCommand <SmartAction>(DeleteActionCommand);
            DeleteSelected = new DelegateCommand(() =>
            {
                if (anyEventSelected)
                {
                    using (script.BulkEdit("Delete events"))
                    {
                        int?nextSelect = firstSelectedIndex;
                        if (multipleEventsSelected)
                        {
                            nextSelect = null;
                        }

                        for (int i = Events.Count - 1; i >= 0; --i)
                        {
                            if (Events[i].IsSelected)
                            {
                                Events.RemoveAt(i);
                            }
                        }

                        if (nextSelect.HasValue)
                        {
                            if (nextSelect.Value < Events.Count)
                            {
                                Events[nextSelect.Value].IsSelected = true;
                            }
                            else if (nextSelect.Value - 1 >= 0 && nextSelect.Value - 1 < Events.Count)
                            {
                                Events[nextSelect.Value - 1].IsSelected = true;
                            }
                        }
                    }
                }
                else if (anyActionSelected)
                {
                    using (script.BulkEdit("Delete actions"))
                    {
                        (int eventIndex, int actionIndex)? nextSelect = firstSelectedActionIndex;
                        if (multipleActionsSelected)
                        {
                            nextSelect = null;
                        }

                        for (int i = 0; i < Events.Count; ++i)
                        {
                            var e = Events[i];
                            for (int j = e.Actions.Count - 1; j >= 0; --j)
                            {
                                if (e.Actions[j].IsSelected)
                                {
                                    e.Actions.RemoveAt(j);
                                }
                            }
                        }

                        if (nextSelect.HasValue && nextSelect.Value.actionIndex < Events[nextSelect.Value.eventIndex].Actions.Count)
                        {
                            Events[nextSelect.Value.eventIndex].Actions[nextSelect.Value.actionIndex].IsSelected = true;
                        }
                    }
                }
            });

            UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo);
            RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo);

            EditSelected = new DelegateCommand(() =>
            {
                if (anyEventSelected)
                {
                    if (!multipleEventsSelected)
                    {
                        EditEventCommand();
                    }
                }
                else if (anyActionSelected && !multipleActionsSelected)
                {
                    EditActionCommand(Events[firstSelectedActionIndex.eventIndex]
                                      .Actions[firstSelectedActionIndex.actionIndex]);
                }
            });

            CopyCommand = new DelegateCommand(() =>
            {
                var selectedEvents = Events.Where(e => e.IsSelected).ToList();
                if (selectedEvents.Count > 0)
                {
                    var lines = string.Join("\n",
                                            selectedEvents.SelectMany((e, index) => e.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, index)).Select(s => s.ToSqlString()));
                    Clipboard.SetText(lines);
                }
                else
                {
                    var selectedActions = Events.SelectMany(e => e.Actions).Where(e => e.IsSelected).ToList();
                    if (selectedActions.Count > 0)
                    {
                        var fakeEvent = new SmartEvent(-1)
                        {
                            ReadableHint = ""
                        };
                        foreach (var a in selectedActions)
                        {
                            fakeEvent.AddAction(a.Copy());
                        }
                        var lines = string.Join("\n", fakeEvent.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, 0).Select(s => s.ToSqlString()));
                        Clipboard.SetText(lines);
                    }
                }
            });
            CutCommand = new DelegateCommand(() =>
            {
                CopyCommand.Execute();
                DeleteSelected.Execute();
            });
            PasteCommand = new DelegateCommand(() =>
            {
                var lines = (Clipboard.GetText() ?? "").Split('\n').Select(line =>
                {
                    if (line.TryToISmartScriptLine(out var s))
                    {
                        return(s);
                    }
                    return(null);
                }).Where(l => l != null).ToList();
                if (lines.Count > 0)
                {
                    if (lines[0].EventType == -1) // actions
                    {
                        int?eventIndex  = null;
                        int?actionIndex = null;
                        using (script.BulkEdit("Paste actions"))
                        {
                            for (int i = 0; i < Events.Count - 1; ++i)
                            {
                                if (Events[i].IsSelected)
                                {
                                    eventIndex = i;
                                }

                                for (int j = Events[i].Actions.Count - 1; j >= 0; j--)
                                {
                                    if (Events[i].Actions[j].IsSelected)
                                    {
                                        eventIndex = i;
                                        if (!actionIndex.HasValue)
                                        {
                                            actionIndex = j;
                                        }
                                        else
                                        {
                                            actionIndex--;
                                        }
                                        //Events[i].Actions.RemoveAt(j);
                                    }
                                }
                            }

                            if (!eventIndex.HasValue)
                            {
                                eventIndex = Events.Count - 1;
                            }

                            if (eventIndex < 0)
                            {
                                return;
                            }

                            if (!actionIndex.HasValue)
                            {
                                actionIndex = Events[eventIndex.Value].Actions.Count - 1;
                            }

                            if (actionIndex < 0)
                            {
                                actionIndex = 0;
                            }

                            DeselectAll.Execute();
                            foreach (var smartAction in lines.Select(line => script.SafeActionFactory(line)))
                            {
                                Events[eventIndex.Value].Actions.Insert(actionIndex.Value, smartAction);
                                smartAction.IsSelected = true;
                                actionIndex++;
                            }
                        }
                    }
                    else
                    {
                        int?index = null;
                        using (script.BulkEdit("Paste events"))
                        {
                            for (int i = Events.Count - 1; i >= 0; --i)
                            {
                                if (Events[i].IsSelected)
                                {
                                    if (!index.HasValue)
                                    {
                                        index = i;
                                    }
                                    else
                                    {
                                        index--;
                                    }
                                    //Events.RemoveAt(i);
                                }
                            }
                            if (!index.HasValue)
                            {
                                index = Events.Count;
                            }
                            script.InsertFromClipboard(index.Value, lines);
                        }
                    }
                }
            });

            Action <bool, int> selectionUpDown = (addToSelection, diff) =>
            {
                if (anyEventSelected)
                {
                    var selectedEventIndex = Math.Clamp(firstSelectedIndex + diff, 0, Events.Count - 1);
                    if (!addToSelection)
                    {
                        DeselectAll.Execute();
                    }
                    Events[selectedEventIndex].IsSelected = true;
                }
                else if (anyActionSelected)
                {
                    var nextActionIndex = firstSelectedActionIndex.actionIndex + diff;
                    var nextEventIndex  = firstSelectedActionIndex.eventIndex;
                    while (nextActionIndex == -1 || nextActionIndex >= Events[nextEventIndex].Actions.Count)
                    {
                        nextEventIndex += diff;
                        if (nextEventIndex >= 0 && nextEventIndex < Events.Count)
                        {
                            nextActionIndex = diff > 0 ? (Events[nextEventIndex].Actions.Count > 0 ? 0 : -1) : Events[nextEventIndex].Actions.Count - 1;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (nextActionIndex != -1 && nextEventIndex >= 0 && nextEventIndex < Events.Count)
                    {
                        DeselectAll.Execute();
                        Events[nextEventIndex].Actions[nextActionIndex].IsSelected = true;
                    }
                }
                else
                {
                    if (Events.Count > 0)
                    {
                        Events[diff > 0 ? 0 : Events.Count - 1].IsSelected = true;
                    }
                }
            };

            SelectionUp   = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, -1));
            SelectionDown = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, 1));
            SelectionLeft = new DelegateCommand(() =>
            {
                if (!anyEventSelected && anyActionSelected)
                {
                    var actionEventIndex = firstSelectedActionIndex;
                    DeselectAll.Execute();
                    Events[actionEventIndex.eventIndex].IsSelected = true;
                }
                else if (!anyEventSelected && !anyActionSelected)
                {
                    selectionUpDown(false, -1);
                }
            });
            SelectionRight = new DelegateCommand(() =>
            {
                if (!anyEventSelected)
                {
                    selectionUpDown(false, -1);
                }
                if (anyEventSelected)
                {
                    var eventIndex = firstSelectedIndex;
                    if (Events[eventIndex].Actions.Count > 0)
                    {
                        DeselectAll.Execute();
                        Events[eventIndex].Actions[0].IsSelected = true;
                    }
                }
            });

            SelectAll = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    e.IsSelected = true;
                }
            });

            this.history.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            };

            token = eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) =>
            {
                if (args.Item is SmartScriptSolutionItem)
                {
                    var itemm = args.Item as SmartScriptSolutionItem;
                    if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType)
                    {
                        args.Sql = new SmartScriptExporter(script, smartFactory).GetSql();
                    }
                }
            });
        }