Пример #1
0
        // fluent API
        override public ConnectionProvider Init(string connectionString)
        {
            string providerName = null;

#if NETFRAMEWORK
            var extraMessage = _usedAfterConfigFile ? " (and is not a valid connection string name)" : "";
#endif
            StringBuilder ConnectionString = new StringBuilder();
            try
            {
                foreach (var configPair in connectionString.Split(';'))
                {
                    if (!string.IsNullOrEmpty(configPair))
                    {
                        var keyValuePair = configPair.Split('=');
                        if ("providername".Equals(keyValuePair[0].Trim(), StringComparison.OrdinalIgnoreCase))
                        {
                            providerName = keyValuePair[1].Trim();
                        }
                        else
                        {
                            ConnectionString.Append(configPair);
                            ConnectionString.Append(";");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Cannot parse as connection string \"" + connectionString + "\""
#if NETFRAMEWORK
                                                    + extraMessage
#endif
                                                    , ex);
            }
            if (providerName == null)
            {
                throw new InvalidOperationException("Cannot find ProviderName=... in connection string passed to MightyOrm"
#if NETFRAMEWORK
                                                    + extraMessage
#endif
                                                    );
            }
            DatabasePluginType = MightyProviderFactories.GetDatabasePluginAsType(providerName);
#if NETFRAMEWORK
            ProviderFactoryInstance = DbProviderFactories.GetFactory(providerName);
#else
            ProviderFactoryInstance = MightyProviderFactories.GetFactory(providerName);
#endif
            this.ConnectionString = ConnectionString.ToString();
            return(this);
        }
Пример #2
0
        // fluent API
        override public ConnectionProvider Init(string connectionStringName)
        {
            ConnectionStringSettings connectionStringSettings = GetConnectionStringSettings(connectionStringName);

            if (connectionStringSettings != null)
            {
                ConnectionString = connectionStringSettings.ConnectionString;
                string providerName = connectionStringSettings.ProviderName;
                if (providerName != null)
                {
                    DatabasePluginType      = MightyProviderFactories.GetDatabasePluginAsType(providerName);
                    ProviderFactoryInstance = DbProviderFactories.GetFactory(providerName);
                }
            }
            return(this);
        }