2
0

ValidationHandler.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. using System;
  22. namespace System.Xml.Schema
  23. {
  24. /// <summary>
  25. /// </summary>
  26. public delegate void ValidationEventHandler(object sender,ValidationEventArgs e);
  27. /// <summary>
  28. /// Docs say we need to raise an exception if ValidationEventHandler is not set(null)
  29. /// So we use this class to raise the events rather than calling the delegate by itself
  30. /// </summary>
  31. internal class ValidationHandler
  32. {
  33. public static void RaiseValidationEvent(ValidationEventHandler handle,
  34. Exception innerException,
  35. string message,
  36. XmlSchemaObject xsobj,
  37. object sender,
  38. string sourceUri,
  39. XmlSeverityType severity)
  40. {
  41. XmlSchemaException ex = new XmlSchemaException (
  42. message, sender, sourceUri, xsobj, innerException);
  43. ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);
  44. if(handle == null)
  45. {
  46. if (e.Severity == XmlSeverityType.Error)
  47. throw e.Exception;
  48. }
  49. else
  50. {
  51. handle(sender,e);
  52. }
  53. }
  54. /*
  55. public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException, object sender, string message, XmlSeverityType severity)
  56. {
  57. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  58. }
  59. public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)
  60. {
  61. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  62. }
  63. public static void RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)
  64. {
  65. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);
  66. }
  67. public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
  68. {
  69. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
  70. }
  71. public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)
  72. {
  73. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);
  74. }
  75. */
  76. }
  77. }