示例#1
0
        public static ParseResult ParseGraphDescriptionFromXmlFile(string inputXmlPath)
        {
            XmlGraphReader graphReader;

            try
            {
                graphReader = XmlGraphReader.CreateFromXmlFile(inputXmlPath);
                return(ParseGraphDescriptionWithXmlGraphReader(graphReader));
            }
            catch (Exception ex)
            {
                var safeReadingEx = new FileReadingSafeException("Error occured while accessing and parsing the file: \"" + inputXmlPath + "\".", ex);
                try
                {
                    throw;
                }
                catch (System.IO.IOException)
                {
                    safeReadingEx.AugmentMessageWithLine("The file or directory wasn't found.");
                }
                catch (System.Security.SecurityException)
                {
                    safeReadingEx.AugmentMessageWithLine("Program has no permissions to access the file.");
                }
                catch (Exception e)
                {
                    if (e is ArgumentException || e is UriFormatException)
                    {
                        safeReadingEx.AugmentMessageWithLine("The file path format is malformed.");
                    }
                }
                throw safeReadingEx;
            }
        }
示例#2
0
        private static ParseResult ParseGraphDescriptionWithXmlGraphReader(XmlGraphReader graphReader)
        {
            XDocument xDoc;

            try
            {
                var xmlReader = graphReader.GetValidatingXmlReader();
                xDoc = XDocument.Load(xmlReader);
            }
            catch (System.Xml.XmlException ex)
            {
                throw new inputValidationSafeException("The structure of the xml input is not correct. Is it an xml?", ex);
            }
            catch (System.Xml.Schema.XmlSchemaValidationException ex)
            {
                var message = String.Format(
                    "The xml input failed to pass validation.\r\nDetails:\r\nline {0}, column {1}\r\n{2}",
                    ex.LineNumber,
                    ex.LinePosition,
                    ex.Message
                    );
                throw new inputValidationSafeException(message, ex);
            }
            return(ParseGraphDescriptionFromXDocument(xDoc));
        }
示例#3
0
        /* Public Parsers */

        public static ParseResult ParseGraphDescriptionFromXmlText(string inputXmlText)
        {
            var graphReader = XmlGraphReader.CreateFromXmlText(inputXmlText);

            return(ParseGraphDescriptionWithXmlGraphReader(graphReader));
        }
 private static ParseResult ParseGraphDescriptionWithXmlGraphReader(XmlGraphReader graphReader)
 {
     XDocument xDoc;
     try
     {
         var xmlReader = graphReader.GetValidatingXmlReader();
         xDoc = XDocument.Load(xmlReader);
     }
     catch (System.Xml.XmlException ex)
     {
         throw new inputValidationSafeException("The structure of the xml input is not correct. Is it an xml?", ex);
     }
     catch (System.Xml.Schema.XmlSchemaValidationException ex)
     {
         var message = String.Format(
             "The xml input failed to pass validation.\r\nDetails:\r\nline {0}, column {1}\r\n{2}",
             ex.LineNumber,
             ex.LinePosition,
             ex.Message
         );
         throw new inputValidationSafeException(message, ex);
     }
     return ParseGraphDescriptionFromXDocument(xDoc);
 }