private void RunSqlCode() { new QueryWindow((ServerConnection)Status.ActiveConnection.Clone(), CurrentDatabaseName, SqlPreview.GetText()).Show(); }
public MainVM() { StartCommand = new DelegateCommandAsync( o => Settings.Connections.CurrentConnection != null && Status.Status == AppStatusCodes.Ready, o => { // show server menu when we need a password or connection if ((o as bool?) != true && Settings.Connections.CurrentConnection?.RawPassword == null) { ServersCommand.Execute(null); return(Task.FromResult <object>(null)); } return(StartTraceAsync()); } ); StopCommand = new DelegateCommandAsync( o => Status.Status != AppStatusCodes.Ready, o => StopTraceAsync() ); ServersCommand = new DelegateCommand( o => Status.Status == AppStatusCodes.Ready, o => new ConnectWindow(Settings.Connections, () => StartCommand.Execute(true)).Show() ); ClearEventsCommand = new DelegateCommand( o => true, o => Events.Clear() ); SelectColumnsCommand = new DelegateCommand( o => true, o => { new ColumnSelectorWindow( Settings.Columns, (result) => { EventGrid.BuildColumns(result, Events); Settings.Columns = result.ToList(); OnPropertyChanged(nameof(Settings)); } ).Show(); } ); CopySqlCommand = new DelegateCommand( o => true, o => SqlPreview.CopyToClipboard() ); UserSettingsCommand = new DelegateCommand( o => true, o => new UserSettingsWindow(Settings).Show() ); AboutCommand = new DelegateCommand( o => true, o => new AboutWindow().Show() ); CheckUpdatesCommand = new DelegateCommandAsync( o => true, o => CheckForUpdates() ); ExitCommand = new DelegateCommand( o => true, o => OnExit() ); RunCommand = new DelegateCommand( o => Status.Status == AppStatusCodes.Running && SelectedEvent?.EventType != EventClassType.Custom && SqlPreview?.GetText() != null, o => RunSqlCode() ); RunBackgroundSqlCommand = new DelegateCommandAsync( o => Status.Status == AppStatusCodes.Running && SelectedEvent?.EventType != EventClassType.Custom && SqlPreview?.GetText() != null, o => { var exec = new ExecQuery((ServerConnection)Status.ActiveConnection.Clone(), CurrentDatabaseName); return(exec.ExecSqlAsync(SqlPreview.GetText())); } ); // capture new events Traces.OnEvent += (status, ev) => { if (status == ProfilerEventStatus.NewEvent && !ev.IsInternal) { Events.Add(ev); } }; // update canExecute() for each command when status changes Status.PropertyChanged += (ee, ss) => StatusChanged(); }