From af5bab651a56a04468654c06057ab6d5ee28f18b Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 29 Apr 2021 19:17:03 +0800 Subject: refactor: ... --- BackEnd/Timeline/GlobalSuppressions.cs | 3 - BackEnd/Timeline/Helpers/LanguageHelper.cs | 12 -- .../Resources/Services/TimelineService.Designer.cs | 144 -------------------- .../Resources/Services/TimelineService.resx | 147 --------------------- .../Services/UserTokenService.Designer.cs | 72 ---------- .../Resources/Services/UserTokenService.resx | 123 ----------------- .../Services/Timeline/Resource.Designer.cs | 135 +++++++++++++++++++ BackEnd/Timeline/Services/Timeline/Resource.resx | 45 +++++++ .../Services/Timeline/TimelinePostService.cs | 33 +++-- .../Timeline/Services/Timeline/TimelineService.cs | 15 ++- .../Timeline/Services/Token/Resource.Designer.cs | 9 ++ BackEnd/Timeline/Services/Token/Resource.resx | 3 + .../Timeline/Services/Token/UserTokenHandler.cs | 2 +- BackEnd/Timeline/Timeline.csproj | 18 --- 14 files changed, 222 insertions(+), 539 deletions(-) delete mode 100644 BackEnd/Timeline/Helpers/LanguageHelper.cs delete mode 100644 BackEnd/Timeline/Resources/Services/TimelineService.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Services/TimelineService.resx delete mode 100644 BackEnd/Timeline/Resources/Services/UserTokenService.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Services/UserTokenService.resx (limited to 'BackEnd') diff --git a/BackEnd/Timeline/GlobalSuppressions.cs b/BackEnd/Timeline/GlobalSuppressions.cs index 1d6905a5..52d36ff7 100644 --- a/BackEnd/Timeline/GlobalSuppressions.cs +++ b/BackEnd/Timeline/GlobalSuppressions.cs @@ -10,7 +10,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Generated error response identifiers.", Scope = "type", Target = "~T:Timeline.Models.Http.ErrorResponse")] [assembly: SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Generated error response identifiers.", Scope = "type", Target = "~T:Timeline.Models.Http.ErrorResponse")] [assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "Generated error response.", Scope = "type", Target = "~T:Timeline.Models.Http.ErrorResponse")] -[assembly: SuppressMessage("Design", "CA1056:Uri properties should not be strings", Justification = "That's unnecessary.")] [assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Redundant")] -[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "No localization demand.")] -[assembly: SuppressMessage("Design", "CA1054:URI-like parameters should not be strings")] diff --git a/BackEnd/Timeline/Helpers/LanguageHelper.cs b/BackEnd/Timeline/Helpers/LanguageHelper.cs deleted file mode 100644 index b0156b8b..00000000 --- a/BackEnd/Timeline/Helpers/LanguageHelper.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Linq; - -namespace Timeline.Helpers -{ - public static class LanguageHelper - { - public static bool AreSame(this bool firstBool, params bool[] otherBools) - { - return otherBools.All(b => b == firstBool); - } - } -} diff --git a/BackEnd/Timeline/Resources/Services/TimelineService.Designer.cs b/BackEnd/Timeline/Resources/Services/TimelineService.Designer.cs deleted file mode 100644 index e16c1337..00000000 --- a/BackEnd/Timeline/Resources/Services/TimelineService.Designer.cs +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Services { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class TimelineService { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal TimelineService() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.TimelineService", typeof(TimelineService).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to The number {0} username is invalid.. - /// - internal static string ExceptionChangeMemberUsernameBadFormat { - get { - return ResourceManager.GetString("ExceptionChangeMemberUsernameBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unknown post content type "{0}" is saved in database.. - /// - internal static string ExceptionDatabaseUnknownContentType { - get { - return ResourceManager.GetString("ExceptionDatabaseUnknownContentType", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The owner username of personal timeline is of bad format.. - /// - internal static string ExceptionFindTimelineUsernameBadFormat { - get { - return ResourceManager.GetString("ExceptionFindTimelineUsernameBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The data entry of the tag of the image post does not exist.. - /// - internal static string ExceptionGetDataDataEntryNotExist { - get { - return ResourceManager.GetString("ExceptionGetDataDataEntryNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Can't get data of a non-image post.. - /// - internal static string ExceptionGetDataNonImagePost { - get { - return ResourceManager.GetString("ExceptionGetDataNonImagePost", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The post has been deleted because content of entity is null.. - /// - internal static string ExceptionPostDeleted { - get { - return ResourceManager.GetString("ExceptionPostDeleted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The timeline name is of bad format.. - /// - internal static string ExceptionTimelineNameBadFormat { - get { - return ResourceManager.GetString("ExceptionTimelineNameBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The timeline with given name already exists.. - /// - internal static string ExceptionTimelineNameConflict { - get { - return ResourceManager.GetString("ExceptionTimelineNameConflict", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Image format type of the post does not exist in column "extra_content". Normally this couldn't be possible because it should be saved when post was created. However, we now re-detect the format and save it.. - /// - internal static string LogGetDataNoFormat { - get { - return ResourceManager.GetString("LogGetDataNoFormat", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Services/TimelineService.resx b/BackEnd/Timeline/Resources/Services/TimelineService.resx deleted file mode 100644 index 9314f51b..00000000 --- a/BackEnd/Timeline/Resources/Services/TimelineService.resx +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - The number {0} username is invalid. - - - Unknown post content type "{0}" is saved in database. - - - The owner username of personal timeline is of bad format. - - - The data entry of the tag of the image post does not exist. - - - Can't get data of a non-image post. - - - The timeline name is of bad format. - - - The timeline with given name already exists. - - - Image format type of the post does not exist in column "extra_content". Normally this couldn't be possible because it should be saved when post was created. However, we now re-detect the format and save it. - - - The post has been deleted because content of entity is null. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Resources/Services/UserTokenService.Designer.cs b/BackEnd/Timeline/Resources/Services/UserTokenService.Designer.cs deleted file mode 100644 index 3c3c7e41..00000000 --- a/BackEnd/Timeline/Resources/Services/UserTokenService.Designer.cs +++ /dev/null @@ -1,72 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Services { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class UserTokenService { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal UserTokenService() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserTokenService", typeof(UserTokenService).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Jwt token key is not set in database. Maybe you forget to migrate the database.. - /// - internal static string JwtKeyNotExist { - get { - return ResourceManager.GetString("JwtKeyNotExist", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Services/UserTokenService.resx b/BackEnd/Timeline/Resources/Services/UserTokenService.resx deleted file mode 100644 index 1ce78427..00000000 --- a/BackEnd/Timeline/Resources/Services/UserTokenService.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Jwt token key is not set in database. Maybe you forget to migrate the database. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs b/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs index 6faea295..5ad03011 100644 --- a/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs +++ b/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs @@ -60,6 +60,42 @@ namespace Timeline.Services.Timeline { } } + /// + /// Looks up a localized string similar to Color is not valid. {0}. + /// + internal static string ExceptionColorInvalid { + get { + return ResourceManager.GetString("ExceptionColorInvalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Data list can't be empty.. + /// + internal static string ExceptionDataListEmpty { + get { + return ResourceManager.GetString("ExceptionDataListEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Data list can't be null.. + /// + internal static string ExceptionDataListNull { + get { + return ResourceManager.GetString("ExceptionDataListNull", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Data list count can't be bigger than 100.. + /// + internal static string ExceptionDataListTooLarge { + get { + return ResourceManager.GetString("ExceptionDataListTooLarge", resourceCulture); + } + } + /// /// Looks up a localized string similar to This timeline name is neither a valid personal timeline name nor a valid ordinary timeline name. {0}. /// @@ -69,6 +105,33 @@ namespace Timeline.Services.Timeline { } } + /// + /// Looks up a localized string similar to Image validation failed.. + /// + internal static string ExceptionPostDataImageInvalid { + get { + return ResourceManager.GetString("ExceptionPostDataImageInvalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to It is not a valid utf-8 sequence.. + /// + internal static string ExceptionPostDataNotValidUtf8 { + get { + return ResourceManager.GetString("ExceptionPostDataNotValidUtf8", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unsupported content type.. + /// + internal static string ExceptionPostDataUnsupportedType { + get { + return ResourceManager.GetString("ExceptionPostDataUnsupportedType", resourceCulture); + } + } + /// /// Looks up a localized string similar to Timeline with given constraints already exist.. /// @@ -131,5 +194,77 @@ namespace Timeline.Services.Timeline { return ResourceManager.GetString("LogPersonalTimelineAutoCreate", resourceCulture); } } + + /// + /// Looks up a localized string similar to A member(user id={0}) is added to timeline(id={1}).. + /// + internal static string LogTimelineAddMember { + get { + return ResourceManager.GetString("LogTimelineAddMember", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A timeline is created with name={0}, id={1}.. + /// + internal static string LogTimelineCreate { + get { + return ResourceManager.GetString("LogTimelineCreate", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A timeline(id={0}) is deleted.. + /// + internal static string LogTimelineDelete { + get { + return ResourceManager.GetString("LogTimelineDelete", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A timeline(id={0}) post(id={1}) is created.. + /// + internal static string LogTimelinePostCreated { + get { + return ResourceManager.GetString("LogTimelinePostCreated", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A timeline(id={0}) post(id={1}) is deleted.. + /// + internal static string LogTimelinePostDeleted { + get { + return ResourceManager.GetString("LogTimelinePostDeleted", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A timeline(id={0}) post(id={1}) is updated.. + /// + internal static string LogTimelinePostUpdated { + get { + return ResourceManager.GetString("LogTimelinePostUpdated", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to A member(user id={0}) is removed from timeline(id={1}).. + /// + internal static string LogTimelineRemoveMember { + get { + return ResourceManager.GetString("LogTimelineRemoveMember", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Timeline with id={0} is updated.. + /// + internal static string LogTimelineUpdated { + get { + return ResourceManager.GetString("LogTimelineUpdated", resourceCulture); + } + } } } diff --git a/BackEnd/Timeline/Services/Timeline/Resource.resx b/BackEnd/Timeline/Services/Timeline/Resource.resx index 3a233e55..cc293d05 100644 --- a/BackEnd/Timeline/Services/Timeline/Resource.resx +++ b/BackEnd/Timeline/Services/Timeline/Resource.resx @@ -117,9 +117,30 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Color is not valid. {0} + + + Data list can't be empty. + + + Data list can't be null. + + + Data list count can't be bigger than 100. + This timeline name is neither a valid personal timeline name nor a valid ordinary timeline name. {0} + + Image validation failed. + + + It is not a valid utf-8 sequence. + + + Unsupported content type. + Timeline with given constraints already exist. @@ -141,4 +162,28 @@ A personal timeline for user with username={0} is created automatically. + + A member(user id={0}) is added to timeline(id={1}). + + + A timeline is created with name={0}, id={1}. + + + A timeline(id={0}) is deleted. + + + A timeline(id={0}) post(id={1}) is created. + + + A timeline(id={0}) post(id={1}) is deleted. + + + A timeline(id={0}) post(id={1}) is updated. + + + A member(user id={0}) is removed from timeline(id={1}). + + + Timeline with id={0} is updated. + \ No newline at end of file diff --git a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs index 65a01b37..a9bb7bd1 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs @@ -50,6 +50,12 @@ namespace Timeline.Services.Timeline throw new UserNotExistException(userId); } + private void CheckColor(string color, string paramName) + { + if (!_colorValidator.Validate(color, out var message)) + throw new ArgumentException(string.Format(Resource.ExceptionColorInvalid, message), paramName); + } + public async Task> GetPostsAsync(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false) { await CheckTimelineExistence(timelineId); @@ -139,19 +145,17 @@ namespace Timeline.Services.Timeline if (request is null) throw new ArgumentNullException(nameof(request)); - { - if (!_colorValidator.Validate(request.Color, out var message)) - throw new ArgumentException("Color is not valid.", nameof(request)); - } + if (request.Color is not null) + CheckColor(request.Color, nameof(request)); if (request.DataList is null) - throw new ArgumentException("Data list can't be null.", nameof(request)); + throw new ArgumentException(Resource.ExceptionDataListNull, nameof(request)); if (request.DataList.Count == 0) - throw new ArgumentException("Data list can't be empty.", nameof(request)); + throw new ArgumentException(Resource.ExceptionDataListEmpty, nameof(request)); if (request.DataList.Count > 100) - throw new ArgumentException("Data list count can't be bigger than 100.", nameof(request)); + throw new ArgumentException(Resource.ExceptionDataListTooLarge, nameof(request)); for (int index = 0; index < request.DataList.Count; index++) { @@ -169,7 +173,7 @@ namespace Timeline.Services.Timeline } catch (ImageException e) { - throw new TimelinePostCreateDataException(index, "Image validation failed.", e); + throw new TimelinePostCreateDataException(index, Resource.ExceptionPostDataImageInvalid, e); } break; case MimeTypes.TextPlain: @@ -180,11 +184,11 @@ namespace Timeline.Services.Timeline } catch (DecoderFallbackException e) { - throw new TimelinePostCreateDataException(index, "Text is not a valid utf-8 sequence.", e); + throw new TimelinePostCreateDataException(index, Resource.ExceptionPostDataNotValidUtf8, e); } break; default: - throw new TimelinePostCreateDataException(index, "Unsupported content type."); + throw new TimelinePostCreateDataException(index, Resource.ExceptionPostDataUnsupportedType); } } @@ -234,6 +238,7 @@ namespace Timeline.Services.Timeline await _database.SaveChangesAsync(); await transaction.CommitAsync(); + _logger.LogInformation(Resource.LogTimelinePostCreated, timelineId, postEntity.Id); return postEntity; } @@ -243,10 +248,8 @@ namespace Timeline.Services.Timeline if (request is null) throw new ArgumentNullException(nameof(request)); - { - if (!_colorValidator.Validate(request.Color, out var message)) - throw new ArgumentException("Color is not valid.", nameof(request)); - } + if (request.Color is not null) + CheckColor(request.Color, nameof(request)); request.Time = request.Time?.MyToUtc(); @@ -269,6 +272,7 @@ namespace Timeline.Services.Timeline entity.LastUpdated = _clock.GetCurrentTime(); await _database.SaveChangesAsync(); + _logger.LogInformation(Resource.LogTimelinePostUpdated, timelineId, postId); return entity; } @@ -302,6 +306,7 @@ namespace Timeline.Services.Timeline await _database.SaveChangesAsync(); await transaction.CommitAsync(); + _logger.LogWarning(Resource.LogTimelinePostDeleted, timelineId, postId); } public async Task DeleteAllPostsOfUserAsync(long userId) diff --git a/BackEnd/Timeline/Services/Timeline/TimelineService.cs b/BackEnd/Timeline/Services/Timeline/TimelineService.cs index cea93272..bde0210a 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelineService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelineService.cs @@ -23,7 +23,6 @@ namespace Timeline.Services.Timeline private readonly IClock _clock; private readonly TimelineNameValidator _timelineNameValidator = new TimelineNameValidator(); - private readonly ColorValidator _colorValidator = new ColorValidator(); public TimelineService(ILoggerFactory loggerFactory, DatabaseContext database, IBasicUserService userService, IClock clock) @@ -36,7 +35,7 @@ namespace Timeline.Services.Timeline } - private void ValidateTimelineName(string name, string paramName) + private void CheckTimelineName(string name, string paramName) { if (!_timelineNameValidator.Validate(name, out var message)) { @@ -60,7 +59,7 @@ namespace Timeline.Services.Timeline throw new ArgumentNullException(nameof(newProperties)); if (newProperties.Name is not null) - ValidateTimelineName(newProperties.Name, nameof(newProperties)); + CheckTimelineName(newProperties.Name, nameof(newProperties)); if (newProperties.Color is not null) { @@ -125,6 +124,7 @@ namespace Timeline.Services.Timeline } await _database.SaveChangesAsync(); + _logger.LogInformation(Resource.LogTimelineUpdated, id); } public async Task AddMemberAsync(long timelineId, long userId) @@ -138,7 +138,6 @@ namespace Timeline.Services.Timeline if (await _database.TimelineMembers.AnyAsync(m => m.TimelineId == timelineId && m.UserId == userId)) return false; - var entity = new TimelineMemberEntity { UserId = userId, TimelineId = timelineId }; _database.TimelineMembers.Add(entity); @@ -146,6 +145,8 @@ namespace Timeline.Services.Timeline timelineEntity.LastModified = _clock.GetCurrentTime(); await _database.SaveChangesAsync(); + _logger.LogInformation(Resource.LogTimelineAddMember, userId, timelineId); + return true; } @@ -166,6 +167,8 @@ namespace Timeline.Services.Timeline timelineEntity.LastModified = _clock.GetCurrentTime(); await _database.SaveChangesAsync(); + _logger.LogInformation(Resource.LogTimelineRemoveMember, userId, timelineId); + return true; } @@ -258,7 +261,7 @@ namespace Timeline.Services.Timeline if (name == null) throw new ArgumentNullException(nameof(name)); - ValidateTimelineName(name, nameof(name)); + CheckTimelineName(name, nameof(name)); var conflict = await _database.Timelines.AnyAsync(t => t.Name == name); @@ -269,6 +272,7 @@ namespace Timeline.Services.Timeline _database.Timelines.Add(entity); await _database.SaveChangesAsync(); + _logger.LogInformation(Resource.LogTimelineCreate, name, entity.Id); return entity; } @@ -282,6 +286,7 @@ namespace Timeline.Services.Timeline _database.Timelines.Remove(entity); await _database.SaveChangesAsync(); + _logger.LogWarning(Resource.LogTimelineDelete, id); } } } diff --git a/BackEnd/Timeline/Services/Token/Resource.Designer.cs b/BackEnd/Timeline/Services/Token/Resource.Designer.cs index 07b0057f..ac6f3707 100644 --- a/BackEnd/Timeline/Services/Token/Resource.Designer.cs +++ b/BackEnd/Timeline/Services/Token/Resource.Designer.cs @@ -60,6 +60,15 @@ namespace Timeline.Services.Token { } } + /// + /// Looks up a localized string similar to Jwt key is not found. Maybe you forget to do the migration.. + /// + internal static string ExceptionJwtKeyNotExist { + get { + return ResourceManager.GetString("ExceptionJwtKeyNotExist", resourceCulture); + } + } + /// /// Looks up a localized string similar to The token didn't pass verification because {0}.. /// diff --git a/BackEnd/Timeline/Services/Token/Resource.resx b/BackEnd/Timeline/Services/Token/Resource.resx index 7abf2e75..06bf03f6 100644 --- a/BackEnd/Timeline/Services/Token/Resource.resx +++ b/BackEnd/Timeline/Services/Token/Resource.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Jwt key is not found. Maybe you forget to do the migration. + The token didn't pass verification because {0}. diff --git a/BackEnd/Timeline/Services/Token/UserTokenHandler.cs b/BackEnd/Timeline/Services/Token/UserTokenHandler.cs index 7b57a06c..c1633f4a 100644 --- a/BackEnd/Timeline/Services/Token/UserTokenHandler.cs +++ b/BackEnd/Timeline/Services/Token/UserTokenHandler.cs @@ -29,7 +29,7 @@ namespace Timeline.Services.Token if (key == null) { - throw new InvalidOperationException(Resources.Services.UserTokenService.JwtKeyNotExist); + throw new InvalidOperationException(Resource.ExceptionJwtKeyNotExist); } _tokenSecurityKey = new SymmetricSecurityKey(key); diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj index 8cf1b31f..f77631c2 100644 --- a/BackEnd/Timeline/Timeline.csproj +++ b/BackEnd/Timeline/Timeline.csproj @@ -128,16 +128,6 @@ True Validator.resx - - True - True - TimelineService.resx - - - True - True - UserTokenService.resx - True True @@ -251,14 +241,6 @@ ResXFileCodeGenerator Validator.Designer.cs - - ResXFileCodeGenerator - TimelineService.Designer.cs - - - ResXFileCodeGenerator - UserTokenService.Designer.cs - ResXFileCodeGenerator Resource.Designer.cs -- cgit v1.2.3