Exemplo n.º 1
0
        private void LoadDbs(XElement doc)
        {
            byte        code;
            DbsProvider provider;
            XElement    currentElement;
            XElement    historyElement;
            string      currentConnectionString;
            string      historyConnectionString;
            bool        currentConnectionStringIsCryptograph;
            bool        historyConnectionStringIsCryptograph;

            foreach (XElement e in doc.GetChildElements(ConnectionKey))
            {
                if (Dbs.IsQualifiedName(e.Name.ToString()))
                {
                    Dbs dbs = Dbs.Create(e.Name.ToString());
                    if (byte.TryParse(GetElementValue(e, PrivoderKey), out code))
                    {
                        DbsProvider.TryGetProvider(code, out provider);
                    }
                    else
                    {
                        provider = DbsProvider.MsSql;
                    }

                    currentConnectionString = GetElementValue(e, CurrentKey);
                    currentElement          = e.GetElement(CurrentKey);
                    if (currentElement != null)
                    {
                        currentConnectionStringIsCryptograph = currentElement.GetAttributeValue <bool>(IsCryptographKey, false);
                        if (currentConnectionStringIsCryptograph)
                        {
                            currentConnectionString = Decrypt(currentConnectionString);
                        }
                    }
                    historyConnectionString = GetElementValue(e, HistoryKey);
                    historyElement          = e.GetElement(HistoryKey);
                    if (historyElement != null)
                    {
                        historyConnectionStringIsCryptograph = historyElement.GetAttributeValue <bool>(IsCryptographKey, false);
                        if (historyConnectionStringIsCryptograph)
                        {
                            historyConnectionString = Decrypt(historyConnectionString);
                        }
                    }

                    DbsSetting setting = new DbsSetting(dbs, DbsProvider.MsSql, currentConnectionString)
                    {
                        Provider = provider,
                        HistoryConnectionString  = historyConnectionString,
                        MetadataAssemblyFullName = GetElementValue(e, MetadataAssemblyKey)
                    };
                    Add(setting);
                }
            }
        }
Exemplo n.º 2
0
        private void LoadFromCofiguration(Dbs dbs)
        {
            ConnectionStringSettings css = WebConfigurationManager.ConnectionStrings[dbs.QualifiedName]
                                           ?? ConfigurationManager.ConnectionStrings[dbs.QualifiedName];

            if (css != null)
            {
                DbsProvider provider = DbsProvider.Providers.FirstOrDefault(a => string.Equals(a.Provider, css.ProviderName, StringComparison.CurrentCultureIgnoreCase) && a.Validate(css.ConnectionString));

                DbsSetting setting = new DbsSetting(dbs, provider, css.ConnectionString)
                {
                    Provider = provider
                };
                Add(setting);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 增加连接串设置
 /// </summary>
 /// <param name="setting"></param>
 public void Add(DbsSetting setting)
 {
     _dbses[setting.Dbs] = setting;
 }