コード例 #1
0
        private static void AddDatasourcesFromMruList(ProviderDataSources datasources, MruConnections mruConnections)
        {
            ProviderType providerId = datasources.ProviderType;
            Datasources  provider   = mruConnections.FindDatasources(providerId);

            if (provider == null)
            {
                return;
            }

            if (provider.Datasource == null || provider.Datasource.Count == 0)
            {
                return;
            }

            foreach (Datasource datasource in provider.Datasource)
            {
                if (!ContainsDatasource(datasources, datasource.Address))
                {
                    datasources.Add(datasource);
                }
            }
        }
コード例 #2
0
        /// <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);
        }