Esempio n. 1
0
        /// <summary>
        /// Handles the file.
        /// </summary>
        /// <param name="fileToHandle"></param>
        public void HandleFile(string fileToHandle)
        {
            //Check to make sure the files are correct and exist
            if (!fileToHandle.EndsWith(".def"))
            {
                throw new XmlDefinitionParsingException("Invalid file format", fileToHandle);
            }
            if (!File.Exists(fileToHandle))
            {
                throw new FileNotFoundException("def file not found", fileToHandle);
            }

            //Load the xml document
            XmlDocument doc = new XmlDocument();

            doc.Load(fileToHandle);

            //Go through each section and call the registered handler
            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                string sectionName = node.Name;
                //Make sure this section has a handler installed, if not, log and ignore
                if (!_sectionHandlers.ContainsKey(sectionName))
                {
                    Logging.Logger.Log("Unknown Node[" + sectionName + "] in file: " + fileToHandle, BASE.Logging.LogPriority.Debug);
                    continue;
                }

                //Section has a registered handler, so Handle it
                ISectionHandler sectionHandler = _sectionHandlers[sectionName];
                sectionHandler.HandleSection(node, fileToHandle);
            }
        }