PostExceptions.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Text;
  5. namespace InABox.Core.Postable
  6. {
  7. #region BaseExceptions
  8. public class BasePosterException : Exception
  9. {
  10. public BasePosterException() : base() { }
  11. public BasePosterException(string message) : base(message) { }
  12. }
  13. public class MissingSettingException : BasePosterException
  14. {
  15. public Type SettingsType { get; }
  16. public string Setting { get; set; }
  17. public MissingSettingException(Type settingsType, string setting): base($"Missing setting '{setting}'")
  18. {
  19. SettingsType = settingsType;
  20. Setting = setting;
  21. }
  22. }
  23. public class MissingSettingException<T> : MissingSettingException
  24. {
  25. public MissingSettingException(Expression<Func<T, object?>> setting) : base(typeof(T), CoreUtils.GetFullPropertyName(setting, ".")) { }
  26. }
  27. public class MissingSettingsException : BasePosterException
  28. {
  29. public Type PostableType { get; }
  30. public MissingSettingsException(Type postableType) : base($"No PostableSettings for ${postableType}")
  31. {
  32. PostableType = postableType;
  33. }
  34. }
  35. #endregion
  36. #region PostExceptions
  37. public class PostException : BasePosterException
  38. {
  39. public PostException() : base() { }
  40. public PostException(string message) : base(message) { }
  41. }
  42. public class EmptyPostException : PostException
  43. {
  44. public EmptyPostException() { }
  45. }
  46. public class PostFailedMessageException : PostException
  47. {
  48. public PostFailedMessageException(string message): base(message) { }
  49. }
  50. public class RepostedException : PostException
  51. {
  52. public RepostedException() : base("Cannot process an item twice.")
  53. {
  54. }
  55. }
  56. public class PostCancelledException : PostException
  57. {
  58. public PostCancelledException() : base("Processing cancelled")
  59. {
  60. }
  61. }
  62. #endregion
  63. #region PullExceptions
  64. public class PullException : BasePosterException
  65. {
  66. public PullException() : base() { }
  67. public PullException(string message) : base(message) { }
  68. }
  69. public class PullCancelledException : PullException
  70. {
  71. public PullCancelledException(): base("Import cancelled") { }
  72. }
  73. public class PullFailedMessageException : PullException
  74. {
  75. public PullFailedMessageException(string message): base(message) { }
  76. }
  77. public class InvalidPullerException : PullException
  78. {
  79. public Type PostableType { get; set; }
  80. public Type? PosterType { get; set; }
  81. public InvalidPullerException(Type postableType)
  82. : base($"Cannot import {postableType.Name}")
  83. {
  84. PostableType = postableType;
  85. PosterType = null;
  86. }
  87. public InvalidPullerException(Type postableType, Type posterType)
  88. : base($"Cannot import {postableType.Name} with {posterType.GetCaptionOrNull(true) ?? posterType.Name}")
  89. {
  90. PostableType = postableType;
  91. PosterType = posterType;
  92. }
  93. }
  94. #endregion
  95. }