protected async Task SaveSolutionItem()
        {
            UpdateSolutionItem();
            solutionManager.Refresh(SolutionItem);
            await taskRunner.ScheduleTask($"Export {Title} to database",
                                          async progress =>
            {
                progress.Report(0, 2, "Generate query");
                var query = await GenerateSaveQuery();
                progress.Report(1, 2, "Execute query");
                try
                {
                    await mySqlExecutor.ExecuteSql(query);
                    History.MarkAsSaved();
                    await AfterSave();
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Success, "Saved to database"));
                }
                catch (IMySqlExecutor.QueryFailedDatabaseException e)
                {
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Couldn't apply SQL: " + e.Message));
                    throw;
                }
                progress.ReportFinished();
            });

            Title = solutionItemName.GetName(SolutionItem);
        }
Esempio n. 2
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();
            }));
        }
Esempio n. 3
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);
     });
 }
        public void SaveAndReloadSolutionTask(ISolutionItem item)
        {
            var itemName = solutionItemNameRegistry.GetName(item);

            taskRunner.ScheduleTask($"Save and reload {itemName} on server",
                                    async progress =>
            {
                progress.Report(0, 1, "Generate query");

                var commands = remoteCommandGenerator.GenerateCommand(item);
                var reduced  = remoteConnectorService.Merge(commands);
                var query    = await sqlGenerator.GenerateSql(item);

                var sqlCount    = Math.Max(1, reduced.Count);
                var reloadCount = reduced.Count;
                var totalCount  = sqlCount + reloadCount;

                progress.Report(0, totalCount, "Update database");
                await sqlExecutor.ExecuteSql(query);

                for (int i = 0; i < reduced.Count; ++i)
                {
                    progress.Report(i + sqlCount, totalCount, reduced[i].GenerateCommand());
                    try
                    {
                        await remoteConnectorService.ExecuteCommand(reduced[i]);
                    }
                    catch (System.Net.Http.HttpRequestException)
                    {
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Error,
                                                                            "Unable to connect to server over SOAP. Check your settings or server settings."));
                        progress.ReportFail();
                        return;
                    }
                    catch (System.Threading.Tasks.TaskCanceledException)
                    {
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Error,
                                                                            "Unable to connect to server over SOAP. Check your settings or server settings."));
                        progress.ReportFail();
                        return;
                    }
                    catch (Exception e)
                    {
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Error,
                                                                            "Unable to connect to the server: " + e.Message));
                        progress.ReportFail();
                        return;
                    }
                }

                progress.ReportFinished();
            });
        }
 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"));
         });
     });
 }
        private async Task UpdatesCheck()
        {
            try
            {
                string?newUpdateUrl = await updateService.CheckForUpdates();

                if (newUpdateUrl != null)
                {
                    if (settingsProvider.Settings.EnableSilentUpdates)
                    {
                        DownloadUpdate();
                        statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Downloading update..."));
                    }
                    else
                    {
                        if (await messageBoxService.ShowDialog(new MessageBoxFactory <bool>()
                                                               .SetTitle("New update")
                                                               .SetMainInstruction("A new update is ready to be downloaded")
                                                               .SetContent("Do you want to download the update now?")
                                                               .WithYesButton(true)
                                                               .WithNoButton(false)
                                                               .SetIcon(MessageBoxIcon.Information)
                                                               .Build()))
                        {
                            DownloadUpdate();
                        }
                        else
                        {
                            statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
                                                                                "New updates are ready to download. Click to download.",
                                                                                new DelegateCommand(DownloadUpdate)));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while checking for the updates: " + e.Message));
            }
        }
Esempio n. 7
0
        public T?Get <T>(T?defaultValue = default) where T : ISettings
        {
            var settingsFile = GetSettingPath <T>();

            if (!fileSystem.Exists(settingsFile))
            {
                return(defaultValue);
            }

            try
            {
                using var file   = fileSystem.OpenRead(settingsFile);
                using var stream = new StreamReader(file);
                using var reader = new JsonTextReader(stream);
                return(json.Deserialize <T>(reader));
            }
            catch (Exception e)
            {
                statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while loading settings: " + e));
                return(defaultValue);
            }
        }
        private async Task UpdatesCheck()
        {
            try
            {
                string?newUpdateUrl = await updateService.CheckForUpdates();

                if (newUpdateUrl != null)
                {
                    statusBar.PublishNotification(new PlainNotification(NotificationType.Info,
                                                                        "New updates are ready to download. Click to download.",
                                                                        new DelegateCommand(() =>
                    {
                        statusBar.PublishNotification(
                            new PlainNotification(NotificationType.Info, "Downloading..."));
                        DownloadUpdate();
                    })));
                }
            }
            catch (Exception e)
            {
                statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while checking for the updates: " + e.Message));
            }
        }
Esempio n. 9
0
    public QuickCommands(Lazy <IQuickAccessService> service,
                         Lazy <IQuickAccessViewModel> viewModel,
                         IClipboardService clipboardService,
                         IStatusBar statusBar)
    {
        CopyCommand = new DelegateCommand <object>(o =>
        {
            var text = o.ToString() ?? "";
            clipboardService.SetText(text);
            statusBar.PublishNotification(new PlainNotification(NotificationType.Info, "Copied " + text));
            viewModel.Value.CloseSearch();
        });

        SetSearchCommand = new DelegateCommand <object>(o =>
        {
            viewModel.Value.OpenSearch(o.ToString());
        });

        NoCommand = new DelegateCommand(() => { });
    }
        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());
                }
            });
        }
Esempio n. 11
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();
                    }
                }
            });
        }