static private void Initialize()
        {
            if (ConnectionState.Open != _initState)
            {
                lock (_lockobj) {
                    switch (_initState)
                    {
                    case ConnectionState.Closed:
                        _initState = ConnectionState.Connecting; // used for preventing recursion
                        try {
                            DataSet configTable = PrivilegedConfigurationManager.GetSection(DbProviderFactoriesConfigurationHandler.sectionName) as DataSet;
                            _providerTable = (null != configTable) ? IncludeFrameworkFactoryClasses(configTable.Tables[DbProviderFactoriesConfigurationHandler.providerGroup]) : IncludeFrameworkFactoryClasses(null);
                        }
                        finally {
                            _initState = ConnectionState.Open;
                        }
                        break;

                    case ConnectionState.Connecting:
                    case ConnectionState.Open:
                        break;

                    default:
                        Debug.Assert(false, "unexpected state");
                        break;
                    }
                }
            }
        }
        static internal RequestCachingSectionInternal GetSection()
        {
            lock (RequestCachingSectionInternal.ClassSyncObject)
            {
                RequestCachingSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.RequestCachingSectionPath) as RequestCachingSection;
                if (section == null)
                {
                    return(null);
                }

                try
                {
                    return(new RequestCachingSectionInternal(section));
                }
                catch (Exception exception)
                {
                    if (NclUtilities.IsFatal(exception))
                    {
                        throw;
                    }

                    throw new ConfigurationErrorsException(SR.GetString(SR.net_config_requestcaching), exception);
                }
                catch
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.net_config_requestcaching), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
                }
            }
        }
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region Initialize()
        /// <summary>
        /// Initializes the current instance using the application configuration settings.
        /// </summary>
        /// <seealso cref="SyndicationResourceHandlerSection"/>
        private void Initialize()
        {
            SyndicationResourceHandlerSection handlerConfiguration = PrivilegedConfigurationManager.GetSyndicationHandlerSection();

            if (handlerConfiguration != null)
            {
                if (handlerConfiguration.UpdatableWithin != TimeSpan.MinValue)
                {
                    this.ContentUpdatableWithin = handlerConfiguration.UpdatableWithin;
                }

                if (handlerConfiguration.ValidFor != TimeSpan.MinValue)
                {
                    this.ContentValidFor = handlerConfiguration.ValidFor;
                }

                this.EnableCaching = handlerConfiguration.EnableCaching;

                if (handlerConfiguration.Format != SyndicationContentFormat.None)
                {
                    this.Format = handlerConfiguration.Format;
                }

                if (!String.IsNullOrEmpty(handlerConfiguration.Id))
                {
                    this.Id = handlerConfiguration.Id;
                }
            }
        }
        static internal DefaultProxySectionInternal GetSection()
        {
            lock (DefaultProxySectionInternal.ClassSyncObject)
            {
#if MONO
                var res = new DefaultProxySectionInternal();
                res.webProxy = GetDefaultProxy_UsingOldMonoCode();
                return(res);
#else
                DefaultProxySection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultProxySectionPath) as DefaultProxySection;
                if (section == null)
                {
                    return(null);
                }

                try
                {
                    return(new DefaultProxySectionInternal(section));
                }
                catch (Exception exception)
                {
                    if (NclUtilities.IsFatal(exception))
                    {
                        throw;
                    }

                    throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), exception);
                }
#endif
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the current instance using the application configuration settings.
        /// </summary>
        /// <seealso cref="XmlRpcClientSection"/>
        private void Initialize()
        {
            TrackbackClientSection clientConfiguration = PrivilegedConfigurationManager.GetTracbackClientSection();

            if (clientConfiguration != null)
            {
                if (clientConfiguration.Timeout.TotalMilliseconds > 0 && clientConfiguration.Timeout < TimeSpan.FromDays(365))
                {
                    this.Timeout = clientConfiguration.Timeout;
                }

                if (!String.IsNullOrEmpty(clientConfiguration.UserAgent))
                {
                    this.UserAgent = clientConfiguration.UserAgent;
                }

                if (clientConfiguration.Network != null)
                {
                    this.UseDefaultCredentials = clientConfiguration.Network.DefaultCredentials;

                    if (clientConfiguration.Network.Credential != null)
                    {
                        this.Credentials = clientConfiguration.Network.Credential;
                    }

                    if (clientConfiguration.Network.Host != null)
                    {
                        this.Host = clientConfiguration.Network.Host;
                    }
                }
            }
        }
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
        {
            Debug.Assert(internalConnection != null, "internalConnection may not be null.");
            cacheMetaDataFactory = false;


            OleDbConnectionInternal oleDbInternalConnection = (OleDbConnectionInternal)internalConnection;
            OleDbConnection         oleDbOuterConnection    = oleDbInternalConnection.Connection;

            Debug.Assert(oleDbOuterConnection != null, "outer connection may not be null.");

            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.oledb");
            Stream XMLStream             = null;
            String providerFileName      = oleDbOuterConnection.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, ODB.DBPROP_PROVIDERFILENAME) as string;

            if (settings != null)
            {
                string [] values      = null;
                string    metaDataXML = null;
                // first try to get the provider specific xml

                // if providerfilename is not supported we can't build the settings key needed to
                // get the provider specific XML path
                if (providerFileName != null)
                {
                    metaDataXML = providerFileName + _metaDataXml;
                    values      = settings.GetValues(metaDataXML);
                }

                // if we did not find provider specific xml see if there is new default xml
                if (values == null)
                {
                    metaDataXML = _defaultMetaDataXml;
                    values      = settings.GetValues(metaDataXML);
                }

                // If there is new XML get it
                if (values != null)
                {
                    XMLStream = ADP.GetXmlStreamFromValues(values, metaDataXML);
                }
            }

            // if the xml was not obtained from machine.config use the embedded XML resource
            if (XMLStream == null)
            {
                XMLStream            = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.OleDb.OleDbMetaData.xml");
                cacheMetaDataFactory = true;
            }

            Debug.Assert(XMLStream != null, "XMLstream may not be null.");

            // using the ServerVersion as the NormalizedServerVersion. Doing this for two reasons
            //  1) The Spec for DBPROP_DBMSVER normalizes the ServerVersion
            //  2) for OLE DB its the only game in town
            return(new OleDbMetaDataFactory(XMLStream,
                                            oleDbInternalConnection.ServerVersion,
                                            oleDbInternalConnection.ServerVersion,
                                            oleDbInternalConnection.GetSchemaRowsetInformation()));
        }
Exemplo n.º 7
0
        static internal DefaultProxySectionInternal GetSection()
        {
            lock (DefaultProxySectionInternal.ClassSyncObject)
            {
                DefaultProxySection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultProxySectionPath) as DefaultProxySection;
                if (section == null)
                {
                    return(null);
                }

                try
                {
                    return(new DefaultProxySectionInternal(section));
                }
                catch (Exception exception)
                {
                    if (NclUtilities.IsFatal(exception))
                    {
                        throw;
                    }

                    throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), exception);
                }
                catch
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.net_config_proxy), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
                }
            }
        }
Exemplo n.º 8
0
        internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context)
        {
            if (!schemas.Contains(XmlSchema.Namespace))
            {
                schemas.AddReference(XmlSchemas.XsdSchema);
                schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
            }
            if (!schemas.Contains(XmlReservedNs.NsXml))
            {
                schemas.AddReference(XmlSchemas.XmlSchema);
                schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
            }
            this.schemas      = schemas;
            this.options      = options;
            this.codeProvider = codeProvider;
            this.context      = context;
            Schemas.SetCache(Context.Cache, Context.ShareTypes);

            SchemaImporterExtensionsSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection;

            if (section != null)
            {
                extensions = section.SchemaImporterExtensionsInternal;
            }
            else
            {
                extensions = new SchemaImporterExtensionCollection();
            }
        }
Exemplo n.º 9
0
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
        {
            Debug.Assert(internalConnection != null, "internalConnection may not be null.");
            cacheMetaDataFactory = false;

            if (internalConnection is SqlInternalConnectionSmi)
            {
                throw SQL.NotAvailableOnContextConnection();
            }

            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.sqlclient");
            Stream XMLStream             = null;

            if (settings != null)
            {
                string [] values = settings.GetValues(_metaDataXml);
                if (values != null)
                {
                    XMLStream = ADP.GetXmlStreamFromValues(values, _metaDataXml);
                }
            }

            // if the xml was not obtained from machine.config use the embedded XML resource
            if (XMLStream == null)
            {
                XMLStream            = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.SqlClient.SqlMetaData.xml");
                cacheMetaDataFactory = true;
            }
            Debug.Assert(XMLStream != null, "XMLstream may not be null.");

            return(new SqlMetaDataFactory(XMLStream,
                                          internalConnection.ServerVersion,
                                          internalConnection.ServerVersion)); //internalConnection.ServerVersionNormalized);
        }
Exemplo n.º 10
0
        static internal DefaultSettingsSection GetSection()
        {
            DefaultSettingsSection retval = (DefaultSettingsSection)PrivilegedConfigurationManager.GetSection(ConfigurationStrings.DefaultSettingsSectionPath);

            if (retval == null)
            {
                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                     SR.GetString(SR.ConfigurationSectionNotFound),
                                                                     ConfigurationStrings.DefaultSettingsSectionPath));
            }
            return(retval);
        }
        static internal ConnectionManagementSectionInternal GetSection()
        {
            lock (ConnectionManagementSectionInternal.ClassSyncObject)
            {
                ConnectionManagementSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.ConnectionManagementSectionPath) as ConnectionManagementSection;
                if (section == null)
                {
                    return(null);
                }

                return(new ConnectionManagementSectionInternal(section));
            }
        }
        internal static SmtpSectionInternal GetSection()
        {
            lock (ClassSyncObject)
            {
                SmtpSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SmtpSectionPath) as SmtpSection;
                if (section == null)
                {
                    return(null);
                }

                return(new SmtpSectionInternal(section));
            }
        }
        static internal AuthenticationModulesSectionInternal GetSection()
        {
            lock (AuthenticationModulesSectionInternal.ClassSyncObject)
            {
                AuthenticationModulesSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.AuthenticationModulesSectionPath) as AuthenticationModulesSection;
                if (section == null)
                {
                    return(null);
                }

                return(new AuthenticationModulesSectionInternal(section));
            }
        }
Exemplo n.º 14
0
        static internal WebRequestModulesSectionInternal GetSection()
        {
            lock (WebRequestModulesSectionInternal.ClassSyncObject)
            {
                WebRequestModulesSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.WebRequestModulesSectionPath) as WebRequestModulesSection;
                if (section == null)
                {
                    return(null);
                }

                return(new WebRequestModulesSectionInternal(section));
            }
        }
Exemplo n.º 15
0
            internal ResultsEnumerator(SearchResultCollection results, string parentUserName, string parentPassword, AuthenticationTypes parentAuthenticationType)
            {
                if (parentUserName != null && parentPassword != null)
                {
                    _parentCredentials = new NetworkCredential(parentUserName, parentPassword);
                }

                _parentAuthenticationType = parentAuthenticationType;
                _results     = results;
                _initialized = false;

                // get the app configuration information
                object o = PrivilegedConfigurationManager.GetSection("system.directoryservices");

                if (o != null && o is bool)
                {
                    _waitForResult = (bool)o;
                }
            }
Exemplo n.º 16
0
 private static SystemDiagnosticsSection GetConfigSection()
 {
     return(s_configSection ??= (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics"));
 }
Exemplo n.º 17
0
        override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
        {
            Debug.Assert(internalConnection != null, "internalConnection may not be null.");
            cacheMetaDataFactory = false;

            OdbcConnection odbcOuterConnection = ((OdbcConnectionOpen)internalConnection).OuterConnection;

            Debug.Assert(odbcOuterConnection != null, "outer connection may not be null.");

            NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("system.data.odbc");
            Stream XMLStream             = null;

            // get the DBMS Name
            object driverName  = null;
            string stringValue = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DRIVER_NAME);

            if (stringValue != null)
            {
                driverName = stringValue;
            }

            if (settings != null)
            {
                string [] values      = null;
                string    metaDataXML = null;
                // first try to get the provider specific xml

                // if driver name is not supported we can't build the settings key needed to
                // get the provider specific XML path
                if (driverName != null)
                {
                    metaDataXML = ((string)driverName) + _MetaData;
                    values      = settings.GetValues(metaDataXML);
                }

                // if we did not find provider specific xml see if there is new default xml
                if (values == null)
                {
                    metaDataXML = _defaultMetaDataXml;
                    values      = settings.GetValues(metaDataXML);
                }

                // If there is an XML file get it
                if (values != null)
                {
                    XMLStream = ADP.GetXmlStreamFromValues(values, metaDataXML);
                }
            }

            // use the embedded xml if the user did not over ride it
            if (XMLStream == null)
            {
                XMLStream            = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("System.Data.Odbc.OdbcMetaData.xml");
                cacheMetaDataFactory = true;
            }

            Debug.Assert(XMLStream != null, "XMLstream may not be null.");

            String versionString = odbcOuterConnection.GetInfoStringUnhandled(ODBC32.SQL_INFO.DBMS_VER);

            return(new OdbcMetaDataFactory(XMLStream,
                                           versionString,
                                           versionString,
                                           odbcOuterConnection));
        }
Exemplo n.º 18
0
        internal static void CreateLocalDBInstance(string instance)
        {
            DemandLocalDBPermissions();
            if (s_configurableInstances == null)
            {
                // load list of instances from configuration, mark them as not created
                bool lockTaken = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    Monitor.Enter(s_configLock, ref lockTaken);
                    if (s_configurableInstances == null)
                    {
                        Dictionary <string, InstanceInfo> tempConfigurableInstances = new Dictionary <string, InstanceInfo>(StringComparer.OrdinalIgnoreCase);
                        object section = PrivilegedConfigurationManager.GetSection("system.data.localdb");
                        if (section != null) // if no section just skip creation
                        {
                            // validate section type
                            LocalDBConfigurationSection configSection = section as LocalDBConfigurationSection;
                            if (configSection == null)
                            {
                                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_BadConfigSectionType"));
                            }
                            foreach (LocalDBInstanceElement confElement in configSection.LocalDbInstances)
                            {
                                Debug.Assert(confElement.Name != null && confElement.Version != null, "Both name and version should not be null");
                                tempConfigurableInstances.Add(confElement.Name.Trim(), new InstanceInfo(confElement.Version.Trim()));
                            }
                        }
                        else
                        {
                            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> No system.data.localdb section found in configuration");
                        }
                        s_configurableInstances = tempConfigurableInstances;
                    }
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit(s_configLock);
                    }
                }
            }

            InstanceInfo instanceInfo = null;

            if (!s_configurableInstances.TryGetValue(instance, out instanceInfo))
            {
                return; // instance name was not in the config
            }
            if (instanceInfo.created)
            {
                return; // instance has already been created
            }
            Debug.Assert(!instance.Contains("\0"), "Instance name should contain embedded nulls");

            if (instanceInfo.version.Contains("\0"))
            {
                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_InvalidVersion"), instance: instance);
            }

            // LocalDBCreateInstance is thread- and cross-process safe method, it is OK to call from two threads simultaneously
            int hr = LocalDBCreateInstance(instanceInfo.version, instance, flags: 0);

            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Starting creation of instance {0} version {1}", instance, instanceInfo.version);

            if (hr < 0)
            {
                throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_CreateFailed"), instance: instance, localDbError: hr);
            }

            SqlClientEventSource.Log.TraceEvent("<sc.LocalDBAPI.CreateLocalDBInstance> Finished creation of instance {0}", instance);
            instanceInfo.created = true; // mark instance as created
        } // CreateLocalDbInstance
Exemplo n.º 19
0
 // This method is required - it gets called through reflection, matching all the other XxxSectionInternal classes.
 // This one gets it fresh for each call.  Generally it shouldn't be used.
 internal static SettingsSectionInternal GetSection()
 {
     return(new SettingsSectionInternal((SettingsSection)PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SettingsSectionPath)));
 }
Exemplo n.º 20
0
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region Initialize()
        /// <summary>
        /// Initializes the <see cref="SyndicationManager"/> using the declaratively configured application settings.
        /// </summary>
        /// <seealso cref="SyndicationResourceSection"/>
        private static void Initialize()
        {
            //------------------------------------------------------------
            //	Verify manager has not already been initialized previously
            //------------------------------------------------------------
            if (syndicationManagerInitialized)
            {
                //------------------------------------------------------------
                //	Throw stored exception if initialization raised an exception
                //------------------------------------------------------------
                if (syndicationManagerInitializationException != null)
                {
                    throw syndicationManagerInitializationException;
                }
            }
            else
            {
                //------------------------------------------------------------
                //	Throw stored exception if initialization raised an exception
                //------------------------------------------------------------
                if (syndicationManagerInitializationException != null)
                {
                    throw syndicationManagerInitializationException;
                }

                lock (syndicationManagerLock)
                {
                    try
                    {
                        //------------------------------------------------------------
                        //	Extract configuration section from application configuration
                        //------------------------------------------------------------
                        SyndicationResourceSection section = PrivilegedConfigurationManager.GetSyndicationResourceSection();

                        if (section != null)
                        {
                            //------------------------------------------------------------
                            //	Raise exception if no providers were specified
                            //------------------------------------------------------------
                            if (((section.DefaultProvider == null) || (section.Providers == null)) || (section.Providers.Count < 1))
                            {
                                throw new ProviderException(String.Format(null, "The syndication resource providers were not specified. Source configuration file was {0}", section.ElementInformation.Source));
                            }

                            //------------------------------------------------------------
                            //	Fill providers collection
                            //------------------------------------------------------------
                            syndicationManagerProviders = new SyndicationResourceProviderCollection();

                            if (HostingEnvironment.IsHosted)
                            {
                                ProvidersHelper.InstantiateProviders(section.Providers, syndicationManagerProviders, typeof(SyndicationResourceProvider));
                            }
                            else
                            {
                                foreach (ProviderSettings settings in section.Providers)
                                {
                                    Type settingsType = Type.GetType(settings.Type, true, true);
                                    if (!typeof(SyndicationResourceProvider).IsAssignableFrom(settingsType))
                                    {
                                        throw new ArgumentException(String.Format(null, "The provider must implement type of {0}. Source configuration file was {1}", typeof(SyndicationResourceProvider).FullName, section.ElementInformation.Source));
                                    }

                                    SyndicationResourceProvider provider      = (SyndicationResourceProvider)Activator.CreateInstance(settingsType);
                                    NameValueCollection         parameters    = settings.Parameters;
                                    NameValueCollection         configuration = new NameValueCollection(parameters.Count, StringComparer.Ordinal);

                                    foreach (string parameter in parameters)
                                    {
                                        configuration[parameter] = parameters[parameter];
                                    }

                                    provider.Initialize(settings.Name, configuration);
                                    syndicationManagerProviders.Add(provider);
                                }
                            }

                            //------------------------------------------------------------
                            //	Set and validate default provider
                            //------------------------------------------------------------
                            syndicationManagerDefaultProvider = syndicationManagerProviders[section.DefaultProvider];

                            if (syndicationManagerDefaultProvider == null)
                            {
                                throw new ConfigurationErrorsException(String.Format(null, "The default syndication resource provider was not found. Source configuration file was {0}", section.ElementInformation.Source), section.ElementInformation.Properties["defaultProvider"].Source, section.ElementInformation.Properties["defaultProvider"].LineNumber);
                            }

                            //------------------------------------------------------------
                            //	Prevent collection from being modified further
                            //------------------------------------------------------------
                            syndicationManagerProviders.SetReadOnly();
                        }
                    }
                    catch (Exception exception)
                    {
                        //------------------------------------------------------------
                        //	Store exception locally and then throw
                        //------------------------------------------------------------
                        syndicationManagerInitializationException = exception;
                        throw;
                    }

                    //------------------------------------------------------------
                    //	Set initialization indicator flag
                    //------------------------------------------------------------
                    syndicationManagerInitialized = true;
                }
            }
        }
        private static SystemDiagnosticsSection GetConfigSection()
        {
            SystemDiagnosticsSection configSection = (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics");

            return(configSection);
        }