aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-31 00:42:06 +0800
committerGitHub <noreply@github.com>2020-10-31 00:42:06 +0800
commit1b80b699e477a0c14a069401cf39126d19668bf0 (patch)
tree0d1c10cd42398bea87e0169e8a4ec385b71f49bc /BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs
parent0062a22423806c9501752132133e14de02355760 (diff)
parent5875e7a19ff8eb244e2849647ba35aa898de6b52 (diff)
downloadtimeline-1b80b699e477a0c14a069401cf39126d19668bf0.tar.gz
timeline-1b80b699e477a0c14a069401cf39126d19668bf0.tar.bz2
timeline-1b80b699e477a0c14a069401cf39126d19668bf0.zip
Merge pull request #161 from crupest/upgrade
Upgrade packages and split front end and back end.
Diffstat (limited to 'BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs')
-rw-r--r--BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs b/BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs
new file mode 100644
index 00000000..7db2e860
--- /dev/null
+++ b/BackEnd/Timeline/Services/Exceptions/EntityAlreadyExistError.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Globalization;
+using System.Text;
+
+namespace Timeline.Services.Exceptions
+{
+ /// <summary>
+ /// Thrown when an entity is already exists.
+ /// </summary>
+ /// <remarks>
+ /// For example, want to create a timeline but a timeline with the same name already exists.
+ /// </remarks>
+ [Serializable]
+ public class EntityAlreadyExistException : Exception
+ {
+ private readonly string? _entityName;
+
+ public EntityAlreadyExistException() : this(null, null, null, null) { }
+
+ public EntityAlreadyExistException(string? entityName) : this(entityName, null) { }
+
+ public EntityAlreadyExistException(string? entityName, Exception? inner) : this(entityName, null, null, null, inner) { }
+
+ public EntityAlreadyExistException(string? entityName, object? entity = null) : this(entityName, null, entity, null, null) { }
+ public EntityAlreadyExistException(Type? entityType, object? entity = null) : this(null, entityType, entity, null, null) { }
+ public EntityAlreadyExistException(string? entityName, Type? entityType, object? entity = null, string? message = null, Exception? inner = null) : base(MakeMessage(entityName, entityType, message), inner)
+ {
+ _entityName = entityName;
+ EntityType = entityType;
+ Entity = entity;
+ }
+
+ private static string MakeMessage(string? entityName, Type? entityType, string? message)
+ {
+ string? name = entityName ?? (entityType?.Name);
+
+ var result = new StringBuilder();
+
+ if (name == null)
+ result.Append(Resources.Services.Exceptions.EntityAlreadyExistErrorDefault);
+ else
+ result.AppendFormat(CultureInfo.InvariantCulture, Resources.Services.Exceptions.EntityAlreadyExistError, name);
+
+ if (message != null)
+ {
+ result.Append(' ');
+ result.Append(message);
+ }
+
+ return result.ToString();
+ }
+
+ protected EntityAlreadyExistException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public string? EntityName => _entityName ?? (EntityType?.Name);
+
+ public Type? EntityType { get; }
+
+ public object? Entity { get; }
+ }
+}