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

public Create ( object parent, object context, XmlNode section ) : object
parent object
context object
section System.Xml.XmlNode
Результат object
Пример #1
0
        public object Create(object parent, object context, XmlNode section)
        {
            IDictionary directories;
            NameValueSectionHandler nameValueSectionHandler;
            XmlNodeList nodes;
            DirectoryConfiguration directory;
            NameValueCollection properties;

            directories = new ListDictionary();

            nameValueSectionHandler = new NameValueSectionHandler();

            nodes = section.SelectNodes("directory");

            foreach(XmlElement element in nodes) {
                if(element.GetAttributeNode("name") == null)
                    throw(new ConfigurationException("Name not specified.", element));

                if(element.GetAttributeNode("type") == null)
                    throw(new ConfigurationException("Type not specified.", element));

                if(element.SelectSingleNode("properties") == null)
                    properties = new NameValueCollection();
                else
                    properties = (NameValueCollection) nameValueSectionHandler.Create(null, context, element.SelectSingleNode("properties"));

                directory = new DirectoryConfiguration(element.GetAttribute("name"), element.GetAttribute("type"), properties);

                directories.Add(directory.Name, directory);
            }

            return(directories);
        }
Пример #2
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            WindowFactory.AddSpecializedWindowFactory(new BrowserWindowFactory());

            NameValueSectionHandler sectionHandler = new NameValueSectionHandler();
            return sectionHandler.Create(parent, configContext, section);
        }
Пример #3
0
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     NameValueCollection configs;
     NameValueSectionHandler baseHandler = new NameValueSectionHandler();
     configs = (NameValueCollection)baseHandler.Create(parent, configContext, section);
     return configs;
 }
Пример #4
0
        public Object Create(Object parent, object configContext, XmlNode section) 
        {
            NameValueCollection settings;

            try 
            {
                NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection) baseHandler.Create(parent, configContext, section);
            } 
            catch
            {
                settings = null;
            }

            if (settings != null) 
            {
                dbServiceName = ReadSetting(settings, "dbServiceName", "JsonDbOpensocialService");
                allowUnauthenticated = ReadSetting(settings, "allowUnauthenticated", "true");
                gadgetDebug = ReadSetting(settings, "gadgetDebug", "true");
                tokenMaxAge = ReadSetting(settings, "tokenMaxAge", "3600");
                gadgetCacheXmlRefreshInterval = ReadSetting(settings, "gadgetCacheXmlRefreshInterval", "300000");
                containerUrlPrefix = ReadSetting(settings, "containerUrlPrefix", "");
                tokenMasterKey = ReadSetting(settings, "tokenMasterKey", "INSECURE_DEFAULT_KEY");
                javaPath = ReadSetting(settings, "javaPath", @"c:\program files\java\jdk1.6.0_12\bin\java.exe");
            }

            return null;
        }
Пример #5
0
        static void load()
        {
            if (!File.Exists("settings.xml"))
            {
                Application.Run(new MessageWindow("Not find 'settings.xml'"));
                return;
            }

            XmlDocument doc = new XmlDocument();
            doc.Load("settings.xml");

            XmlNode xNode = doc.GetElementsByTagName("settings").Item(0);

            IConfigurationSectionHandler csh = new NameValueSectionHandler();
            NameValueCollection nvc = (NameValueCollection)csh.Create(null, null, xNode);

            JAVA_HOME = nvc.Get("JAVA_HOME");
            XMS = nvc.Get("XMS");
            XMX = nvc.Get("XMX");

            if (JAVA_HOME == null)
            {
                Application.Run(new MessageWindow("Not find 'JAVA_HOME' in 'settings.xml'"));
                return;
            }
            if (!File.Exists(JAVA_HOME + "javaw.exe"))
            {
                Application.Run(new MessageWindow("Not find javaw.exe in 'JAVA_HOME'"));
                return;
            }
        }
Пример #6
0
        // Create a configuration object for a section.
        public Object Create(Object parent, Object configContext, XmlNode section)
        {
            Object            coll;
            String            filename;
            ConfigXmlDocument doc;

            // Remove the "file" attribute from the section.
            XmlAttribute file =
                (section.Attributes.RemoveNamedItem("file")
                 as XmlAttribute);

            // Load the main name/value pairs from the children.
            coll = NameValueSectionHandler.Create
                       (parent, section, "key", "value");

            // Process the "file" attribute, if it is present.
            if (file != null && file.Value != String.Empty)
            {
                // Combine the base filename with the new filename.
                filename = file.Value;
                if (file is IConfigXmlNode)
                {
                    filename = Path.Combine
                                   (Path.GetDirectoryName
                                       (((IConfigXmlNode)file).Filename), filename);
                }
                if (File.Exists(filename))
                {
                    // Load the new configuration file into memory.
                    doc = new ConfigXmlDocument();
                    try
                    {
                        doc.Load(filename);
                    }
                    catch (XmlException xe)
                    {
                        throw new ConfigurationException
                                  (xe.Message, xe, filename, xe.LineNumber);
                    }

                    // The document root must match the section name.
                    if (doc.DocumentElement.Name != section.Name)
                    {
                        throw new ConfigurationException
                                  (S._("Config_DocNameMatch"),
                                  doc.DocumentElement);
                    }

                    // Load the contents of the file.
                    coll = NameValueSectionHandler.Create
                               (coll, doc.DocumentElement, "key", "value");
                }
            }

            // Return the final collection to the caller.
            return(coll);
        }
        bool IConfigurationProvider.TryGetNameValueCollectionSection(string section, out NameValueCollection collection)
        {
            ConfigurationSection configurationSection = GetSection(section);
            if (configurationSection == null)
            {
                collection = null;
                return false;
            }

            string xml = configurationSection.SectionInformation.GetRawXml();
            var sectionXmlDocument = new XmlDocument();
            sectionXmlDocument.LoadXml(xml);
            if (sectionXmlDocument.DocumentElement == null)
            {
                collection = null;
                return false;
            }

            var handler = new NameValueSectionHandler();
            collection = handler.Create(null, null, sectionXmlDocument.DocumentElement) as NameValueCollection;
            return collection != null;
        }
      public object Create(object parent, object configContext, System.Xml.XmlNode section)
      {
         NameValueSectionHandler handler = new NameValueSectionHandler();
         OrderedHashTable schemes = new OrderedHashTable();

         NameValueCollection options = (NameValueCollection)
            handler.Create(parent, configContext, section);

         if ( options != null )
         {
            foreach ( string key in options.Keys )
            {
               Type type = Type.GetType(options[key]);
               if ( type == null )
                  throw new ConfigurationException(string.Format("Type '{0}' not found", key));
               if ( !typeof(IAMQCallbackHandler).IsAssignableFrom(type) )
                  throw new ConfigurationException(string.Format("Type '{0}' does not implement IAMQCallbackHandler", key));

               schemes.Add(key, type);
            }
         }

         return schemes;
      }
        protected static object GetAppSettingsFileHandler(string sectionName, IConfigurationSectionHandler parentHandler, XmlDocument xmlDoc)
        {
            object handler = null;
            XmlNode node = xmlDoc.SelectSingleNode("//" + sectionName);
            XmlAttribute att = (XmlAttribute)node.Attributes.RemoveNamedItem("file");

            if (att == null || att.Value == null || att.Value.Length == 0)
            {
                return parentHandler.Create(null, null, node);
            }
            else
            {
                string fileName = att.Value;
                string dir = Path.GetDirectoryName(fileName);
                string fullName = Path.Combine(dir, fileName);
                XmlDocument xmlDoc2 = new XmlDocument();
                xmlDoc2.Load(fullName);

                object parent = parentHandler.Create(null, null, node);
                IConfigurationSectionHandler h = new NameValueSectionHandler();
                handler = h.Create(parent, null, xmlDoc2.DocumentElement);
            }

            return handler;
        }
Пример #10
0
        public static void load()
        {
            _message.Clear();

            var doc = new XmlDocument();
            doc.Load(DIR + "\\localization\\" + RConfig.Instance.Localization);

            XmlNode xNode = doc.GetElementsByTagName("localization").Item(0);
            IConfigurationSectionHandler csh = new NameValueSectionHandler();
            var nvc = (NameValueCollection) csh.Create(null, null, xNode);

            String[] msg = Enum.GetNames(typeof (Word));

            foreach (String st in msg)
            {
                _message.Add(st, get(nvc, st));
            }
        }
Пример #11
0
            public object Create(object parent, object configContext, XmlNode section)
            {
                NameValueCollection settings;

                try
                {
                    NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                    settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
                }
                catch
                {
                    settings = null;
                }

                if (settings != null)
                {
                    m_connectionString = AppConfig.ReadSetting(settings, "ConnectionString", String.Empty);
                    m_userCount = Convert.ToInt32(AppConfig.ReadSetting(settings, "UserCount", "0"));
                }

                return settings;
            }
Пример #12
0
        public Object Create(Object parent, object configContext, XmlNode section)
        {
            NameValueCollection settings;

            try
            {
                NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
            }
            catch(Exception exc)
            {
                Common.LogWriter.Instance.WriteEventLogEntry(exc);
                settings = null;
            }

            return settings;
        }
Пример #13
0
 /// <summary>
 /// 实现接口以读写app.config
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="configContext"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     System.Configuration.NameValueSectionHandler handler = new System.Configuration.NameValueSectionHandler();
     return(handler.Create(parent, configContext, section));
 }
Пример #14
0
        /// <summary>
        /// 在调用ASP.NET应用程序之前从Web.Config中获取系统配置参数
        /// </summary>
        /// <param name="parent">
        ///  对应父配置节中的配置设置。 
        /// </param>
        /// <param name="configContext">
        /// 在从 ASP.NET 配置系统中调用 Create 时为 HttpConfigurationContext。否则,该参数是保留参数,并且为空引用(Visual Basic 中为 Nothing)。 
        /// </param>
        /// <param name="section">
        /// 一个 XmlNode,它包含配置文件中的配置信息。提供对配置节 XML 内容的直接访问。 
        /// </param>
        /// <returns>	配置对象。</returns>
        public Object Create(Object parent, object configContext, XmlNode section)
        {
            NameValueCollection settings;

            try
            {
                NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
            }
            catch
            {
                settings = null;
            }

            if (settings == null)
            {
                _ConnectionString = DATAACCESS_CONNECTIONSTRING_DEFAULT;
            }
            else
            {
                _ConnectionString = ReadSetting(settings, DATAACCESS_CONNECTIONSTRING, DATAACCESS_CONNECTIONSTRING_DEFAULT);

            }

            return settings;
        }
 /// <summary>
 /// 实现接口以读写app.config
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="configContext"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     System.Configuration.NameValueSectionHandler handler = new System.Configuration.NameValueSectionHandler();
     return handler.Create(parent, configContext, section);
 }
Пример #16
0
        private static NameValueCollection LoadGlobalSettings()
        {
            NameValueCollection objCol;
            System.Configuration.ConfigXmlDocument objDoc = new System.Configuration.ConfigXmlDocument();

            try
            {
                if (System.IO.File.Exists(General.Environment.Current.GetBinDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetBinDirectory() + "General.config");
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, objDoc.SelectSingleNode("General.Configuration/GlobalSettings"));
                }
                else if (System.IO.File.Exists(General.Environment.Current.GetAppDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetAppDirectory() + "General.config");
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, objDoc.SelectSingleNode("General.Configuration/GlobalSettings"));
                }
                else
                {
                    objCol = null;
                    //throw new System.IO.FileNotFoundException("General.config could not be loaded");
                }
            }
            catch
            {
                objCol = null;
            }
            return objCol;
        }
Пример #17
0
        /// <summary>
        ///     Called from OnApplicationStart to initialize settings from
        ///     the Web.Config file(s). 
        ///     <remarks>
        ///         The app domain will restart if settings change, so there is 
        ///         no reason to read these values more than once. This funtion
        ///         uses the NameValueSectionHandler base class to generate a 
        ///         hashtablefrom the XML, which is then used to store the current
        ///         settings.  Because all settings are read here, we do not actually 
        ///         store the generated hashtable object for later retrieval by
        ///         Context.GetConfig. The application should use the accessor
        ///         functions directly.
        ///     </remarks>
        ///     <param name="parent">An object created by processing a section 
        ///         with this name in a Config.Web file in a parent directory.
        ///     </param>
        ///     <param name="configContext">The config's context.</param>
        ///     <param name="section">The section to be read.</param>
        ///     <retvalue>
        ///		    <para>
        ///             A ConfigOutput object: which we leave empty because all settings
        ///             are stored at this point.
        ///		    </para>
        ///		    <para>
        ///             null:  if there was an error.
        ///		    </para>
        ///	    </retvalue>
        /// </summary>
        public Object Create(Object parent, object configContext, XmlNode section)
        {
            NameValueCollection settings;

            try
            {
            NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection)baseHandler.Create(parent, configContext, section);
            }
            catch
            {
                settings = null;
            }

            if (settings == null)
            {
                tracingEnabled = TRACING_ENABLED_DEFAULT;
                tracingTraceFile = TRACING_TRACEFILE_DEFAULT;
                tracingTraceLevel = TRACING_TRACELEVEL_DEFAULT;
                tracingSwitchName = TRACING_SWITCHNAME_DEFAULT;
                tracingSwitchDescription = TRACING_SWITCHDESCRIPTION_DEFAULT;
                eventLogEnabled = EVENTLOG_ENABLED_DEFAULT;
                eventLogMachineName = EVENTLOG_MACHINENAME_DEFAULT;
                eventLogSourceName = EVENTLOG_SOURCENAME_DEFAULT;
                eventLogTraceLevel = EVENTLOG_TRACELEVEL_DEFAULT;
            }
            else
            {
                tracingEnabled = ReadSetting(settings, TRACING_ENABLED, TRACING_ENABLED_DEFAULT);
                tracingTraceFile = ReadSetting(settings, TRACING_TRACEFILE, TRACING_TRACEFILE_DEFAULT);
                tracingTraceLevel = ReadSetting(settings, TRACING_TRACELEVEL, TRACING_TRACELEVEL_DEFAULT);
                tracingSwitchName = ReadSetting(settings, TRACING_SWITCHNAME, TRACING_SWITCHNAME_DEFAULT);
                tracingSwitchDescription = ReadSetting(settings, TRACING_SWITCHDESCRIPTION, TRACING_SWITCHDESCRIPTION_DEFAULT);
                eventLogEnabled = ReadSetting(settings, EVENTLOG_ENABLED, EVENTLOG_ENABLED_DEFAULT);
                eventLogMachineName = ReadSetting(settings, EVENTLOG_MACHINENAME, EVENTLOG_MACHINENAME_DEFAULT);
                eventLogSourceName = ReadSetting(settings, EVENTLOG_SOURCENAME, EVENTLOG_SOURCENAME_DEFAULT);
                eventLogTraceLevel = ReadSetting(settings, EVENTLOG_TRACELEVEL, EVENTLOG_TRACELEVEL_DEFAULT);
            }

            return null;
        }
Пример #18
0
        private static NameValueCollection LoadHostSettings(string host)
        {
            NameValueCollection objCol;
            System.Configuration.ConfigXmlDocument objDoc = new System.Configuration.ConfigXmlDocument();

            try
            {
                if (System.IO.File.Exists(General.Environment.Current.GetBinDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetBinDirectory() + "General.config");
                    XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + host + "']");
                    if (node == null)
                        return new NameValueCollection();
                    node.Attributes.RemoveAll();
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, node);
                }
                else if (System.IO.File.Exists(General.Environment.Current.GetAppDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetAppDirectory() + "General.config");
                    XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + host + "']");
                    if (node == null)
                        return new NameValueCollection();
                    node.Attributes.RemoveAll();
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, node);
                }
                else
                {
                    objCol = (NameValueCollection)null;
                }
            }
            catch
            {
                objCol = (NameValueCollection)null;
            }
            return objCol;

            /*
             This is the old code that throws exceptions all the time
            try
            {
                objDoc.Load(General.Environment.Current.GetBinDirectory() + "General.config");
                XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + GetCurrentHost() + "']");
                if (node == null)
                    return null;
                node.Attributes.RemoveAll();
                System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                objCol = (NameValueCollection)nvsh.Create(null, null, node);
            }
            catch
            {
                try
                {
                    objDoc.Load(General.Environment.Current.GetAppDirectory() + "General.config");
                    XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + GetCurrentHost() + "']");
                    if (node == null)
                        return null;
                    node.Attributes.RemoveAll();
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, node);
                }
                catch
                {
                    objCol = (NameValueCollection)null;
                }
            }
            return objCol;
            */
        }
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <param name="parent">Parent object.</param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section">Section XML node.</param>
        /// <returns>The created section handler object.</returns>
        public Object Create(Object parent, object configContext, XmlNode section)
        {
            NameValueCollection settings;
            try
            {
                NameValueSectionHandler baseHandler = new NameValueSectionHandler();
                settings = (NameValueCollection)baseHandler.Create(parent,
                    configContext, section);
            }
            catch
            {
                settings = null;
            }

            if (settings != null)
            {
                // Read Application settings from configuration file.
                friendConnectLibVersion = ReadSetting(settings, FRIENDCONNECT_LIB_VERSION, "");
                friendConnectSiteId = ReadSetting(settings, FRIENDCONNECT_SITE_ID, "");
                friendConnectCookie = ReadSetting(settings, FRIENDCONNECT_COOKIE, "");
                mysqlConnectionString = ReadSetting(settings, MYSQL_CONNECTION_STRING, "");
                yahooSearchKey = ReadSetting(settings, YAHOO_SEARCH_KEY, "");
                yahooSearchUrl = ReadSetting(settings, YAHOO_SEARCH_URL, "");
                googleMapsKey = ReadSetting(settings, GOOGLE_MAPS_KEY, "");
                friendConnectOAuthKey = ReadSetting(settings, FRIENDCONNECT_OAUTH_KEY, "");
                friendConnectOAuthSecret = ReadSetting(settings, FRIENDCONNECT_OAUTH_SECRET, "");
                friendConnectApiUrl = ReadSetting(settings, FRIENDCONNECT_API_URL, "");
                googleMapsApiUrl = ReadSetting(settings, GOOGLEMAPS_API_URL, "");
            }
            return null;
        }
Пример #20
0
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     var settings = new NameValueSectionHandler();
     return settings.Create(parent, configContext, section) as NameValueCollection ?? new NameValueCollection();
 }
Пример #21
0
        private static NameValueCollection LoadHostSettings(string host)
        {
            NameValueCollection objCol;

            System.Configuration.ConfigXmlDocument objDoc = new System.Configuration.ConfigXmlDocument();

            try
            {
                if (System.IO.File.Exists(General.Environment.Current.GetBinDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetBinDirectory() + "General.config");
                    XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + host + "']");
                    if (node == null)
                    {
                        return(new NameValueCollection());
                    }
                    node.Attributes.RemoveAll();
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, node);
                }
                else if (System.IO.File.Exists(General.Environment.Current.GetAppDirectory() + "General.config"))
                {
                    objDoc.Load(General.Environment.Current.GetAppDirectory() + "General.config");
                    XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + host + "']");
                    if (node == null)
                    {
                        return(new NameValueCollection());
                    }
                    node.Attributes.RemoveAll();
                    System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
                    objCol = (NameValueCollection)nvsh.Create(null, null, node);
                }
                else
                {
                    objCol = (NameValueCollection)null;
                }
            }
            catch
            {
                objCol = (NameValueCollection)null;
            }
            return(objCol);

            /*
             * This is the old code that throws exceptions all the time
             * try
             * {
             *  objDoc.Load(General.Environment.Current.GetBinDirectory() + "General.config");
             *  XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + GetCurrentHost() + "']");
             *  if (node == null)
             *      return null;
             *  node.Attributes.RemoveAll();
             *  System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
             *  objCol = (NameValueCollection)nvsh.Create(null, null, node);
             * }
             * catch
             * {
             *  try
             *  {
             *      objDoc.Load(General.Environment.Current.GetAppDirectory() + "General.config");
             *      XmlNode node = objDoc.SelectSingleNode("//HostSettings" + "[@host='" + GetCurrentHost() + "']");
             *      if (node == null)
             *          return null;
             *      node.Attributes.RemoveAll();
             *      System.Configuration.NameValueSectionHandler nvsh = new System.Configuration.NameValueSectionHandler();
             *      objCol = (NameValueCollection)nvsh.Create(null, null, node);
             *  }
             *  catch
             *  {
             *      objCol = (NameValueCollection)null;
             *  }
             * }
             * return objCol;
             */
        }