Remove() публичный Метод

public Remove ( ConnectionStringSettings settings ) : void
settings ConnectionStringSettings
Результат void
Пример #1
0
        /// <summary>
        /// Gets all the values stored in the connectionStrings.
        /// This will provide a single collection containing the defaults or 
        /// overrides as appropriate.
        /// </summary>
        /// <returns>The collection of all connection strings.</returns>
        public ConnectionStringSettingsCollection GetConnectionStrings()
        {
            ConnectionStringSettingsCollection allConnections =
                new ConnectionStringSettingsCollection();

            // Put in all the default values
            foreach (ConnectionStringSettings connSetting in
                ConfigurationManager.ConnectionStrings)
            {
                allConnections.Add(connSetting);
            }

            if (m_overridenConfig.HasFile)
            {
                foreach (ConnectionStringSettings connSetting in
                    m_overridenConfig.ConnectionStrings.ConnectionStrings)
                {
                    // Remove the default if already present
                    if (allConnections[connSetting.Name] != null)
                    {
                        allConnections.Remove(connSetting.Name);
                    }
                    allConnections.Add(connSetting);
                }
            }

            return allConnections;
        }
Пример #2
0
        private void ImportProject(string importConfigPath)
        {
            if(File.Exists(importConfigPath))
            {
                FileInfo fi = new FileInfo(importConfigPath);
                DirectoryInfo di = fi.Directory;
                if(di != null)
                {
                    string originalDirectory = di.FullName;
                    string projectName = di.Name;

                    ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
                    fileMap.ExeConfigFilename = importConfigPath;
                    Configuration subConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
                    SubSonicSection section = (SubSonicSection)subConfig.GetSection(ConfigurationSectionName.SUB_SONIC_SERVICE);

                    if(section != null)
                    {
                        MasterStore.ProjectsRow newProject = MM.Projects.NewProjectsRow();
                        newProject.Name = projectName;
                        newProject.OriginalLocation = originalDirectory;
                        newProject.EnableTrace = Convert.ToBoolean(!String.IsNullOrEmpty(section.EnableTrace) ? section.EnableTrace : MM.Projects.EnableTraceColumn.DefaultValue);
                        newProject.TemplateDirectory =
                            Convert.ToString(!String.IsNullOrEmpty(section.TemplateDirectory) ? section.TemplateDirectory : MM.Projects.TemplateDirectoryColumn.DefaultValue);
                        MM.Projects.AddProjectsRow(newProject);

                        ConnectionStringSettingsCollection connStrings = new ConnectionStringSettingsCollection();
                        if(subConfig.ConnectionStrings != null)
                            connStrings = subConfig.ConnectionStrings.ConnectionStrings;

                        List<int> insertedConnStringIds = new List<int>();
                        //Loop through connection strings and remove any that aren't referenced by the provider.
                        foreach(ConnectionStringSettings connSetting in connStrings)
                        {
                            bool foundMatch = false;
                            foreach(ProviderSettings providerSettings in section.Providers)
                            {
                                if(providerSettings.Parameters.Get(ConfigurationPropertyName.CONNECTION_STRING_NAME) != null)
                                {
                                    if(providerSettings.Parameters.Get(ConfigurationPropertyName.CONNECTION_STRING_NAME) == connSetting.Name)
                                    {
                                        foundMatch = true;
                                        break;
                                    }
                                }
                            }
                            if(!foundMatch)
                                connStrings.Remove(connSetting);
                            else
                            {
                                int referencedId = -1;
                                foreach(MasterStore.ConnectionStringsRow existingConnection in MM.ConnectionStrings)
                                {
                                    if(existingConnection.Name == connSetting.Name && existingConnection.ConnectionString == connSetting.ConnectionString)
                                    {
                                        referencedId = existingConnection.ConnectionStringId;
                                        break;
                                    }
                                }
                                if(referencedId < 0)
                                {
                                    MasterStore.ConnectionStringsRow newConnection = (MasterStore.ConnectionStringsRow)MM.ConnectionStrings.NewRow();
                                    newConnection.Name = connSetting.Name;
                                    newConnection.ConnectionString = connSetting.ConnectionString;
                                    MM.ConnectionStrings.AddConnectionStringsRow(newConnection);
                                    referencedId = newConnection.ConnectionStringId;
                                }
                                insertedConnStringIds.Add(referencedId);
                            }
                        }

                        foreach(ProviderSettings pset in section.Providers)
                        {
                            MasterStore.ProvidersRow newProvider = (MasterStore.ProvidersRow)MM.Providers.NewRow();
                            newProvider.Name = pset.Name;
                            newProvider.ProjectId = newProject.ProjectId;

                            string connectionName = GetConfig(pset, ConfigurationPropertyName.CONNECTION_STRING_NAME, null).ToString();

                            MasterStore.ConnectionStringsRow[] conns =
                                (MasterStore.ConnectionStringsRow[])MM.ConnectionStrings.Select(MM.ConnectionStrings.NameColumn + " = '" + connectionName + "'");

                            int activeConnectionId = -1;
                            if(conns.Length > 1)
                            {
                                foreach(MasterStore.ConnectionStringsRow cRow in MM.ConnectionStrings)
                                {
                                    if(insertedConnStringIds.Contains(cRow.ConnectionStringId))
                                    {
                                        activeConnectionId = cRow.ConnectionStringId;
                                        break;
                                    }
                                }
                            }
                            else if(conns.Length == 1)
                                activeConnectionId = conns[0].ConnectionStringId;
                            else
                                ShowStatus("Invalid Configuration File... Import Aborted.");

                            newProvider.ConnectionStringId = activeConnectionId;
                            string providerType = section.Providers[0].Type.Split(new char[] {'.', ','})[1].Trim();

                            bool foundProvider = false;
                            foreach(MasterStore.ProviderTypesRow providerTypeRow in MM.ProviderTypes)
                            {
                                if(providerTypeRow.InternalName == providerType)
                                {
                                    newProvider.ProviderTypeId = providerTypeRow.ProviderTypeId;
                                    foundProvider = true;
                                    break;
                                }
                            }

                            if(!foundProvider)
                                newProvider.ProviderTypeId = MM.ProviderTypes[0].ProviderTypeId;

                            newProvider.AppendWith = GetConfig(pset, ConfigurationPropertyName.APPEND_WITH, MM.Providers.AppendWithColumn).ToString();
                            newProvider.AdditionalNamespaces = GetConfig(pset, ConfigurationPropertyName.ADDITIONAL_NAMESPACES, MM.Providers.AdditionalNamespacesColumn).ToString();
                            newProvider.ExcludeProcedureList = GetConfig(pset, ConfigurationPropertyName.EXCLUDE_PROCEDURE_LIST, MM.Providers.ExcludeProcedureListColumn).ToString();
                            newProvider.ExcludeTableList = GetConfig(pset, ConfigurationPropertyName.EXCLUDE_TABLE_LIST, MM.Providers.ExcludeTableListColumn).ToString();
                            newProvider.ExtractClassNameFromSPName =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.EXTRACT_CLASS_NAME_FROM_SP_NAME, MM.Providers.ExtractClassNameFromSPNameColumn));
                            newProvider.FixDatabaseObjectCasing =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.FIX_DATABASE_OBJECT_CASING, MM.Providers.FixDatabaseObjectCasingColumn));
                            newProvider.FixPluralClassNames =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.FIX_PLURAL_CLASS_NAMES, MM.Providers.FixPluralClassNamesColumn));
                            newProvider.GeneratedNamespace = GetConfig(pset, ConfigurationPropertyName.GENERATED_NAMESPACE, MM.Providers.GeneratedNamespaceColumn).ToString();
                            newProvider.GenerateLazyLoads = Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.GENERATE_LAZY_LOADS, MM.Providers.GenerateLazyLoadsColumn));
                            newProvider.GenerateNullableProperties =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.GENERATE_NULLABLE_PROPERTIES, MM.Providers.GenerateNullablePropertiesColumn));
                            newProvider.GenerateODSControllers =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.GENERATE_ODS_CONTROLLERS, MM.Providers.GenerateODSControllersColumn));
                            newProvider.GenerateRelatedTablesAsProperties =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.GENERATE_RELATED_TABLES_AS_PROPERTIES,
                                    MM.Providers.GenerateRelatedTablesAsPropertiesColumn));
                            newProvider.IncludeProcedureList = GetConfig(pset, ConfigurationPropertyName.INCLUDE_PROCEDURE_LIST, MM.Providers.IncludeProcedureListColumn).ToString();
                            newProvider.IncludeTableList = GetConfig(pset, ConfigurationPropertyName.INCLUDE_TABLE_LIST, MM.Providers.IncludeTableListColumn).ToString();
                            newProvider.RegexDictionaryReplace =
                                GetConfig(pset, ConfigurationPropertyName.REGEX_DICTIONARY_REPLACE, MM.Providers.RegexDictionaryReplaceColumn).ToString();
                            newProvider.RegexIgnoreCase = Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.REGEX_IGNORE_CASE, MM.Providers.RegexIgnoreCaseColumn));
                            newProvider.RegexMatchExpression = GetConfig(pset, ConfigurationPropertyName.REGEX_MATCH_EXPRESSION, MM.Providers.RegexMatchExpressionColumn).ToString();
                            newProvider.RegexReplaceExpression =
                                GetConfig(pset, ConfigurationPropertyName.REGEX_REPLACE_EXPRESSION, MM.Providers.RegexReplaceExpressionColumn).ToString();
                            newProvider.RelatedTableLoadPrefix =
                                GetConfig(pset, ConfigurationPropertyName.RELATED_TABLE_LOAD_PREFIX, MM.Providers.RelatedTableLoadPrefixColumn).ToString();
                            newProvider.RemoveUnderscores = Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.REMOVE_UNDERSCORES, MM.Providers.RemoveUnderscoresColumn));
                            newProvider.SetPropertyDefaultsFromDatabase =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.SET_PROPERTY_DEFAULTS_FROM_DATABASE, MM.Providers.SetPropertyDefaultsFromDatabaseColumn));
                            newProvider.SPStartsWith = GetConfig(pset, ConfigurationPropertyName.SP_STARTS_WITH, MM.Providers.SPStartsWithColumn).ToString();
                            newProvider.SPClassName = GetConfig(pset, ConfigurationPropertyName.STORED_PROCEDURE_CLASS_NAME, MM.Providers.SPClassNameColumn).ToString();
                            newProvider.StoredProcedureBaseClass =
                                GetConfig(pset, ConfigurationPropertyName.STORED_PROCEDURE_BASE_CLASS, MM.Providers.StoredProcedureBaseClassColumn).ToString();
                            newProvider.StripColumnText = GetConfig(pset, ConfigurationPropertyName.STRIP_COLUMN_TEXT, MM.Providers.StripColumnTextColumn).ToString();
                            newProvider.StripParamText = GetConfig(pset, ConfigurationPropertyName.STRIP_PARAM_TEXT, MM.Providers.StripParamTextColumn).ToString();
                            newProvider.StripSPText = GetConfig(pset, ConfigurationPropertyName.STRIP_STORED_PROCEDURE_TEXT, MM.Providers.StripSPTextColumn).ToString();
                            newProvider.StripTableText = GetConfig(pset, ConfigurationPropertyName.STRIP_TABLE_TEXT, MM.Providers.StripTableTextColumn).ToString();
                            newProvider.StripViewText = GetConfig(pset, ConfigurationPropertyName.STRIP_VIEW_TEXT, MM.Providers.StripViewTextColumn).ToString();
                            newProvider.TableBaseClass = GetConfig(pset, ConfigurationPropertyName.TABLE_BASE_CLASS, MM.Providers.TableBaseClassColumn).ToString();
                            newProvider.UseExtendedProperties =
                                Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.USE_EXTENDED_PROPERTIES, MM.Providers.UseExtendedPropertiesColumn));
                            newProvider.UseSPs = Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.USE_STORED_PROCEDURES, MM.Providers.UseSPsColumn));
                            newProvider.UseUTC = Convert.ToBoolean(GetConfig(pset, ConfigurationPropertyName.USE_UTC_TIMES, MM.Providers.UseUTCColumn));
                            newProvider.ViewBaseClass = GetConfig(pset, ConfigurationPropertyName.VIEW_BASE_CLASS, MM.Providers.ViewBaseClassColumn).ToString();
                            newProvider.ViewStartsWith = GetConfig(pset, ConfigurationPropertyName.VIEW_STARTS_WITH, MM.Providers.ViewStartsWithColumn).ToString();

                            MM.Providers.AddProvidersRow(newProvider);

                            if(!String.IsNullOrEmpty(section.DefaultProvider))
                            {
                                if(Utility.IsMatch(section.DefaultProvider, newProvider.Name))
                                    newProject.DefaultProvider = newProvider.ProviderId;
                            }
                        }
                        MM.Save();
                        BuildTree();
                    }
                }
            }
        }