aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/ImageException.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-12 19:56:20 +0800
committerGitHub <noreply@github.com>2020-03-12 19:56:20 +0800
commit904f98bda60b3bd92331aacde3771dedde62d2b5 (patch)
tree70681348ddfc3bc8c3d9a92ae010a02020830573 /Timeline/Services/ImageException.cs
parenta37874830399c193392cc78367efcecbe8275ceb (diff)
parentf8ff7e20eb5d5673575d36b8964a013765b77bf8 (diff)
downloadtimeline-904f98bda60b3bd92331aacde3771dedde62d2b5.tar.gz
timeline-904f98bda60b3bd92331aacde3771dedde62d2b5.tar.bz2
timeline-904f98bda60b3bd92331aacde3771dedde62d2b5.zip
Merge pull request #69 from crupest/image
Post image feature.
Diffstat (limited to 'Timeline/Services/ImageException.cs')
-rw-r--r--Timeline/Services/ImageException.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/Timeline/Services/ImageException.cs b/Timeline/Services/ImageException.cs
new file mode 100644
index 00000000..c6126aa3
--- /dev/null
+++ b/Timeline/Services/ImageException.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Globalization;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class ImageException : Exception
+ {
+ public enum ErrorReason
+ {
+ /// <summary>
+ /// Decoding image failed.
+ /// </summary>
+ CantDecode,
+ /// <summary>
+ /// Decoding succeeded but the real type is not the specified type.
+ /// </summary>
+ UnmatchedFormat,
+ /// <summary>
+ /// Image is not a square.
+ /// </summary>
+ NotSquare
+ }
+
+ public ImageException() : base(MakeMessage(null)) { }
+ public ImageException(string message) : base(message) { }
+ public ImageException(string message, Exception inner) : base(message, inner) { }
+
+ public ImageException(ErrorReason error, byte[]? data = null, string? requestType = null, string? realType = null) : base(MakeMessage(error)) { Error = error; ImageData = data; RequestType = requestType; RealType = realType; }
+ public ImageException(Exception inner, ErrorReason error, byte[]? data = null, string? requestType = null, string? realType = null) : base(MakeMessage(error), inner) { Error = error; ImageData = data; RequestType = requestType; RealType = realType; }
+
+ protected ImageException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ private static string MakeMessage(ErrorReason? reason) =>
+ string.Format(CultureInfo.InvariantCulture, Resources.Services.Exception.ImageException, reason switch
+ {
+ ErrorReason.CantDecode => Resources.Services.Exception.ImageExceptionCantDecode,
+ ErrorReason.UnmatchedFormat => Resources.Services.Exception.ImageExceptionUnmatchedFormat,
+ ErrorReason.NotSquare => Resources.Services.Exception.ImageExceptionBadSize,
+ _ => Resources.Services.Exception.ImageExceptionUnknownError
+ });
+
+ public ErrorReason? Error { get; }
+#pragma warning disable CA1819 // Properties should not return arrays
+ public byte[]? ImageData { get; }
+#pragma warning restore CA1819 // Properties should not return arrays
+ public string? RequestType { get; }
+
+ // This field will be null if decoding failed.
+ public string? RealType { get; }
+ }
+}