public void NodeReaderMoveToNextAttributeWithAttributeXml()
        {
            string        xml        = "<root attr='cal' attr2='val'></root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read());
            Assert.True(nodeReader.MoveToNextAttribute());

            nodeReader.ReadContentAsBase64(new byte[33], 10, 10);
            Assert.True(nodeReader.MoveToNextAttribute());
        }
        public void NodeReaderMoveToNextAttributeWithEmptyXml()
        {
            var xmlDoc     = new XmlDocument();
            var nodeReader = new XmlNodeReader(xmlDoc);

            Assert.False(nodeReader.MoveToNextAttribute());
        }
        public void NodeReaderMoveToNextAttributeWithSimpleXml()
        {
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader("<root></root>");

            Assert.True(nodeReader.Read());
            Assert.False(nodeReader.MoveToNextAttribute());
        }
Exemplo n.º 4
0
        [Test]         // bug #550379
        public void MoveToNextAttributeFromValue()
        {
            document.LoadXml("<ul test='xxx'></ul>");
            XmlNodeReader nr = new XmlNodeReader(document);

            nr.Read();
            nr.Read();
            Assert.IsTrue(nr.MoveToFirstAttribute(), "#1");
            Assert.IsTrue(nr.ReadAttributeValue(), "#2");
            Assert.IsFalse(nr.MoveToNextAttribute(), "#3");
        }
Exemplo n.º 5
0
        public override bool MoveToNextAttribute()
        {
            if (IsXmlDataNode)
            {
                return(_xmlNodeReader.MoveToNextAttribute());
            }

            if (_attributeIndex + 1 >= _attributeCount)
            {
                return(false);
            }
            MoveToAttribute(_attributeIndex + 1);
            return(true);
        }
Exemplo n.º 6
0
        internal override void InnerLoad(XmlNodeReader reader, string endpoint)
        {
            if (reader == null)
            {
                return;
            }
            bool emptyNode = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                string attributeName  = reader.Name;
                string attributeValue = reader.Value;
                SetValueEx(attributeName, attributeValue);
            }

            if (emptyNode)
            {
                return;
            }

            reader.Read();
            while (!reader.EOF)
            {
                if (reader.Name == endpoint)
                {
                    break;
                }
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                    continue;
                }

                string strEleName = reader.Name.Trim();
                if (strEleName.Length == 0)
                {
                    reader.Read();
                    continue;
                }

                bool hasAlreadyMoveToNext = false;
                SetValue(strEleName, reader, ref hasAlreadyMoveToNext);

                if (!hasAlreadyMoveToNext)
                {
                    reader.Read();
                }
            }
        }
Exemplo n.º 7
0
        private List <string> GetPageLinks(XmlDocument doc)
        {
            List <string> links  = new List <string>();
            XmlReader     reader = new XmlNodeReader(doc);

            // Look for <loc> and <a> tags
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name.ToLower() == "loc")
                    {
                        if (reader.Read() && IsLinkAllowed(reader.Value))
                        {
                            links.Add(reader.Value.ToLower().Trim());
                        }
                    }
                    else if (reader.Name.ToLower() == "a")
                    {
                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                if (reader.Name.ToLower() == "href")
                                {
                                    string URL = reader.Value.ToLower();
                                    if (URL[0] == '/')
                                    {
                                        // Append relative path to domain
                                        URL = crawlURL + URL.Substring(1, URL.Length - 1);
                                    }

                                    if (IsLinkAllowed(URL))
                                    {
                                        links.Add(URL);
                                    }
                                }
                                break;
                            }
                            reader.MoveToElement();
                        }
                    }
                }
            }

            return(links);
        }
Exemplo n.º 8
0
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book genre='novel' ISBN='1-861003-78'> " +
                        "<title>Pride And Prejudice</title>" +
                        "<price>19.95</price>" +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            //Read the attributes on the book element.
            reader.MoveToContent();
            while (reader.MoveToNextAttribute())
            {
                Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
            }

            //Move the reader to the title element.
            reader.Read();

            //Read the title and price elements.
            Console.WriteLine(reader.ReadElementString());
            Console.WriteLine(reader.ReadElementString());
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
Exemplo n.º 9
0
        public ConfigurationManager(String xmlConfigFileName)
        {
            configFullFileName = xmlConfigFileName;

            // Open the configuration document
            XmlDocument xmlConfigStruct = new XmlDocument();

            xmlConfigStruct.Load(xmlConfigFileName);

            // Get reader reference
            XmlNodeReader reader = new XmlNodeReader(xmlConfigStruct);

            // Initialize error supress array. Default is error enabled
            errSupressArr = new int[Enum.GetValues(typeof(ErrorCode)).Length];
            for (int i = 0; i < errSupressArr.Length; i++)
            {
                errSupressArr[i] = Logger.NOT_SUPRESS_ERR_CODE;
            }

            // Parse the xml file
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "ConfigurationParameter" || reader.Name == "Configuration")
                    {
                        if (reader.HasAttributes)
                        {
                            // Read attibutes using linked list of attributes
                            while (reader.MoveToNextAttribute())
                            {
                                switch (reader.Name)
                                {
                                case "LogFile":
                                    logFile           = new StreamWriter(File.Open(reader.Value, FileMode.OpenOrCreate, FileAccess.Write), Encoding.Unicode);
                                    logFile.AutoFlush = true;
                                    break;

                                case "RootTrainDirectory":
                                    rootTrainDirectory = reader.Value;
                                    break;

                                case "RootTestDirectory":
                                    rootTestDirectory = reader.Value;
                                    break;

                                case "ConfigurationEnvironmentDirectory":
                                    configEnvDirectory = reader.Value;
                                    break;

                                case "MrfFolderName":
                                    mrfFolderName = reader.Value;
                                    break;

                                case "PosFolderName":
                                    posFolderName = reader.Value;
                                    break;

                                case "DirectorySeparator":
                                    directorySeparator = reader.Value;
                                    break;

                                case "FileExensionSeparator":
                                    fileExtensionSeparator = reader.Value;
                                    break;

                                case "MrfFileExtension":
                                    mrfFileExtension = reader.Value;
                                    break;

                                case "POSFileExtension":
                                    posFileExtension = reader.Value;
                                    break;

                                case "DebugMode":
                                    debugMode = bool.Parse(reader.Value);
                                    break;

                                case "ErrorLogMode":
                                    errorLogMode = bool.Parse(reader.Value);
                                    break;

                                case "ConsoleLogMode":
                                    consoleLogMode = bool.Parse(reader.Value);
                                    break;

                                case "SuppressErrType":
                                    try
                                    {
                                        errSupressArr[Int32.Parse(reader.Value) - 1] = Logger.SUPRESS_ERR_CODE;
                                    }
                                    catch (IndexOutOfRangeException e)
                                    {
                                        Console.WriteLine("Incorrect configuration parameter. Error type code is out of range. Please provide code less than " + Enum.GetValues(typeof(ErrorCode)).Length);
                                        throw (e);
                                    }

                                    break;

                                case "FeaturesFormat":
                                    featuresFormat = reader.Value;
                                    break;

                                case "MatlabFunctionName":
                                    matlabOutFileName = "DCONV_convertMatlabInput_" + featuresFormat + ".m";
                                    break;

                                case "MatlabFilePath":
                                    matlabOutFilePath = reader.Value;
                                    break;

                                case "OutputFeatures":
                                    outputFeatures = reader.Value;
                                    break;



                                case "OutputFile":
                                    // Either Encoding.Default of leave empty otherwise MATLAB will not understand the lines: extrac characters are added
                                    outputFile = new StreamWriter(File.Open(reader.Value + "_" + featuresFormat + ".txt", FileMode.OpenOrCreate, FileAccess.Write), Encoding.Default);
                                    break;

                                case "OutputFileFormat":
                                    outputFileFormat = reader.Value;
                                    break;

                                case "ContextType":    // Type 1 (considering before and after fixed num. of words) or Type 2 (considering context length with no constraint on before and after)
                                    contextType = reader.Value;
                                    break;

                                case "ContextBeforeLength":    // Type 1
                                    contextBeforeLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextAfterLength":     // Type 1
                                    contextAfterLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextLength":     // Type 2
                                    contextLength = Int32.Parse(reader.Value);
                                    break;

                                case "LastCharFeaturesDepth":
                                    lastCharFeaturesDepth = Int32.Parse(reader.Value);
                                    break;

                                default:
                                    Console.WriteLine("Incorrect configuration parameter." + reader.Value + " is invalid value for Configuration Parameter" + reader.Name);
                                    break;
                                } // end switch (reader.Name)
                            }     // end while (reader.MoveToNextAttribute())
                        }         // end if (reader.HasAttributes)

                        // Get back to root element
                        reader.MoveToElement();
                    }// end if (reader.NodeType == XmlNodeType.Element)
                    else
                    {
                        Console.WriteLine("Incorrect configuration parameter. Expected: ConfigurationParameter, Found: " + reader.Name);
                    }
                }
            }// end of while (reader.Read())
        }
Exemplo n.º 10
0
        internal override void InnerLoad(XmlNodeReader reader, string endpoint)
        {
            this.Clear();
            if (reader == null)
            {
                return;
            }
            bool emptyNode = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                string attributeName  = reader.Name;
                string attributeValue = reader.Value;
                SetValueEx(attributeName, attributeValue);
            }

            if (emptyNode)
            {
                return;
            }

            reader.Read();
            while (!reader.EOF)
            {
                string strEleName = reader.Name.Trim();
                if (strEleName.Length == 0)
                {
                    reader.Read();
                    continue;
                }
                if (strEleName == endpoint)
                {
                    break;
                }

                bool hasAlreadyMoveToNext = false;

                object item  = null;
                string tname = _ChildItemType.ToString();
                if (strEleName == XMLChildNodeName)
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        item = _ChildItemType.Assembly.CreateInstance(tname);

                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, item, new object[] { reader, strEleName });

                        this.Add(item as XBase);
                    }
                    else
                    {
                        item = null;
                    }

                    // assume that InnerLoad should not exceed the border of element
                }
                else
                {
                    SetValue(strEleName, reader, ref hasAlreadyMoveToNext);
                }

                if (!hasAlreadyMoveToNext)
                {
                    reader.Read();
                }
            }
        }
Exemplo n.º 11
0
        private abstract_Element process_element(XmlNodeReader nodeReader, int current_page_count)
        {
            string type    = String.Empty;
            string subtype = String.Empty;

            // Step through all the attributes until the type is found
            nodeReader.MoveToFirstAttribute();
            do
            {
                // Get the type attribute
                if (nodeReader.Name.ToUpper().Trim() == "TYPE")
                {
                    type = nodeReader.Value;
                }

                // Get the subtype attribute
                if (nodeReader.Name.ToUpper().Trim() == "SUBTYPE")
                {
                    subtype = nodeReader.Value;
                }
            } while (nodeReader.MoveToNextAttribute());

            // Make sure a type was specified
            if (type == String.Empty)
            {
                return(null);
            }

            // Build the element
            abstract_Element newElement = Element_Factory.getElement(type, subtype);

            // If thie element was null, return null
            if (newElement == null)
            {
                return(null);
            }

            // Set the page number for post back reasons
            newElement.Template_Page = current_page_count;

            // Some special logic here
            if ((newElement.Type == Element_Type.Type) && (newElement.Display_SubType == "form"))
            {
                (( Type_Format_Form_Element )newElement).Set_Postback("javascript:__doPostBack('newpagebutton" + current_page_count + "','')");
            }


            if ((newElement.Type == Element_Type.Title) && (newElement.Display_SubType == "form"))
            {
                complexMainTitleExists = true;
            }

            if ((newElement.Type == Element_Type.Note) && (newElement.Display_SubType == "complex"))
            {
                ((Note_Complex_Element)newElement).Include_Statement_Responsibility = !complexMainTitleExists;
            }

            // Now, step through all the attributes again
            nodeReader.MoveToFirstAttribute();
            do
            {
                switch (nodeReader.Name.ToUpper().Trim())
                {
                case "REPEATABLE":
                    bool repeatable;
                    if (Boolean.TryParse(nodeReader.Value, out repeatable))
                    {
                        newElement.Repeatable = repeatable;
                    }
                    break;

                case "MANDATORY":
                    bool mandatory;
                    if (Boolean.TryParse(nodeReader.Value, out mandatory))
                    {
                        newElement.Mandatory = mandatory;
                    }
                    break;

                case "READONLY":
                    bool isReadOnly;
                    if (Boolean.TryParse(nodeReader.Value, out isReadOnly))
                    {
                        newElement.Read_Only = isReadOnly;
                    }
                    break;

                case "ACRONYM":
                    newElement.Acronym = nodeReader.Value;
                    break;
                }
            } while (nodeReader.MoveToNextAttribute());

            // Move back to the element, if there were attributes (should be)
            nodeReader.MoveToElement();

            // Is there element_data?
            if (!nodeReader.IsEmptyElement)
            {
                nodeReader.Read();
                if ((nodeReader.NodeType == XmlNodeType.Element) && (nodeReader.Name.ToLower() == "element_data"))
                {
                    // Create the new tree
                    StringWriter  sw = new StringWriter();
                    XmlTextWriter tw = new XmlTextWriter(sw);
                    tw.WriteNode(nodeReader, true);
                    tw.Close();

                    // Let the element process this inner data
                    newElement.Read_XML(new XmlTextReader(new StringReader(sw.ToString())));
                }
            }

            // Return this built element
            return(newElement);
        }
Exemplo n.º 12
0
        private abstract_Element process_element(XmlNodeReader nodeReader, int current_page_count)
        {
            string type    = String.Empty;
            string subtype = String.Empty;

            // Step through all the attributes until the type is found
            nodeReader.MoveToFirstAttribute();
            do
            {
                // Get the type attribute
                if (nodeReader.Name.ToUpper().Trim() == "TYPE")
                {
                    type = nodeReader.Value;
                }

                // Get the subtype attribute
                if (nodeReader.Name.ToUpper().Trim() == "SUBTYPE")
                {
                    subtype = nodeReader.Value;
                }
            } while (nodeReader.MoveToNextAttribute());

            // Make sure a type was specified
            if (type == String.Empty)
            {
                return(null);
            }

            // Build the element
            abstract_Element newElement = Element_Factory.getElement(type, subtype);

            // If thie element was null, return null
            if (newElement == null)
            {
                return(null);
            }

            // Set the page number for post back reasons
            newElement.Template_Page = current_page_count;

            // Now, step through all the attributes again
            nodeReader.MoveToFirstAttribute();
            do
            {
                switch (nodeReader.Name.ToUpper().Trim())
                {
                case "REPEATABLE":
                    bool repeatable;
                    if (Boolean.TryParse(nodeReader.Value, out repeatable))
                    {
                        newElement.Repeatable = repeatable;
                    }
                    break;

                case "MANDATORY":
                    bool mandatory;
                    if (Boolean.TryParse(nodeReader.Value, out mandatory))
                    {
                        newElement.Mandatory = mandatory;
                    }
                    break;

                case "READONLY":
                    bool isReadOnly;
                    if (Boolean.TryParse(nodeReader.Value, out isReadOnly))
                    {
                        newElement.Read_Only = isReadOnly;
                    }
                    break;

                case "ACRONYM":
                    newElement.Acronym = nodeReader.Value;
                    break;
                }
            } while (nodeReader.MoveToNextAttribute());

            // Move back to the element, if there were attributes (should be)
            nodeReader.MoveToElement();

            // Is there element_data?
            if (!nodeReader.IsEmptyElement)
            {
                nodeReader.Read();
                if ((nodeReader.NodeType == XmlNodeType.Element) && (nodeReader.Name.ToLower() == "element_data"))
                {
                    // Let the element process this inner data
                    newElement.Read_XML(nodeReader.ReadSubtree());
                }
            }

            // Return this built element
            return(newElement);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Writes the XML.
        /// </summary>
        /// <param name="xmlDocument">The XML document.</param>
        private void WriteXml(XmlDocument xmlDocument)
        {
            XmlNodeReader reader = null;

            try
            {
                //Create an XmlNodeReader to read the XmlDocument.
                reader = new XmlNodeReader(xmlDocument);

                //Parse the file and display each of the nodes.
                while (reader.Read())
                {
                    UpdateLevel(reader.Depth);
                    //Write("{0}", reader.Depth.ToString("00"));
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (_currentNodeName != string.Empty)
                        {
                            WriteLine();
                        }
                        _currentNodeName = reader.Name;
                        Write("<{0}", reader.Name);
                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                Write(" {0}=\"{1}\"", reader.Name, reader.Value);
                            }
                            Write(" ");
                            // Move the reader back to the element node.
                            reader.MoveToElement();
                        }
                        Write(reader.IsEmptyElement ? "/>" : ">");
                        if (reader.IsEmptyElement)
                        {
                            _currentNodeName = string.Empty;
                            WriteLine();
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (_currentNodeName == reader.Name)
                        {
                            _currentNodeName = string.Empty;
                        }
                        WriteLine("</{0}>", reader.Name);
                        break;

                    case XmlNodeType.Text:
                        Write(reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        Write(reader.Value);
                        break;

                    case XmlNodeType.ProcessingInstruction:
                    case XmlNodeType.XmlDeclaration:
                        WriteLine("<?{0} {1}?>", reader.Name, reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        WriteLine("<!--{0}-->", reader.Value);
                        break;

                    case XmlNodeType.Document:
                        break;

                    default:
                        WriteLine();
                        WriteLine("ERROR: Unexpected node type ({0}) encountered", reader.NodeType);
                        WriteLine();
                        break;
                    }
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
        private abstract_Element process_element(XmlNodeReader nodeReader)
        {
            string type    = String.Empty;
            string subtype = String.Empty;

            // Step through all the attributes until the type is found
            nodeReader.MoveToFirstAttribute();
            do
            {
                // Get the type attribute
                if (nodeReader.Name.ToUpper().Trim() == "TYPE")
                {
                    type = nodeReader.Value;
                }

                // Get the subtype attribute
                if (nodeReader.Name.ToUpper().Trim() == "SUBTYPE")
                {
                    subtype = nodeReader.Value;
                }
            } while (nodeReader.MoveToNextAttribute());

            // Make sure a type was specified
            if (type == String.Empty)
            {
                return(null);
            }

            // Build the element
            abstract_Element newElement = Element_Factory.getElement(type, subtype);

            // Some special code to make the creator element aware if there is a contributor element
            if ((newElement.Type == Element_Type.Creator) && (newElement.Display_SubType == "simple"))
            {
                creatorSimpleElement = (Creator_Simple_Element)newElement;
            }
            if ((newElement.Type == Element_Type.Contributor) && (creatorSimpleElement != null))
            {
                creatorSimpleElement.Contributor_Exists = true;
            }

            // Some special code to let the simple subject element know if there is a simple spatial element
            if ((newElement.Type == Element_Type.Subject) && ((newElement.Display_SubType == "simple") || (newElement.Display_SubType == "dublincore")))
            {
                if (spatialSimpleElement != null)
                {
                    ((Subject_Simple_Element)newElement).Seperate_Dublin_Core_Spatial_Exists = true;
                }
                else
                {
                    subjectSimpleElement = (Subject_Simple_Element)newElement;
                }
            }
            if ((newElement.Type == Element_Type.Spatial) && (newElement.Display_SubType == "dublincore"))
            {
                if (subjectSimpleElement != null)
                {
                    subjectSimpleElement.Seperate_Dublin_Core_Spatial_Exists = true;
                }
                else
                {
                    spatialSimpleElement = (Spatial_Simple_Element)newElement;
                }
            }

            // Now, step through all the attributes again
            nodeReader.MoveToFirstAttribute();
            do
            {
                try
                {
                    switch (nodeReader.Name.ToUpper().Trim())
                    {
                    case "X":
                        newElement.Location = new Point(Convert.ToInt16(nodeReader.Value), newElement.Location.Y);
                        break;

                    case "Y":
                        newElement.Location = new Point(newElement.Location.X, Convert.ToInt16(nodeReader.Value));
                        break;

                    case "HEIGHT":
                        newElement.Height = Convert.ToInt16(nodeReader.Value);
                        break;

                    case "WIDTH":
                        newElement.Width = Convert.ToInt16(nodeReader.Value);
                        break;

                    case "REPEATABLE":
                        newElement.Repeatable = Convert.ToBoolean(nodeReader.Value);
                        break;

                    case "MANDATORY":
                        newElement.Mandatory = Convert.ToBoolean(nodeReader.Value);
                        break;
                    }
                }
                catch { }
            } while (nodeReader.MoveToNextAttribute());

            // Move back to the element, if there were attributes (should be)
            nodeReader.MoveToElement();

            // Is there element_data?
            if (!nodeReader.IsEmptyElement)
            {
                nodeReader.Read();
                if ((nodeReader.NodeType == XmlNodeType.Element) && (nodeReader.Name.ToLower() == "element_data"))
                {
                    // Create the new tree
                    StringWriter  sw = new StringWriter();
                    XmlTextWriter tw = new XmlTextWriter(sw);
                    tw.WriteNode(nodeReader, true);
                    tw.Close();

                    // Let the element process this inner data
                    newElement.Read_XML(new XmlTextReader(new StringReader(sw.ToString())));
                }
            }

            // If this is the METS ObjectID, suppress it if the SobekCM add-on is enabled
            if ((newElement.Type == Element_Type.METS_ObjectID) && (addonsEnabled.Contains("SOBEKCM")))
            {
                return(null);
            }

            // Return this built element
            return(newElement);
        }
Exemplo n.º 15
0
        private void ExecuteSection(XmlNode section)
        {
            using (XmlNodeReader readerXML = new XmlNodeReader(section))
            {
                try
                {
                    Dictionary <String, String> actionParameters = new Dictionary <String, String>();
                    while (readerXML.Read())
                    {
                        actionParameters.Clear();
                        while (readerXML.MoveToNextAttribute())
                        {
                            actionParameters.Add(readerXML.Name, readerXML.Value);
                        }
                        readerXML.MoveToElement();
                        switch (readerXML.NodeType)
                        {
                        case XmlNodeType.Element:
                            switch (readerXML.Name)
                            {
                            case "True":
                                if (!_activeRuleSets.Peek().EngineState.ConditionalStack.Peek())
                                {
                                    readerXML.Skip();
                                }
                                break;

                            case "False":
                                if (_activeRuleSets.Peek().EngineState.ConditionalStack.Peek())
                                {
                                    readerXML.Skip();
                                }
                                break;

                            case "Optional":
                                if (MessageBox.Show(String.Format("Would you like to process {0} optional section?", actionParameters.ContainsKey("Name") ? actionParameters["Name"] : "the following"), "Optional Section Execution Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.No)
                                {
                                    readerXML.Skip();
                                }
                                break;

                            default:
                                ExecuteElementStartRule(readerXML.Name, actionParameters);
                                break;
                            }
                            break;

                        case XmlNodeType.EndElement:
                            switch (readerXML.Name)
                            {
                            case "True":
                            case "False":
                            case "Optional":
                                break;

                            default:
                                ExecuteElementEndRule(readerXML.Name);
                                break;
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemplo n.º 16
0
        public ConfigurationManager(String xmlConfigFileName)
        {
            configFullFileName = xmlConfigFileName;

            // Open the configuration document
            XmlDocument xmlConfigStruct = new XmlDocument();

            xmlConfigStruct.Load(xmlConfigFileName);


            // Get reader reference
            XmlNodeReader reader = new XmlNodeReader(xmlConfigStruct);

            // Initialize error supress array. Default is error enabled
            errSupressArr = new int[Enum.GetValues(typeof(ErrorCode)).Length];
            for (int i = 0; i < errSupressArr.Length; i++)
            {
                errSupressArr[i] = Logger.NOT_SUPRESS_ERR_CODE;
            }

            currPOSTagger = -1;
            // Parse the xml file
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "ConfigurationParameter" || reader.Name == "Configuration")
                    {
                        if (reader.HasAttributes)
                        {
                            // Read attibutes using linked list of attributes
                            while (reader.MoveToNextAttribute())
                            {
                                switch (reader.Name)
                                {
                                case "LogFile":
                                    try
                                    {
                                        logFile           = new StreamWriter(File.Open(configEnvDirectory + "\\" + reader.Value, FileMode.OpenOrCreate, FileAccess.Write), Encoding.Unicode);
                                        logFile.AutoFlush = true;
                                    }
                                    catch
                                    {
                                        break;
                                    }
                                    break;

                                case "RootTrainDirectory":
                                    rootTrainDirectory = reader.Value;
                                    break;

                                case "RootTestDirectory":
                                    rootTestDirectory = reader.Value;
                                    break;

                                case "ConfigurationEnvironmentDirectory":
                                    configEnvDirectory = reader.Value;
                                    try
                                    {
                                        File.Copy(configFullFileName, configEnvDirectory + "\\" + configFullFileName.Split("\\".ToCharArray()).Last(), true);
                                    }
                                    catch
                                    {
                                        break;
                                    }
                                    break;

                                case "MrfFolderName":
                                    mrfFolderName = reader.Value;
                                    break;

                                case "PosFolderName":
                                    posFolderName = reader.Value;
                                    break;

                                case "TxtFolderName":
                                    txtFolderName = reader.Value;
                                    break;

                                case "DirectorySeparator":
                                    directorySeparator = reader.Value;
                                    break;

                                case "FileExensionSeparator":
                                    fileExtensionSeparator = reader.Value;
                                    break;

                                case "MrfFileExtension":
                                    mrfFileExtension = reader.Value;
                                    break;

                                case "POSFileExtension":
                                    posFileExtension = reader.Value;
                                    break;

                                case "TxtFileExtension":
                                    txtFileExtension = reader.Value;
                                    break;

                                case "DebugMode":
                                    debugMode = bool.Parse(reader.Value);
                                    break;

                                case "ErrorLogMode":
                                    errorLogMode = bool.Parse(reader.Value);
                                    break;

                                case "ConsoleLogMode":
                                    consoleLogMode = bool.Parse(reader.Value);
                                    break;

                                case "SuppressErrType":
                                    try
                                    {
                                        errSupressArr[Int32.Parse(reader.Value) - 1] = Logger.SUPRESS_ERR_CODE;
                                    }
                                    catch (IndexOutOfRangeException e)
                                    {
                                        Console.WriteLine("Incorrect configuration parameter. Error type code is out of range. Please provide code less than " + Enum.GetValues(typeof(ErrorCode)).Length);
                                        throw (e);
                                    }

                                    break;

                                case "FeaturesFormat":
                                    featuresFormat = reader.Value;
                                    break;

                                case "MatlabFunctionName":
                                    matlabOutFileName = "DCONV_convertMatlabInput_" + featuresFormat + ".m";
                                    break;

                                case "MatlabFilePath":
                                    matlabOutFilePath = reader.Value;
                                    break;

                                case "OutputFeatures":
                                    outputFeatures = reader.Value;
                                    break;

                                case "OutputFile":
                                    // Either Encoding.Default of leave empty otherwise MATLAB will not understand the lines: extrac characters are added
                                    try
                                    {
                                        outputFile = new StreamWriter(File.Open(configEnvDirectory + "\\" + reader.Value + "_" + featuresFormat + ".txt", FileMode.OpenOrCreate, FileAccess.Write), Encoding.Default);
                                    }
                                    catch
                                    {
                                        break;
                                    }

                                    break;

                                case "OutputFileFormat":
                                    outputFileFormat = reader.Value;
                                    break;

                                case "ContextType":    // Type 1 (considering before and after fixed num. of items) or Type 2 (considering context length with no constraint on before and after)
                                    contextType = reader.Value;
                                    break;

                                case "ContextBeforeLength":    // Type 1
                                    contextBeforeLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextAfterLength":     // Type 1
                                    contextAfterLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextTargetBeforeLength":    // Type 1
                                    contextTargetBeforeLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextTargetAfterLength":     // Type 1
                                    contextTargetAfterLength = Int32.Parse(reader.Value);
                                    break;

                                case "CentralWordContextBeforeLength":    // Type 1
                                    centralWordContextBeforeLength = Int32.Parse(reader.Value);
                                    break;

                                case "CentralWordContextAfterLength":     // Type 1
                                    centralWordContextAfterLength = Int32.Parse(reader.Value);
                                    break;

                                case "ContextLength":     // Type 2
                                    contextLength = Int32.Parse(reader.Value);
                                    break;

                                case "LastCharFeaturesDepth":
                                    lastCharFeaturesDepth = Int32.Parse(reader.Value);
                                    break;

                                case "SuppressFeature":
                                    suppressFeaturesHashTable.Add(reader.Value, "Suppress");
                                    break;

                                case "SuppressTarget":
                                    suppressTargetsHashTable.Add(reader.Value, "Suppress");
                                    break;

                                case "AddFeatureToCentralContextWord":
                                    addFeaturesToCentralContextWord.Add(reader.Value, "Add");
                                    break;

                                case "TrainInputFormat":
                                    trainInputFormat = reader.Value;
                                    break;

                                case "TestInputFormat":
                                    testInputFormat = reader.Value;
                                    break;

                                case "NumberPOSTaggers":
                                    numPOSTaggers = Int32.Parse(reader.Value);

                                    posTaggersParams = new POSTaggerParams[numPOSTaggers];

                                    break;

                                case "POSTaggerName":
                                    currPOSTagger++;
                                    //numPOSTaggers = 1;
                                    posTaggersParams[currPOSTagger] = new POSTaggerParams();
                                    posTaggersParams[currPOSTagger].posTaggerName = reader.Value;

                                    break;

                                case "POSTaggerType":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].posTaggerType = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].posTaggerType = reader.Value;
                                    }
                                    break;

                                case "StanfordRemoveDiacritics":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].stanfordRemoveDiacritics = bool.Parse(reader.Value);
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].stanfordRemoveDiacritics = bool.Parse(reader.Value);
                                    }
                                    break;

                                case "StanfordTaggerModelName":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].stanfordTaggerModelName = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].stanfordTaggerModelName = reader.Value;
                                    }
                                    break;

                                case "StanfordTaggerOutFileName":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].stanfordTaggerOutFileName = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].stanfordTaggerOutFileName = reader.Value;
                                    }
                                    break;

                                case "StanfordFileWithoutDiacs":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].stanfordFileWithoutDiacs = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].stanfordFileWithoutDiacs = reader.Value;
                                    }
                                    break;

                                case "MapStanfordToRDI":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].stanfordMapStanfordToRDI = bool.Parse(reader.Value);
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].stanfordMapStanfordToRDI = bool.Parse(reader.Value);
                                    }
                                    break;

                                case "FinalNetFullPath":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].DNN_POSTaggerFinalNetFullPath = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].DNN_POSTaggerMaxIDInfoFileFullPath = reader.Value;
                                    }
                                    break;

                                case "MaxIDInfoFileFullPath":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].DNN_POSTaggerMaxIDInfoFileFullPath = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].DNN_POSTaggerMaxIDInfoFileFullPath = reader.Value;
                                    }
                                    break;

                                case "ConfigurationFileFullPath":
                                    try
                                    {
                                        posTaggersParams[currPOSTagger].DNN_POSTaggerConfigurationFileFullPath = reader.Value;
                                    }
                                    catch
                                    {
                                        currPOSTagger++;
                                        numPOSTaggers       = 1;
                                        posTaggersParams    = new POSTaggerParams[1];
                                        posTaggersParams[0] = new POSTaggerParams();
                                        posTaggersParams[0].DNN_POSTaggerConfigurationFileFullPath = reader.Value;
                                    }
                                    break;

                                case "ClassifierName":
                                    clsParams = new ClassifierParams();
                                    clsParams.classifierName = reader.Value;
                                    break;

                                case "ClsFinalNetFullPath":
                                    clsParams.finalNetFullPath = reader.Value;
                                    break;

                                case "ClsConfigurationFileFullPath":
                                    clsParams.configurationFileFullPath = reader.Value;
                                    break;

                                case "ClsMaxIDInfoFileFullPath":
                                    clsParams.maxIDInfoFileFullPath = reader.Value;
                                    break;

                                case "TrainInputParsingMode":
                                    trainInputParsingMode = reader.Value;
                                    break;

                                case "TestInputParsingMode":
                                    testInputParsingMode = reader.Value;
                                    break;

                                case "LogExamplesEvenNoTargetDetected":
                                    logExamplesEvenNoTargetDetected = bool.Parse(reader.Value);
                                    break;

                                case "WordOnlyVocabularyScope":
                                    wordOnlyVocabularyScope = reader.Value;
                                    break;

                                case "TargetType":
                                    targetType = reader.Value;
                                    break;

                                case "TargetMode":
                                    targetMode = reader.Value;
                                    break;

                                case "WordOnlyEncoding":
                                    wordOnlyEncoding = reader.Value;
                                    break;

                                default:
                                    Console.WriteLine("Incorrect configuration parameter." + reader.Value + " is invalid bitfieldValue for Configuration Parameter" + reader.Name);
                                    break;
                                } // end switch (reader.Name)
                            }     // end while (reader.MoveToNextAttribute())
                        }         // end if (reader.HasAttributes)

                        // Get back to root element
                        reader.MoveToElement();
                    }// end if (reader.NodeType == XmlNodeType.Element)
                    else
                    {
                        Console.WriteLine("Incorrect configuration parameter. Expected: ConfigurationParameter, Found: " + reader.Name);
                    }
                }
            }// end of while (reader.Read())
        }