예제 #1
0
        private void BuildChildNodesGui(DatabaseConnectionContext context, bool connected, object state)
        {
            ITreeBuilder builder = Context.GetTreeBuilder(state);

            builder.Update();
            if (connected)
            {
                ISchemaProvider provider = context.SchemaProvider;

                if (provider.IsSchemaActionSupported(SchemaType.Table, SchemaActions.Schema))
                {
                    builder.AddChild(new TablesNode(context));
                }

                if (provider.IsSchemaActionSupported(SchemaType.View, SchemaActions.Schema))
                {
                    builder.AddChild(new ViewsNode(context));
                }

                if (provider.IsSchemaActionSupported(SchemaType.Procedure, SchemaActions.Schema))
                {
                    builder.AddChild(new ProceduresNode(context));
                }

                if (provider.IsSchemaActionSupported(SchemaType.User, SchemaActions.Schema))
                {
                    builder.AddChild(new UsersNode(context));
                }

                //TODO: custom datatypes, sequences, roles, operators, languages, groups and aggregates

                builder.Expanded = true;
            }
        }
예제 #2
0
        public BaseNode(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context = context;
        }
        public void AddDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            store.AppendValues(context.ConnectionSettings.Name, context);
        }
        protected virtual void ConnectionChanged(object sender, EventArgs e)
        {
            CheckOkState();

            if (entryName.Text.Length == 0)
            {
                DatabaseConnectionContext context = comboConnections.DatabaseConnection;
                entryName.Text = context.ConnectionSettings.Name;
            }
        }
예제 #5
0
        public ViewNode(DatabaseConnectionContext context, ViewSchema view)
            : base(context)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            this.view = view;
        }
예제 #6
0
        public TableNode(DatabaseConnectionContext context, TableSchema table)
            : base(context)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            this.table = table;
        }
예제 #7
0
        public ParametersNode(DatabaseConnectionContext context, ProcedureSchema procedure)
            : base(context)
        {
            if (procedure == null)
            {
                throw new ArgumentNullException("procedure");
            }

            this.procedure = procedure;
        }
예제 #8
0
        public ConstraintsNode(DatabaseConnectionContext context, ISchema schema)
            : base(context)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            this.schema = schema;
        }
예제 #9
0
        public ColumnNode(DatabaseConnectionContext context, ColumnSchema column)
            : base(context)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            this.column = column;
        }
예제 #10
0
        public UserNode(DatabaseConnectionContext context, UserSchema user)
            : base(context)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.user = user;
        }
예제 #11
0
        protected void OnRemoveConnection()
        {
            DatabaseConnectionContext context = (DatabaseConnectionContext)CurrentNode.DataItem;

            if (MessageService.Confirm(
                    AddinCatalog.GetString("Are you sure you want to remove connection '{0}'?", context.ConnectionSettings.Name),
                    AlertButton.Remove))
            {
                ConnectionContextService.RemoveDatabaseConnectionContext(context);
            }
        }
예제 #12
0
        protected void OnDisconnectConnection()
        {
            DatabaseConnectionContext context = (DatabaseConnectionContext)CurrentNode.DataItem;

            if (context.HasConnectionPool)
            {
                context.ConnectionPool.Close();
                context.Refresh();
                CurrentNode.Expanded = false;
            }
        }
        private void CheckOkState()
        {
            DatabaseConnectionContext context = comboConnections.DatabaseConnection;

            if (context != null)
            {
                buttonSelect.Sensitive = context.DbFactory.IsCapabilitySupported("ConnectionSettings", SchemaActions.Schema, ConnectionSettingsCapabilities.SelectDatabase);
            }
            buttonOk.Sensitive = context != null &&
                                 entryDatabase.Text.Length > 0 && entryName.Text.Length > 0;
        }
        protected void OnCreateDatabase()
        {
            CreateDatabaseDialog dlg = new CreateDatabaseDialog();

            if (dlg.Run() == (int)ResponseType.Ok)
            {
                DatabaseConnectionContext context = dlg.DatabaseConnection;
                WaitDialog.ShowDialog("Creating database ...");
                ThreadPool.QueueUserWorkItem(new WaitCallback(OnCreateDatabaseThreaded), context);
            }
            dlg.Destroy();
        }
        protected virtual void NewClicked(object sender, System.EventArgs e)
        {
            DatabaseConnectionSettingsDialog dlg = new DatabaseConnectionSettingsDialog(true);

            if (dlg.Run() == (int)ResponseType.Ok)
            {
                DatabaseConnectionContext context = new DatabaseConnectionContext(dlg.ConnectionSettings, true);
                context.IsTemporary = true;
                comboConnections.AddDatabaseConnectionContext(context);
                comboConnections.DatabaseConnection = context;
            }
        }
예제 #16
0
 private void ChangeCurrentNotebookPage(object o, ChangeCurrentPageArgs args)
 {
     if (notebook.Page == 1)
     {
         //we are switching to the "classes" page, refresh the content if the selected database changed
         DatabaseConnectionContext db = comboDatabase.DatabaseConnection;
         if (db != selectedDatabase)
         {
             selectedDatabase = db;
             FillClassesPage();
         }
     }
 }
예제 #17
0
        protected void OnDropDatabase()
        {
            DatabaseConnectionContext context = (DatabaseConnectionContext)CurrentNode.DataItem;
            AlertButton dropButton            = new AlertButton(AddinCatalog.GetString("Drop"), Gtk.Stock.Delete);

            if (MessageService.Confirm(
                    AddinCatalog.GetString("Are you sure you want to drop database '{0}'", context.ConnectionSettings.Database),
                    dropButton
                    ))
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(OnDropDatabaseThreaded), CurrentNode.DataItem);
            }
        }
예제 #18
0
        protected void OnUpdateConnectConnection(CommandInfo info)
        {
            DatabaseConnectionContext context = (DatabaseConnectionContext)CurrentNode.DataItem;

            if (context.HasConnectionPool)
            {
                info.Enabled = !context.ConnectionPool.IsInitialized;
            }
            else
            {
                info.Enabled = true;
            }
        }
        protected virtual void RefreshClickedThreaded(object state)
        {
            DatabaseConnectionSettings settings = state as DatabaseConnectionSettings;
            DatabaseConnectionContext  context  = new DatabaseConnectionContext(settings);
            IDbFactory         fac  = DbFactoryService.GetDbFactory(settings.ProviderIdentifier);
            FakeConnectionPool pool = null;

            try {
                pool = new FakeConnectionPool(fac, fac.ConnectionProvider, context);
                pool.Initialize();
                if (pool.HasErrors)
                {
                    MessageService.ShowError(pool.Error);
                    return;
                }

                ISchemaProvider          prov      = fac.CreateSchemaProvider(pool);
                DatabaseSchemaCollection databases = prov.GetDatabases();

                DispatchService.GuiDispatch(delegate() {
                    foreach (DatabaseSchema db in databases)
                    {
                        storeDatabases.AppendValues(db.Name);
                    }
                });
                isDatabaseListEmpty = databases.Count == 0;
            } catch {
            } finally {
                if (pool != null)
                {
                    pool.Close();
                }
            }

            if (isDatabaseListEmpty)
            {
                DispatchService.GuiDispatch(delegate() {
                    storeDatabases.AppendValues(AddinCatalog.GetString("No databases found!"));
                });
            }
            else
            {
                DispatchService.GuiDispatch(delegate() {
                    TreeIter iter;
                    if (storeDatabases.GetIterFirst(out iter))
                    {
                        comboDatabase.SetActiveIter(iter);
                    }
                });
            }
        }
예제 #20
0
        private void Initialize(IDbFactory factory)
        {
            if (DatabaseConnection != null)
            {
                DatabaseConnection.ConnectionPool.Close();
            }
            DatabaseConnectionSettings settings = new DatabaseConnectionSettings(connectionWidget.ConnectionSettings);

            settings.Database = "mysql";
            // Create Context, Pool, Connection
            DatabaseConnectionContext ctx = new DatabaseConnectionContext(settings, true);

            ctx.ConnectionPool.Initialize();
            this.DatabaseConnection = ctx;
        }
예제 #21
0
        private void ExecuteQueryCallback(DatabaseConnectionContext context, bool connected, object state)
        {
            if (!connected)
            {
                Services.MessageService.ShowErrorFormatted(
                    GettextCatalog.GetString("Unable to connect to database '{0}'"), context.ConnectionSettings.Name);
                return;
            }

            currentQueryState = new object();
            IPooledDbConnection conn    = context.ConnectionPool.Request();
            IDbCommand          command = conn.CreateCommand(Text);

            conn.ExecuteSetAsync(command, new ExecuteCallback <DataSet> (ExecuteQueryThreaded), currentQueryState);
        }
예제 #22
0
        protected void OnEditConnection()
        {
            DatabaseConnectionContext  context = (DatabaseConnectionContext)CurrentNode.DataItem;
            DatabaseConnectionSettings newSettings;

            if (context.DbFactory.GuiProvider.ShowEditConnectionDialog(context.DbFactory,
                                                                       context.ConnectionSettings,
                                                                       out newSettings))
            {
                DatabaseConnectionContext newContext = new DatabaseConnectionContext(newSettings);
                ConnectionContextService.RemoveDatabaseConnectionContext(context);
                ConnectionContextService.AddDatabaseConnectionContext(newContext);
                newContext.Refresh();
            }
        }
        private void OnCreateDatabaseThreaded(object state)
        {
            DatabaseConnectionContext context = state as DatabaseConnectionContext;

            ISchemaProvider schemaProvider = context.SchemaProvider;
            DatabaseSchema  db             = new DatabaseSchema(schemaProvider);

            db.Name = context.ConnectionSettings.Database;

            schemaProvider.CreateDatabase(db);

            DispatchService.GuiDispatch(delegate() {
                WaitDialog.HideDialog();
                ConnectionContextService.AddDatabaseConnectionContext(context);
            });
        }
예제 #24
0
        private void ExecuteQueryCallback(DatabaseConnectionContext context, bool connected, object state)
        {
            if (!connected)
            {
                MessageService.ShowError(
                    AddinCatalog.GetString("Unable to connect to database '{0}'"), context.ConnectionSettings.Name);
                return;
            }

            ISchemaProvider provider = context.SchemaProvider;

            tables = provider.GetTables();

            DispatchService.GuiDispatch(delegate() {
                //TODO: initialize the table mapper
            });
        }
        private TreeIter GetTreeIter(DatabaseConnectionContext context)
        {
            TreeIter iter;

            if (store.GetIterFirst(out iter))
            {
                do
                {
                    object obj = store.GetValue(iter, 1);
                    if (obj == context)
                    {
                        return(iter);
                    }
                } while (store.IterNext(ref iter));
            }
            return(TreeIter.Zero);
        }
예제 #26
0
        private void OnDropDatabaseThreaded(object state)
        {
            DatabaseConnectionContext context = (DatabaseConnectionContext)CurrentNode.DataItem;

            try {
                context.ConnectionPool.Initialize();
                ISchemaProvider     provider       = context.SchemaProvider;
                DatabaseSchema      db             = provider.CreateDatabaseSchema(context.ConnectionSettings.Database);
                IEditSchemaProvider schemaProvider = (IEditSchemaProvider)context.SchemaProvider;
                schemaProvider.DropDatabase(db);
                ConnectionContextService.RemoveDatabaseConnectionContext(context);
            } catch (Exception ex) {
                DispatchService.GuiDispatch(delegate {
                    MessageService.ShowException(ex);
                });
            }
        }
        protected override ConnectionSettingsWidget CreateConnectionSettingsWidget(IDbFactory factory)
        {
            connectionWidget = new SqliteConnectionSettingsWidget(factory);
            connectionWidget.ShowSettings(factory.GetDefaultConnectionSettings());
            connectionWidget.EnableOpenButton = true;
            connectionWidget.EnableTestButton = false;

            DatabaseConnectionSettings settings = new DatabaseConnectionSettings(connectionWidget.ConnectionSettings);

            // Set a temp database to avoid exception of the default connection pool.
            settings.Database = System.IO.Path.GetTempFileName();
            // Create Context, Pool, Connection
            DatabaseConnectionContext ctx = new DatabaseConnectionContext(settings, true);

            ctx.ConnectionPool.Initialize();
            this.DatabaseConnection = ctx;
            return(connectionWidget);
        }
        protected virtual void SaveAsClicked(object sender, System.EventArgs e)
        {
            DatabaseConnectionContext context = comboConnections.DatabaseConnection;

            if (context == null)
            {
                return;
            }

            IDbFactory fac = context.DbFactory;

            string database = null;

            if (fac.GuiProvider.ShowSelectDatabaseDialog(true, out database))
            {
                entryDatabase.Text = database;
            }
        }
        protected virtual void OnButtonEditClicked(object sender, System.EventArgs e)
        {
            DatabaseConnectionSettings settings = null;
            DatabaseConnectionContext  ctx;

            if (comboConnection.DatabaseConnection != null)
            {
                ctx = comboConnection.DatabaseConnection;
                if (ctx.DbFactory.GuiProvider.ShowEditConnectionDialog(comboConnection.DatabaseConnection.DbFactory,
                                                                       comboConnection.DatabaseConnection.ConnectionSettings,
                                                                       out settings))
                {
                    DatabaseConnectionContext newContext = new DatabaseConnectionContext(settings);
                    ConnectionContextService.RemoveDatabaseConnectionContext(ctx);
                    ConnectionContextService.AddDatabaseConnectionContext(newContext);
                }
            }
        }
        protected virtual void TestClickedThreaded(object state)
        {
            DatabaseConnectionSettings settings = state as DatabaseConnectionSettings;
            DatabaseConnectionContext  context  = new DatabaseConnectionContext(settings);
            IDbFactory fac = DbFactoryService.GetDbFactory(settings.ProviderIdentifier);

            bool   success = false;
            string error   = null;

            FakeConnectionPool  pool = null;
            IPooledDbConnection conn = null;

            try {
                pool    = new FakeConnectionPool(fac, fac.ConnectionProvider, context);
                success = pool.Initialize();
                error   = pool.Error;
            } catch (System.Data.DataException ex) {
                error   = ex.Message;
                success = false;
            } finally {
                if (conn != null)
                {
                    conn.Release();
                    conn.Dispose();
                }
                if (pool != null)
                {
                    pool.Close();
                }
            }

            DispatchService.GuiDispatch(delegate() {
                buttonTest.Sensitive = true;
                if (success)
                {
                    labelTest.Text = AddinCatalog.GetString("Test Succeeded.");
                }
                else
                {
                    labelTest.Text = AddinCatalog.GetString("Test Failed: {0}.", error);
                }
            });
        }
예제 #31
0
		public IConnectionPool CreateConnectionPool (DatabaseConnectionContext context)
		{
			return new DefaultConnectionPool (this, ConnectionProvider, context);
		}
 public IConnectionPool CreateConnectionPool(DatabaseConnectionContext context)
 {
     Console.WriteLine("CreateConnectionPool");
     return new DefaultConnectionPool (this, ConnectionProvider, context);
 }