Пример #1
0
		public BaseNode (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			this.context = context;
		}
Пример #2
0
		//TODO: show errors
		public static void EnsureConnection (DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			if (callback == null)
				throw new ArgumentNullException ("callback");
			
			IConnectionPool pool = context.ConnectionPool;
			if (pool.IsInitialized) {
				callback (context, true, state);
				return;
			}
			
			IDbFactory fac = DbFactoryService.GetDbFactory (context.ConnectionSettings);
			bool requiresPassword = fac.GetCapabilities ("ConnectionSettings", SchemaActions.Schema) == (int)ConnectionSettingsCapabilities.Password;
			
			if (!context.ConnectionSettings.SavePassword && String.IsNullOrEmpty (context.ConnectionSettings.Password) && requiresPassword) {
				string password = Services.MessageService.GetPassword (
					GettextCatalog.GetString ("Please enter the password for connection '{0}'",
					context.ConnectionSettings.Name),
					GettextCatalog.GetString ("Enter Password")
				);
				
				if (String.IsNullOrEmpty (password)) {
					callback (context, false, state);
					return;
				} else {
					context.ConnectionSettings.Password = password;
				}
			}
			
			EnsureConnectionState internalState = new EnsureConnectionState (context, callback, state);
			ThreadPool.QueueUserWorkItem (new WaitCallback (EnsureConnectionThreaded), internalState);
		}
		public void AddDatabaseConnectionContext (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			store.AppendValues (context.ConnectionSettings.Name, context);
		}
Пример #4
0
		public TableNode (DatabaseConnectionContext context, TableSchema table)
			: base (context)
		{
			if (table == null)
				throw new ArgumentNullException ("table");
			
			this.table = table;
		}
		public static DatabaseConnectionContext AddDatabaseConnectionContext (DatabaseConnectionSettings settings)
		{
			if (settings == null)
				throw new ArgumentNullException ("settings");
			
			DatabaseConnectionContext context = new DatabaseConnectionContext (settings);
			AddDatabaseConnectionContext (context);
			return context;
		}
		public static void RemoveDatabaseConnectionContext (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			contexts.Remove (context);
			Save ();
			if (ConnectionContextRemoved != null)
				ConnectionContextRemoved (null, new DatabaseConnectionContextEventArgs (context));
		}
Пример #7
0
		public static IConnectionPool CreateConnectionPool (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			IDbFactory fac = GetDbFactory (context.ConnectionSettings);
			if (fac != null)
				return fac.CreateConnectionPool (context);
			return null;
		}
		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;
		}
		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 ();
				}
			}
		}
Пример #10
0
        public static DatabaseConnectionContext AddDatabaseConnectionContext(DatabaseConnectionSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            DatabaseConnectionContext context = new DatabaseConnectionContext(settings);

            AddDatabaseConnectionContext(context);
            return(context);
        }
		public static void AddDatabaseConnectionContext (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			if (!contexts.Contains (context)) {
				contexts.Add (context);
				Save ();
				if (ConnectionContextAdded != null)
					ConnectionContextAdded (null, new DatabaseConnectionContextEventArgs (context));
			}
		}
Пример #12
0
        public static void EditDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            Save();
            if (ConnectionContextEdited != null)
            {
                ConnectionContextEdited(null, new DatabaseConnectionContextEventArgs(context));
            }
        }
		public static void AddDatabaseConnectionContext (DatabaseConnectionContext context)
		{
			if (context == null)
				throw new ArgumentNullException ("context");
			
			if (!DatabaseConnectionContextExist (context.ConnectionSettings)) {
				contexts.Add (context);
				Save ();
				if (ConnectionContextAdded != null)
					ConnectionContextAdded (null, new DatabaseConnectionContextEventArgs (context));
			} else
				throw new DuplicatedConnectionContextException (context.ConnectionSettings.Name);
		}
Пример #14
0
		public FakeConnectionPool (IDbFactory factory, IConnectionProvider connectionProvider, DatabaseConnectionContext context)
		{
			if (factory == null)
				throw new ArgumentNullException ("factory");
			if (connectionProvider == null)
				throw new ArgumentNullException ("connectionProvider");
			if (context == null)
				throw new ArgumentNullException ("context");
			
			this.factory = factory;
			this.connectionProvider = connectionProvider;
			this.context = context;
		}
 public void addNewTable(string name, DatabaseConnectionContext context, ISchemaProvider schemaProvider)
 {
     //TODO: improve way of assing last parameter
     TableModel tableModel  = new TableModel (name,context,schemaProvider,true);
     TableFigure tableFigure = new TableFigure (tableModel,canvas,diagram);
     tableModel.FigureOwner = tableFigure;
     view.Drawing.Add (tableFigure);
     System.Console.WriteLine("added table");
     foreach ( IFigure fig in view.Drawing.FiguresEnumerator){
         System.Console.WriteLine("figura"+fig.ToString());
     }
     diagram.AddTable(tableFigure);
 }
Пример #16
0
        public static void RemoveDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            contexts.Remove(context);
            Save();
            if (ConnectionContextRemoved != null)
            {
                ConnectionContextRemoved(null, new DatabaseConnectionContextEventArgs(context));
            }
        }
Пример #17
0
        public static IConnectionPool CreateConnectionPool(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IDbFactory fac = GetDbFactory(context.ConnectionSettings);

            if (fac != null)
            {
                return(fac.CreateConnectionPool(context));
            }
            return(null);
        }
		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 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;
		}
		public DefaultConnectionPool (IDbFactory factory, IConnectionProvider connectionProvider, DatabaseConnectionContext context)
		{
			if (factory == null)
				throw new ArgumentNullException ("factory");
			if (connectionProvider == null)
				throw new ArgumentNullException ("connectionProvider");
			if (context == null)
				throw new ArgumentNullException ("context");
			
			this.factory = factory;
			this.connectionProvider = connectionProvider;
			this.context = context;
			
			connections = new List<IPooledDbConnection> ();
			freeConnections = new Queue<IPooledDbConnection> ();
		}
Пример #21
0
        //TODO: show errors
        public static void EnsureConnection(DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            IConnectionPool pool = context.ConnectionPool;

            if (pool.IsInitialized)
            {
                callback(context, true, state);
                return;
            }

            IDbFactory fac = DbFactoryService.GetDbFactory(context.ConnectionSettings);
            //FIXME: connection settings dialog
            //bool requiresPassword = fac.GetCapabilities ("ConnectionSettings", SchemaActions.Schema) == (int)ConnectionSettingsCapabilities.Password;
            bool requiresPassword = true;

            if (!context.ConnectionSettings.SavePassword && String.IsNullOrEmpty(context.ConnectionSettings.Password) && requiresPassword)
            {
                string password = MessageService.GetPassword(
                    AddinCatalog.GetString("Please enter the password for connection '{0}'",
                                           context.ConnectionSettings.Name),
                    AddinCatalog.GetString("Enter Password")
                    );

                if (password == null)
                {
                    callback(context, false, state);
                    return;
                }
                else
                {
                    context.ConnectionSettings.Password = password;
                }
            }

            EnsureConnectionState internalState = new EnsureConnectionState(context, callback, state);

            ThreadPool.QueueUserWorkItem(new WaitCallback(EnsureConnectionThreaded), internalState);
        }
        public static void AddDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!contexts.Contains(context))
            {
                contexts.Add(context);
                Save();
                if (ConnectionContextAdded != null)
                {
                    ConnectionContextAdded(null, new DatabaseConnectionContextEventArgs(context));
                }
            }
        }
		protected virtual void OkClicked (object sender, System.EventArgs e)
		{
			context = comboConnections.DatabaseConnection;
			if (context.IsTemporary) {
				//make it a real connection context and fill in the database
				context.ConnectionSettings.Database = entryDatabase.Text;
				context.ConnectionSettings.Name = entryName.Text;
				context.IsTemporary = false;
			} else {
				//create a copy of the settings and create a new context
				DatabaseConnectionSettings settings = new DatabaseConnectionSettings (context.ConnectionSettings);
				settings.Database = entryDatabase.Text;
				settings.Name = entryName.Text;
				context = new DatabaseConnectionContext (settings);
			}

			Respond (ResponseType.Ok);
			Destroy ();
		}
Пример #24
0
        public static ISchemaProvider CreateSchemaProvider(DatabaseConnectionContext context, IConnectionPool pool)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (pool == null)
            {
                throw new ArgumentNullException("pool");
            }

            IDbFactory fac = GetDbFactory(context.ConnectionSettings);

            if (fac != null)
            {
                return(fac.CreateSchemaProvider(pool));
            }
            return(null);
        }
Пример #25
0
        public FakeConnectionPool(IDbFactory factory, IConnectionProvider connectionProvider, DatabaseConnectionContext context)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (connectionProvider == null)
            {
                throw new ArgumentNullException("connectionProvider");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.factory            = factory;
            this.connectionProvider = connectionProvider;
            this.context            = context;
        }
Пример #26
0
        public static void AddDatabaseConnectionContext(DatabaseConnectionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (!DatabaseConnectionContextExist(context.ConnectionSettings))
            {
                contexts.Add(context);
                Save();
                if (ConnectionContextAdded != null)
                {
                    ConnectionContextAdded(null, new DatabaseConnectionContextEventArgs(context));
                }
            }
            else
            {
                throw new DuplicatedConnectionContextException(context.ConnectionSettings.Name);
            }
        }
        public DefaultConnectionPool(IDbFactory factory, IConnectionProvider connectionProvider, DatabaseConnectionContext context)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (connectionProvider == null)
            {
                throw new ArgumentNullException("connectionProvider");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.factory            = factory;
            this.connectionProvider = connectionProvider;
            this.context            = context;

            connections     = new List <IPooledDbConnection> ();
            freeConnections = new Queue <IPooledDbConnection> ();
        }
Пример #28
0
		public TablesNode (DatabaseConnectionContext context)
			: base (context)
		{
		}
Пример #29
0
		public ViewNode (DatabaseConnectionContext context, ViewSchema view)
			: base (context)
		{
			if (view == null)
				throw new ArgumentNullException ("view");
			
			this.view = view;
		}
		private void BuildChildNodesGui (DatabaseConnectionContext context, bool connected, object state)
		{
			ITreeBuilder builder = Context.GetTreeBuilder (state);
			
			builder.Update ();
			if (connected) {
				IDbFactory fac = context.DbFactory;

				if (fac.IsActionSupported ("Table", SchemaActions.Schema))
					builder.AddChild (new TablesNode (context));

				if (fac.IsActionSupported ("View", SchemaActions.Schema))
					builder.AddChild (new ViewsNode (context));
				
				if (fac.IsActionSupported ("Procedure", SchemaActions.Schema))
					builder.AddChild (new ProceduresNode (context));

				if (fac.IsActionSupported ("User", SchemaActions.Schema))
					builder.AddChild (new UsersNode (context));
				
				//TODO: custom datatypes, sequences, roles, operators, languages, groups and aggregates
				
				builder.Expanded = true;
			}
		}
Пример #31
0
 public override IConnectionPool CreateConnectionPool(DatabaseConnectionContext context)
 {
     return(new DefaultConnectionPool(this, ConnectionProvider, context));
 }
		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;
			}
			
			currentQueryState = new object ();
			IPooledDbConnection conn = context.ConnectionPool.Request ();
			IDbCommand command = conn.CreateCommand (QueryText);
			if (history.Text.EndsWith (Environment.NewLine) || history.Text == string.Empty)
				history.Text = string.Concat (history.Text, QueryText);
			else
				history.Text = string.Concat (history.Text, Environment.NewLine, "------------------------", QueryText);
			queryStart = DateTime.Now;
			conn.ExecuteSetAsync (command, new ExecuteCallback<DataSet> (ExecuteQueryThreaded), currentQueryState);
		}
Пример #33
0
		public EnsureConnectionState (DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state)
		{
			ConnectionContext = context;
			Callback = callback;
			State = state;
		}
		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;
		}
		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 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;
			}
		}
 public DatabaseConnectionContextEventArgs(DatabaseConnectionContext context)
 {
     this.context = context;
 }
Пример #38
0
 public EnsureConnectionState(DatabaseConnectionContext context, DatabaseConnectionContextCallback callback, object state)
 {
     ConnectionContext = context;
     Callback          = callback;
     State             = state;
 }
		public ConnectionContextMenuItem (DatabaseConnectionContext context)
			: base (context.ConnectionSettings.Name)
		{
			this.context = context;
		}
		public SqlQueryView ()
		{
			stoppedQueries = new List<object> ();
			MonoDevelop.SourceEditor.Extension.TemplateExtensionNodeLoader.Init ();
			this.UntitledName = string.Concat (AddinCatalog.GetString ("Untitled Sql Script"), ".sql");
			
			vbox = new VBox (false, 6);
			vbox.BorderWidth = 6;
			
			Toolbar toolbar = new Toolbar ();
			toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
			
			buttonExecute = new ToolButton (ImageService.GetImage ("md-db-execute", IconSize.SmallToolbar),
			                                AddinCatalog.GetString ("_Execute"));
			buttonExecute.Label = AddinCatalog.GetString ("Execute");
			buttonExecute.Sensitive = false;
			buttonExecute.TooltipMarkup = AddinCatalog.GetString ("Execute Query");
			buttonExecute.IsImportant = true;
			buttonExecute.Clicked += new EventHandler (ExecuteClicked);

			buttonStop = new ToolButton ("gtk-stop");
			buttonStop.TooltipText = AddinCatalog.GetString ("Stop Query Execution");
			buttonStop.Sensitive = false;
			buttonStop.Clicked += new EventHandler (StopClicked);
			
			buttonClear = new ToolButton (ImageService.GetImage ("gtk-clear", IconSize.Button), 
			                              AddinCatalog.GetString ("Clear Results"));
			buttonClear.TooltipText = AddinCatalog.GetString ("Clear Results");
			buttonClear.Clicked += new EventHandler (ClearClicked);
			
			comboConnections = new DatabaseConnectionContextComboBox ();
			selectedConnection = comboConnections.DatabaseConnection;
			comboConnections.Changed += new EventHandler (ConnectionChanged);
			ToolItem comboItem = new ToolItem ();
			comboItem.Child = comboConnections;
			
			toolbar.Add (buttonExecute);
			toolbar.Add (buttonStop);
			toolbar.Add (buttonClear);
			toolbar.Add (new SeparatorToolItem ());
			toolbar.Add (comboItem);
			
			pane = new VPaned ();

			// Sql History Window
			ScrolledWindow windowHistory = new ScrolledWindow ();
			history = new SqlEditorWidget ();
			history.Editable = false;
			windowHistory.AddWithViewport (history);
			
			// Status of the Last Query
			ScrolledWindow windowStatus = new ScrolledWindow ();
			status = new TextView ();
			windowStatus.Add (status);
			
			notebook = new Notebook ();
			notebook.AppendPage (windowStatus, new Label (AddinCatalog.GetString ("Status")));
			notebook.AppendPage (windowHistory, new Label (AddinCatalog.GetString ("Query History")));
			
			pane.Pack2 (notebook, true, true);
			vbox.PackStart (toolbar, false, true, 0);
			vbox.PackStart (pane, true, true, 0);
			this.Document.TextReplaced += SqlChanged;
			vbox.ShowAll ();
			Document.DocumentUpdated += delegate (object sender, EventArgs args) {
				// Default mime type or a provider defined.
				if (selectedConnection == null)
					Document.MimeType = "text/x-sql";
				else 
					Document.MimeType = GetMimeType ();
				
			};
			notebook.Hide ();
		}
Пример #41
0
		public ParametersNode (DatabaseConnectionContext context, ProcedureSchema procedure)
			: base (context)
		{
			if (procedure == null)
				throw new ArgumentNullException ("procedure");
			
			this.procedure = procedure;
		}
		private void ConnectionChanged (object sender, EventArgs args)
		{
			selectedConnection = comboConnections.DatabaseConnection;
			Document.MimeType = GetMimeType ();
			buttonExecute.Sensitive = QueryText.Length > 0;
		}
Пример #43
0
		
		public IConnectionPool CreateConnectionPool (DatabaseConnectionContext context)
		{
			return new DefaultConnectionPool (this, ConnectionProvider, context);