示例#1
0
        private Task SaveSolutionToDatabaseTask(ISolutionItem item, ISolutionItemDocument?document, Func <ISolutionItem, ISolutionItemDocument?, Task <IQuery> > queryGenerator)
        {
            if (!CanSaveToDatabase)
            {
                return(Task.CompletedTask);
            }
            var itemName = solutionItemNameRegistry.GetName(item);

            return(taskRunner.ScheduleTask($"Export {itemName} to database",
                                           async progress =>
            {
                progress.Report(0, 2, "Generate query");
                var query = await queryGenerator(item, document);
                progress.Report(1, 2, "Execute query");
                try
                {
                    await sqlExecutor.ExecuteSql(query);
                }
                catch (IMySqlExecutor.QueryFailedDatabaseException e)
                {
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Couldn't apply SQL: " + e.Message));
                    throw;
                }
                progress.ReportFinished();
            }));
        }
 public RowPickerViewModel(ViewModelBase baseViewModel,
                           ITaskRunner taskRunner,
                           ISolutionItemSqlGeneratorRegistry queryGeneratorRegistry,
                           IClipboardService clipboardService,
                           IWindowManager windowManager,
                           IEventAggregator eventAggregator,
                           ISolutionItemEditorRegistry solutionItemEditorRegistry,
                           ISessionService sessionService,
                           IMessageBoxService messageBoxService,
                           ISolutionTasksService solutionTasksService,
                           bool noSaveMode = false)
 {
     this.baseViewModel = baseViewModel;
     this.solutionItemEditorRegistry = solutionItemEditorRegistry;
     this.sessionService             = sessionService;
     this.messageBoxService          = messageBoxService;
     this.noSaveMode = noSaveMode;
     Watch(baseViewModel, o => o.IsModified, nameof(Title));
     ExecuteChangedCommand = noSaveMode ? AlwaysDisabledCommand.Command : new AsyncAutoCommand(async() =>
     {
         baseViewModel.Save.Execute(null);
         eventAggregator.GetEvent <DatabaseTableChanged>().Publish(baseViewModel.TableDefinition.TableName);
         await taskRunner.ScheduleTask("Update session", async() => await sessionService.UpdateQuery(baseViewModel));
         if (solutionTasksService.CanReloadRemotely)
         {
             await solutionTasksService.ReloadSolutionRemotelyTask(baseViewModel.SolutionItem);
         }
     });
     CopyCurrentSqlCommand = new AsyncAutoCommand(async() =>
     {
         await taskRunner.ScheduleTask("Generating SQL",
                                       async() => { clipboardService.SetText((await baseViewModel.GenerateQuery()).QueryString); });
     });
     GenerateCurrentSqlCommand = new AsyncAutoCommand(async() =>
     {
         var sql    = await baseViewModel.GenerateQuery();
         var item   = new MetaSolutionSQL(new JustQuerySolutionItem(sql.QueryString));
         var editor = solutionItemEditorRegistry.GetEditor(item);
         await windowManager.ShowDialog((IDialog)editor);
     });
     PickSelected = new AsyncAutoCommand(async() =>
     {
         await AskIfSave(false);
     });
     Cancel = new DelegateCommand(() =>
     {
         CloseCancel?.Invoke();
     });
     Accept = PickSelected;
 }
示例#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 UpdateViewModel(IUpdateService updateService,
                               ITaskRunner taskRunner,
                               IStatusBar statusBar,
                               IUpdaterSettingsProvider settingsProvider,
                               IAutoUpdatePlatformService platformService,
                               IFileSystem fileSystem,
                               IStandaloneUpdater standaloneUpdater,
                               IApplication application,
                               IMessageBoxService messageBoxService)
        {
            this.updateService     = updateService;
            this.taskRunner        = taskRunner;
            this.statusBar         = statusBar;
            this.settingsProvider  = settingsProvider;
            this.platformService   = platformService;
            this.fileSystem        = fileSystem;
            this.messageBoxService = messageBoxService;
            CheckForUpdatesCommand = new DelegateCommand(() =>
            {
                if (updateService.CanCheckForUpdates())
                {
                    taskRunner.ScheduleTask("Check for updates", UpdatesCheck);
                }
            }, updateService.CanCheckForUpdates);

            if (!settingsProvider.Settings.DisableAutoUpdates)
            {
                CheckForUpdatesCommand.Execute(null);
            }
        }
示例#5
0
 private SqlEditorViewModel(IMySqlExecutor mySqlExecutor,
                            IStatusBar statusBar,
                            IDatabaseProvider databaseProvider,
                            ITaskRunner taskRunner,
                            INativeTextDocument sql)
 {
     Code       = sql;
     ExecuteSql = new DelegateCommand(() =>
     {
         taskRunner.ScheduleTask("Executing query",
                                 async() =>
         {
             statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Executing query"));
             try
             {
                 await mySqlExecutor.ExecuteSql(Code.ToString());
                 statusBar.PublishNotification(new PlainNotification(NotificationType.Success, "Query executed"));
             }
             catch (Exception e)
             {
                 statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Failure during query execution"));
                 Console.WriteLine(e);
             }
         });
     }, () => databaseProvider.IsConnected);
     IsLoading = false;
     Save      = new DelegateCommand(() =>
     {
         ExecuteSql.Execute(null);
     });
 }
示例#6
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);
        }
示例#7
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);
        }
        public void SaveSolutionToDatabaseTask(ISolutionItem item)
        {
            if (!CanSaveToDatabase)
            {
                return;
            }
            var itemName = solutionItemNameRegistry.GetName(item);

            taskRunner.ScheduleTask($"Export {itemName} to database",
                                    async progress =>
            {
                progress.Report(0, 2, "Generate query");
                var query = await sqlGenerator.GenerateSql(item);
                progress.Report(1, 2, "Execute query");
                await sqlExecutor.ExecuteSql(query);
                progress.ReportFinished();
            });
        }
        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 SqlEditorViewModel(IMySqlExecutor mySqlExecutor, IStatusBar statusBar, ITaskRunner taskRunner, string sql)
 {
     Code       = new TextDocument(sql);
     ExecuteSql = new DelegateCommand(() =>
     {
         taskRunner.ScheduleTask("Executing query",
                                 async() =>
         {
             statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Executing query"));
             await mySqlExecutor.ExecuteSql(Code.Text);
             statusBar.PublishNotification(new PlainNotification(NotificationType.Success, "Query executed"));
         });
     });
 }
示例#11
0
 public SqlEditorViewModel(IMySqlExecutor mySqlExecutor,
                           IStatusBar statusBar,
                           IDatabaseProvider databaseProvider,
                           ITaskRunner taskRunner,
                           ISolutionItemSqlGeneratorRegistry sqlGeneratorsRegistry,
                           INativeTextDocument sql,
                           MetaSolutionSQL item) : this(mySqlExecutor, statusBar, databaseProvider, taskRunner, sql)
 {
     IsLoading = true;
     taskRunner.ScheduleTask("Generating SQL",
                             async() =>
     {
         string sql = await sqlGeneratorsRegistry.GenerateSql(item.ItemToGenerate);
         Code.FromString(sql);
         IsLoading = false;
     });
 }
 private void DownloadUpdate()
 {
     statusBar.PublishNotification(
         new PlainNotification(NotificationType.Info, "Downloading..."));
     taskRunner.ScheduleTask("Downloading update", DownloadUpdateTask);
 }
示例#13
0
        public TextDocumentViewModel(IWindowManager windowManager,
                                     ITaskRunner taskRunner,
                                     IStatusBar statusBar,
                                     IMySqlExecutor mySqlExecutor,
                                     IDatabaseProvider databaseProvider,
                                     INativeTextDocument nativeTextDocument,
                                     IQueryParserService queryParserService,
                                     ISessionService sessionService,
                                     IMessageBoxService messageBoxService)
        {
            Extension      = "txt";
            Title          = "New file";
            this.statusBar = statusBar;
            document       = nativeTextDocument;

            SaveCommand = new AsyncAutoCommand(async() =>
            {
                var path = await windowManager.ShowSaveFileDialog($"{Extension} file|{Extension}|All files|*");
                if (path != null)
                {
                    await File.WriteAllTextAsync(path, document.ToString());
                }
            });
            ExecuteSqlSaveSession = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Executing query",
                                        () => WrapStatusbar(async() =>
                {
                    var query = Document.ToString();
                    IList <ISolutionItem>?solutionItems = null;
                    IList <string>?errors = null;
                    if (inspectQuery && sessionService.IsOpened && !sessionService.IsPaused)
                    {
                        (solutionItems, errors) = await queryParserService.GenerateItemsForQuery(query);
                    }

                    await mySqlExecutor.ExecuteSql(query);

                    if (solutionItems != null)
                    {
                        foreach (var item in solutionItems)
                        {
                            await sessionService.UpdateQuery(item);
                        }
                        if (errors !.Count > 0)
                        {
                            await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                               .SetTitle("Apply query")
                                                               .SetMainInstruction("Some queries couldn't be transformed into session items")
                                                               .SetContent("Details:\n\n" + string.Join("\n", errors.Select(s => "  - " + s)))
                                                               .WithOkButton(true)
                                                               .Build());
                        }
                    }
                }));
            }, () => databaseProvider.IsConnected);
            ExecuteSql = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Executing query",
                                        () => WrapStatusbar(() => mySqlExecutor.ExecuteSql(Document.ToString())));
            }, () => databaseProvider.IsConnected);
        }
 protected Task ScheduleLoading()
 {
     IsLoading = true;
     return(taskRunner.ScheduleTask($"Loading {Title}..", InternalLoadData));
 }
示例#15
0
 protected void ScheduleLoading()
 {
     IsLoading = true;
     taskRunner.ScheduleTask($"Loading {Title}..", LoadTableDefinition);
 }
        public WizardStyleViewModelBase(
            IMessageBoxService messageBoxService,
            ICoreSourceSettings coreSourceSettings,
            ISourceSqlUpdateService sqlUpdateService,
            IAuthMySqlExecutor authExecutor,
            IMySqlExecutor worldExecutor,
            IWindowManager windowManager,
            ITaskRunner taskRunner,
            IStatusBar statusBar,
            INativeTextDocument resultCode)
        {
            ResultCode       = resultCode;
            CoreSourceFolder = coreSourceSettings.CurrentCorePath;
            if (!string.IsNullOrEmpty(coreSourceSettings.CurrentCorePath))
            {
                Dispatcher.UIThread.Post(() => WizardStep++);
            }

            CommandPreviousStep = new DelegateCommand(() => WizardStep--, () => !IsLoading && WizardStep > 0)
                                  .ObservesProperty(() => IsLoading)
                                  .ObservesProperty(() => WizardStep);

            CommandNextStep = new DelegateCommand(() => WizardStep++, () => !IsLoading && WizardStep < TotalSteps - 1)
                              .ObservesProperty(() => IsLoading)
                              .ObservesProperty(() => WizardStep);

            PickCoreSourceFolder = new AsyncAutoCommand(async() =>
            {
                var selectedPath = await windowManager.ShowFolderPickerDialog(coreSourceFolder);
                if (selectedPath != null)
                {
                    if (!coreSourceSettings.SetCorePath(selectedPath))
                    {
                        await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                           .SetTitle("Invalid folder")
                                                           .SetMainInstruction("Invalid wow source folder")
                                                           .SetContent(
                                                               "It looks like it is not an valid wow server source folder.\n\nThe folder should contain src/ and sql/ subfolders")
                                                           .WithOkButton(true)
                                                           .Build());
                    }
                    CoreSourceFolder = coreSourceSettings.CurrentCorePath;
                }
            });

            ExecuteSqlCommand = new AsyncAutoCommand(async() =>
            {
                var(auth, world) = GenerateSql();
                try
                {
                    await taskRunner.ScheduleTask("Executing commands update", async() =>
                    {
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Executing query"));
                        if (auth != null)
                        {
                            if (authExecutor.IsConnected)
                            {
                                await authExecutor.ExecuteSql(auth);
                            }
                            else
                            {
                                await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                                   .SetTitle("Auth database not connected")
                                                                   .SetIcon(MessageBoxIcon.Warning)
                                                                   .SetMainInstruction("Auth database not connected")
                                                                   .SetContent(
                                                                       "You are trying to execute auth query, but auth database is not connected.\n\nEnsure you have correct auth database data in settings.")
                                                                   .WithOkButton(true)
                                                                   .Build());
                            }
                        }

                        if (world != null)
                        {
                            if (worldExecutor.IsConnected)
                            {
                                await worldExecutor.ExecuteSql(world);
                            }
                            else
                            {
                                await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                                   .SetTitle("World database not connected")
                                                                   .SetIcon(MessageBoxIcon.Warning)
                                                                   .SetMainInstruction("World database not connected")
                                                                   .SetContent(
                                                                       "You are trying to execute world query, but world database is not connected.\n\nEnsure you have correct world database data in settings.")
                                                                   .WithOkButton(true)
                                                                   .Build());
                            }
                        }

                        statusBar.PublishNotification(new PlainNotification(NotificationType.Success,
                                                                            "Executed query"));
                    });
                }
                catch (Exception)
                {
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while executing query. Check Database Query Debug window"));
                }
            }, _ => worldExecutor.IsConnected || authExecutor.IsConnected);

            SaveSqlCommand = new AsyncAutoCommand(async() =>
            {
                var(auth, world) = GenerateSql();

                if (auth != null)
                {
                    sqlUpdateService.SaveAuthUpdate(SqlSuffixName, auth);
                }

                if (world != null)
                {
                    sqlUpdateService.SaveWorldUpdate(SqlSuffixName, world);
                }

                if (auth != null || world != null)
                {
                    await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                       .SetTitle("Done!")
                                                       .SetContent("SQL files saved to sql/updates/")
                                                       .SetIcon(MessageBoxIcon.Information)
                                                       .WithOkButton(true)
                                                       .Build());
                }
            });
        }
 private void DownloadUpdate()
 {
     taskRunner.ScheduleTask("Downloading update", DownloadUpdateTask);
 }