From 2a3c2d60cadbae348632ad9f2023367c5ea1e905 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 15 May 2021 19:22:13 +0800 Subject: refactor: Move strings to resource. --- BackEnd/Timeline/SignalRHub/Resource.Designer.cs | 108 ++++++++++++++++++ BackEnd/Timeline/SignalRHub/Resource.resx | 135 +++++++++++++++++++++++ BackEnd/Timeline/SignalRHub/TimelineHub.cs | 10 +- BackEnd/Timeline/Timeline.csproj | 9 ++ 4 files changed, 257 insertions(+), 5 deletions(-) create mode 100644 BackEnd/Timeline/SignalRHub/Resource.Designer.cs create mode 100644 BackEnd/Timeline/SignalRHub/Resource.resx (limited to 'BackEnd/Timeline') diff --git a/BackEnd/Timeline/SignalRHub/Resource.Designer.cs b/BackEnd/Timeline/SignalRHub/Resource.Designer.cs new file mode 100644 index 00000000..cdef0940 --- /dev/null +++ b/BackEnd/Timeline/SignalRHub/Resource.Designer.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// 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.SignalRHub { + 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 Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// 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.SignalRHub.Resource", typeof(Resource).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 Connection {0} is added to group {1} to listen to timeline post change.. + /// + internal static string LogSubscribeTimelinePostChange { + get { + return ResourceManager.GetString("LogSubscribeTimelinePostChange", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remove connection {0} from group {1} to stop listening to timeline post change.. + /// + internal static string LogUnsubscribeTimelinePostChange { + get { + return ResourceManager.GetString("LogUnsubscribeTimelinePostChange", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You are forbidden to do this.. + /// + internal static string MessageForbidden { + get { + return ResourceManager.GetString("MessageForbidden", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Timeline name is illegal.. + /// + internal static string MessageTimelineNameInvalid { + get { + return ResourceManager.GetString("MessageTimelineNameInvalid", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Timeline does not exist.. + /// + internal static string MessageTimelineNotExist { + get { + return ResourceManager.GetString("MessageTimelineNotExist", resourceCulture); + } + } + } +} diff --git a/BackEnd/Timeline/SignalRHub/Resource.resx b/BackEnd/Timeline/SignalRHub/Resource.resx new file mode 100644 index 00000000..699521d1 --- /dev/null +++ b/BackEnd/Timeline/SignalRHub/Resource.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Connection {0} is added to group {1} to listen to timeline post change. + + + Remove connection {0} from group {1} to stop listening to timeline post change. + + + You are forbidden to do this. + + + Timeline name is illegal. + + + Timeline does not exist. + + \ No newline at end of file diff --git a/BackEnd/Timeline/SignalRHub/TimelineHub.cs b/BackEnd/Timeline/SignalRHub/TimelineHub.cs index 2ad7bd66..0bfda84c 100644 --- a/BackEnd/Timeline/SignalRHub/TimelineHub.cs +++ b/BackEnd/Timeline/SignalRHub/TimelineHub.cs @@ -32,19 +32,19 @@ namespace Timeline.SignalRHub var timelineId = await _timelineService.GetTimelineIdByNameAsync(timelineName); var user = Context.User; if (!user.HasPermission(UserPermission.AllTimelineManagement) && !await _timelineService.HasReadPermissionAsync(timelineId, user.GetOptionalUserId())) - throw new HubException("Forbidden."); + throw new HubException(Resource.MessageForbidden); var group = GenerateTimelinePostChangeListeningGroupName(timelineName); await Groups.AddToGroupAsync(Context.ConnectionId, group); - _logger.LogInformation("Add connection {0} to group {1}", Context.ConnectionId, group); + _logger.LogInformation(Resource.LogSubscribeTimelinePostChange, Context.ConnectionId, group); } catch (ArgumentException) { - throw new HubException("Timeline name is illegal."); + throw new HubException(Resource.MessageTimelineNameInvalid); } catch (EntityNotExistException) { - throw new HubException("Timeline not exist."); + throw new HubException(Resource.MessageTimelineNotExist); } } @@ -52,7 +52,7 @@ namespace Timeline.SignalRHub { var group = GenerateTimelinePostChangeListeningGroupName(timelineName); await Groups.RemoveFromGroupAsync(Context.ConnectionId, group); - _logger.LogInformation("Remove connection {0} from group {1}", Context.ConnectionId, group); + _logger.LogInformation(Resource.LogUnsubscribeTimelinePostChange, Context.ConnectionId, group); } } } diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj index 955947af..0d0c08a0 100644 --- a/BackEnd/Timeline/Timeline.csproj +++ b/BackEnd/Timeline/Timeline.csproj @@ -123,6 +123,11 @@ True Resource.resx + + True + True + Resource.resx + @@ -186,5 +191,9 @@ ResXFileCodeGenerator Resource.Designer.cs + + ResXFileCodeGenerator + Resource.Designer.cs + \ No newline at end of file -- cgit v1.2.3