示例#1
0
		/// <summary>
		///     <para>
		///       Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
		///    </para>
		/// </summary>
		/// <param name='value'>
		///       A array of <see cref='.Provider'/> objects with which to intialize the collection
		/// </param>
		public ProviderCollection (Provider[] value) 
		{
			if (value == null) 
				throw new System.ArgumentNullException ("value");

			this.AddRange (value);
		}
示例#2
0
		public DataSourceConnection (string name, string setting, Provider provider, 
									ConnectionString cstring, IDbConnection con) 
		{
			this.name = name;
			this.setting = setting;
			this.provider = provider;
			this.cstring = cstring;
			this.con = con;
		}
示例#3
0
		public void Dispose () 
		{
			provider = null;
			cstring = null;
			if (con != null) {
				if (con.State == ConnectionState.Open)
					con.Close ();
				con = null;
			}
		}
		public virtual object Create (object parent, object configContext, XmlNode section)
		{
			if (section == null)
				throw new System.ArgumentNullException ("section");

			ProviderCollection providers = new ProviderCollection ();
			
			XmlNodeList ProviderList = section.SelectNodes ("./provider");

			foreach (XmlNode ProviderNode in ProviderList) {
				Provider provider = new Provider(
					GetStringValue (ProviderNode, "name", true),
					GetStringValue (ProviderNode, "connection", true),
					GetStringValue (ProviderNode, "adapter", true),
					GetStringValue (ProviderNode, "command", true),
					GetStringValue (ProviderNode, "assembly", true),
					GetStringValue (ProviderNode, "description", false),
					GetStringValue (ProviderNode, "parameterprefix", false),
					GetStringValue (ProviderNode, "commandbuilder", false));
				providers.Add (provider);
			}
			return providers;
		}
示例#5
0
		/// <summary>
		///    <para> Removes a specific <see cref='.Provider'/> from the 
		///    <see cref='.ProviderCollection'/> .</para>
		/// </summary>
		/// <param name='value'>The <see cref='.Provider'/> to remove from the <see cref='.ProviderCollection'/> .</param>
		/// <returns><para>None.</para></returns>
		/// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
		public void Remove(Provider value) 
		{
			if (value == null) 
				throw new System.ArgumentNullException ("value");

			Dictionary.Remove(value);
		}
示例#6
0
		/// <summary>
		/// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
		///    specified index.</para>
		/// </summary>
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='.ProviderCollection'/> .</para></param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='.ProviderCollection'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='System.Array'/>
		public void CopyTo(Provider[] array, int index) 
		{
			if (array == null) 
				throw new System.ArgumentNullException ("array");

			Dictionary.CopyTo(array, index);
		}
示例#7
0
		/// <summary>
		/// <para>Gets a value indicating whether the 
		///    <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
		/// </summary>
		/// <param name='value'>The <see cref='.Provider'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='.ProviderCollection.IndexOf'/>
		public bool Contains (Provider value) 
		{
			if (value == null) 
				throw new System.ArgumentNullException("value");

			return Dictionary.Contains (value);
		}
示例#8
0
		/// <summary>
		/// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
		/// </summary>
		/// <param name='value'>
		///    An array of type <see cref='.Provider'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <seealso cref='.ProviderCollection.Add'/>
		public void AddRange (Provider[] value) 
		{
			if (value == null) 
				throw new System.ArgumentNullException ("value");

			for (int i = 0; i < value.Length; i++) 
				this.Add (value [i]);
		}
示例#9
0
		/// <summary>
		///    <para>Adds a <see cref='.Provider'/> with the specified value to the 
		///    <see cref='.ProviderCollection'/> .</para>
		/// </summary>
		/// <param name='value'>The <see cref='.Provider'/> to add.</param>
		/// <returns>
		///    <para>The index at which the new element was inserted.</para>
		/// </returns>
		/// <seealso cref='.ProviderCollection.AddRange'/>
		public void Add(Provider value) 
		{
			if (value == null) 
				throw new System.ArgumentNullException ("value");

			Dictionary.Add (value.Name, value);
		}
示例#10
0
		public void PopulateProcedures (TreeIter parentIter, Provider provider, IDbConnection con) 
		{
			TreeIter procsIter = parentIter;
			
			Schema browser = new Schema (provider.Name, con);
			
			if (browser.MetaData != null) {
				SetStatusBarText ("Getting Meta Data: Procudures...");
				while (Application.EventsPending ()) 
					Application.RunIteration ();

				MetaProcedureCollection procs = browser.GetProcedures ("");
				string procType = "~";
				foreach (MetaProcedure proc in procs) {
					if (!procType.Equals(proc.ProcedureType)) {
						procType = proc.ProcedureType;
						procsIter = tree.Store.AppendValues (parentIter, procType, "");
					}
					TreeIter procIter = tree.Store.AppendValues (procsIter, proc.ToString(), "");

					//if (proc.HasProcedures)
					//	PopulatePackageProcedures (procIter, proc);
					//else 
					//	PopulateProcedureArguments (procIter, proc);
				}
			}
		}
示例#11
0
		void OnDataSourceChanged (object o, EventArgs args) 
		{
			ComboBox combo = o as ComboBox;
			if (o == null)
				return;

			TreeIter iter;

			if (combo.GetActiveIter (out iter)) {
				if (!combo.Model.GetValue (iter, 0).Equals(NotConnected)) {
					string datasourceName = combo.Model.GetValue (iter, 0).ToString();
					dataSource = dataSources[datasourceName];
					provider = dataSource.Provider;
					conn = dataSource.Connection;
					connectionString = dataSource.ConnectionString.GetConnectionString ();
				}
			}
			SetFocusToEditor ();
		}
示例#12
0
		public void PopulateViews (TreeIter parentIter, Provider provider, IDbConnection con) 
		{
			TreeIter viewsIter = tree.Store.AppendValues (parentIter, "Views", "");
			
			Schema browser = new Schema (provider.Name, con);
			
			if (browser.MetaData != null) {
				SetStatusBarText ("Getting Meta Data: Views...");
				while (Application.EventsPending ()) 
					Application.RunIteration ();

				MetaViewCollection views = browser.GetViews (true);
				foreach (MetaView view in views)
					tree.Store.AppendValues (viewsIter, view.ToString(), "");
			}
		}
示例#13
0
		public void PopulateTables (TreeIter parentIter, Provider provider, IDbConnection con, bool IsParent) 
		{
			TreeIter tablesIter = parentIter;
			if (IsParent == true)
				tablesIter = tree.Store.AppendValues (parentIter, "Tables", "");
			
			Schema browser = new Schema (provider.Name, con);
			
			if (browser.MetaData != null) {
				SetStatusBarText ("Getting Meta Data: Tables...");
				while (Application.EventsPending ()) 
					Application.RunIteration ();

				MetaTableCollection tables = browser.GetTables (false);		
				TreeIter iter;
				TreeIter columnsIter;
				foreach(MetaTable table in tables) {
					iter = tree.Store.AppendValues (tablesIter, table.ToString (), "", table.Owner, table.Name);
					columnsIter = tree.Store.AppendValues (iter, "Columns", NotPopulated);
					tree.Store.AppendValues (columnsIter, "NotPopulated", NotPopulated);
					//PopulateTableColumns(columnsIter, table, browser);
				}
			}
		}
示例#14
0
		public bool OpenDataSource (Provider theProvider, string theConnectionString, string connectionName) 
		{
			provider = theProvider;
			connectionString = theConnectionString;

			string msg;
			msg = "Attempt to open connection...";
			AppendText (msg);

			conn = null;

			try {
				switch (provider.Name) {
				case "System.Data.SqlClient":
					conn = new SqlConnection ();
					break;
				case "System.Data.Odbc":
					conn = new OdbcConnection ();
					break;
				case "System.Data.OleDb":
					conn = new OleDbConnection ();
					break;
				default:
					conn = provider.CreateConnection ();
					break;
				}
			} catch (Exception e) {
				msg = "Error: Unable to create Connection object. \n" + 
					"Check to make sure the provider is setup correctly in your config file. \n" + 
					e.Message;
				Error (msg);
				return false;
			}

			ConnectionString conString = new ConnectionString (connectionString);
			conn.ConnectionString = connectionString;
			
			try {
				conn.Open ();
				if( conn.State == ConnectionState.Open)
					AppendText ("Open was successfull.");
				else {
					AppendText ("Error: Open failed.");
					return false;
				}
			} catch (Exception e) {
				msg = "Error: Could not open data source: " + e.Message;
				Error (msg);
				conn = null;
				return false;
			}

			// database connected - do other things
			//SetStatusBarText ("Connected.");
			lastConnection++;
			string dataSourceName = "";
			if (connectionName.Equals(""))
				dataSourceName = lastConnection.ToString () + ":" + provider.Name;
			else
				dataSourceName = lastConnection.ToString () + ":" + connectionName;

			dataSource = new DataSourceConnection (dataSourceName, connectionName, provider, conString, conn);
			dataSources.Add (dataSource);
			
			combo.AppendText (dataSourceName);
			ComboHelper.SetActiveText (combo, dataSourceName);

			TreeIter iterDataSource = tree.Store.AppendValues (tree.RootIter, dataSourceName, "");
			tree.Store.SetValue(iterDataSource, 1, "");
			//string sz = tree.Store.GetValue(iterDataSource, 1).ToString();
			//AppendText("sz: " + sz);

			// TODO: only load meta data when the user expands a tree node
			//       or Refreshes
			SetStatusBarText ("Getting Meta Data...");
			while (Application.EventsPending ()) 
				Application.RunIteration ();
			
			PopulateTables (iterDataSource, provider, conn, true);
			//PopulateViews (iterDataSource, provider, conn);
			//PopulateProcedures (iterDataSource, provider, conn);
			
			SetStatusBarText ("Connected.");

			SetFocusToEditor ();

			return true;
		}
示例#15
0
		void OnMenu_SessionDisconnectAll (object o, EventArgs args) 
		{
			AppendText ("Disconnecting All...");
			try {
				for(int i = 0; i < dataSources.Count; i++) {
					DataSourceConnection c = dataSources[i];
					c.Connection.Close ();
				}
				dataSources.Clear ();
				conn = null;
				dataSource = null;
				provider = null;
				((ListStore) combo.Model).Clear ();
				combo.AppendText (NotConnected);
				combo.Active = 0;
				tree.Clear ();
			}
			catch (Exception e) {
				Error ("Error: Unable to disconnect." + e.Message);
				conn = null;
				return;
			}
			AppendText ("Disconnected.");
		}
示例#16
0
		void OnMenu_SessionDisconnect (object o, EventArgs args) 
		{
			AppendText ("Disconnecting...");
			try {

				if (combo.Active < 0)
					return;

				ListStore comboStore = (ListStore) combo.Model;
				TreeIter comboIter;
				comboStore.IterNthChild(out comboIter, combo.Active);
				string dataSourceRemove  = comboStore.GetValue (comboIter, 0).ToString();

				if (dataSourceRemove.Equals(NotConnected))
					return;

				if (dataSourceRemove.Equals(""))
					return;

				TreeIter iter, iterParent;
				string tvalue = "";
				conn.Close ();
				conn = null;
				dataSources.Remove (dataSources[dataSourceRemove]);
				dataSource = null;
				provider = null;
				comboStore.Remove (ref comboIter);

				if (dataSources.Count > 0) {
					dataSource = dataSources[0];
					provider = dataSource.Provider;
					conn = dataSource.Connection;
					connectionString = dataSource.ConnectionString.GetConnectionString ();
					ComboHelper.SetActiveText (combo, dataSource.Name);
					
					// remove the selected connected data source from the left tree view
					tree.Store.IterChildren (out iterParent);
					tree.Store.IterChildren (out iter, iterParent);
					GLib.Value v = GLib.Value.Empty;
					tree.Store.GetValue (iter, 0, ref v);
					tvalue = (string) v.Val;
					if (tvalue.Equals (dataSourceRemove)) 
						tree.Store.Remove (ref iter);
					else {
						bool found = tree.Store.IterNext (ref iter);
						while (found == true) {
							v = GLib.Value.Empty;
							tree.Store.GetValue (iter, 0, ref v);
							tvalue = (string) v.Val;
							if (tvalue.Equals (dataSourceRemove)) {
								tree.Store.Remove (ref iter);
								found = false;
							}
							else
								found = tree.Store.IterNext (ref iter);
						}
					}
				}
				else {
					// removed last connected data source from tree view
					comboStore.Clear ();
					combo.AppendText (NotConnected);
					combo.Active = 0;

					tree.Store.IterChildren (out iterParent);
					tree.Store.IterChildren (out iter, iterParent);
					tree.Store.Remove (ref iter);						
				}			
			}
			catch (Exception e) {
				Error ("Error: Unable to disconnect." + e.Message);
				conn = null;
				return;
			}
			AppendText ("Disconnected.");
		}