private static void AddCatalogsFromMruList(ICollection <string> catalogs, MruConnections mruConnections, ProviderType providerId, Datasource datasource) { Datasources providerDatasources = mruConnections.FindDatasources(providerId); if (providerDatasources == null) { return; } if (providerDatasources.Datasource == null || providerDatasources.Datasource.Count == 0) { return; } Datasource mruDatasource = providerDatasources.FindDatasourceByAddress(datasource.Address); if (mruDatasource == null || mruDatasource.Catalogs == null) { return; } foreach (string catalog in mruDatasource.Catalogs) { if (catalogs.Count >= MaxMruEntries) { break; } if (!catalogs.Contains(catalog)) { catalogs.Add(catalog); } } }
public void GetMruDbConnectionParameterTest() { var datasources1 = new Datasources() { Provider = ProviderType.Oracle }; var datasource1_1 = new Datasource() { Address = "datasource1_1" }; var datasourcesList1 = new List <Datasource>(); datasourcesList1.Add(datasource1_1); datasources1.Datasource = datasourcesList1; var datasources2 = new Datasources(); datasources2.Provider = ProviderType.Sybase; var history = new MruConnections() { Datasources = new List <Datasources>() }; history.Datasources.Add(datasources1); history.Datasources.Add(datasources2); DbConnectionParameter murParameter = MruDbConnectionParameterAdapter.GetMruDbConnectionParameter(history); Assert.AreEqual(datasources1.Provider, murParameter.Provider); Assert.AreEqual(datasource1_1.Address, murParameter.DatasourceAddress); }
private static void AddAuthenticationsFromMruList(AuthenticationList authentications, MruConnections mruConnections, ProviderType providerId, Datasource datasource) { Datasources providerDatasources = mruConnections.FindDatasources(providerId); if (providerDatasources == null) { return; } if (providerDatasources.Datasource == null || providerDatasources.Datasource.Count == 0) { return; } Datasource mruDatasource = providerDatasources.FindDatasourceByAddress(datasource.Address); if (mruDatasource == null || mruDatasource.Authentications == null) { return; } foreach (var authentication in mruDatasource.Authentications) { if (authentications.Count >= MaxMruEntries) { break; } if (!authentications.Contains(authentication)) { authentications.Add(authentication); } } }
/// <summary> /// Finds the datasource by the user specified comment. /// </summary> /// <param name="provider">The id of the provider.</param> /// <param name="datasourceComment">The comment for the datasource.</param> /// <returns> /// The datasource for the specified provider and comment or <c>null</c> /// if the history does not contain any record for it. /// </returns> public Datasource FindDatasourceByComment(ref ProviderType provider, string datasourceComment) { // First lookup the datasource for the current provider. Datasources datasourcesOfProvider = FindDatasources(provider); if (datasourcesOfProvider == null) { return(null); } Datasource datasource = datasourcesOfProvider.FindDatasourceByComment(datasourceComment); if (datasource != null) { return(datasource); } // If the datasource was not found seek all datasources and return the first matching entry. foreach (var datasources in this.Datasources) { datasource = datasources.FindDatasourceByComment(datasourceComment); if (datasource != null) { provider = datasources.Provider; return(datasource); } } return(null); }
private static void AddCatalogs(Datasource datasource, MruConnections mruConnections, DbConnectionParameter mruParameter) { List <string> catalogs = new List <string>(); catalogs.Add(mruParameter.Catalog ?? ""); AddCatalogsFromMruList(catalogs, mruConnections, mruParameter.Provider, datasource); datasource.Catalogs = catalogs; }
/// <summary> /// Find the datasource with the specified address (i.e. server name). /// </summary> /// <param name="provider">The id of the provider.</param> /// <param name="datasourceAddress">The name of the datasource e.g. the server name or IP address.</param> /// <returns> /// The datasource for the specified provider and address or <c>null</c> /// if the history does not contain any record for it. /// </returns> public Datasource FindDatasourceByAddress(ProviderType provider, string datasourceAddress) { Datasources datasourcesOfProvider = FindDatasources(provider); if (datasourcesOfProvider == null) { return(null); } Datasource datasource = datasourcesOfProvider.FindDatasourceByAddress(datasourceAddress); return(datasource); }
private static void AddAuthentications(Datasource datasource, MruConnections mruConnections, DbConnectionParameter mruParameter) { AuthenticationList authentications = new AuthenticationList(); Authentication authentication = new Authentication() { Integrated = mruParameter.IntegratedSecurity, UserId = mruParameter.UserId, Password = mruParameter.Password }; if (authentication.IsUsable) { authentications.Add(authentication); } AddAuthenticationsFromMruList(authentications, mruConnections, mruParameter.Provider, datasource); datasource.Authentications = authentications; }
/// <summary> /// Get the moust recently used connection parameter stored in the murConnection list. /// </summary> /// <param name="mruConnections">The most recently used database connection.</param> /// <returns>The first entry in the list.</returns> public static DbConnectionParameter GetMruDbConnectionParameter(MruConnections mruConnections) { DbConnectionParameter result = new DbConnectionParameter(); if (mruConnections.Datasources == null || mruConnections.Datasources.Count == 0) { return(result); } Datasources mruDatasources = mruConnections.Datasources[0]; result.Provider = mruDatasources.Provider; if (mruDatasources.Datasource == null || mruDatasources.Datasource.Count == 0) { return(result); } Datasource mruDatasource = mruDatasources.Datasource[0]; result.DatasourceAddress = mruDatasource.Address; result.DatasourcePort = mruDatasource.Port; result.DatasourceComment = mruDatasource.Comment; if (mruDatasource.Catalogs != null && mruDatasource.Catalogs.Count != 0) { string mruCatalog = mruDatasource.Catalogs[0]; result.Catalog = mruCatalog; } if (mruDatasource.Authentications != null && mruDatasource.Authentications.Count != 0) { Authentication mruAuthentication = mruDatasource.Authentications[0]; result.IntegratedSecurity = mruAuthentication.Integrated; result.UserId = mruAuthentication.UserId; result.Password = mruAuthentication.Password; } return(result); }
/// <summary> /// Update the most recently used connection store with the latest parameters used. /// </summary> /// <param name="mruConnections">The most recently used connection store.</param> /// <param name="mruParameter">The most recently connection parameter used.</param> /// <returns><c>true</c> if the store was update. <c>false</c> if the store is up to date.</returns> public static bool SetMruDbConnectionParameter(MruConnections mruConnections, DbConnectionParameter mruParameter) { if (mruParameter == null) { return(false); } DbConnectionParameter currentMruParameter = MruDbConnectionParameterAdapter.GetMruDbConnectionParameter(mruConnections); if (Object.Equals(currentMruParameter, mruParameter)) { return(false); } DatasourcesList newMruDatasources = new DatasourcesList(); if (mruParameter.Provider != ProviderType.Undefined) { Datasources newFirstDatasources = new Datasources() { Provider = mruParameter.Provider }; ProviderDataSources datasources = new ProviderDataSources(mruParameter.Provider); if (!String.IsNullOrEmpty(mruParameter.DatasourceAddress)) { Datasource newFirstDatasource = new Datasource() { Address = mruParameter.DatasourceAddress, Comment = mruParameter.DatasourceComment }; datasources.Add(newFirstDatasource); AddCatalogs(newFirstDatasource, mruConnections, mruParameter); AddAuthentications(newFirstDatasource, mruConnections, mruParameter); AddDatasourcesFromMruList(datasources, mruConnections); } newFirstDatasources.Datasource = datasources; newMruDatasources.Add(newFirstDatasources); } // Add all previously used datasources IEnumerable <Datasources> otherDatasources = mruConnections.Datasources; foreach (Datasources mruDatasources in otherDatasources) { if (newMruDatasources.Count >= MaxMruEntries) { break; } if (newMruDatasources.Contains(mruDatasources)) { continue; } newMruDatasources.Add(mruDatasources); } mruConnections.Datasources = newMruDatasources; return(true); }