-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
206 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/PetroglyphTools/PG.StarWarsGame.Files.XML/ParseErrorEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Xml.Linq; | ||
using AnakinRaW.CommonUtilities; | ||
|
||
namespace PG.StarWarsGame.Files.XML; | ||
|
||
public class ParseErrorEventArgs : EventArgs | ||
{ | ||
public string File { get; } | ||
|
||
public XElement? Element { get; } | ||
|
||
public XmlParseErrorKind ErrorKind { get; } | ||
|
||
public string Message { get; } | ||
|
||
public ParseErrorEventArgs(string file, XElement? element, XmlParseErrorKind errorKind, string message) | ||
{ | ||
ThrowHelper.ThrowIfNullOrEmpty(file); | ||
File = file; | ||
Element = element; | ||
ErrorKind = errorKind; | ||
Message = message; | ||
} | ||
|
||
public static ParseErrorEventArgs FromMissingFile(string file) | ||
{ | ||
ThrowHelper.ThrowIfNullOrEmpty(file); | ||
return new ParseErrorEventArgs(file, null, XmlParseErrorKind.MissingFile, $"XML file '{file}' not found."); | ||
} | ||
|
||
public static ParseErrorEventArgs FromEmptyRoot(string file, XElement element) | ||
{ | ||
ThrowHelper.ThrowIfNullOrEmpty(file); | ||
return new ParseErrorEventArgs(file, element, XmlParseErrorKind.EmptyRoot, $"XML file '{file}' has an empty root node."); | ||
} | ||
} | ||
|
||
public enum XmlParseErrorKind | ||
{ | ||
/// <summary> | ||
/// The error not specified any further. | ||
/// </summary> | ||
Unknown, | ||
/// <summary> | ||
/// The XML file could not be found. | ||
/// </summary> | ||
MissingFile, | ||
/// <summary> | ||
/// The root node of an XML file is empty. | ||
/// </summary> | ||
EmptyRoot, | ||
/// <summary> | ||
/// A tag's value is syntactically correct, but the semantics of value are not valid. For example, | ||
/// when the input is '-1' but an uint type is expected. | ||
/// </summary> | ||
InvalidValue, | ||
/// <summary> | ||
/// A tag's value is has an invalid syntax. | ||
/// </summary> | ||
MalformedValue, | ||
/// <summary> | ||
/// The value is too long | ||
/// </summary> | ||
TooLongData, | ||
/// <summary> | ||
/// The data is missing an XML attribute. Usually this is the Name attribute. | ||
/// </summary> | ||
MissingAttribute, | ||
/// <summary> | ||
/// The data points to a non-existing reference. | ||
/// </summary> | ||
MissingReference, | ||
} |
9 changes: 6 additions & 3 deletions
9
src/PetroglyphTools/PG.StarWarsGame.Files.XML/Parsers/IPetroglyphXmlParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
using System.Xml.Linq; | ||
using System; | ||
using System.Xml.Linq; | ||
|
||
namespace PG.StarWarsGame.Files.XML.Parsers; | ||
|
||
public interface IPetroglyphXmlParser | ||
{ | ||
public object Parse(XElement element); | ||
event EventHandler<ParseErrorEventArgs> ParseError; | ||
|
||
object Parse(XElement element); | ||
} | ||
|
||
public interface IPetroglyphXmlParser<T> : IPetroglyphXmlParser | ||
{ | ||
public new T Parse(XElement element); | ||
new T Parse(XElement element); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.