Esempio n. 1
0
        private static IDictionary <string, string> GetAppSettings(string cfgFilePath)
        {
            Dictionary <string, string> AppSettings = new Dictionary <string, string>();
            const string appConfigNodeName          = "appSettings";

            try
            {
                //string to hold the name of the
                //config file for the assembly
                //create a new XML Document
                XmlDocument doc = new XmlDocument();
                //load an XML document by using the
                //XMLTextReader class of the XML Namespace
                //Now open the cfgFile
                doc.Load(new XmlTextReader(cfgFilePath));
                //retrieve a list of nodes in the document
                XmlNode configNode = doc.SelectSingleNode(string.Format("//{0}", appConfigNodeName));
                if (configNode != null)
                {
                    DictionarySectionHandler handler = new DictionarySectionHandler();
                    //return the new handler
                    IDictionary configSection = (IDictionary)handler.Create(null, null, configNode);
                    foreach (string key in configSection.Keys)
                    {
                        AppSettings.Add(key, (string)configSection[key]);
                    }
                }
            }
            catch (Exception e)
            {
                LOGGER.Warn(e);
            }
            return(AppSettings);
        }
Esempio n. 2
0
        public static IDictionary GetConfig(string cfgFile, string nodeName)
        {
            // Open and parse configuration file for specified
            // assembly, returning collection to caller for future
            // use outside of this class.
            //
            try
            {
                //string cfgFile = asm.CodeBase + ".config";
                //const string nodeName = "appSettings";//"assemblySettings";

                XmlDocument doc = new XmlDocument();
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        return((IDictionary)handler.Create(null, null, node));
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Open and parse configuration file for specified assembly,
        /// returning collection to caller for future use outside of this class.
        /// </summary>
        /// <param name="asm"></param>
        /// <returns></returns>
        public static IDictionary GetConfig(Assembly asm)
        {
            try
            {
                string       cfgFile  = asm.CodeBase + ".config";
                const string nodeName = "assemblysettings";

                XmlDocument doc = new XmlDocument();
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        return((IDictionary)handler.Create(null, null, node));
                    }
                }
            }
            catch
            { }

            return(null);
        }
Esempio n. 4
0
        public IDictionary GetConfig(string NameValue)
        {
            XmlNodeList Section = XmlConfiguration.GetElementsByTagName(NameValue);

            foreach (XmlNode Node in Section)
            {
                if (Node.LocalName == NameValue)
                {
                    DictionarySectionHandler NodeHandler = new DictionarySectionHandler();
                    return((IDictionary)NodeHandler.Create(null, null, Node));
                }
            }

            return(null);
        }
        public static IDictionary GetConfig(Assembly asm)
        {
            // Open and parse configuration file for specified
            // assembly, returning collection to caller for future
            // use outside of this class.
            string cfgFile = asm.CodeBase + ".config";

            try
            {
                const string nodeName = "assemblySettings";

                XmlDocument doc = new XmlDocument();
                //if (File.Exists(cfgFile))
                //{
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        return((IDictionary)handler.Create(null, null, node));
                    }
                }
                // }
                // else
                // {
                //     _log.Warn("Assembly configuration file not found: " + cfgFile);
                // }
            }
            catch (FileNotFoundException)
            {
                _log.Warn("Assembly configuration file not found: " + cfgFile);
            }
            catch (Exception e)
            {
                _log.Warn("Failed to load .config file: " + cfgFile, e);
            }

            return(null);
        }
Esempio n. 6
0
        public static void Main()
        {
            try
            {
                const string appConfigNodeName      = "appSettings";
                Dictionary <string, string> dicData = new Dictionary <string, string>();

                //string to hold the name of the
                //config file for the assembly
                string cfgFile = "D:\\Working\\kblaa\\3.SourceCode\\OCRCore\\OCRCore\\App.config";
                //create a new XML Document
                XmlDocument doc = new XmlDocument();
                //load an XML document by using the
                //XMLTextReader class of the XML Namespace
                //Now open the cfgFile
                doc.Load(new XmlTextReader(cfgFile));
                //retrieve a list of nodes in the document
                XmlNode configNode = doc.SelectSingleNode(string.Format("//{0}", appConfigNodeName));
                if (configNode != null)
                {
                    DictionarySectionHandler handler = new DictionarySectionHandler();
                    //return the new handler
                    IDictionary configSection = (IDictionary)handler.Create(null, null, configNode);
                    foreach (string key in configSection.Keys)
                    {
                        dicData.Add(key, (string)configSection[key]);
                    }
                }

                Console.WriteLine("TEST=" + dicData.Keys);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            //System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap("E:\\Working\\Java\\acomsolutions\\solution-net\\CustomAcom\\CustomAcom.Stamford\\Web.config"); //Path to your config file
            //System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
            //ConfigurationSection section = configuration.GetSection("ConnectionStrings");

            //Console.WriteLine("TEST=" + configuration.ConnectionStrings.ConnectionStrings["DefaultConnection"].ConnectionString);
        }
Esempio n. 7
0
        //------------------------------------------ private
        static IDictionary getConfig(string pConfigFile, string pSection)
        {
            try {
                var _cfgFile = new XmlDocument();
                var _reader  = new XmlTextReader(pConfigFile);
                _cfgFile.Load(_reader);
                _reader.Close();

                var _nodes = _cfgFile.GetElementsByTagName(pSection);
                foreach (XmlNode _node in _nodes)
                {
                    if (_node.LocalName == pSection)
                    {
                        var _handler = new DictionarySectionHandler();
                        return((IDictionary)_handler.Create(null, null, _node));
                    }
                }
            }
            catch { }
            return(null);
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="asm"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public static IDictionary GetConfig(Assembly asm, string section)
        {
            // Open and parse configuration file for specified
            // assembly, returning collection to caller for future
            // use outside of this class.
            //
            try
            {
                if (settings != null && settings.Count > 0)
                {
                    return(settings);
                }

                string cfgFile  = asm.CodeBase + ".config";
                string nodeName = section;

                XmlDocument doc = new XmlDocument();
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        settings = (IDictionary)handler.Create(null, null, node);
                    }
                }
                return(settings);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 9
0
    public static IDictionary GetConfig(Assembly asm)
    {
        // Open and parse configuration file for specified
        // assembly, returning collection to caller for future
        // use outside of this class.
        //
        try
        {
            string cfgUncPath = asm.CodeBase + ".config";
            string cfgFile    = new Uri(cfgUncPath).LocalPath; // convert file:// with more forward slashes into a proper path

            const string nodeName = "assemblySettings";

            XmlDocument doc = new XmlDocument();
            if (System.IO.File.Exists(cfgFile))
            {
                doc.Load(new XmlTextReader(cfgFile));

                XmlNodeList nodes = doc.GetElementsByTagName(nodeName);

                foreach (XmlNode node in nodes)
                {
                    if (node.LocalName == nodeName)
                    {
                        DictionarySectionHandler handler = new DictionarySectionHandler();
                        return((IDictionary)handler.Create(null, null, node));
                    }
                }
            }
        }
        catch
        {
        }

        return(null);
    }
Esempio n. 10
0
    public IDictionary GetConfig(string NameValue)
    {
        XmlNodeList Section = XmlConfiguration.GetElementsByTagName(NameValue);
        foreach (XmlNode Node in Section)
        {
            if (Node.LocalName == NameValue)
            {
                DictionarySectionHandler NodeHandler = new DictionarySectionHandler();
                return (IDictionary)NodeHandler.Create(null, null, Node);
            }
        }

        return null;
    }
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            if (section.Attributes != null && section.Attributes.Count != 0)
            {
                ThrowException("Unrecognized attribute", section);
            }

            ArrayList providers = new ArrayList();

            XmlNodeList providerElements = section.SelectNodes("provider");

            foreach (XmlNode child in providerElements)
            {
                XmlNodeType ntype = child.NodeType;
                if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
                {
                    continue;
                }

                if (ntype != XmlNodeType.Element)
                {
                    ThrowException("Only elements allowed", child);
                }

                object       parentProvider = null;
                XmlAttribute extends        = child.Attributes["parent"];
                if (extends != null)
                {
                    string super       = extends.Value;
                    string sectionName = super.Substring(0, super.IndexOf('#'));
                    string id          = super.Substring(sectionName.Length + 1);
                    IList  supers      = (IList)ConfigurationSettings.GetConfig(sectionName);
                    for (int i = 0; i < supers.Count; i++)
                    {
                        Hashtable ht    = (Hashtable)supers[i];
                        string    curId = (string)ht["id"];
                        if (String.CompareOrdinal(id, curId) == 0)
                        {
                            parentProvider = ht;
                            break;
                        }
                    }
                    child.Attributes.Remove(extends);
                }

                DictionarySectionHandler handler = new DictionarySectionHandler();
                Hashtable col = (Hashtable)handler.Create(parentProvider, null, child);
                providers.Add(col);
            }
            if (parent != null && parent is IList)
            {
                IList parentList = (IList)parent;
                for (int i = 0; i < parentList.Count; i++)
                {
                    Hashtable htParent  = (Hashtable)parentList[i];
                    string    parentId  = (string)htParent["id"];
                    bool      overriden = false;
                    for (int y = 0; y < providers.Count; y++)
                    {
                        Hashtable htMe = (Hashtable)providers[y];
                        string    myId = (string)htMe["id"];
                        if (String.CompareOrdinal(parentId, myId) == 0)
                        {
                            overriden = true;
                            foreach (object key in htParent.Keys)
                            {
                                if (!htMe.ContainsKey(key))
                                {
                                    htMe[key] = htParent[key];
                                }
                            }
                            break;
                        }
                    }

                    if (!overriden)
                    {
                        providers.Add(htParent);
                    }
                }
            }

            return(providers);
        }