Beispiel #1
0
 /// <summary> Outputs a SAXParseException warning to the logger.
 ///
 /// </summary>
 /// <param name="exception">  Exception to output
 ///
 /// </param>
 //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
 public virtual void warning(System.Xml.XmlException exception)
 {
     if (reportErrors)
     {
         print("warning", exception);
     }
 }
        private static bool IsExceptionKnown(Exception ex)
        {
            System.Threading.ThreadAbortException threadAbortException = ex as System.Threading.ThreadAbortException;
            if (null != threadAbortException)
            {
                return(true);
            }

            System.Messaging.MessageQueueException messageQueueException = ex as System.Messaging.MessageQueueException;
            if (null != messageQueueException && messageQueueException.MessageQueueErrorCode == System.Messaging.MessageQueueErrorCode.IOTimeout)
            {
                return(true);
            }

            System.Xml.XmlException xmlException = ex as System.Xml.XmlException;
            if (null != xmlException && xmlException.Message.StartsWith("Name cannot begin with the '<' character"))
            {
                return(true);
            }

            System.IO.FileNotFoundException fileNotFoundException = ex as System.IO.FileNotFoundException;
            if (null != fileNotFoundException &&
                null != fileNotFoundException.FileName &&
                fileNotFoundException.FileName.Contains("XmlSerializers"))
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Interrogates the exception to return the content two lines above and one line below
        /// exception
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public string GetParseExceptionContent(System.Xml.XmlException exception)
        {
            if (null == Parent)
            {
                throw new Exception("Parent GadgetMaster has not been initialized");
            }
            if (null == exception)
            {
                return(null);
            }
            string fullGadgetSrc = Parent.RawTag;

            if (string.IsNullOrEmpty(fullGadgetSrc))
            {
                return(null);
            }

            // ... Line NN, position MM.
            string lineSearch = "Line ";
            // string posSearch = "position ";

            string msg          = exception.Message;
            int    pos          = msg.IndexOf(lineSearch);
            int    endOfLinePos = pos + lineSearch.Length;
            int    commaPos     = msg.IndexOf(",", endOfLinePos);

            if (pos == -1 || commaPos == -1)
            {
                return(null);
            }

            string tmp = msg.Substring(endOfLinePos, commaPos - endOfLinePos);
            int    line;

            if (!Int32.TryParse(tmp, out line))
            {
                return(null);
            }

            string[] lines = new string[4];
            using (StringReader reader = new StringReader(fullGadgetSrc))
            {
                int curLine = 0;
                while (curLine++ < (line - 2) && null != reader.ReadLine())
                {
                }

                for (int i = 0; i < 4; i++)
                {
                    lines[i] = reader.ReadLine();
                    if (lines[i] == null)
                    {
                        break;
                    }
                }
            }
            return(String.Join("\n", lines));
        }
Beispiel #4
0
        // for recoverable errors, like validity problems

        /// <summary> Outputs a SAXParseException error to the logger.
        ///
        /// </summary>
        /// <param name="exception">  Exception to output
        ///
        /// </param>
        //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
        public virtual void error(System.Xml.XmlException exception)
        {
            if (reportErrors)
            {
                print("error", exception);
            }
            if (abortOnErrors)
            {
                throw exception;
            }
        }
Beispiel #5
0
 /// <summary> Internal procedure that outputs an SAXParseException with a significance level
 /// to the cdk.tools.LoggingTool logger.
 ///
 /// </summary>
 /// <param name="level">    significance level
 /// </param>
 /// <param name="exception">Exception to output
 /// </param>
 //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
 private void print(System.String level, System.Xml.XmlException exception)
 {
     //if (level.Equals("warning"))
     //{
     //    logger.warn("** " + level + ": " + exception.Message);
     //    logger.warn("   URI  = " + exception.Source);
     //    logger.warn("   line = " + exception.LineNumber);
     //}
     //else
     //{
     //    logger.error("** " + level + ": " + exception.Message);
     //    logger.error("   URI  = " + exception.Source);
     //    logger.error("   line = " + exception.LineNumber);
     //}
 }
        public void Invalid_Namespaces_UndeclaredPrefix()
        {
            string toValidate  = Resources.IValidationService.Invalid.Namespaces.UndeclaredPrefix;
            var    interpreter = new DebugIntepreter();

            interpreter.InterpretationFunction = (exception) =>
            {
                if (false == (exception is System.Xml.XmlException))
                {
                    Assert.Fail("Expected System.Xml.XmlException");
                }
                System.Xml.XmlException e = exception as System.Xml.XmlException;
                if (e.LineNumber != 6)
                {
                    Assert.Fail("This test should fail on line 6");
                }
                if (e.LinePosition != 6)
                {
                    Assert.Fail("This test should fail at line position 6");
                }
                Assert.IsTrue
                (
                    exception.Message == "'dc' is an undeclared prefix. Line 6, position 6.",
                    "Exception expected to complain about schema information missing for root catalog element"
                );
                return(XCRI.Validation.XmlExceptionInterpretation.InterpretationStatus.Interpreted);
            };
            var t = base.Instantiate();

            t.AttemptSchemaLocationInjection = false;
            t.XmlExceptionInterpreters.Add(interpreter);
            t.Source = new XCRI.Validation.XmlRetrieval.StringSource(null, this.XmlResolver);
            var results = t.Validate(toValidate);

            Assert.AreEqual <int>(1, results.Count, "1 exception expected");
        }
        public void Invalid_Structure_XmlNesting()
        {
            string toValidate  = Resources.IValidationService.Invalid.Structure.XmlNesting;
            var    interpreter = new DebugIntepreter();

            interpreter.InterpretationFunction = (exception) =>
            {
                if (false == (exception is System.Xml.XmlException))
                {
                    Assert.Fail("Expected System.Xml.XmlException");
                }
                System.Xml.XmlException e = exception as System.Xml.XmlException;
                if (e.LineNumber != 7)
                {
                    Assert.Fail("This test should fail on line 7");
                }
                if (e.LinePosition != 5)
                {
                    Assert.Fail("This test should fail at line position 5");
                }
                Assert.IsTrue
                (
                    e.Message == "The 'provider' start tag on line 5 position 4 does not match the end tag of 'catalog'. Line 7, position 5.",
                    "The test should faul because of incorrect tag nesting"
                );
                return(XCRI.Validation.XmlExceptionInterpretation.InterpretationStatus.Interpreted);
            };

            var t = base.Instantiate();

            t.XmlExceptionInterpreters.Add(interpreter);
            t.Source = new XCRI.Validation.XmlRetrieval.StringSource(null, this.XmlResolver);
            var results = t.Validate(toValidate);

            Assert.AreEqual <int>(1, results.Count, "1 exception expected");
        }
 protected ReturnCodeErrXml CreateReturnCodeErrXml(System.Xml.XmlException xex)
 {
     _lastReturnCode = new ReturnCodeErrXml(xex, GetErrCodeXml());
     return((ReturnCodeErrXml)_lastReturnCode);
 }
 public ReturnCodeErrXml(System.Xml.XmlException xex, TEnumError errCode)
     : base(xex, errCode)
 {
 }
Beispiel #10
0
		private void HandleError (XmlSchemaException ex)
		{
#if DTD_HANDLE_EVENTS
			if (this.ValidationEventHandler != null)
				ValidationEventHandler (this, new ValidationEventArgs (ex, ex.Message, XmlSeverityType.Error));
#else
			DTD.AddError (ex);
#endif
		}
 public WeatherDataServiceException(string message, System.Xml.XmlException inner) : base(message, inner)
 {
     Console.WriteLine(message + "XML file problem. \n" + inner + "\n");
 }
 //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
 public override void  fatalError(System.Xml.XmlException e)
 {
     throw e;
 }
 //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
 public override void  error(System.Xml.XmlException e)
 {
     // no op
 }
 //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
 public override void  warning(System.Xml.XmlException e)
 {
     // no op
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GodModeException"/> class.
 /// </summary>
 /// <param name="msg">The MSG.</param>
 /// <param name="xmlException">The XML exception.</param>
 public GodModeException(string msg, System.Xml.XmlException xmlException)
     : base(msg, xmlException)
 {
 }
Beispiel #16
0
 public WeatherDataServiceException(string message, System.Xml.XmlException inner) : base(message, inner)
 {
     Console.WriteLine(message + "There was a problem with with the XML File. \n" + inner + "\n");
 }
Beispiel #17
0
 public override void  error(System.Xml.XmlException e)
 {
     // TODO: remove.
     System.Console.Error.WriteLine("Error in " + GetType() + ": " + e);
 }
Beispiel #18
0
        // private functions

        private IChemFile readChemFile(IChemFile file)
        {
            //logger.debug("Started parsing from input...");
            ChemFileCDO cdo = new ChemFileCDO(file);

            try
            {
                parser.setFeature("http://xml.org/sax/features/validation", false);
                //logger.info("Deactivated validation");
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException e)
            {
                //logger.warn("Cannot deactivate validation.");
                return(cdo);
            }
            parser.setContentHandler(new CMLHandler((IChemicalDocumentObject)cdo));
            parser.setEntityResolver(new CMLResolver());
            //UPGRADE_TODO: Method 'org.xml.sax.XMLReader.setErrorHandler' was converted to 'XmlSAXDocumentManager.SetErrorHandler' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_orgxmlsaxXMLReadersetErrorHandler_orgxmlsaxErrorHandler'"
            parser.setErrorHandler(new CMLErrorHandler());
            try
            {
                if (input == null)
                {
                    //logger.debug("Parsing from URL: ", url);
                    parser.parse(url);
                }
                else
                {
                    //logger.debug("Parsing from Reader");
                    input.BaseStream.Seek(0, SeekOrigin.Begin);
                    parser.parse(new XmlSourceSupport(input));
                }
            }
            catch (System.IO.IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.String error = "Error while reading file: " + e.Message;
                //logger.error(error);
                //logger.debug(e);
                throw new CDKException(error, e);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            catch (System.Xml.XmlException saxe)
            {
                //UPGRADE_TODO: Class 'org.xml.sax.SAXParseException' was converted to 'System.xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                System.Xml.XmlException spe   = (System.Xml.XmlException)saxe;
                System.String           error = "Found well-formedness error in line " + spe.LineNumber;
                //logger.error(error);
                //logger.debug(saxe);
                throw new CDKException(error, saxe);
            }
            //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            //catch (System.Xml.XmlException saxe)
            //{
            //    System.String error = "Error while parsing XML: " + saxe.Message;
            //    //logger.error(error);
            //    //logger.debug(saxe);
            //    throw new CDKException(error, saxe);
            //}
            return(cdo);
        }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TitaniaException"/> class.
 /// </summary>
 /// <param name="msg">The MSG.</param>
 /// <param name="xmlException">The XML exception.</param>
 public TitaniaException(string msg, System.Xml.XmlException xmlException)
     : base(msg, xmlException)
 {
 }
 public void AddError(XmlSchemaException ex)
 {
     validationErrors.Add(ex);
 }
Beispiel #21
0
 public override void OnXmlException(System.Xml.XmlException ex)
 {
     // do nothing
 }