private void Initialize()
        {
            var connectionConfiguration = ConfigurationProvider.GetConnectionConfiguration(CurrentConnection.Name);
            var infrastructureFactory   = connectionConfiguration.InfrastructureFactory;

            _databaseMonitor     = infrastructureFactory.CreateDatabaseMonitor(CurrentConnection);
            _sessionDetailViewer = _databaseMonitor.CreateSessionDetailViewer();
            _sessionDetailViewer.RestoreConfiguration(_customProperties);

            var providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(CurrentConnection.ProviderName);

            ActiveSessionOnly = providerConfiguration.DatabaseMonitorConfiguration.ActiveSessionOnly;
            UserSessionOnly   = providerConfiguration.DatabaseMonitorConfiguration.UserSessionOnly;
            MasterSessionOnly = providerConfiguration.DatabaseMonitorConfiguration.MasterSessionOnly;

            if (!String.IsNullOrEmpty(providerConfiguration.DatabaseMonitorConfiguration.SortMemberPath))
            {
                SessionDataGridSource.SortDescriptions.Clear();
                SessionDataGridSource.SortDescriptions.Add(new SortDescription(providerConfiguration.DatabaseMonitorConfiguration.SortMemberPath, providerConfiguration.DatabaseMonitorConfiguration.SortColumnOrder));
            }

            lock (_databaseSessions)
            {
                _databaseSessions.Clear();
            }

            Refresh();
        }
Ejemplo n.º 2
0
        private void WindowTraceLogClosingHandler(object sender, CancelEventArgs args)
        {
            WorkDocumentCollection.StoreWindowProperties(this);

            args.Cancel = true;
            Hide();
        }
Ejemplo n.º 3
0
        private void WindowLoadedHandler(object sender, RoutedEventArgs args)
        {
            _windowDatabaseMonitor.Owner = WindowTraceLog.Instance.Owner = this;

            CommandBindings.Add(new CommandBinding(GenericCommands.SaveAll, SaveAllCommandExecutedHandler));

            WorkDocumentCollection.RestoreWindowProperties(this);
            _windowDatabaseMonitor.RestoreAppearance();

            if (WorkDocumentCollection.WorkingDocuments.Count > 0)
            {
                foreach (var workingDocument in WorkDocumentCollection.WorkingDocuments.OrderBy(d => d.TabIndex))
                {
                    AddNewDocumentPage(workingDocument);
                }
            }
            else
            {
                AddNewDocumentPage();
            }

            DocumentTabControl.SelectionChanged += TabControlSelectionChangedHandler;

            DocumentTabControl.SelectedIndex = WorkDocumentCollection.ActiveDocumentIndex;

            ClipboardManager.RegisterWindow(this);
            ClipboardManager.ClipboardChanged += ClipboardChangedHandler;

            EditorNavigationService.Initialize(ActiveDocument.WorkDocument);
        }
Ejemplo n.º 4
0
        public OutputViewer(DocumentPage documentPage)
        {
            DocumentPage = documentPage;

            FileResultViewer = new FileResultViewer(this);

            InitializeComponent();

            _timerExecutionMonitor = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher)
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _timerExecutionMonitor.Tick += TimerExecutionMonitorTickHandler;

            Application.Current.Deactivated += ApplicationDeactivatedHandler;

            Initialize();

            _providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(DocumentPage.CurrentConnection.ProviderName);

            ConnectionAdapter = DocumentPage.DatabaseModel.CreateConnectionAdapter();

            StatementValidator = DocumentPage.InfrastructureFactory.CreateStatementValidator();

            ExecutionPlanViewer      = DocumentPage.InfrastructureFactory.CreateExecutionPlanViewer(this);
            TabExecutionPlan.Content = ExecutionPlanViewer.Control;

            TraceViewer      = DocumentPage.InfrastructureFactory.CreateTraceViewer(ConnectionAdapter);
            TabTrace.Content = TraceViewer.Control;

            BreakOnExceptions = DocumentPage.WorkDocument.BreakOnExceptions;
        }
Ejemplo n.º 5
0
        internal static void ShowExecutionHistory(string providerName)
        {
            lock (ExecutionHistoryWindows)
            {
                MainWindow.ActiveDocument.EnsurePopupClosed();

                var configuration = WorkDocumentCollection.GetProviderConfiguration(providerName);

                if (!ExecutionHistoryWindows.TryGetValue(providerName, out var window))
                {
                    ExecutionHistoryWindows[providerName] = window = new StatementExecutionHistory(providerName)
                    {
                        Owner = MainWindow
                    };
                }

                window.ExecutionHistoryEntries.Clear();
                window.ExecutionHistoryEntries.AddRange(configuration.StatementExecutionHistory);

                if (window.IsVisible)
                {
                    window.Focus();
                }
                else
                {
                    window.Show();
                }
            }
        }
        private void UpdateFilterSettings(Action <DatabaseMonitorConfiguration> updateConfigurationAction)
        {
            var providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(CurrentConnection.ProviderName);

            updateConfigurationAction(providerConfiguration.DatabaseMonitorConfiguration);

            SessionDataGridSource.View.Refresh();
        }
Ejemplo n.º 7
0
        public StatementExecutionHistory(string providerName)
        {
            InitializeComponent();

            _providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(providerName);

            _collectionView = CollectionViewSource.GetDefaultView(_historyEntries);
            _collectionView.SortDescriptions.Add(new SortDescription("ExecutedAt", ListSortDirection.Descending));
        }
        public void RestoreAppearance()
        {
            _customProperties = WorkDocumentCollection.RestoreWindowProperties(this);

            double sessionDataGridHeight = 0;

            if (_customProperties?.TryGetValue(SessionDataGridHeightProperty, out sessionDataGridHeight) == true)
            {
                RowDefinitionSessionDataGrid.Height = new GridLength(sessionDataGridHeight);
            }
        }
        private void SessionDataGridSortingHandler(object sender, DataGridSortingEventArgs args)
        {
            var sortDirection = args.Column.SortDirection == ListSortDirection.Ascending
                                ? ListSortDirection.Descending
                                : ListSortDirection.Ascending;

            var providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(CurrentConnection.ProviderName);

            providerConfiguration.DatabaseMonitorConfiguration.SortMemberPath  = args.Column.SortMemberPath;
            providerConfiguration.DatabaseMonitorConfiguration.SortColumnOrder = sortDirection;
        }
Ejemplo n.º 10
0
        private void StoreWindowConfiguration()
        {
            _customProperties =
                new Dictionary <string, double>
            {
                { SessionDataGridHeightProperty, RowDefinitionSessionDataGrid.ActualHeight }
            };

            _sessionDetailViewer?.StoreConfiguration(_customProperties);

            WorkDocumentCollection.StoreWindowProperties(this, _customProperties);
        }
Ejemplo n.º 11
0
        internal void SaveWorkingDocuments()
        {
            foreach (var document in AllDocuments)
            {
                document.SaveWorkingDocument();
                document.WorkDocument.TabIndex = DocumentTabControl.Items.IndexOf(document.TabItem);
            }

            WorkDocumentCollection.StoreWindowProperties(this);
            WorkDocumentCollection.Save();

            TraceLog.WriteLine($"Working document collection saved. ");
        }
Ejemplo n.º 12
0
        private DocumentPage OpenExistingFile(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }

            var document = WorkDocument.IsSqlxFile(fileName)
                                ? WorkDocumentCollection.LoadDocumentFromFile(fileName)
                                : new WorkDocument {
                DocumentFileName = fileName
            };

            return(OpenExistingWorkDocument(document));
        }
Ejemplo n.º 13
0
        private DocumentPage OpenExistingWorkDocument(WorkDocument document)
        {
            DocumentPage documentPage;

            if (WorkDocumentCollection.TryGetWorkingDocumentFor(document.DocumentFileName, out var workDocument))
            {
                documentPage = AllDocuments.Single(d => d.WorkDocument == workDocument);
                DocumentTabControl.SelectedItem = documentPage.TabItem;
            }
            else
            {
                WorkDocumentCollection.AddDocument(document);
                documentPage = AddNewDocumentPage(document);
            }

            return(documentPage);
        }
Ejemplo n.º 14
0
        private static void Initialize()
        {
            ReleaseConfigurationLock();

            try
            {
                _lockFile = new FileStream(Path.Combine(ConfigurationProvider.FolderNameWorkArea, LockFileName), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
            }
            catch (Exception e)
            {
                TraceLog.WriteLine("Configuration lock aquire failed: " + e);
            }

            if (!ReadConfiguration(_fileName))
            {
                _allowBackupOverwrite = ReadConfiguration(_backupFileName);
            }

            if (_instance == null)
            {
                _instance = new WorkDocumentCollection();
            }
            else
            {
                if (_instance._workingDocuments == null)
                {
                    _instance._workingDocuments = new Dictionary <Guid, WorkDocument>();
                }

                if (_instance._recentFiles == null)
                {
                    _instance._recentFiles = new List <WorkDocument>();
                }

                if (_instance._windowConfigurations == null)
                {
                    _instance._windowConfigurations = new Dictionary <Type, WindowProperties>();
                }
            }

            if (_instance._databaseProviderConfigurations == null)
            {
                _instance._databaseProviderConfigurations = new Dictionary <string, DatabaseProviderConfiguration>();
            }
        }
Ejemplo n.º 15
0
        private void OpenRecentFileHandler(object sender, ExecutedRoutedEventArgs args)
        {
            var workDocument = (WorkDocument)args.Parameter;

            if (workDocument.File.Exists)
            {
                WorkDocumentCollection.AddRecentDocument(workDocument);
                OpenExistingWorkDocument(workDocument);
            }
            else
            {
                var result = MessageBox.Show(this, $"File '{workDocument.DocumentFileName}' does not exist anymore. Do you want to remove the link? ", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
                if (result == MessageBoxResult.Yes)
                {
                    WorkDocumentCollection.RemoveRecentDocument(workDocument);
                }
            }
        }
Ejemplo n.º 16
0
        internal bool CloseDocument(DocumentPage document)
        {
            DocumentTabControl.SelectedItem = document.TabItem;

            if (document.IsDirty && !ConfirmDocumentSave(document))
            {
                return(false);
            }

            document.SaveWorkingDocument();

            SelectNewTabItem();
            DocumentTabControl.RemoveTabItemWithoutBindingError(document.TabItem);

            WorkDocumentCollection.CloseDocument(document.WorkDocument);

            document.Dispose();
            return(true);
        }
Ejemplo n.º 17
0
        public static void Initialize()
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Trace log window has been already initialized. ");
            }

            var contentBuilder = new StringBuilder();

            foreach (var message in _messages.OrderBy(m => m))
            {
                contentBuilder.AppendLine(message);
            }

            Instance = new WindowTraceLog {
                TraceLog = contentBuilder.ToString()
            };
            _messages = new ConcurrentBag <string>();
            WorkDocumentCollection.RestoreWindowProperties(Instance);
        }
Ejemplo n.º 18
0
        private static bool ReadConfiguration(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(true);
            }

            using (var file = File.OpenRead(fileName))
            {
                try
                {
                    _instance = (WorkDocumentCollection)Serializer.Deserialize(file, _instance, typeof(WorkDocumentCollection));

                    TraceLog.WriteLine($"WorkDocumentCollection ({_instance._workingDocuments.Count} document(s)) successfully loaded from '{fileName}'. ");
                    return(true);
                }
                catch (Exception e)
                {
                    TraceLog.WriteLine($"WorkDocumentCollection deserialization from '{fileName}' failed: {e}");
                }
            }

            return(false);
        }
Ejemplo n.º 19
0
 private static void ConfigureWorkArea()
 {
     CreateDirectoryIfNotExists(FolderNameWorkArea);
     WorkDocumentCollection.Configure();
 }
Ejemplo n.º 20
0
 public static void Dispose()
 {
     ConfigurationWatcher.Dispose();
     WorkDocumentCollection.ReleaseConfigurationLock();
 }
Ejemplo n.º 21
0
 public static void Configure()
 {
     _instance = null;
     _fileName = GetWorkingDocumentConfigurationFileName(ConfigurationProvider.FolderNameWorkArea);
     ConfigureBackupFile();
 }