Пример #1
0
        /// <summary>
        /// Drop table from Db
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void DropTableHandler(object sender, TableModel e)
        {
            var dialog = await this.ShowMessageAsync("Drop table", $"Do you really want to drop {e.Title} ? Changes can't be undone!",
                                                     MessageDialogStyle.AffirmativeAndNegative);

            if (dialog == MessageDialogResult.Affirmative)
            {
                var res = _updater.DropTable(e);

                if (res != null)
                {
                    await this.ShowMessageAsync("Drop table", res);

                    Output.WriteLine(OutputPanelListener.PrepareException(res));
                    return;
                }

                DatabaseModelDesigner designer;
                if (TryGetSelectedDesigner(out designer))
                {
                    var facade = new DiagramFacade(designer);
                    facade.RemoveTable(e);
                }
                await DatabaseConnectionSidebar.RefreshTreeData();
            }
        }
Пример #2
0
        /// <summary>
        /// Changed DB in Connection panel - MS Sql Server only
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="s">Selected DB</param>
        private async void DatabaseConnectionSidebarOnMsSqlDatabaseChanged(object sender, string s)
        {
            await DiagramFacade.CloseDiagramsOnDisconnect(this);

            SessionProvider.Instance.Database = s;
            await DatabaseConnectionSidebar.LoadMsSqlData(true);
        }
Пример #3
0
        /// <summary>
        /// Drop selected DB - MS Sql Server only
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="dbName">DB for drop</param>
        private async void DatabaseConnectionSidebarOnDropMsSqlDatabase(object sender, string dbName)
        {
            if (dbName.Equals(SessionProvider.Instance.Database))
            {
                await this.ShowMessageAsync("Drop database", $"Database {dbName} is currently in use");

                return;
            }

            var progress = await this.ShowProgressAsync($"Drop database {dbName}", "Please wait...");

            progress.SetIndeterminate();

            try
            {
                using (IMsSqlMapper mapper = new MsSqlMapper())
                {
                    await Task.Factory.StartNew(() => mapper.DropDatabase(dbName));

                    await DatabaseConnectionSidebar.LoadMsSqlData(true);

                    await progress.CloseAsync();

                    await this.ShowMessageAsync("Drop database", $"Database {dbName} dropped successfully");
                }
            }
            catch (SqlException ex)
            {
                await progress.CloseAsync();

                await this.ShowMessageAsync("Drop database", ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// Open saved diagram
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="diagramModel">Diagram for opening</param>
        private async void DatabaseConnectionSidebarOnAddDiagram(object sender, DiagramModel diagramModel)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            DiagramFacade.CreateNewDiagram(this, diagramModel.Name);

            LayoutAnchorable panel;

            if (TryGetSelectedPanel(out panel))
            {
                DatabaseModelDesigner designer;
                if (TryGetSelectedDesigner(out designer))
                {
                    panel.IsActiveChanged -= AnchorableDesignerActiveChangedHandler;
                    var facade = new DiagramFacade(designer.ViewModel);
                    try
                    {
                        await facade.LoadDiagram(designer.ModelDesignerCanvas, XDocument.Parse(diagramModel.Xml));
                    }
                    catch (Exception exception) when(exception is SqlException || exception is OracleException)
                    {
                        Output.WriteLine(OutputPanelListener.PrepareException(exception.Message));
                    }

                    panel.IsActiveChanged += AnchorableDesignerActiveChangedHandler;
                }
            }
            await DatabaseConnectionSidebar.RefreshTreeData();

            Mouse.OverrideCursor = null;
        }
Пример #5
0
        /// <summary>
        /// End current session
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private async void DatabaseConnectionSidebarOnDisconnectClick(object sender, System.EventArgs eventArgs)
        {
            await DiagramFacade.CloseDiagramsOnDisconnect(this);

            SessionProvider.Instance.Disconnect();
            DatabaseConnectionSidebar.HideDatabaseStackPanels();
        }
Пример #6
0
        /// <summary>
        /// Save diagram to DB and refresh treeview in panel
        /// </summary>
        /// <param name="vm"></param>
        private async void SaveDiagramAndRefresh(DatabaseModelDesignerViewModel vm)
        {
            var facade = new DiagramFacade(vm);
            var res    = facade.SaveDiagram();

            Output.WriteLine(DiagramFacade.DiagramSaved);
            await DatabaseConnectionSidebar.RefreshTreeData();
        }
Пример #7
0
        /// <summary>
        /// Create new DB - MS Sql Server only
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private async void DatabaseConnectionSidebarOnCreateMsSqlDatabase(object sender, System.EventArgs eventArgs)
        {
            string name = await this.ShowInputAsync("Create database", "Database name");

            if (name == null || name.Equals(string.Empty))
            {
                return;
            }

            try
            {
                using (IMsSqlMapper mapper = new MsSqlMapper())
                {
                    mapper.CreateDatabase(name);
                    await DatabaseConnectionSidebar.LoadMsSqlData(true);
                }
            }
            catch (SqlException exc)
            {
                await this.ShowMessageAsync("Create database", exc.Message);
            }
        }
Пример #8
0
        /// <summary>
        /// Rename selected table and refresh treeview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void RenameTableHandler(object sender, TableModel e)
        {
            var originalName = e.Title;
            var dialog       = new TableNameDialog()
            {
                Model = e,
                Owner = this
            };

            dialog.ShowDialog();

            string res = _updater.RenameTable(originalName, e);

            if (res != null)
            {
                await this.ShowMessageAsync("Rename table", res);

                Output.WriteLine(OutputPanelListener.PrepareException(res));
                return;
            }

            await DatabaseConnectionSidebar.RefreshTreeData();
        }
Пример #9
0
 /// <summary>
 /// Refresh treeview after table creation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public async void CreateTableHandler(object sender, System.EventArgs e)
 {
     await DatabaseConnectionSidebar.RefreshTreeData();
 }
Пример #10
0
        /// <summary>
        /// Connect to Oracle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ConnectToOracle_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            await DiagramFacade.CloseDiagramsOnDisconnect(this);

            SessionProvider.Instance.Disconnect();
            DatabaseConnectionSidebar.HideDatabaseStackPanels();

            ProgressDialogController progressDialogController = null;

            Func <ProgressDialogController, Task> closeProgress = async t =>
            {
                if (t != null)
                {
                    if (t.IsOpen)
                    {
                        await t.CloseAsync();
                    }
                }
            };

            try
            {
                progressDialogController = await this.ShowProgressAsync("Please wait", "Connecting to server...", false, new MetroDialogSettings()
                {
                    AnimateShow = false,
                    AnimateHide = false
                });

                progressDialogController.SetIndeterminate();

                var db = new OracleDatabase();
                await db.BuildSession(OracleServerNameTextBox.Text, OraclePortTextBox.Text, OracleSidTextBox.Text,
                                      OracleUsernameTextBox.Text, OraclePasswordBox.Password);

                //Init work
                await Task.Factory.StartNew(() =>
                {
                    using (IOracleMapper mapper = new OracleMapper())
                    {
                        TableModel model = mapper.ListTables().FirstOrDefault();
                        if (model != null)
                        {
                            mapper.ListForeignKeys(model.Title);
                        }
                    }
                });

                await closeProgress(progressDialogController);

                await this.ShowMessageAsync("Connected", $"Successfuly connected to {SessionProvider.Instance.ServerName}");

                var flyout = Flyouts.Items[2] as Flyout;

                if (flyout != null)
                {
                    flyout.IsOpen = !flyout.IsOpen;
                }

                await DatabaseConnectionSidebar.LoadOracleData();
            }
            catch (OracleException exception)
            {
                await closeProgress(progressDialogController);

                await this.ShowMessageAsync("Connection error", exception.Message);

                Output.WriteLine(OutputPanelListener.PrepareException(exception.Message));
                SessionProvider.Instance.ConnectionType = ConnectionType.None;
            }
        }
Пример #11
0
        /// <summary>
        /// Connect to MS SQL Server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ConnectToMsSql_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            await DiagramFacade.CloseDiagramsOnDisconnect(this);

            SessionProvider.Instance.Disconnect();
            DatabaseConnectionSidebar.HideDatabaseStackPanels();

            ProgressDialogController progressDialogController = null;

            Func <ProgressDialogController, Task> closeProgress = async t =>
            {
                if (t != null)
                {
                    if (t.IsOpen)
                    {
                        await t.CloseAsync();
                    }
                }
            };

            try
            {
                progressDialogController = await this.ShowProgressAsync("Please wait", "Connecting to server...", false, new MetroDialogSettings()
                {
                    AnimateShow = false,
                    AnimateHide = false
                });

                progressDialogController.SetIndeterminate();

                MsSqlDatabase db = new MsSqlDatabase();
                string        name = null, pass = null;
                bool          integratedSecurity = true;

                var server = MsSqlServerNameTextBox.Text;
                if (WinAuthSwitch.IsChecked != null)
                {
                    integratedSecurity = !WinAuthSwitch.IsChecked.Value;
                }

                if (!integratedSecurity)
                {
                    name = MsSqlUsernameTextBox.Text;
                    pass = MsSqlPasswordBox.Password;
                }

                await db.BuildSession(server, integratedSecurity, name, pass);

                await closeProgress(progressDialogController);

                await this.ShowMessageAsync("Connected", $"Successfuly connected to {SessionProvider.Instance.ServerName}");

                var flyout = Flyouts.Items[0] as Flyout;

                if (flyout != null)
                {
                    flyout.IsOpen = !flyout.IsOpen;
                }

                await DatabaseConnectionSidebar.LoadMsSqlData();
            }
            catch (SqlException exception)
            {
                await closeProgress(progressDialogController);

                await this.ShowMessageAsync("Connection error", exception.Message);

                SessionProvider.Instance.ConnectionType = ConnectionType.None;
            }
        }
Пример #12
0
        private async void ConnectToOracleOwnConnString_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var example =
                @"USER ID=c##username;PASSWORD=y0urP455woRd;DATA SOURCE=""(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.14.10)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))""";
            var res = await this.ShowInputAsync("Connection string", $"Use customized connection string \n (Example: {example})");

            if (res != null)
            {
                await DiagramFacade.CloseDiagramsOnDisconnect(this);

                SessionProvider.Instance.Disconnect();
                DatabaseConnectionSidebar.HideDatabaseStackPanels();

                ProgressDialogController progressDialogController = null;

                Func <ProgressDialogController, Task> closeProgress = async t =>
                {
                    if (t != null)
                    {
                        if (t.IsOpen)
                        {
                            await t.CloseAsync();
                        }
                    }
                };

                try
                {
                    progressDialogController = await this.ShowProgressAsync("Please wait", "Connecting to server...", false, new MetroDialogSettings()
                    {
                        AnimateShow = false,
                        AnimateHide = false
                    });

                    progressDialogController.SetIndeterminate();

                    var db = new OracleDatabase();
                    OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder(res);
                    builder.ConnectionTimeout = 2;

                    await db.TryToConnectToServer(builder.ConnectionString);

                    SessionProvider.Instance.OwnConnectionString    = res;
                    SessionProvider.Instance.UseOwnConnectionString = true;
                    SessionProvider.Instance.Username       = builder.UserID;
                    SessionProvider.Instance.ConnectionType = ConnectionType.Oracle;

                    //Init work
                    await Task.Factory.StartNew(() =>
                    {
                        using (IOracleMapper mapper = new OracleMapper())
                        {
                            TableModel model = mapper.ListTables().FirstOrDefault();
                            if (model != null)
                            {
                                mapper.ListForeignKeys(model.Title);
                            }
                        }
                    });

                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connected", $"Successfuly connected to server");

                    var flyout = Flyouts.Items[2] as Flyout;

                    if (flyout != null)
                    {
                        flyout.IsOpen = !flyout.IsOpen;
                    }

                    await DatabaseConnectionSidebar.LoadOracleData();
                }
                catch (OracleException exception)
                {
                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connection error", exception.Message);

                    Output.WriteLine(OutputPanelListener.PrepareException(exception.Message));
                    SessionProvider.Instance.ConnectionType = ConnectionType.None;
                }
                catch (ArgumentException)
                {
                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connection error", "Connection string is not valid");

                    SessionProvider.Instance.ConnectionType = ConnectionType.None;
                }
            }
        }
Пример #13
0
        private async void ConnectToMsSqlServerOwnConnString_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var example =
                @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Init;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True";
            var res = await this.ShowInputAsync("Connection string", $"Use customized connection string \n (Example: {example})");

            if (res != null)
            {
                await DiagramFacade.CloseDiagramsOnDisconnect(this);

                SessionProvider.Instance.Disconnect();
                DatabaseConnectionSidebar.HideDatabaseStackPanels();

                ProgressDialogController progressDialogController = null;

                Func <ProgressDialogController, Task> closeProgress = async t =>
                {
                    if (t != null)
                    {
                        if (t.IsOpen)
                        {
                            await t.CloseAsync();
                        }
                    }
                };

                try
                {
                    progressDialogController = await this.ShowProgressAsync("Please wait", "Connecting to server...", false,
                                                                            new MetroDialogSettings()
                    {
                        AnimateShow = false,
                        AnimateHide = false
                    });

                    progressDialogController.SetIndeterminate();

                    var db = new MsSqlDatabase();
                    await db.TryToConnectToServer(res);

                    SessionProvider.Instance.OwnConnectionString    = res;
                    SessionProvider.Instance.UseOwnConnectionString = true;
                    SessionProvider.Instance.ConnectionType         = ConnectionType.SqlServer;

                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connected", $"Successfuly connected to server");

                    var flyout = Flyouts.Items[0] as Flyout;

                    if (flyout != null)
                    {
                        flyout.IsOpen = !flyout.IsOpen;
                    }

                    await DatabaseConnectionSidebar.LoadMsSqlData();
                }
                catch (SqlException exception)
                {
                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connection error", exception.Message);

                    SessionProvider.Instance.ConnectionType = ConnectionType.None;
                }
                catch (ArgumentException)
                {
                    await closeProgress(progressDialogController);

                    await this.ShowMessageAsync("Connection error", "Connection string is not valid");

                    SessionProvider.Instance.ConnectionType = ConnectionType.None;
                }
            }
        }
Пример #14
0
 /// <summary>
 /// Delete saved diagram
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="diagramModel">Diagram for deletion</param>
 private async void DatabaseConnectionSidebarOnDropDiagram(object sender, DiagramModel diagramModel)
 {
     var ctx = new DatabaseContext(SessionProvider.Instance.ConnectionType);
     var res = ctx.DeleteDiagram(diagramModel.Name);
     await DatabaseConnectionSidebar.RefreshTreeData();
 }