From edfc86d84da81fcabc00bb27e875f26038bf94f7 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Mon, 4 Nov 2019 21:02:12 +0800 Subject: Complete designing timeline service though there may be many bugs in the design. --- Timeline/Resources/Services/Exception.Designer.cs | 18 +++++++ Timeline/Resources/Services/Exception.resx | 6 +++ Timeline/Services/TimelineAlreadyExistException.cs | 17 ++++++ .../TimelineMemberOperationUserException.cs | 28 ++++++++++ Timeline/Services/TimelineService.cs | 63 ++++++++++++++-------- .../Services/TimelineUserNotMemberException.cs | 15 ++++++ 6 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 Timeline/Services/TimelineAlreadyExistException.cs create mode 100644 Timeline/Services/TimelineMemberOperationUserException.cs create mode 100644 Timeline/Services/TimelineUserNotMemberException.cs (limited to 'Timeline') diff --git a/Timeline/Resources/Services/Exception.Designer.cs b/Timeline/Resources/Services/Exception.Designer.cs index a5785cb6..1f6493cb 100644 --- a/Timeline/Resources/Services/Exception.Designer.cs +++ b/Timeline/Resources/Services/Exception.Designer.cs @@ -267,6 +267,15 @@ namespace Timeline.Resources.Services { } } + /// + /// Looks up a localized string similar to The timeline with that name already exists.. + /// + internal static string TimelineAlreadyExistException { + get { + return ResourceManager.GetString("TimelineAlreadyExistException", resourceCulture); + } + } + /// /// Looks up a localized string similar to An exception happened when add or remove member on timeline.. /// @@ -303,6 +312,15 @@ namespace Timeline.Resources.Services { } } + /// + /// Looks up a localized string similar to The use is not a member of the timeline.. + /// + internal static string TimelineUserNotMemberException { + get { + return ResourceManager.GetString("TimelineUserNotMemberException", resourceCulture); + } + } + /// /// Looks up a localized string similar to The username is of bad format.. /// diff --git a/Timeline/Resources/Services/Exception.resx b/Timeline/Resources/Services/Exception.resx index e6622094..3e9d3747 100644 --- a/Timeline/Resources/Services/Exception.resx +++ b/Timeline/Resources/Services/Exception.resx @@ -186,6 +186,9 @@ version claim is not a number. + + The timeline with that name already exists. + An exception happened when add or remove member on timeline. @@ -198,6 +201,9 @@ Timeline does not exist. If this is a personal timeline, it means the user does not exist and inner exception should be a UserNotExistException. + + The use is not a member of the timeline. + The username is of bad format. diff --git a/Timeline/Services/TimelineAlreadyExistException.cs b/Timeline/Services/TimelineAlreadyExistException.cs new file mode 100644 index 00000000..c2dea1f9 --- /dev/null +++ b/Timeline/Services/TimelineAlreadyExistException.cs @@ -0,0 +1,17 @@ +using System; + +namespace Timeline.Services +{ + [Serializable] + public class TimelineAlreadyExistException : Exception + { + public TimelineAlreadyExistException() : base(Resources.Services.Exception.TimelineAlreadyExistException) { } + public TimelineAlreadyExistException(string name) : base(Resources.Services.Exception.TimelineAlreadyExistException) { Name = name; } + public TimelineAlreadyExistException(string name, Exception inner) : base(Resources.Services.Exception.TimelineAlreadyExistException, inner) { Name = name; } + protected TimelineAlreadyExistException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + + public string? Name { get; set; } + } +} diff --git a/Timeline/Services/TimelineMemberOperationUserException.cs b/Timeline/Services/TimelineMemberOperationUserException.cs new file mode 100644 index 00000000..998f1a6e --- /dev/null +++ b/Timeline/Services/TimelineMemberOperationUserException.cs @@ -0,0 +1,28 @@ +using System; +using System.Globalization; + +namespace Timeline.Services +{ + [Serializable] + public class TimelineMemberOperationUserException : Exception + { + public TimelineMemberOperationUserException() : base(Resources.Services.Exception.TimelineMemberOperationException) { } + public TimelineMemberOperationUserException(string message) : base(message) { } + public TimelineMemberOperationUserException(string message, Exception inner) : base(message, inner) { } + protected TimelineMemberOperationUserException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + + public TimelineMemberOperationUserException(int index, string username, Exception inner) : base(MakeIndexMessage(index), inner) { Index = index; Username = username; } + + private static string MakeIndexMessage(int index) => string.Format(CultureInfo.CurrentCulture, + Resources.Services.Exception.TimelineMemberOperationExceptionIndex, index); + + /// + /// The index of the member on which the operation failed. + /// + public int? Index { get; set; } + + public string? Username { get; set; } + } +} diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index cf130a70..9d309e7e 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Threading.Tasks; using Timeline.Entities; @@ -8,25 +7,6 @@ using Timeline.Models; namespace Timeline.Services { - - [Serializable] - public class TimelineMemberOperationException : Exception - { - public TimelineMemberOperationException() : base(Resources.Services.Exception.TimelineMemberOperationException) { } - public TimelineMemberOperationException(string message) : base(message) { } - public TimelineMemberOperationException(string message, Exception inner) : base(message, inner) { } - protected TimelineMemberOperationException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - - public TimelineMemberOperationException(int index, Exception inner) : base(MakeIndexMessage(index), inner) { Index = index; } - - private static string MakeIndexMessage(int index) => string.Format(CultureInfo.CurrentCulture, - Resources.Services.Exception.TimelineMemberOperationExceptionIndex, index); - - public int? Index { get; set; } - } - /// /// This define the common interface of both personal timeline /// and normal timeline. @@ -141,8 +121,12 @@ namespace Timeline.Services /// For personal timeline, it means the user of that username does not exist /// and the inner exception should be a . /// - /// - /// TODO! complete this documents. + /// + /// Thrown when an exception occurs on users in the list. + /// The inner exception is + /// when one of the username is not valid. + /// The inner exception is + /// when one of the user does not exist. /// Task AddMember(string name, IList usernames); @@ -164,6 +148,13 @@ namespace Timeline.Services /// For personal timeline, it means the user of that username does not exist /// and the inner exception should be a . /// + /// + /// Thrown when an exception occurs on the user list. + /// The inner exception is + /// when one of the username is invalid. + /// The inner exception is + /// when one of the user is not a member of the timeline. + /// Task RemoveMember(string name, IList usernames); } @@ -177,6 +168,13 @@ namespace Timeline.Services /// /// The name of the timeline. /// The timeline info. + /// Thrown when is null. + /// + /// Thrown when timeline name is invalid. Currently it means it is an empty string. + /// + /// + /// Thrown when timeline with the name does not exist. + /// Task GetTimeline(string name); /// @@ -184,6 +182,18 @@ namespace Timeline.Services /// /// The name of the timeline. /// The owner of the timeline. + /// Thrown when or is null. + /// + /// Thrown when timeline name is invalid. Currently it means it is an empty string. + /// + /// + /// Thrown when the timeline already exists. + /// + /// + /// Thrown when the username of the owner is not valid. + /// + /// + /// Thrown when the owner user does not exist. Task CreateTimeline(string name, string owner); } @@ -194,6 +204,15 @@ namespace Timeline.Services /// /// The username of the owner of the personal timeline. /// The timeline info. + /// + /// Thrown when is null. + /// + /// + /// Thrown when is of bad format. Inner exception MUST be . + /// + /// + /// Thrown when the user does not exist. Inner exception MUST be . + /// Task GetTimeline(string username); } } diff --git a/Timeline/Services/TimelineUserNotMemberException.cs b/Timeline/Services/TimelineUserNotMemberException.cs new file mode 100644 index 00000000..260beb02 --- /dev/null +++ b/Timeline/Services/TimelineUserNotMemberException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Timeline.Services +{ + [Serializable] + public class TimelineUserNotMemberException : Exception + { + public TimelineUserNotMemberException() : base(Resources.Services.Exception.TimelineUserNotMemberException) { } + public TimelineUserNotMemberException(string message) : base(message) { } + public TimelineUserNotMemberException(string message, Exception inner) : base(message, inner) { } + protected TimelineUserNotMemberException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + } +} -- cgit v1.2.3