From 5d28fb661363540f476b060065342cb1059215f5 Mon Sep 17 00:00:00 2001 From: wzh425 Date: Thu, 23 Feb 2023 17:23:33 +0800 Subject: [PATCH] chore : Upgrade the package and remove some useless configurations (#321) * chore : Upgrade the package and remove some useless configurations * chore : Remove some extensions --- Directory.Build.props | 2 +- .../Masa.Mc.ApiGateways.Caller.csproj | 1 - .../Masa.Mc.ApiGateways.Caller/McCaller.cs | 3 - .../ServiceCollectionExtensions.cs | 2 +- .../Extensions/CollectionExtensions.cs | 113 ---- .../Extensions/StringExtensions.cs | 540 ------------------ .../Helper/ReflectionHelper.cs | 4 +- .../Helper/TypeHelper.cs | 340 ----------- .../Masa.Mc.Infrastructure.Common.csproj | 3 +- .../Middleware/LogMiddleware.cs | 2 +- .../Middleware/ValidatorMiddleware.cs | 2 +- src/Services/Masa.Mc.Service/Program.cs | 21 +- .../Masa.Mc.Service/Services/OssService.cs | 2 +- src/Services/Masa.Mc.Service/_Imports.cs | 4 +- .../Masa.Mc.Service/appsettings.Develop.json | 10 +- .../appsettings.Development.json | 18 +- .../Masa.Mc.Service/appsettings.Staging.json | 10 +- src/Services/Masa.Mc.Service/appsettings.json | 22 - src/Web/Masa.Mc.Web.Admin.Server/Program.cs | 29 +- src/Web/Masa.Mc.Web.Admin.Server/_Imports.cs | 4 +- .../appsettings.Develop.json | 23 - .../appsettings.Development.json | 23 - .../appsettings.Staging.json | 23 - .../Masa.Mc.Web.Admin.Server/appsettings.json | 1 - .../DefaultGenericColumnRender.razor | 7 +- .../Masa.Mc.Web.Admin.csproj | 2 +- .../Modules/ChannelExtraProperties.razor.cs | 10 - .../Modules/MessageRecordDetailModal.razor | 8 +- .../Modules/MessageSendingRules.razor.cs | 4 +- .../Modules/MessageTaskCard.razor | 2 +- .../Modules/MessageTaskDetailModal.razor | 4 +- .../Shared/AdminCompontentBase.cs | 3 + 32 files changed, 70 insertions(+), 1172 deletions(-) delete mode 100644 src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/CollectionExtensions.cs delete mode 100644 src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/StringExtensions.cs delete mode 100644 src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/TypeHelper.cs diff --git a/Directory.Build.props b/Directory.Build.props index 44712305..053ae277 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 0.7.0-preview.25 + 1.0.0-preview.9 diff --git a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/Masa.Mc.ApiGateways.Caller.csproj b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/Masa.Mc.ApiGateways.Caller.csproj index 18c73aed..d47aa0e4 100644 --- a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/Masa.Mc.ApiGateways.Caller.csproj +++ b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/Masa.Mc.ApiGateways.Caller.csproj @@ -7,7 +7,6 @@ - diff --git a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/McCaller.cs b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/McCaller.cs index d0f18b6c..9b175e92 100644 --- a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/McCaller.cs +++ b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/McCaller.cs @@ -41,14 +41,11 @@ public class McCaller : HttpClientCallerBase protected override string BaseAddress { get; set; } - public override string Name { get; set; } - public McCaller( IServiceProvider serviceProvider, TokenProvider tokenProvider, McApiOptions options) : base(serviceProvider) { - Name = nameof(McCaller); BaseAddress = options.McServiceBaseAddress; _tokenProvider = tokenProvider; } diff --git a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/ServiceCollectionExtensions.cs b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/ServiceCollectionExtensions.cs index 9199d900..a93ed166 100644 --- a/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/ServiceCollectionExtensions.cs +++ b/src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/ServiceCollectionExtensions.cs @@ -13,7 +13,7 @@ public static IServiceCollection AddMcApiGateways(this IServiceCollection servic configure?.Invoke(options); services.AddSingleton(options); services.AddScoped(); - services.AddCaller(Assembly.Load("Masa.Mc.ApiGateways.Caller")); + services.AddAutoRegistrationCaller(Assembly.Load("Masa.Mc.ApiGateways.Caller")); return services; } } \ No newline at end of file diff --git a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/CollectionExtensions.cs b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/CollectionExtensions.cs deleted file mode 100644 index 192da778..00000000 --- a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/CollectionExtensions.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Mc.Infrastructure.Common.Extensions; - -/// -/// Extension methods for Collections. -/// -public static class CollectionExtensions -{ - /// - /// Checks whatever given collection object is null or has no item. - /// - public static bool IsNullOrEmpty(this ICollection source) - { - return source == null || source.Count <= 0; - } - - /// - /// Adds an item to the collection if it's not already in the collection. - /// - /// The collection - /// Item to check and add - /// Type of the items in the collection - /// Returns True if added, returns False if not. - public static bool AddIfNotContains(this ICollection source, T item) - { - if (source.Contains(item)) - { - return false; - } - - source.Add(item); - return true; - } - - /// - /// Adds items to the collection which are not already in the collection. - /// - /// The collection - /// Item to check and add - /// Type of the items in the collection - /// Returns the added items. - public static IEnumerable AddIfNotContains(this ICollection source, IEnumerable items) - { - var addedItems = new List(); - - foreach (var item in items) - { - if (source.Contains(item)) - { - continue; - } - - source.Add(item); - addedItems.Add(item); - } - - return addedItems; - } - - /// - /// Adds an item to the collection if it's not already in the collection based on the given . - /// - /// The collection - /// The condition to decide if the item is already in the collection - /// A factory that returns the item - /// Type of the items in the collection - /// Returns True if added, returns False if not. - public static bool AddIfNotContains(this ICollection source, Func predicate, Func itemFactory) - { - if (source.Any(predicate)) - { - return false; - } - - source.Add(itemFactory()); - return true; - } - - /// - /// Removes all items from the collection those satisfy the given . - /// - /// Type of the items in the collection - /// The collection - /// The condition to remove the items - /// List of removed items - public static IList RemoveAll(this ICollection source, Func predicate) - { - var items = source.Where(predicate).ToList(); - - foreach (var item in items) - { - source.Remove(item); - } - - return items; - } - - /// - /// Removes all items from the collection. - /// - /// Type of the items in the collection - /// The collection - /// Items to be removed from the list - public static void RemoveAll(this ICollection source, IEnumerable items) - { - foreach (var item in items) - { - source.Remove(item); - } - } -} diff --git a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/StringExtensions.cs b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/StringExtensions.cs deleted file mode 100644 index 330f107a..00000000 --- a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Extensions/StringExtensions.cs +++ /dev/null @@ -1,540 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Mc.Infrastructure.Common.Extensions; - -/// -/// Extension methods for String class. -/// -public static class StringExtensions -{ - /// - /// Adds a char to end of given string if it does not ends with the char. - /// - public static string EnsureEndsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal) - { - if (str.EndsWith(c.ToString(), comparisonType)) - { - return str; - } - - return str + c; - } - - /// - /// Adds a char to beginning of given string if it does not starts with the char. - /// - public static string EnsureStartsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal) - { - if (str.StartsWith(c.ToString(), comparisonType)) - { - return str; - } - - return c + str; - } - - /// - /// Indicates whether this string is null or an System.String.Empty string. - /// - public static bool IsNullOrEmpty(this string str) - { - return string.IsNullOrEmpty(str); - } - - /// - /// indicates whether this string is null, empty, or consists only of white-space characters. - /// - public static bool IsNullOrWhiteSpace(this string str) - { - return string.IsNullOrWhiteSpace(str); - } - - /// - /// Gets a substring of a string from beginning of the string. - /// - /// Thrown if is null - /// Thrown if is bigger that string's length - public static string Left(this string str, int len) - { - if (str.Length < len) - { - throw new ArgumentException("len argument can not be bigger than given string's length!"); - } - - return str.Substring(0, len); - } - - /// - /// Converts line endings in the string to . - /// - public static string NormalizeLineEndings(this string str) - { - return str.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine); - } - - /// - /// Gets index of nth occurrence of a char in a string. - /// - /// source string to be searched - /// Char to search in - /// Count of the occurrence - public static int NthIndexOf(this string str, char c, int n) - { - var count = 0; - for (var i = 0; i < str.Length; i++) - { - if (str[i] != c) - { - continue; - } - - if ((++count) == n) - { - return i; - } - } - - return -1; - } - - /// - /// Removes first occurrence of the given postfixes from end of the given string. - /// - /// The string. - /// one or more postfix. - /// Modified string or the same string if it has not any of given postfixes - public static string RemovePostFix(this string str, params string[] postFixes) - { - return str.RemovePostFix(StringComparison.Ordinal, postFixes); - } - - /// - /// Removes first occurrence of the given postfixes from end of the given string. - /// - /// The string. - /// String comparison type - /// one or more postfix. - /// Modified string or the same string if it has not any of given postfixes - public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes) - { - if (str.IsNullOrEmpty()) - { - return str; - } - - if (postFixes.IsNullOrEmpty()) - { - return str; - } - - foreach (var postFix in postFixes) - { - if (str.EndsWith(postFix, comparisonType)) - { - return str.Left(str.Length - postFix.Length); - } - } - - return str; - } - - /// - /// Removes first occurrence of the given prefixes from beginning of the given string. - /// - /// The string. - /// one or more prefix. - /// Modified string or the same string if it has not any of given prefixes - public static string RemovePreFix(this string str, params string[] preFixes) - { - return str.RemovePreFix(StringComparison.Ordinal, preFixes); - } - - /// - /// Removes first occurrence of the given prefixes from beginning of the given string. - /// - /// The string. - /// String comparison type - /// one or more prefix. - /// Modified string or the same string if it has not any of given prefixes - public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes) - { - if (str.IsNullOrEmpty()) - { - return str; - } - - if (preFixes.IsNullOrEmpty()) - { - return str; - } - - foreach (var preFix in preFixes) - { - if (str.StartsWith(preFix, comparisonType)) - { - return str.Right(str.Length - preFix.Length); - } - } - - return str; - } - - public static string ReplaceFirst(this string str, string search, string replace, StringComparison comparisonType = StringComparison.Ordinal) - { - var pos = str.IndexOf(search, comparisonType); - if (pos < 0) - { - return str; - } - - return str.Substring(0, pos) + replace + str.Substring(pos + search.Length); - } - - /// - /// Gets a substring of a string from end of the string. - /// - /// Thrown if is null - /// Thrown if is bigger that string's length - public static string Right(this string str, int len) - { - if (str.Length < len) - { - throw new ArgumentException("len argument can not be bigger than given string's length!"); - } - - return str.Substring(str.Length - len, len); - } - - /// - /// Uses string.Split method to split given string by given separator. - /// - public static string[] Split(this string str, string separator) - { - return str.Split(new[] { separator }, StringSplitOptions.None); - } - - /// - /// Uses string.Split method to split given string by given separator. - /// - public static string[] Split(this string str, string separator, StringSplitOptions options) - { - return str.Split(new[] { separator }, options); - } - - /// - /// Uses string.Split method to split given string by . - /// - public static string[] SplitToLines(this string str) - { - return str.Split(Environment.NewLine); - } - - /// - /// Uses string.Split method to split given string by . - /// - public static string[] SplitToLines(this string str, StringSplitOptions options) - { - return str.Split(Environment.NewLine, options); - } - - /// - /// Converts PascalCase string to camelCase string. - /// - /// String to convert - /// set true to use current culture. Otherwise, invariant culture will be used. - /// set true to if you want to convert 'XYZ' to 'xyz'. - /// camelCase of the string - public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false) - { - if (string.IsNullOrWhiteSpace(str)) - { - return str; - } - - if (str.Length == 1) - { - return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant(); - } - - if (handleAbbreviations && IsAllUpperCase(str)) - { - return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant(); - } - - return (useCurrentCulture ? char.ToLower(str[0]) : char.ToLowerInvariant(str[0])) + str.Substring(1); - } - - /// - /// Converts given PascalCase/camelCase string to sentence (by splitting words by space). - /// Example: "ThisIsSampleSentence" is converted to "This is a sample sentence". - /// - /// String to convert. - /// set true to use current culture. Otherwise, invariant culture will be used. - public static string ToSentenceCase(this string str, bool useCurrentCulture = false) - { - if (string.IsNullOrWhiteSpace(str)) - { - return str; - } - - return useCurrentCulture - ? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1])) - : Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLowerInvariant(m.Value[1])); - } - - /// - /// Converts given PascalCase/camelCase string to kebab-case. - /// - /// String to convert. - /// set true to use current culture. Otherwise, invariant culture will be used. - public static string ToKebabCase(this string str, bool useCurrentCulture = false) - { - if (string.IsNullOrEmpty(str)) - { - return str; - } - return Regex.Replace(str, @"(\B[A-Z])", "-$1").ToLower(); - } - - /// - /// Converts given PascalCase/camelCase string to snake case. - /// Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence". - /// https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51 - /// - /// String to convert. - /// - public static string ToSnakeCase(this string str) - { - if (string.IsNullOrWhiteSpace(str)) - { - return str; - } - - var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5)); - var previousCategory = default(UnicodeCategory?); - - for (var currentIndex = 0; currentIndex < str.Length; currentIndex++) - { - var currentChar = str[currentIndex]; - if (currentChar == '_') - { - builder.Append('_'); - previousCategory = null; - continue; - } - - var currentCategory = char.GetUnicodeCategory(currentChar); - switch (currentCategory) - { - case UnicodeCategory.UppercaseLetter: - case UnicodeCategory.TitlecaseLetter: - if (previousCategory == UnicodeCategory.SpaceSeparator || - previousCategory == UnicodeCategory.LowercaseLetter || - previousCategory != UnicodeCategory.DecimalDigitNumber && - previousCategory != null && - currentIndex > 0 && - currentIndex + 1 < str.Length && - char.IsLower(str[currentIndex + 1])) - { - builder.Append('_'); - } - - currentChar = char.ToLower(currentChar); - break; - - case UnicodeCategory.LowercaseLetter: - case UnicodeCategory.DecimalDigitNumber: - if (previousCategory == UnicodeCategory.SpaceSeparator) - { - builder.Append('_'); - } - break; - - default: - if (previousCategory != null) - { - previousCategory = UnicodeCategory.SpaceSeparator; - } - continue; - } - - builder.Append(currentChar); - previousCategory = currentCategory; - } - - return builder.ToString(); - } - - /// - /// Converts string to enum value. - /// - /// Type of enum - /// String value to convert - /// Returns enum object - public static T ToEnum(this string value) - where T : struct - { - return (T)Enum.Parse(typeof(T), value); - } - - /// - /// Converts string to enum value. - /// - /// Type of enum - /// String value to convert - /// Ignore case - /// Returns enum object - public static T ToEnum(this string value, bool ignoreCase) - where T : struct - { - return (T)Enum.Parse(typeof(T), value, ignoreCase); - } - - public static string ToMd5(this string str) - { - using (var md5 = MD5.Create()) - { - var inputBytes = Encoding.UTF8.GetBytes(str); - var hashBytes = md5.ComputeHash(inputBytes); - - var sb = new StringBuilder(); - foreach (var hashByte in hashBytes) - { - sb.Append(hashByte.ToString("X2")); - } - - return sb.ToString(); - } - } - - /// - /// Converts camelCase string to PascalCase string. - /// - /// String to convert - /// set true to use current culture. Otherwise, invariant culture will be used. - /// PascalCase of the string - public static string ToPascalCase(this string str, bool useCurrentCulture = false) - { - if (string.IsNullOrWhiteSpace(str)) - { - return str; - } - - if (str.Length == 1) - { - return useCurrentCulture ? str.ToUpper() : str.ToUpperInvariant(); - } - - return (useCurrentCulture ? char.ToUpper(str[0]) : char.ToUpperInvariant(str[0])) + str.Substring(1); - } - - /// - /// Gets a substring of a string from beginning of the string if it exceeds maximum length. - /// - /// Thrown if is null - public static string Truncate(this string str, int maxLength) - { - if (str == null) - { - return null; - } - - if (str.Length <= maxLength) - { - return str; - } - - return str.Left(maxLength); - } - - /// - /// Gets a substring of a string from Ending of the string if it exceeds maximum length. - /// - /// Thrown if is null - public static string TruncateFromBeginning(this string str, int maxLength) - { - if (str == null) - { - return null; - } - - if (str.Length <= maxLength) - { - return str; - } - - return str.Right(maxLength); - } - - /// - /// Gets a substring of a string from beginning of the string if it exceeds maximum length. - /// It adds a "..." postfix to end of the string if it's truncated. - /// Returning string can not be longer than maxLength. - /// - /// Thrown if is null - public static string TruncateWithPostfix(this string str, int maxLength) - { - return TruncateWithPostfix(str, maxLength, "..."); - } - - /// - /// Gets a substring of a string from beginning of the string if it exceeds maximum length. - /// It adds given to end of the string if it's truncated. - /// Returning string can not be longer than maxLength. - /// - /// Thrown if is null - public static string TruncateWithPostfix(this string str, int maxLength, string postfix) - { - if (str == null) - { - return null; - } - - if (str == string.Empty || maxLength == 0) - { - return string.Empty; - } - - if (str.Length <= maxLength) - { - return str; - } - - if (maxLength <= postfix.Length) - { - return postfix.Left(maxLength); - } - - return str.Left(maxLength - postfix.Length) + postfix; - } - - /// - /// Converts given string to a byte array using encoding. - /// - public static byte[] GetBytes(this string str) - { - return str.GetBytes(Encoding.UTF8); - } - - /// - /// Converts given string to a byte array using the given - /// - public static byte[] GetBytes(this string str, Encoding encoding) - { - return encoding.GetBytes(str); - } - - private static bool IsAllUpperCase(string input) - { - for (int i = 0; i < input.Length; i++) - { - if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i])) - { - return false; - } - } - - return true; - } -} diff --git a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/ReflectionHelper.cs b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/ReflectionHelper.cs index 71e77e19..acb95e09 100644 --- a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/ReflectionHelper.cs +++ b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/ReflectionHelper.cs @@ -51,14 +51,14 @@ private static void AddImplementedGenericTypes(List result, Type givenType if (givenTypeInfo.IsGenericType && givenType.GetGenericTypeDefinition() == genericType) { - result.AddIfNotContains(givenType); + result.TryAdd(givenType); } foreach (var interfaceType in givenTypeInfo.GetInterfaces()) { if (interfaceType.GetTypeInfo().IsGenericType && interfaceType.GetGenericTypeDefinition() == genericType) { - result.AddIfNotContains(interfaceType); + result.TryAdd(interfaceType); } } diff --git a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/TypeHelper.cs b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/TypeHelper.cs deleted file mode 100644 index f9a42eca..00000000 --- a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Helper/TypeHelper.cs +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the Apache License. See LICENSE.txt in the project root for license information. - -namespace Masa.Mc.Infrastructure.Common.Helper; - -public static class TypeHelper -{ - private static readonly HashSet FloatingTypes = new HashSet - { - typeof(float), - typeof(double), - typeof(decimal) - }; - - private static readonly HashSet NonNullablePrimitiveTypes = new HashSet - { - typeof(byte), - typeof(short), - typeof(int), - typeof(long), - typeof(sbyte), - typeof(ushort), - typeof(uint), - typeof(ulong), - typeof(bool), - typeof(float), - typeof(decimal), - typeof(DateTime), - typeof(DateTimeOffset), - typeof(TimeSpan), - typeof(Guid) - }; - - public static bool IsNonNullablePrimitiveType(Type type) - { - return NonNullablePrimitiveTypes.Contains(type); - } - - public static bool IsFunc(object obj) - { - if (obj == null) - { - return false; - } - - var type = obj.GetType(); - if (!type.GetTypeInfo().IsGenericType) - { - return false; - } - - return type.GetGenericTypeDefinition() == typeof(Func<>); - } - - public static bool IsFunc(object obj) - { - return obj != null && obj.GetType() == typeof(Func); - } - - public static bool IsPrimitiveExtended(Type type, bool includeNullables = true, bool includeEnums = false) - { - if (IsPrimitiveExtendedInternal(type, includeEnums)) - { - return true; - } - - if (includeNullables && IsNullable(type) && type.GenericTypeArguments.Any()) - { - return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0], includeEnums); - } - - return false; - } - - public static bool IsNullable(Type type) - { - return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); - } - - public static Type GetFirstGenericArgumentIfNullable(this Type t) - { - if (t.GetGenericArguments().Length > 0 && t.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return t.GetGenericArguments().FirstOrDefault(); - } - - return t; - } - - public static bool IsEnumerable(Type type, out Type itemType, bool includePrimitives = true) - { - if (!includePrimitives && IsPrimitiveExtended(type)) - { - itemType = null; - return false; - } - - var enumerableTypes = ReflectionHelper.GetImplementedGenericTypes(type, typeof(IEnumerable<>)); - if (enumerableTypes.Count == 1) - { - itemType = enumerableTypes[0].GenericTypeArguments[0]; - return true; - } - - if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type)) - { - itemType = typeof(object); - return true; - } - - itemType = null; - return false; - } - - public static bool IsDictionary(Type type, out Type keyType, out Type valueType) - { - var dictionaryTypes = ReflectionHelper - .GetImplementedGenericTypes( - type, - typeof(IDictionary<,>) - ); - - if (dictionaryTypes.Count == 1) - { - keyType = dictionaryTypes[0].GenericTypeArguments[0]; - valueType = dictionaryTypes[0].GenericTypeArguments[1]; - return true; - } - - if (typeof(System.Collections.IDictionary).IsAssignableFrom(type)) - { - keyType = typeof(object); - valueType = typeof(object); - return true; - } - - keyType = null; - valueType = null; - - return false; - } - - private static bool IsPrimitiveExtendedInternal(Type type, bool includeEnums) - { - if (type.IsPrimitive) - { - return true; - } - - if (includeEnums && type.IsEnum) - { - return true; - } - - return type == typeof(string) || - type == typeof(decimal) || - type == typeof(DateTimeOffset) || - type == typeof(DateTimeOffset) || - type == typeof(TimeSpan) || - type == typeof(Guid); - } - - public static T GetDefaultValue() - { - return default; - } - - public static object GetDefaultValue(Type type) - { - if (type.IsValueType) - { - return Activator.CreateInstance(type); - } - - return null; - } - - public static string GetFullNameHandlingNullableAndGenerics(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return type.GenericTypeArguments[0].FullName + "?"; - } - - if (type.IsGenericType) - { - var genericType = type.GetGenericTypeDefinition(); - return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>"; - } - - return type.FullName ?? type.Name; - } - - public static string GetSimplifiedName(Type type) - { - if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) - { - return GetSimplifiedName(type.GenericTypeArguments[0]) + "?"; - } - - if (type.IsGenericType) - { - var genericType = type.GetGenericTypeDefinition(); - return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>"; - } - - if (type == typeof(string)) - { - return "string"; - } - else if (type == typeof(int)) - { - return "number"; - } - else if (type == typeof(long)) - { - return "number"; - } - else if (type == typeof(bool)) - { - return "boolean"; - } - else if (type == typeof(char)) - { - return "string"; - } - else if (type == typeof(double)) - { - return "number"; - } - else if (type == typeof(float)) - { - return "number"; - } - else if (type == typeof(decimal)) - { - return "number"; - } - else if (type == typeof(DateTimeOffset)) - { - return "string"; - } - else if (type == typeof(DateTimeOffset)) - { - return "string"; - } - else if (type == typeof(TimeSpan)) - { - return "string"; - } - else if (type == typeof(Guid)) - { - return "string"; - } - else if (type == typeof(byte)) - { - return "number"; - } - else if (type == typeof(sbyte)) - { - return "number"; - } - else if (type == typeof(short)) - { - return "number"; - } - else if (type == typeof(ushort)) - { - return "number"; - } - else if (type == typeof(uint)) - { - return "number"; - } - else if (type == typeof(ulong)) - { - return "number"; - } - else if (type == typeof(IntPtr)) - { - return "number"; - } - else if (type == typeof(UIntPtr)) - { - return "number"; - } - else if (type == typeof(object)) - { - return "object"; - } - - return type.FullName ?? type.Name; - } - - public static bool IsFloatingType(Type type, bool includeNullable = true) - { - if (FloatingTypes.Contains(type)) - { - return true; - } - - if (includeNullable && - IsNullable(type) && - FloatingTypes.Contains(type.GenericTypeArguments[0])) - { - return true; - } - - return false; - } - - public static object ConvertFrom(object value) - { - return ConvertFrom(typeof(TTargetType), value); - } - - public static object ConvertFrom(Type targetType, object value) - { - return TypeDescriptor - .GetConverter(targetType) - .ConvertFrom(value); - } - - public static Type StripNullable(Type type) - { - return IsNullable(type) - ? type.GenericTypeArguments[0] - : type; - } - - public static bool IsDefaultValue(object obj) - { - if (obj == null) - { - return true; - } - - return obj.Equals(GetDefaultValue(obj.GetType())); - } -} diff --git a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Masa.Mc.Infrastructure.Common.csproj b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Masa.Mc.Infrastructure.Common.csproj index b309d428..4f39021e 100644 --- a/src/Infrastructure/Masa.Mc.Infrastructure.Common/Masa.Mc.Infrastructure.Common.csproj +++ b/src/Infrastructure/Masa.Mc.Infrastructure.Common/Masa.Mc.Infrastructure.Common.csproj @@ -7,7 +7,8 @@ - + + diff --git a/src/Services/Masa.Mc.Service/Infrastructure/Middleware/LogMiddleware.cs b/src/Services/Masa.Mc.Service/Infrastructure/Middleware/LogMiddleware.cs index db3833b3..3a3e0a2a 100644 --- a/src/Services/Masa.Mc.Service/Infrastructure/Middleware/LogMiddleware.cs +++ b/src/Services/Masa.Mc.Service/Infrastructure/Middleware/LogMiddleware.cs @@ -3,7 +3,7 @@ namespace Masa.Mc.Service.Infrastructure.Middleware; -public class LogMiddleware : IMiddleware +public class LogMiddleware : IEventMiddleware where TEvent : notnull, IEvent { private readonly ILogger> _logger; diff --git a/src/Services/Masa.Mc.Service/Infrastructure/Middleware/ValidatorMiddleware.cs b/src/Services/Masa.Mc.Service/Infrastructure/Middleware/ValidatorMiddleware.cs index eb0bef96..be974c58 100644 --- a/src/Services/Masa.Mc.Service/Infrastructure/Middleware/ValidatorMiddleware.cs +++ b/src/Services/Masa.Mc.Service/Infrastructure/Middleware/ValidatorMiddleware.cs @@ -3,7 +3,7 @@ namespace Masa.Mc.Service.Infrastructure.Middleware; -public class ValidatorMiddleware : IMiddleware +public class ValidatorMiddleware : IEventMiddleware where TEvent : notnull, IEvent { private readonly ILogger> _logger; diff --git a/src/Services/Masa.Mc.Service/Program.cs b/src/Services/Masa.Mc.Service/Program.cs index 162d8c2b..e8c58e50 100644 --- a/src/Services/Masa.Mc.Service/Program.cs +++ b/src/Services/Masa.Mc.Service/Program.cs @@ -1,10 +1,7 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -using Masa.Mc.Service.Admin.Infrastructure.Extensions; - var builder = WebApplication.CreateBuilder(args); -builder.Services.AddObservable(builder.Logging, builder.Configuration); #if DEBUG builder.Services.AddDaprStarter(opt => @@ -22,14 +19,28 @@ configurationBuilder.UseDcc(); }); var publicConfiguration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetPublic(); + +builder.Services.AddObservable(builder.Logging, () => +{ + return new MasaObservableOptions + { + ServiceNameSpace = builder.Environment.EnvironmentName, + ServiceVersion = "1.0.0",//todo global version + ServiceName = "masa-mc-service-admin" + }; +}, () => +{ + return publicConfiguration.GetValue("$public.AppSettings:OtlpUrl"); +}); + var ossOptions = publicConfiguration.GetSection("$public.OSS").Get(); -builder.Services.AddAliyunStorage(new AliyunStorageOptions(ossOptions.AccessId, ossOptions.AccessSecret, ossOptions.Endpoint, ossOptions.RoleArn, ossOptions.RoleSessionName) +builder.Services.AddObjectStorage(option => option.UseAliyunStorage(new AliyunStorageOptions(ossOptions.AccessId, ossOptions.AccessSecret, ossOptions.Endpoint, ossOptions.RoleArn, ossOptions.RoleSessionName) { Sts = new AliyunStsOptions() { RegionId = ossOptions.RegionId } -}); +})); builder.Services.AddMasaIdentity(options => { options.Environment = "environment"; diff --git a/src/Services/Masa.Mc.Service/Services/OssService.cs b/src/Services/Masa.Mc.Service/Services/OssService.cs index 82737f04..87741e39 100644 --- a/src/Services/Masa.Mc.Service/Services/OssService.cs +++ b/src/Services/Masa.Mc.Service/Services/OssService.cs @@ -10,7 +10,7 @@ public OssService(IServiceCollection services) : base("api/oss") } - public async Task GetSecurityTokenAsync([FromServices] IClient client, [FromServices] IOptions ossOptions) + public async Task GetSecurityTokenAsync([FromServices] IObjectStorageClient client, [FromServices] IOptions ossOptions) { var region = "oss-cn-hangzhou"; var response = client.GetSecurityToken(); diff --git a/src/Services/Masa.Mc.Service/_Imports.cs b/src/Services/Masa.Mc.Service/_Imports.cs index 6e6e6932..90f2612d 100644 --- a/src/Services/Masa.Mc.Service/_Imports.cs +++ b/src/Services/Masa.Mc.Service/_Imports.cs @@ -191,4 +191,6 @@ global using static AlibabaCloud.SDK.Dysmsapi20170525.Models.QuerySmsTemplateListResponseBody; global using Masa.BuildingBlocks.StackSdks.Auth.Contracts.Consts; global using Masa.BuildingBlocks.Ddd.Domain.Services; -global using Masa.BuildingBlocks.Isolation; \ No newline at end of file +global using Masa.BuildingBlocks.Isolation; +global using Masa.Contrib.StackSdks.Tsc; +global using Masa.Mc.Service.Admin.Infrastructure.Extensions; \ No newline at end of file diff --git a/src/Services/Masa.Mc.Service/appsettings.Develop.json b/src/Services/Masa.Mc.Service/appsettings.Develop.json index 04841bb5..c58a814d 100644 --- a/src/Services/Masa.Mc.Service/appsettings.Develop.json +++ b/src/Services/Masa.Mc.Service/appsettings.Develop.json @@ -31,13 +31,5 @@ "AppId": "masa-mc-service-admin", "Environment": "Develop", "Secret": "", - "Cluster": "Default", - "Masa": { - "Observable": { - "ServiceName": "masa-mc-service", - "ServiceNameSpace": "Develop", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel-collector-dev.open-telemetry:4317" - } - } + "Cluster": "Default" } diff --git a/src/Services/Masa.Mc.Service/appsettings.Development.json b/src/Services/Masa.Mc.Service/appsettings.Development.json index 7d7a6382..1412d6e0 100644 --- a/src/Services/Masa.Mc.Service/appsettings.Development.json +++ b/src/Services/Masa.Mc.Service/appsettings.Development.json @@ -15,14 +15,6 @@ "AccessKeyId": "", "EndPoint": "dysmsapi.aliyuncs.com" }, - "DaprOptions": { - "AppId": "masa-mc-service", - "AppPort": 19511, - "AppIdSuffix": "", - "MetricsPort": 20600, - "DaprHttpPort": 20602, - "DaprGrpcPort": 20601 - }, "DccOptions": { "ManageServiceAddress": "https://dcc-service-develop.masastack.com/", "RedisOptions": { @@ -39,13 +31,5 @@ "AppId": "masa-mc-service-admin", "Environment": "Development", "Secret": "", - "Cluster": "Default", - "Masa": { - "Observable": { - "ServiceName": "masa-mc-service", - "ServiceNameSpace": "Development", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel.lonsid.cn:32247" - } - } + "Cluster": "Default" } diff --git a/src/Services/Masa.Mc.Service/appsettings.Staging.json b/src/Services/Masa.Mc.Service/appsettings.Staging.json index 64ca362e..18935303 100644 --- a/src/Services/Masa.Mc.Service/appsettings.Staging.json +++ b/src/Services/Masa.Mc.Service/appsettings.Staging.json @@ -31,13 +31,5 @@ "AppId": "masa-mc-service-admin", "Environment": "Staging", "Secret": "", - "Cluster": "Default", - "Masa": { - "Observable": { - "ServiceName": "masa-mc-service", - "ServiceNameSpace": "Staging", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel-collector-dev.open-telemetry:4317" - } - } + "Cluster": "Default" } diff --git a/src/Services/Masa.Mc.Service/appsettings.json b/src/Services/Masa.Mc.Service/appsettings.json index 2148f73e..4d4470c6 100644 --- a/src/Services/Masa.Mc.Service/appsettings.json +++ b/src/Services/Masa.Mc.Service/appsettings.json @@ -12,27 +12,5 @@ "AccessKeyId": "", "EndPoint": "dysmsapi.aliyuncs.com" }, - "RedisConfig": { - "Servers": [ - { - "Host": "redis", - "Port": "6379" - } - ], - "DefaultDatabase": 0, - "Password": "", - "SyncTimeout": 600000 - }, - "DaprOptions": { - "AppId": "masa-mc-service", - "AppPort": 19511, - "AppIdSuffix": "", - "MetricsPort": 20600, - "DaprHttpPort": 20602, - "DaprGrpcPort": 20601 - }, - "AuthClient": { - "Url": "https://auth-service-develop.masastack.com/" - }, "AppId": "masa-mc-service-admin" } diff --git a/src/Web/Masa.Mc.Web.Admin.Server/Program.cs b/src/Web/Masa.Mc.Web.Admin.Server/Program.cs index ebc2372d..d0c9dbd9 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/Program.cs +++ b/src/Web/Masa.Mc.Web.Admin.Server/Program.cs @@ -23,7 +23,7 @@ options.CheckCertificateRevocation = false; }); }); -builder.Services.AddObservable(builder.Logging, builder.Configuration, true); + // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); @@ -34,22 +34,29 @@ opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat( new[] { "application/octet-stream" }); }); -var authBaseAddress = builder.Configuration["AuthServiceBaseAddress"]; -var mcBaseAddress = builder.Configuration["McServiceBaseAddress"]; -builder.Services.AddMcApiGateways(option => option.McServiceBaseAddress = mcBaseAddress); -#if DEBUG -builder.AddMasaStackComponentsForServer("wwwroot/i18n", authBaseAddress, "https://localhost:19501"); -#else -builder.AddMasaStackComponentsForServer("wwwroot/i18n", authBaseAddress, mcBaseAddress); -#endif +builder.AddMasaStackComponentsForServer(); +var publicConfiguration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetPublic(); +var mcBaseAddress = publicConfiguration.GetValue("$public.AppSettings:McClient:Url"); +builder.Services.AddMcApiGateways(option => option.McServiceBaseAddress = mcBaseAddress); +builder.Services.AddObservable(builder.Logging, () => +{ + return new MasaObservableOptions + { + ServiceNameSpace = builder.Environment.EnvironmentName, + ServiceVersion = "1.0.0",//todo global version + ServiceName = "masa-mc-web-admin" + }; +}, () => +{ + return publicConfiguration.GetValue("$public.AppSettings:OtlpUrl"); +}, true); builder.Services.AddHttpContextAccessor(); builder.Services.AddGlobalForServer(); builder.Services.AddScoped(); builder.Services.AddSingleton(); TypeAdapterConfig.GlobalSettings.Scan(Assembly.GetExecutingAssembly(), Assembly.Load("Masa.Mc.Contracts.Admin")); -var oidcOptions = builder.Services.GetMasaConfiguration().Local.GetSection("$public.OIDC:AuthClient").Get(); -builder.Services.AddMasaOpenIdConnect(oidcOptions); +builder.Services.AddMasaOpenIdConnect(publicConfiguration.GetSection("$public.OIDC").Get()); StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration); diff --git a/src/Web/Masa.Mc.Web.Admin.Server/_Imports.cs b/src/Web/Masa.Mc.Web.Admin.Server/_Imports.cs index 09831209..f9e52a9e 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/_Imports.cs +++ b/src/Web/Masa.Mc.Web.Admin.Server/_Imports.cs @@ -21,4 +21,6 @@ global using Microsoft.IdentityModel.Protocols.OpenIdConnect; global using Masa.Contrib.Service.Caller.Authentication.OpenIdConnect; global using Masa.Stack.Components.Extensions; -global using Masa.Stack.Components.Extensions.OpenIdConnect; \ No newline at end of file +global using Masa.Stack.Components.Extensions.OpenIdConnect; +global using Masa.Contrib.Configuration.ConfigurationApi.Dcc; +global using Masa.Contrib.StackSdks.Tsc; \ No newline at end of file diff --git a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Develop.json b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Develop.json index 384f5fbe..3ecfdb76 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Develop.json +++ b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Develop.json @@ -6,29 +6,6 @@ } }, "AllowedHosts": "*", - "McServiceBaseAddress": "https://mc-service-develop.masastack.com", - "AuthServiceBaseAddress": "https://auth-service-develop.masastack.com/", - "OIDC": { - "Authority": "https://sso-develop.masastack.com", - "ClientId": "masa.stack.web-develop", - "ClientSecret": "" - }, - "Masa": { - "Observable": { - "ServiceName": "masa-mc-web", - "ServiceNameSpace": "Develop", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel-collector-dev.open-telemetry:4317" - } - }, - "UserAutoComplete": "user_index", - "$public.OIDC": { - "AuthClient": { - "Authority": "https://sso-develop.masastack.com", - "ClientId": "masa.stack.web-develop", - "ClientSecret": "" - } - }, "DccOptions": { "ManageServiceAddress": "https://dcc-service-develop.masastack.com/", "RedisOptions": { diff --git a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Development.json b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Development.json index a6ddb66f..2a2433fd 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Development.json +++ b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Development.json @@ -7,29 +7,6 @@ } }, "AllowedHosts": "*", - "McServiceBaseAddress": "https://localhost:19501", - "AuthServiceBaseAddress": "https://auth-service-develop.masastack.com/", - "OIDC": { - "Authority": "https://sso-develop.masastack.com", - "ClientId": "masa.stack.web-development", - "ClientSecret": "" - }, - "Masa": { - "Observable": { - "ServiceName": "masa-mc-web", - "ServiceNameSpace": "Development", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel.lonsid.cn:32247" - } - }, - "UserAutoComplete": "user_index", - "$public.OIDC": { - "AuthClient": { - "Authority": "https://sso-develop.masastack.com", - "ClientId": "masa.stack.web-development", - "ClientSecret": "" - } - }, "DccOptions": { "ManageServiceAddress": "https://dcc-service-develop.masastack.com/", "RedisOptions": { diff --git a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Staging.json b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Staging.json index ebaf202b..8e76d466 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Staging.json +++ b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.Staging.json @@ -6,29 +6,6 @@ } }, "AllowedHosts": "*", - "McServiceBaseAddress": "https://mc-service-staging.masastack.com", - "AuthServiceBaseAddress": "https://auth-service-staging.masastack.com/", - "OIDC": { - "Authority": "https://sso-staging.masastack.com", - "ClientId": "masa.stack.web-staging", - "ClientSecret": "" - }, - "Masa": { - "Observable": { - "ServiceName": "masa-mc-web", - "ServiceNameSpace": "Staging", - "ServiceVersion": "1.0.0", - "OtlpUrl": "http://otel-collector-dev.open-telemetry:4317" - } - }, - "UserAutoComplete": "user_index_staging", - "$public.OIDC": { - "AuthClient": { - "Authority": "https://sso-staging.masastack.com", - "ClientId": "masa.stack.web-staging", - "ClientSecret": "" - } - }, "DccOptions": { "ManageServiceAddress": "https://dcc-service-develop.masastack.com/", "RedisOptions": { diff --git a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.json b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.json index 7acd7cfb..683b5dfc 100644 --- a/src/Web/Masa.Mc.Web.Admin.Server/appsettings.json +++ b/src/Web/Masa.Mc.Web.Admin.Server/appsettings.json @@ -6,6 +6,5 @@ } }, "AllowedHosts": "*", - "McServiceBaseAddress": "", "AppId": "masa-mc-web-admin" } diff --git a/src/Web/Masa.Mc.Web.Admin/Components/GenericColumnRender/DefaultGenericColumnRender.razor b/src/Web/Masa.Mc.Web.Admin/Components/GenericColumnRender/DefaultGenericColumnRender.razor index 8d422f69..0fd51c64 100644 --- a/src/Web/Masa.Mc.Web.Admin/Components/GenericColumnRender/DefaultGenericColumnRender.razor +++ b/src/Web/Masa.Mc.Web.Admin/Components/GenericColumnRender/DefaultGenericColumnRender.razor @@ -1,10 +1,10 @@ @if (Value is DateTime dateTime) { - + } else if (Value is DateTimeOffset dateTimeOffset) { - + } else { @@ -28,4 +28,7 @@ else [Parameter] public StringNumber? Width { get; set; } + + [Inject] + public JsInitVariables JsInitVariables { get; set; } = default!; } diff --git a/src/Web/Masa.Mc.Web.Admin/Masa.Mc.Web.Admin.csproj b/src/Web/Masa.Mc.Web.Admin/Masa.Mc.Web.Admin.csproj index 3eebdd11..f13d8ada 100644 --- a/src/Web/Masa.Mc.Web.Admin/Masa.Mc.Web.Admin.csproj +++ b/src/Web/Masa.Mc.Web.Admin/Masa.Mc.Web.Admin.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Web/Masa.Mc.Web.Admin/Pages/Channels/Modules/ChannelExtraProperties.razor.cs b/src/Web/Masa.Mc.Web.Admin/Pages/Channels/Modules/ChannelExtraProperties.razor.cs index e1c5721b..30b3a0d8 100644 --- a/src/Web/Masa.Mc.Web.Admin/Pages/Channels/Modules/ChannelExtraProperties.razor.cs +++ b/src/Web/Masa.Mc.Web.Admin/Pages/Channels/Modules/ChannelExtraProperties.razor.cs @@ -31,16 +31,6 @@ public ExtraPropertyDictionary Value private ChannelSmsExtraProperties? _smsExtraPropertiesRef; private ChannelAppExtraProperties? _appExtraPropertiesRef; - protected override void OnInitialized() - { - base.OnInitialized(); - Watcher - .Watch(nameof(Value), async val => - { - await ValueChanged.InvokeAsync(Value); - }); - } - public void HandleChangeAsync(string value, string key) { Value[key] = value; diff --git a/src/Web/Masa.Mc.Web.Admin/Pages/MessageRecords/Modules/MessageRecordDetailModal.razor b/src/Web/Masa.Mc.Web.Admin/Pages/MessageRecords/Modules/MessageRecordDetailModal.razor index 2e52de34..c1f8734f 100644 --- a/src/Web/Masa.Mc.Web.Admin/Pages/MessageRecords/Modules/MessageRecordDetailModal.razor +++ b/src/Web/Masa.Mc.Web.Admin/Pages/MessageRecords/Modules/MessageRecordDetailModal.razor @@ -27,8 +27,8 @@
-
@(_messageTask.ExpectSendTime?.ToOffset(TimezoneOffset).ToString(T("$DateFormat")))
-
@(_messageTask.ExpectSendTime?.ToOffset(TimezoneOffset).ToString(T("$TimeFormat")))
+
@(_messageTask.ExpectSendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateFormat")))
+
@(_messageTask.ExpectSendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$TimeFormat")))
@@ -41,8 +41,8 @@
-
@_messageRecord.SendTime?.ToOffset(TimezoneOffset).ToString(T("$DateFormat"))
-
@_messageRecord.SendTime?.ToOffset(TimezoneOffset).ToString(T("$TimeFormat"))
+
@_messageRecord.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateFormat"))
+
@_messageRecord.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$TimeFormat"))
diff --git a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageSendingRules.razor.cs b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageSendingRules.razor.cs index 2822396e..108bc412 100644 --- a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageSendingRules.razor.cs +++ b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageSendingRules.razor.cs @@ -60,7 +60,7 @@ private void GetNextRunTime(int showCount = 10) var cronExpression = new CronExpression(Value.CronExpression); - var timezone = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(p => p.BaseUtcOffset == TimezoneOffset); + var timezone = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(p => p.BaseUtcOffset == JsInitVariables.TimezoneOffset); if (timezone != null) cronExpression.TimeZone = timezone; @@ -72,7 +72,7 @@ private void GetNextRunTime(int showCount = 10) if (nextExcuteTime.HasValue) { startTime = nextExcuteTime.Value; - sb.AppendLine(startTime.ToOffset(TimezoneOffset).ToString("yyyy-MM-dd HH:mm:ss")); + sb.AppendLine(startTime.ToOffset(JsInitVariables.TimezoneOffset).ToString("yyyy-MM-dd HH:mm:ss")); } } diff --git a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskCard.razor b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskCard.razor index 06c7d713..ee405969 100644 --- a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskCard.razor +++ b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskCard.razor @@ -66,7 +66,7 @@
@MessageTask.DisplayName
-
@((MessageTask.SendTime?.ToOffset(TimezoneOffset)??MessageTask.ExpectSendTime?.ToOffset(TimezoneOffset))?.ToString(T("$DateTimeFormat")))
+
@((MessageTask.SendTime?.ToOffset(JsInitVariables.TimezoneOffset) ?? MessageTask.ExpectSendTime?.ToOffset(JsInitVariables.TimezoneOffset))?.ToString(T("$DateTimeFormat")))
@MessageTask.Content
diff --git a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskDetailModal.razor b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskDetailModal.razor index d082b7ad..cf23d2bb 100644 --- a/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskDetailModal.razor +++ b/src/Web/Masa.Mc.Web.Admin/Pages/MessageTasks/Modules/MessageTaskDetailModal.razor @@ -58,7 +58,7 @@ {
@item.TaskHistoryNo
} -
@item.SendTime?.ToOffset(TimezoneOffset).ToString(T("$DateTimeFormat"))
+
@item.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateTimeFormat"))
@@ -81,7 +81,7 @@ @if (_historyInfo.SendTime.HasValue) { - @T(string.Format(T("Description.MessageTaskHistory.SendTimeTips"),_historyInfo.SendTime?.ToOffset(TimezoneOffset).ToString(T("$DateTimeFormat")))) + @T(string.Format(T("Description.MessageTaskHistory.SendTimeTips"),_historyInfo.SendTime?.ToOffset(JsInitVariables.TimezoneOffset).ToString(T("$DateTimeFormat")))) } diff --git a/src/Web/Masa.Mc.Web.Admin/Shared/AdminCompontentBase.cs b/src/Web/Masa.Mc.Web.Admin/Shared/AdminCompontentBase.cs index c3e4e0f2..c56295f1 100644 --- a/src/Web/Masa.Mc.Web.Admin/Shared/AdminCompontentBase.cs +++ b/src/Web/Masa.Mc.Web.Admin/Shared/AdminCompontentBase.cs @@ -68,6 +68,9 @@ public NavigationManager NavigationManager [Inject] public McApiOptions McApiOptions { get; set; } = default!; + [Inject] + public JsInitVariables JsInitVariables { get; set; } = default!; + public bool Loading { get => GlobalConfig.Loading;