Returns information about the last XML related exception.
Inheritance: Exception
コード例 #1
0
ファイル: XmlException.cs プロジェクト: johnhhm/corefx
 public int v3()
 {
     Exception inner = new Exception();
     XmlException e = new XmlException("error", inner, 14, 36);
     CompareException(e, "Xml_UserException", inner, 14, 36);
     return TEST_PASS;
 }
コード例 #2
0
 public XmlValidationError( XmlException ex )
 {
     LineNumber = ex.LineNumber;
     LinePosition = ex.LinePosition;
     Message = ex.Message;
     Severity = XmlSeverityType.Error;
 }
コード例 #3
0
 internal BuildEventFileInfo(XmlException e)
 {
   ErrorUtilities.VerifyThrow(e != null, "Need exception context.");
   this.file = e.SourceUri.Length == 0 ? string.Empty : new Uri(e.SourceUri).LocalPath;
   this.line = e.LineNumber;
   this.column = e.LinePosition;
   this.endLine = 0;
   this.endColumn = 0;
 }
コード例 #4
0
ファイル: XmlExceptionHelper.cs プロジェクト: neris/corefx
 static public void ThrowXmlException(XmlDictionaryReader reader, XmlException exception)
 {
     string s = exception.Message;
     IXmlLineInfo lineInfo = reader as IXmlLineInfo;
     if (lineInfo != null && lineInfo.HasLineInfo())
     {
         s += " " + SR.Format(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition);
     }
     throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s));
 }
コード例 #5
0
ファイル: CDataReaderTestCase.cs プロジェクト: johnhhm/corefx
        protected void CheckXmlException(string expectedCode, XmlException e, int expectedLine, int expectedPosition)
        {
            string actualCode = expectedCode;
            CError.WriteLine("***Exception");
            CError.WriteLineIgnore(e.ToString());
            CError.Compare(e.LineNumber, expectedLine, "CheckXmlException:LineNumber");
            CError.Compare(e.LinePosition, expectedPosition, "CheckXmlException:LinePosition");

            CError.Compare(actualCode, expectedCode, "ec" + e.Message);
        }
コード例 #6
0
ファイル: GuideEntry.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Creates the guide entry from the given text and relvant attributes
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="hiddenStatus"></param>
        /// <param name="style"></param>
        /// <param name="editing"></param>
        /// <returns></returns>
        static public XmlElement CreateGuideEntry(string text, int hiddenStatus, GuideEntryStyle style, int canRead)
        {

            XmlDocument doc = new XmlDocument();
            if (hiddenStatus > 0 && canRead == 0)
            {
                doc.LoadXml("<GUIDE><BODY>This article has been hidden pending moderation.</BODY></GUIDE>");
            }
            else
            {
                try
                {
                    switch (style)
                    {
                        case GuideEntryStyle.GuideML:
                            text = text.Trim();
                            text = Entities.ReplaceEntitiesWithNumericValues(text);
                            //text = HtmlUtils.ReplaceCRsWithBRs(text);
                            text = HtmlUtils.EscapeNonEscapedAmpersands(text);
                            doc.PreserveWhitespace = true;
                            doc.LoadXml(text);
                            AdjustFootnotes(doc);
                            //doc["GUIDE"]["BODY"].InnerXml = HtmlUtils.ReplaceCRsWithBRs(doc["GUIDE"]["BODY"].InnerXml);
                            break;

                        case GuideEntryStyle.PlainText:
                            doc.LoadXml(StringUtils.PlainTextToGuideML(text));
                            break;

                        case GuideEntryStyle.Html:
                            doc.LoadXml("<GUIDE><BODY><PASSTHROUGH><![CDATA[" + text + "]]></PASSTHROUGH></BODY></GUIDE>");
                            break;

                        default:
                            goto case GuideEntryStyle.GuideML;//null styles are generally guideml...
                        //throw new NotImplementedException("Don't know what type of entry we've got here!");
                    }
                }
                catch (XmlException e)
                {
                    //If something has gone wrong log stuff
                    DnaDiagnostics.Default.WriteExceptionToLog(e);

                    var errorMessage = Regex.Replace(e.Message, "position +[0-9][0-9]* ", "", RegexOptions.IgnoreCase);

                    var xmlException = new XmlException(errorMessage, e);

                    throw new ApiException("GuideML Transform Failed", xmlException);
                }
            }

            return doc.DocumentElement;
        }
コード例 #7
0
ファイル: XmlException.cs プロジェクト: johnhhm/corefx
 private void CompareException(XmlException e, string ec, Exception inner, int ln, int lp)
 {
     CError.WriteLine(e);
     CError.Compare((object)e.InnerException, (object)inner, "InnerException");
     CError.Compare(e.LineNumber, ln, "LineNumber");
     CError.Compare(e.LinePosition, lp, "LinePosition");
     string s1 = e.StackTrace;
     Type t = e.GetType();
     Exception e2 = e.GetBaseException();
     int i = e.GetHashCode();
     CError.Compare(!String.IsNullOrEmpty(e.Message), "Message");
     string s3 = e.ToString();
 }
コード例 #8
0
        public void DoScratch()
        {
            try {

              //  int i = Int32.Parse("22r");

                XmlException x = new XmlException("Blah error", null, 25, 100);
                throw x;
            }
            catch (XmlException e) {
                Console.WriteLine("Line Number {0}", e.LineNumber);
                Console.WriteLine("Line Position {0}", e.LinePosition);
                Console.WriteLine("Source URI {0}", e.SourceUri);
                Console.WriteLine("Message {0}", e.Message);
                Console.WriteLine("Stack Trace {0}", e.StackTrace);

            }

            catch (FormatException e) {
                Console.WriteLine("Caught Format Exception");

                Console.WriteLine("Helplink {0}", e.HelpLink);
                Console.WriteLine("Message {0}", e.Message);
                Console.WriteLine("Source {0}", e.Source);
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");
                //Console.WriteLine(" {0}");

                if (e.Data != null) {
                    Console.WriteLine("Getting extra details");
                    foreach (DictionaryEntry item in e.Data) {
                        Console.WriteLine("The key is '{0}' and the value is: {1}", item.Key, item.Value);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine("Caught Exception");
                if (e.Data != null) {
                    foreach (DictionaryEntry item in e.Data) {
                        Console.WriteLine("The key is '{0}' and the value is: {1}", item.Key, item.Value);
                    }
                }
            }
        }
コード例 #9
0
        private static string BuildXmlErrorMessage(string fileName, XmlException exception)
        {
            string msg = Path.GetFileName(fileName) + " is not wel-formed." + Environment.NewLine +
                         "Line " + exception.LineNumber + " at position " + exception.LinePosition + Environment.NewLine +
                         exception.Message;

            var lines = File.ReadAllLines(fileName);
            if (exception.LineNumber >= 0 && exception.LineNumber < lines.Count())
            {
                msg += Environment.NewLine + Environment.NewLine;
                if (exception.LineNumber > 1)
                    msg += (exception.LineNumber - 1) + ":  " + lines[exception.LineNumber - 2] + Environment.NewLine;
                if (exception.LineNumber > 0)
                    msg += (exception.LineNumber) + ":  " + lines[exception.LineNumber - 1] + Environment.NewLine;
                msg += (exception.LineNumber + 1) + ":  " + lines[exception.LineNumber];
            }
            return msg;
        }
コード例 #10
0
		public void SetUpFixture()
		{
			List<string> dialogs = new List<string>();
			dialogs.Add("WelcomeDialog");
			dialogs.Add("ProgressDialog");
			wixDocumentFileName = @"C:\Projects\Test\setup.wxs";
			using (SetupDialogListView control = new SetupDialogListView()) {
				control.AddDialogs(wixDocumentFileName, new ReadOnlyCollection<string>(dialogs));
				
				hasErrorsAtStart = control.HasErrors;
				XmlException xmlEx = new XmlException("Error occurred", null, 10, 5);
				control.AddError(wixDocumentFileName, xmlEx);
				Exception ex = new Exception("Error");
				control.AddError(wixDocumentFileName);
				nodesAdded = control.Items.Count;
				
				SetupDialogListViewItem welcomeDialogListItem = (SetupDialogListViewItem)control.Items[0];
				welcomeDialogText = welcomeDialogListItem.Text;
				welcomeDialogId = welcomeDialogListItem.Id;
				welcomeDialogFileName = welcomeDialogListItem.FileName;

				SetupDialogListViewItem progressDialogListItem = (SetupDialogListViewItem)control.Items[1];
				progressDialogText = progressDialogListItem.Text;
				progressDialogId = progressDialogListItem.Id;
				progressDialogFileName = progressDialogListItem.FileName;
				
				SetupDialogErrorListViewItem xmlErrorDialogListItem = (SetupDialogErrorListViewItem)control.Items[2];
				xmlErrorDialogText = xmlErrorDialogListItem.Text;
				xmlErrorDialogErrorLine = xmlErrorDialogListItem.Line;
				xmlErrorDialogErrorColumn = xmlErrorDialogListItem.Column;
				xmlErrorDialogTextColour = xmlErrorDialogListItem.ForeColor;
				xmlErrorDialogTextBackColour = xmlErrorDialogListItem.BackColor;

				SetupDialogErrorListViewItem errorDialogListItem = (SetupDialogErrorListViewItem)control.Items[3];
				errorDialogText = errorDialogListItem.Text;
				errorDialogErrorLine = errorDialogListItem.Line;
				errorDialogErrorColumn = errorDialogListItem.Column;
				errorDialogTextColour = errorDialogListItem.ForeColor;				
				errorDialogTextBackColour = errorDialogListItem.BackColor;
				
				hasErrors = control.HasErrors;
			}
		}
コード例 #11
0
ファイル: HtmlUtils.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Helper method that parses Xml Exception messages to dna meesages
 /// </summary>
 /// <param name="ex">The Xml Exception</param>
 /// <returns>The dna mundged version</returns>
 private static string FormatXmlErrorMessageFromExceptionMessage(XmlException ex)
 {
     string errorMessage = "";
     string exceptionMessge = ex.Message;
     int comma = exceptionMessge.IndexOf(',');
     int fullstop = exceptionMessge.IndexOf('.');
     if (fullstop < comma)
     {
         errorMessage = exceptionMessge.Substring(0, fullstop);
     }
     else
     {
         errorMessage = exceptionMessge.Substring(0, comma);
         comma = exceptionMessge.IndexOf(',', comma + 1);
         if (fullstop > comma && comma != -1)
         {
             errorMessage += exceptionMessge.Substring(comma, fullstop - comma);
         }
     }
     return errorMessage + " on line " + ex.LineNumber.ToString();
 }
コード例 #12
0
ファイル: Channel.cs プロジェクト: matthiase/odeo-mobile
        public void Process(Stream stream)
        {
            XmlTextReader rss = null;
            ChannelItem item = null;
            ChannelItemCollection items = new ChannelItemCollection();
            Exception error = null;

            rss = new XmlTextReader(stream);
            rss.WhitespaceHandling = WhitespaceHandling.None;

            try
            {
                while (rss.Read())
                {
                    try
                    {
                        if (rss.IsStartElement())
                        {
                            if (String.Compare(rss.Name, "title", true) == 0)
                                this.Title = XmlHelper.Decode(rss.ReadString());
                            else if (String.Compare(rss.Name, "link", true) == 0)
                                this.Link = XmlHelper.Decode(rss.ReadString());
                            else if (String.Compare(rss.Name, "description", true) == 0)
                                this.Description = XmlHelper.Decode(rss.ReadString());
                            else if (String.Compare(rss.Name, "language", true) == 0)
                                this.Language = XmlHelper.Decode(rss.ReadString());
                            else if (String.Compare(rss.Name, "ttl", true) == 0)
                                this.TTL = XmlHelper.Decode(rss.ReadString());
                            else if (String.Compare(rss.Name, "item", true) == 0)
                            {
                                item = new ChannelItem(this);
                                while ((String.Compare(rss.Name, "item", true) == 0 &&
                                    rss.NodeType == XmlNodeType.EndElement) == false)
                                {
                                    if (rss.Read() && rss.IsStartElement())
                                    {
                                        if (String.Compare(rss.Name, "title", true) == 0)
                                            item.Title = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "link", true) == 0)
                                            item.Link = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "description", true) == 0)
                                            item.Description = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "guid", true) == 0)
                                            item.Guid = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "pubDate", true) == 0)
                                            item.PublicationDate = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "enclosure", true) == 0)
                                        {
                                            item.Enclosure.Url = XmlHelper.Decode(rss.GetAttribute("url"));

                                            try { item.Enclosure.Length = long.Parse(rss.GetAttribute("length")); }
                                            catch (Exception) { item.Enclosure.Length = 0; }

                                            item.Enclosure.Type = XmlHelper.Decode(rss.GetAttribute("type"));
                                        }
                                        else if (String.Compare(rss.Name, "itunes:author", true) == 0)
                                            item.Author = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "itunes:keywords", true) == 0)
                                            item.Keywords = XmlHelper.Decode(rss.ReadString());
                                        else if (String.Compare(rss.Name, "media:thumbnail", true) == 0)
                                        {
                                            item.Thumbnail = new Thumbnail(item);
                                            item.Thumbnail.Url = XmlHelper.Decode(rss.GetAttribute("url"));

                                            try { item.Thumbnail.Height = int.Parse(rss.GetAttribute("height")); }
                                            catch (Exception) { item.Thumbnail.Height = 0; }

                                            try { item.Thumbnail.Width = int.Parse(rss.GetAttribute("width")); }
                                            catch (Exception) { item.Thumbnail.Width = 0; }
                                        }
                                    }
                                }
                                items.Add(item);
                            }
                        }
                    }
                    catch (XmlException ex)
                    {
                        if (error == null)
                        {
                            error = new XmlException(String.Format("An XML error occurred while processing {0}.",
                                item.Title), ex);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (error == null)
                            error = ex;
                    }

                }
            }
            catch (Exception ex)
            {
                error = new Exception(String.Format("An unknown error occurred while processing {0}.",
                    item.Title), ex);
            }
            finally
            {
                if (rss != null)
                    rss.Close();
            }

            if (error != null)
                throw error;

            _items.Merge(items);
        }
コード例 #13
0
    OnXmlException
    (
        String sGraphMLFileName,
        XmlException oXmlException
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(sGraphMLFileName) );
        Debug.Assert(oXmlException != null);
        AssertValid();

        m_oInvalidGraphMLFileNames.Add( String.Format(
        
            "{0}: {1}"
            ,
            sGraphMLFileName,
            oXmlException.Message
            ) );
    }
コード例 #14
0
        public override bool Read()
        {
            switch (_state)
            {
            case State.Initial:
                _state = State.Interactive;
                if (base.reader.ReadState == ReadState.Initial)
                {
                    goto case State.Interactive;
                }
                break;

            case State.Error:
                return(false);

            case State.InReadBinary:
                FinishReadBinary();
                _state = State.Interactive;
                goto case State.Interactive;

            case State.Interactive:
                if (!base.reader.Read())
                {
                    return(false);
                }
                break;

            default:
                Debug.Fail($"Unexpected state {_state}");
                return(false);
            }

            XmlNodeType nodeType = base.reader.NodeType;

            if (!_checkCharacters)
            {
                switch (nodeType)
                {
                case XmlNodeType.Comment:
                    if (_ignoreComments)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.Whitespace:
                    if (_ignoreWhitespace)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    if (_ignorePis)
                    {
                        return(Read());
                    }
                    break;

                case XmlNodeType.DocumentType:
                    if (_dtdProcessing == DtdProcessing.Prohibit)
                    {
                        Throw(SR.Xml_DtdIsProhibitedEx, string.Empty);
                    }
                    else if (_dtdProcessing == DtdProcessing.Ignore)
                    {
                        return(Read());
                    }
                    break;
                }
                return(true);
            }
            else
            {
                switch (nodeType)
                {
                case XmlNodeType.Element:
                    if (_checkCharacters)
                    {
                        // check element name
                        ValidateQName(base.reader.Prefix, base.reader.LocalName);

                        // check values of attributes
                        if (base.reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                ValidateQName(base.reader.Prefix, base.reader.LocalName);
                                CheckCharacters(base.reader.Value);
                            } while (base.reader.MoveToNextAttribute());

                            base.reader.MoveToElement();
                        }
                    }
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    if (_checkCharacters)
                    {
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EntityReference:
                    if (_checkCharacters)
                    {
                        // check name
                        ValidateQName(base.reader.Name);
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                    if (_ignorePis)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Name);
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.Comment:
                    if (_ignoreComments)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        CheckCharacters(base.reader.Value);
                    }
                    break;

                case XmlNodeType.DocumentType:
                    if (_dtdProcessing == DtdProcessing.Prohibit)
                    {
                        Throw(SR.Xml_DtdIsProhibitedEx, string.Empty);
                    }
                    else if (_dtdProcessing == DtdProcessing.Ignore)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Name);
                        CheckCharacters(base.reader.Value);

                        string str;
                        str = base.reader.GetAttribute("SYSTEM");
                        if (str != null)
                        {
                            CheckCharacters(str);
                        }

                        str = base.reader.GetAttribute("PUBLIC");
                        if (str != null)
                        {
                            int i;
                            if ((i = _xmlCharType.IsPublicId(str)) >= 0)
                            {
                                Throw(SR.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(str, i));
                            }
                        }
                    }
                    break;

                case XmlNodeType.Whitespace:
                    if (_ignoreWhitespace)
                    {
                        return(Read());
                    }
                    if (_checkCharacters)
                    {
                        CheckWhitespace(base.reader.Value);
                    }
                    break;

                case XmlNodeType.SignificantWhitespace:
                    if (_checkCharacters)
                    {
                        CheckWhitespace(base.reader.Value);
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (_checkCharacters)
                    {
                        ValidateQName(base.reader.Prefix, base.reader.LocalName);
                    }
                    break;

                default:
                    break;
                }
                _lastNodeType = nodeType;
                return(true);
            }
        }
コード例 #15
0
ファイル: XmlExceptionCas.cs プロジェクト: nobled/mono
		public void PermitOnlySerializationFormatter_GetObjectData ()
		{
			StreamingContext sc = new StreamingContext (StreamingContextStates.All);
			XmlException xe = new XmlException ();
			xe.GetObjectData (null, sc);
		}
コード例 #16
0
        /// <summary>
        /// Looks for well formed image comment in line of text and tries to parse parameters
        /// </summary>
        /// <param name="matchedText">Input: Line of text in editor window</param>
        /// <param name="imageUrl">Output: URL of image</param>
        /// <param name="imageScale">Output: Scale factor of image </param>
        /// <param name="ex">Instance of any exception generated. Null if function finished succesfully</param>
        /// <returns>Returns true if successful, otherwise false</returns>
        public static bool TryParse(string matchedText, out string imageUrl, out double imageScale, out Exception exception)
        {
            exception = null;
            imageUrl = "";
            imageScale = 0; // See MyImage.cs for explanation of default value here

            // Try parse text
            if (matchedText != "")
            {
                string tagText = _xmlImageTagRegex.Match(matchedText).Value;
                try
                {
                    XElement imgEl = XElement.Parse(tagText);
                    XAttribute srcAttr = imgEl.Attribute("url");
                    if (srcAttr == null)
                    {
                        exception = new XmlException("url attribute not specified.");
                        return false;
                    }
                    imageUrl = srcAttr.Value;
                    XAttribute scaleAttr = imgEl.Attribute("scale");
                    if (scaleAttr != null)
                        double.TryParse(scaleAttr.Value, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out imageScale);
                    return true;
                }
                catch (Exception ex)
                {
                    exception = ex;
                    return false;
                }
            }
            else
            {
                exception = new XmlException("<image... /> tag not in correct format.");
                return false;
            }
        }
コード例 #17
0
        public override void WriteWhitespace(string?ws)
        {
            if (ws == null)
            {
                ws = string.Empty;
            }

            // "checkNames" is intentional here; if false, the whitespace is checked in XmlWellformedWriter
            if (_checkNames)
            {
                int i;
                if ((i = XmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
                {
                    throw new ArgumentException(SR.Format(SR.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionArgs(ws, i)));
                }
            }

            if (_replaceNewLines)
            {
                ws = ReplaceNewLines(ws);
            }

            writer.WriteWhitespace(ws);
        }
コード例 #18
0
        public override async Task WriteDocTypeAsync(string name, string pubid, string sysid, string subset)
        {
            try {
                if (name == null || name.Length == 0)
                {
                    throw new ArgumentException(Res.GetString(Res.Xml_EmptyName));
                }
                XmlConvert.VerifyQName(name, ExceptionType.XmlException);

                if (conformanceLevel == ConformanceLevel.Fragment)
                {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_DtdNotAllowedInFragment));
                }

                await AdvanceStateAsync(Token.Dtd).ConfigureAwait(false);

                if (dtdWritten)
                {
                    currentState = State.Error;
                    throw new InvalidOperationException(Res.GetString(Res.Xml_DtdAlreadyWritten));
                }

                if (conformanceLevel == ConformanceLevel.Auto)
                {
                    conformanceLevel = ConformanceLevel.Document;
                    stateTable       = StateTableDocument;
                }

                int i;

                // check characters
                if (checkCharacters)
                {
                    if (pubid != null)
                    {
                        if ((i = xmlCharType.IsPublicId(pubid)) >= 0)
                        {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(pubid, i)), "pubid");
                        }
                    }
                    if (sysid != null)
                    {
                        if ((i = xmlCharType.IsOnlyCharData(sysid)) >= 0)
                        {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(sysid, i)), "sysid");
                        }
                    }
                    if (subset != null)
                    {
                        if ((i = xmlCharType.IsOnlyCharData(subset)) >= 0)
                        {
                            throw new ArgumentException(Res.GetString(Res.Xml_InvalidCharacter, XmlException.BuildCharExceptionArgs(subset, i)), "subset");
                        }
                    }
                }

                // write doctype
                await writer.WriteDocTypeAsync(name, pubid, sysid, subset).ConfigureAwait(false);

                dtdWritten = true;
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }
コード例 #19
0
 public void AddError(XmlSchemaException ex)
 {
     validationErrors.Add(ex);
 }
コード例 #20
0
 public virtual void  warning(System.Xml.XmlException e)
 {
     System.Console.Error.WriteLine("Warning: " + e.Message);
 }
コード例 #21
0
 public virtual void  fatalError(System.Xml.XmlException e)
 {
     throw e;
 }
コード例 #22
0
		/// <summary>
		/// Adds a detected validation exception.
		/// </summary>
		/// <param name="e">The exception.</param>
		protected virtual void AddValidationException(XmlException e)
		{
			validationExceptions.Add(e);
		}
コード例 #23
0
 public void ShowXmlIsNotWellFormedMessage(XmlException ex)
 {
     notWellFormedMessageDisplayed = true;
     notWellFormedException = ex;
 }
コード例 #24
0
 private object GenerateObjectFromDataNodeInfo(DataNodeInfo dataNodeInfo, ITypeResolutionService typeResolver)
 {
     object obj2 = null;
     string mimeType = dataNodeInfo.MimeType;
     string typeName = ((dataNodeInfo.TypeName == null) || (dataNodeInfo.TypeName.Length == 0)) ? MultitargetUtil.GetAssemblyQualifiedName(typeof(string), this.typeNameConverter) : dataNodeInfo.TypeName;
     if ((mimeType != null) && (mimeType.Length > 0))
     {
         if ((string.Equals(mimeType, ResXResourceWriter.BinSerializedObjectMimeType) || string.Equals(mimeType, ResXResourceWriter.Beta2CompatSerializedObjectMimeType)) || string.Equals(mimeType, ResXResourceWriter.CompatBinSerializedObjectMimeType))
         {
             byte[] buffer = FromBase64WrappedString(dataNodeInfo.ValueData);
             if (this.binaryFormatter == null)
             {
                 this.binaryFormatter = new BinaryFormatter();
                 this.binaryFormatter.Binder = new ResXSerializationBinder(typeResolver);
             }
             IFormatter binaryFormatter = this.binaryFormatter;
             if ((buffer != null) && (buffer.Length > 0))
             {
                 obj2 = binaryFormatter.Deserialize(new MemoryStream(buffer));
                 if (obj2 is ResXNullRef)
                 {
                     obj2 = null;
                 }
             }
             return obj2;
         }
         if (string.Equals(mimeType, ResXResourceWriter.SoapSerializedObjectMimeType) || string.Equals(mimeType, ResXResourceWriter.CompatSoapSerializedObjectMimeType))
         {
             byte[] buffer2 = FromBase64WrappedString(dataNodeInfo.ValueData);
             if ((buffer2 != null) && (buffer2.Length > 0))
             {
                 obj2 = this.CreateSoapFormatter().Deserialize(new MemoryStream(buffer2));
                 if (obj2 is ResXNullRef)
                 {
                     obj2 = null;
                 }
             }
             return obj2;
         }
         if ((!string.Equals(mimeType, ResXResourceWriter.ByteArraySerializedObjectMimeType) || (typeName == null)) || (typeName.Length <= 0))
         {
             return obj2;
         }
         System.Type type = this.ResolveType(typeName, typeResolver);
         if (type != null)
         {
             TypeConverter converter = TypeDescriptor.GetConverter(type);
             if (converter.CanConvertFrom(typeof(byte[])))
             {
                 byte[] buffer3 = FromBase64WrappedString(dataNodeInfo.ValueData);
                 if (buffer3 != null)
                 {
                     obj2 = converter.ConvertFrom(buffer3);
                 }
             }
             return obj2;
         }
         string str6 = System.Windows.Forms.SR.GetString("TypeLoadException", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X });
         XmlException exception = new XmlException(str6, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X);
         TypeLoadException exception2 = new TypeLoadException(str6, exception);
         throw exception2;
     }
     if ((typeName == null) || (typeName.Length <= 0))
     {
         return obj2;
     }
     System.Type type2 = this.ResolveType(typeName, typeResolver);
     if (type2 != null)
     {
         if (type2 == typeof(ResXNullRef))
         {
             return null;
         }
         if ((typeName.IndexOf("System.Byte[]") != -1) && (typeName.IndexOf("mscorlib") != -1))
         {
             return FromBase64WrappedString(dataNodeInfo.ValueData);
         }
         TypeConverter converter2 = TypeDescriptor.GetConverter(type2);
         if (!converter2.CanConvertFrom(typeof(string)))
         {
             return obj2;
         }
         string valueData = dataNodeInfo.ValueData;
         try
         {
             return converter2.ConvertFromInvariantString(valueData);
         }
         catch (NotSupportedException exception3)
         {
             string str8 = System.Windows.Forms.SR.GetString("NotSupported", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X, exception3.Message });
             XmlException innerException = new XmlException(str8, exception3, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X);
             NotSupportedException exception5 = new NotSupportedException(str8, innerException);
             throw exception5;
         }
     }
     string message = System.Windows.Forms.SR.GetString("TypeLoadException", new object[] { typeName, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X });
     XmlException inner = new XmlException(message, null, dataNodeInfo.ReaderPosition.Y, dataNodeInfo.ReaderPosition.X);
     TypeLoadException exception7 = new TypeLoadException(message, inner);
     throw exception7;
 }
コード例 #25
0
        public void ShowXmlNotWellFormed()
        {
            XmlException ex = new XmlException("Message");
            treeViewContainer.ShowXmlIsNotWellFormedMessage(ex);

            Assert.AreEqual(0, treeView.Nodes.Count, "TreeView should be cleared.");
            Assert.AreEqual(ex.Message, treeViewContainer.ErrorMessage);
            Assert.AreEqual(0, splitContainer.Panel2.Controls.IndexOf(errorMessageTextBox), "ErrorMessageTextBox should be on top");
            Assert.AreEqual(ex.Message, errorMessageTextBox.Text);
            Assert.IsTrue(errorMessageTextBox.TabStop);
            Assert.IsFalse(attributesGrid.TabStop);
            Assert.IsFalse(textBox.TabStop);
        }
コード例 #26
0
 public abstract void OnXmlException(XmlException ex);
コード例 #27
0
 public BuildFileLoadException(string message, XmlException error)
     : this(message, error.LineNumber, error.LinePosition, error)
 {
 }
コード例 #28
0
ファイル: InternalDeserializer.cs プロジェクト: nickchal/pash
 private XmlException NewXmlException(string resourceString, Exception innerException, params object[] args)
 {
     string message = StringUtil.Format(resourceString, args);
     XmlException exception = null;
     XmlTextReader reader = this._reader as XmlTextReader;
     if ((reader != null) && reader.HasLineInfo())
     {
         exception = new XmlException(message, innerException, reader.LineNumber, reader.LinePosition);
     }
     if (exception == null)
     {
         exception = new XmlException(message, innerException);
     }
     return exception;
 }
コード例 #29
0
        private void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(SR.Xml_EmptyName);
            }
            int len = ValidateNames.ParseNCName(ncname, 0);

            if (len != ncname.Length)
            {
                throw new ArgumentException(SR.Format(len == 0 ? SR.Xml_BadStartNameChar : SR.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(ncname, len)));
            }
        }
コード例 #30
0
		private void LoadData ()
		{
			hasht = new Hashtable ();
#if NET_2_0
			hashtm = new Hashtable ();
#endif
			if (fileName != null) {
				stream = File.OpenRead (fileName);
			}

			try {
				xmlReader = null;
				if (stream != null) {
					xmlReader = new XmlTextReader (stream);
				} else if (reader != null) {
					xmlReader = new XmlTextReader (reader);
				}

				if (xmlReader == null) {
					throw new InvalidOperationException ("ResourceReader is closed.");
				}

				xmlReader.WhitespaceHandling = WhitespaceHandling.None;

				ResXHeader header = new ResXHeader ();
				try {
					while (xmlReader.Read ()) {
						if (xmlReader.NodeType != XmlNodeType.Element)
							continue;

						switch (xmlReader.LocalName) {
						case "resheader":
							ParseHeaderNode (header);
							break;
						case "data":
							ParseDataNode (false);
							break;
#if NET_2_0
						case "metadata":
							ParseDataNode (true);
							break;
#endif
						}
					}
#if NET_2_0
				} catch (XmlException ex) {
					throw new ArgumentException ("Invalid ResX input.", ex);
				} catch (Exception ex) {
					XmlException xex = new XmlException (ex.Message, ex, 
						xmlReader.LineNumber, xmlReader.LinePosition);
					throw new ArgumentException ("Invalid ResX input.", xex);
				}
#else
				} catch (Exception ex) {
					throw new ArgumentException ("Invalid ResX input.", ex);
				}
#endif
				header.Verify ();
			} finally {
コード例 #31
0
		public void ShowXmlIsNotWellFormedMessage(XmlException ex)
		{
			ShowErrorMessage(ex.Message);
		}
コード例 #32
0
        private void ReadXml()
        {
            try
            {
                XmlReader xmlReader = XmlReader.Create(_streamReader, InternalDeserializer.XmlReaderSettingsForCliXml);
                Deserializer des = new Deserializer(xmlReader);
                while (!des.Done())
                {
                    string streamName;
                    object obj = des.Deserialize(out streamName);

                    //Decide the stream to which data belongs
                    MinishellStream stream = MinishellStream.Unknown;
                    if (streamName != null)
                    {
                        stream = StringToMinishellStreamConverter.ToMinishellStream(streamName);
                    }
                    if (stream == MinishellStream.Unknown)
                    {
                        stream = _isOutput ? MinishellStream.Output : MinishellStream.Error;
                    }

                    //Null is allowed only in output stream
                    if (stream != MinishellStream.Output && obj == null)
                    {
                        continue;
                    }

                    if (stream == MinishellStream.Error)
                    {
                        if (obj is PSObject)
                        {
                            obj = ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj));
                        }
                        else
                        {
                            string errorMessage = null;
                            try
                            {
                                errorMessage = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                            }
                            catch (PSInvalidCastException)
                            {
                                continue;
                            }
                            obj = new ErrorRecord(new RemoteException(errorMessage),
                                                "NativeCommandError", ErrorCategory.NotSpecified, errorMessage);
                        }
                    }
                    else if (stream == MinishellStream.Information)
                    {
                        if (obj is PSObject)
                        {
                            obj = InformationRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj));
                        }
                        else
                        {
                            string messageData = null;
                            try
                            {
                                messageData = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                            }
                            catch (PSInvalidCastException)
                            {
                                continue;
                            }

                            obj = new InformationRecord(messageData, null);
                        }
                    }
                    else if (stream == MinishellStream.Debug ||
                             stream == MinishellStream.Verbose ||
                             stream == MinishellStream.Warning)
                    {
                        //Convert to string
                        try
                        {
                            obj = LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture);
                        }
                        catch (PSInvalidCastException)
                        {
                            continue;
                        }
                    }
                    AddObjectToWriter(obj, stream);
                }
            }
            catch (XmlException originalException)
            {
                string template = NativeCP.CliXmlError;
                string message = string.Format(
                    null,
                    template,
                    _isOutput ? MinishellStream.Output : MinishellStream.Error,
                    _processPath,
                    originalException.Message);
                XmlException newException = new XmlException(
                    message,
                    originalException);

                ErrorRecord error = new ErrorRecord(
                    newException,
                    "ProcessStreamReader_CliXmlError",
                    ErrorCategory.SyntaxError,
                    _processPath);
                AddObjectToWriter(error, MinishellStream.Error);
            }
        }
コード例 #33
0
 /// <summary>
 /// Constructs an instance based on a <see cref="XmlException"/> that occurred.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="ex"></param>
 public XmlFileValidationErrorList( string filePath, XmlException ex )
 {
     Path = filePath;
     Errors = new List<XmlValidationError> { new XmlValidationError( ex ) };
     XmlExceptionOccurred = true;
 }
コード例 #34
0
 public ApiXmlException(ApiEdit editor, XmlException innerException, string get, string post, string content)
     : base(editor, "XmlException in ApiEdit.CheckForErrors", innerException)
 {
     GetUrl = get;
     PostQuery = post;
     Content = content;
 }
コード例 #35
0
        private void ValidateNCName(string ncname)
        {
            if (ncname.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.Xml_EmptyName));
            }
            int len = ValidateNames.ParseNCName(ncname, 0);

            if (len != ncname.Length)
            {
                throw new ArgumentException(Res.GetString(len == 0 ? Res.Xml_BadStartNameChar : Res.Xml_BadNameChar, XmlException.BuildCharExceptionStr(ncname[len])));
            }
        }
コード例 #36
0
		/// <summary>
		/// Adds an error to the list.
		/// </summary>
		public void AddError(string fileName, XmlException ex)
		{
			SetupDialogErrorListViewItem errorItem = new SetupDialogErrorListViewItem(fileName, ex);
			Items.Add(errorItem);
		}
コード例 #37
0
 public Ds3BadResponseException(XmlException innerException)
     : base(BuildResponseParseException(innerException), innerException)
 {
 }
コード例 #38
0
 private static string BuildResponseParseException(XmlException innerException)
 {
     return string.Format(Resources.XmlResponseErrorException, innerException.Message);
 }
コード例 #39
0
 public override void WriteWhitespace(string ws)
 {
     // "checkNames" is intentional here; if false, the whitespaces are checked in XmlWellformedWriter
     if (checkNames)
     {
         int i;
         if ((i = xmlCharType.IsOnlyWhitespaceWithPos(ws)) != -1)
         {
             throw new ArgumentException(Res.GetString(Res.Xml_InvalidWhitespaceCharacter, XmlException.BuildCharExceptionStr(ws[i])));
         }
     }
     writer.WriteWhitespace(ws);
 }