Exemplo n.º 1
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.º 2
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);
        }
        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
            }
        }
        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;
                    }
                }
            }
        }
        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.º 6
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)));
                }
            }
        }
        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)));
                }
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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));
            }
        }
        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));
            }
        }
        static internal ConnectionManagementSectionInternal GetSection()
        {
            lock (ConnectionManagementSectionInternal.ClassSyncObject)
            {
                ConnectionManagementSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.ConnectionManagementSectionPath) as ConnectionManagementSection;
                if (section == null)
                {
                    return(null);
                }

                return(new ConnectionManagementSectionInternal(section));
            }
        }
Exemplo n.º 13
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.º 14
0
 private static SystemDiagnosticsSection GetConfigSection()
 {
     return(s_configSection ??= (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics"));
 }
Exemplo n.º 15
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.º 16
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.º 17
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)));
 }
        private static SystemDiagnosticsSection GetConfigSection()
        {
            SystemDiagnosticsSection configSection = (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics");

            return(configSection);
        }