diff options
author | 杨宇千 <crupest@outlook.com> | 2019-11-04 21:02:12 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-11-04 21:02:12 +0800 |
commit | edfc86d84da81fcabc00bb27e875f26038bf94f7 (patch) | |
tree | 3adcbc9e73cf98d6ee2ae0566ad0578b351edb5e | |
parent | 640b80e501ef7f6240afdd968de4b23cd57f2ae1 (diff) | |
download | timeline-edfc86d84da81fcabc00bb27e875f26038bf94f7.tar.gz timeline-edfc86d84da81fcabc00bb27e875f26038bf94f7.tar.bz2 timeline-edfc86d84da81fcabc00bb27e875f26038bf94f7.zip |
Complete designing timeline service though there may be many bugs in the design.
-rw-r--r-- | Timeline/Resources/Services/Exception.Designer.cs | 18 | ||||
-rw-r--r-- | Timeline/Resources/Services/Exception.resx | 6 | ||||
-rw-r--r-- | Timeline/Services/TimelineAlreadyExistException.cs | 17 | ||||
-rw-r--r-- | Timeline/Services/TimelineMemberOperationUserException.cs | 28 | ||||
-rw-r--r-- | Timeline/Services/TimelineService.cs | 63 | ||||
-rw-r--r-- | Timeline/Services/TimelineUserNotMemberException.cs | 15 |
6 files changed, 125 insertions, 22 deletions
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 @@ -268,6 +268,15 @@ namespace Timeline.Resources.Services { }
/// <summary>
+ /// Looks up a localized string similar to The timeline with that name already exists..
+ /// </summary>
+ internal static string TimelineAlreadyExistException {
+ get {
+ return ResourceManager.GetString("TimelineAlreadyExistException", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to An exception happened when add or remove member on timeline..
/// </summary>
internal static string TimelineMemberOperationException {
@@ -304,6 +313,15 @@ namespace Timeline.Resources.Services { }
/// <summary>
+ /// Looks up a localized string similar to The use is not a member of the timeline..
+ /// </summary>
+ internal static string TimelineUserNotMemberException {
+ get {
+ return ResourceManager.GetString("TimelineUserNotMemberException", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to The username is of bad format..
/// </summary>
internal static string UsernameBadFormatException {
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 @@ <data name="JwtVerifyExceptionVersionClaimBadFormat" xml:space="preserve">
<value>version claim is not a number.</value>
</data>
+ <data name="TimelineAlreadyExistException" xml:space="preserve">
+ <value>The timeline with that name already exists.</value>
+ </data>
<data name="TimelineMemberOperationException" xml:space="preserve">
<value>An exception happened when add or remove member on timeline.</value>
</data>
@@ -198,6 +201,9 @@ <data name="TimelineNotExistException" xml:space="preserve">
<value>Timeline does not exist. If this is a personal timeline, it means the user does not exist and inner exception should be a UserNotExistException.</value>
</data>
+ <data name="TimelineUserNotMemberException" xml:space="preserve">
+ <value>The use is not a member of the timeline.</value>
+ </data>
<data name="UsernameBadFormatException" xml:space="preserve">
<value>The username is of bad format.</value>
</data>
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);
+
+ /// <summary>
+ /// The index of the member on which the operation failed.
+ /// </summary>
+ 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; }
- }
-
/// <summary>
/// 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 <see cref="UserNotExistException"/>.
/// </exception>
- /// <exception cref="TimelineMemberOperationException">
- /// TODO! complete this documents.
+ /// <exception cref="TimelineMemberOperationUserException">
+ /// Thrown when an exception occurs on users in the list.
+ /// The inner exception is <see cref="UsernameBadFormatException"/>
+ /// when one of the username is not valid.
+ /// The inner exception is <see cref="UserNotExistException"/>
+ /// when one of the user does not exist.
/// </exception>
Task AddMember(string name, IList<string> 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 <see cref="UserNotExistException"/>.
/// </exception>
+ /// <exception cref="TimelineMemberOperationUserException">
+ /// Thrown when an exception occurs on the user list.
+ /// The inner exception is <see cref="UsernameBadFormatException"/>
+ /// when one of the username is invalid.
+ /// The inner exception is <see cref="TimelineUserNotMemberException"/>
+ /// when one of the user is not a member of the timeline.
+ /// </exception>
Task RemoveMember(string name, IList<string> usernames);
}
@@ -177,6 +168,13 @@ namespace Timeline.Services /// </summary>
/// <param name="name">The name of the timeline.</param>
/// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> is null.</exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when timeline name is invalid. Currently it means it is an empty string.
+ /// </exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when timeline with the name does not exist.
+ /// </exception>
Task<TimelineInfo> GetTimeline(string name);
/// <summary>
@@ -184,6 +182,18 @@ namespace Timeline.Services /// </summary>
/// <param name="name">The name of the timeline.</param>
/// <param name="owner">The owner of the timeline.</param>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="name"/> or <paramref name="owner"/> is null.</exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when timeline name is invalid. Currently it means it is an empty string.
+ /// </exception>
+ /// <exception cref="TimelineAlreadyExistException">
+ /// Thrown when the timeline already exists.
+ /// </exception>
+ /// <exception cref="UsernameBadFormatException">
+ /// Thrown when the username of the owner is not valid.
+ /// </exception>
+ /// <exception cref="UserNotExistException">
+ /// Thrown when the owner user does not exist.</exception>
Task CreateTimeline(string name, string owner);
}
@@ -194,6 +204,15 @@ namespace Timeline.Services /// </summary>
/// <param name="username">The username of the owner of the personal timeline.</param>
/// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">
+ /// Thrown when <paramref name="username"/> is null.
+ /// </exception>
+ /// <exception cref="TimelineNameBadFormatException">
+ /// Thrown when <paramref name="username"/> is of bad format. Inner exception MUST be <see cref="UsernameBadFormatException"/>.
+ /// </exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when the user does not exist. Inner exception MUST be <see cref="UserNotExistException"/>.
+ /// </exception>
Task<BaseTimelineInfo> 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) { }
+ }
+}
|