Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Grand.SharedKestrel - Code cleanup (ReSharper)

support5f2a9ce46a85
diff --git a/src/Core/Grand.SharedKernel/Attributes/DBFieldNameAttribute.cs b/src/Core/Grand.SharedKernel/Attributes/DBFieldNameAttribute.cs
index 48aec32e2..7061409e0 100644
--- a/src/Core/Grand.SharedKernel/Attributes/DBFieldNameAttribute.cs
+++ b/src/Core/Grand.SharedKernel/Attributes/DBFieldNameAttribute.cs
@@ -1,14 +1,14 @@
-namespace Grand.SharedKernel.Attributes
+namespace Grand.SharedKernel.Attributes;
+
+[AttributeUsage(AttributeTargets.Property)]
+public class DBFieldNameAttribute : Attribute
{
- [AttributeUsage(AttributeTargets.Property)]
- public class DBFieldNameAttribute : Attribute
- {
- private string name;
+ private readonly string name;
- public DBFieldNameAttribute(string name)
- {
- this.name = name;
- }
- public virtual string Name => name;
+ public DBFieldNameAttribute(string name)
+ {
+ this.name = name;
}
-}
+
+ public virtual string Name => name;
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs b/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs
index 2306dc9f8..aba6d153d 100644
--- a/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/CommonHelper.cs
@@ -3,254 +3,250 @@ using System.Globalization;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
-namespace Grand.SharedKernel.Extensions
+namespace Grand.SharedKernel.Extensions;
+
+/// <summary>
+/// Represents a common helper
+/// </summary>
+public static class CommonHelper
{
/// <summary>
- /// Represents a common helper
+ /// Ensures the subscriber email or throw.
/// </summary>
- public static class CommonHelper
+ /// <param name="email">The email.</param>
+ /// <returns></returns>
+ public static string EnsureSubscriberEmailOrThrow(string email)
{
- /// <summary>
- /// Ensures the subscriber email or throw.
- /// </summary>
- /// <param name="email">The email.</param>
- /// <returns></returns>
- public static string EnsureSubscriberEmailOrThrow(string email)
- {
- var output = EnsureNotNull(email);
- output = output.Trim();
- output = EnsureMaximumLength(output, 255);
+ var output = EnsureNotNull(email);
+ output = output.Trim();
+ output = EnsureMaximumLength(output, 255);
- if (!IsValidEmail(output))
- {
- throw new GrandException("Email is not valid.");
- }
+ if (!IsValidEmail(output)) throw new GrandException("Email is not valid.");
- return output;
- }
+ return output;
+ }
- /// <summary>
- /// Verifies that a string is in valid e-mail format
- /// </summary>
- /// <param name="email">Email to verify</param>
- /// <returns>true if the string is a valid e-mail address and false if it's not</returns>
- public static bool IsValidEmail(string email)
- {
- if (String.IsNullOrEmpty(email))
- return false;
+ /// <summary>
+ /// Verifies that a string is in valid e-mail format
+ /// </summary>
+ /// <param name="email">Email to verify</param>
+ /// <returns>true if the string is a valid e-mail address and false if it's not</returns>
+ public static bool IsValidEmail(string email)
+ {
+ if (string.IsNullOrEmpty(email))
+ return false;
+
+ email = email.Trim();
+ var result = Regex.IsMatch(email,
+ "^(?:[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+\\.)*[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!\\.)){0,61}[a-zA-Z0-9]?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\\[(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\]))$",
+ RegexOptions.IgnoreCase);
+ return result;
+ }
- email = email.Trim();
- var result = Regex.IsMatch(email, "^(?:[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+\\.)*[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!\\.)){0,61}[a-zA-Z0-9]?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\\[(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\]))$", RegexOptions.IgnoreCase);
- return result;
- }
+ /// <summary>
+ /// Generate random digit code
+ /// </summary>
+ /// <param name="length">Length</param>
+ /// <returns>Result string</returns>
+ public static string GenerateRandomDigitCode(int length)
+ {
+ var str = string.Empty;
+ using var rng = RandomNumberGenerator.Create();
+ var byteArray = new byte[length];
+ rng.GetBytes(byteArray);
+ for (var i = 0; i < length; i++)
+ str = string.Concat(str, byteArray[i].ToString());
+
+ return str[..length];
+ }
- /// <summary>
- /// Generate random digit code
- /// </summary>
- /// <param name="length">Length</param>
- /// <returns>Result string</returns>
- public static string GenerateRandomDigitCode(int length)
- {
- var str = string.Empty;
- using var rng = RandomNumberGenerator.Create();
- var byteArray = new byte[length];
- rng.GetBytes(byteArray);
- for (var i = 0; i < length; i++)
- str = string.Concat(str, byteArray[i].ToString());
-
- return str[..length];
- }
+ /// <summary>
+ /// Returns an random interger number within a specified rage
+ /// </summary>
+ /// <param name="min">Minimum number</param>
+ /// <param name="max">Maximum number</param>
+ /// <returns>Result</returns>
+ public static int GenerateRandomInteger(int min = 0, int max = int.MaxValue)
+ {
+ var randomNumberBuffer = new byte[10];
+ RandomNumberGenerator.Create().GetBytes(randomNumberBuffer);
+ return new Random(BitConverter.ToInt32(randomNumberBuffer, 0)).Next(min, max);
+ }
- /// <summary>
- /// Returns an random interger number within a specified rage
- /// </summary>
- /// <param name="min">Minimum number</param>
- /// <param name="max">Maximum number</param>
- /// <returns>Result</returns>
- public static int GenerateRandomInteger(int min = 0, int max = int.MaxValue)
- {
- var randomNumberBuffer = new byte[10];
- RandomNumberGenerator.Create().GetBytes(randomNumberBuffer);
- return new Random(BitConverter.ToInt32(randomNumberBuffer, 0)).Next(min, max);
- }
+ /// <summary>
+ /// Ensure that a string doesn't exceed maximum allowed length
+ /// </summary>
+ /// <param name="str">Input string</param>
+ /// <param name="maxLength">Maximum length</param>
+ /// <param name="postfix">A string to add to the end if the original string was shorten</param>
+ /// <returns>Input string if its lengh is OK; otherwise, truncated input string</returns>
+ public static string EnsureMaximumLength(string str, int maxLength, string postfix = null)
+ {
+ if (string.IsNullOrEmpty(str))
+ return str;
- /// <summary>
- /// Ensure that a string doesn't exceed maximum allowed length
- /// </summary>
- /// <param name="str">Input string</param>
- /// <param name="maxLength">Maximum length</param>
- /// <param name="postfix">A string to add to the end if the original string was shorten</param>
- /// <returns>Input string if its lengh is OK; otherwise, truncated input string</returns>
- public static string EnsureMaximumLength(string str, int maxLength, string postfix = null)
+ if (str.Length > maxLength)
{
- if (string.IsNullOrEmpty(str))
- return str;
+ var pLen = postfix?.Length ?? 0;
- if (str.Length > maxLength)
- {
- var pLen = postfix?.Length ?? 0;
+ var result = str[..(maxLength - pLen)];
+ if (string.IsNullOrEmpty(result))
+ return str[..maxLength];
- var result = str[..(maxLength - pLen)];
- if(string.IsNullOrEmpty(result))
- return str[..maxLength];
+ if (!string.IsNullOrEmpty(postfix)) result += postfix;
+ return result;
+ }
- if (!string.IsNullOrEmpty(postfix))
- {
- result += postfix;
- }
- return result;
- }
+ return str;
+ }
- return str;
- }
+ /// <summary>
+ /// Ensure that a string is not null
+ /// </summary>
+ /// <param name="str">Input string</param>
+ /// <returns>Result</returns>
+ public static string EnsureNotNull(string str)
+ {
+ return str ?? string.Empty;
+ }
- /// <summary>
- /// Ensure that a string is not null
- /// </summary>
- /// <param name="str">Input string</param>
- /// <returns>Result</returns>
- public static string EnsureNotNull(string str)
- {
- return str ?? string.Empty;
- }
+ /// <summary>
+ /// Compare two arrasy
+ /// </summary>
+ /// <typeparam name="T">Type</typeparam>
+ /// <param name="a1">Array 1</param>
+ /// <param name="a2">Array 2</param>
+ /// <returns>Result</returns>
+ public static bool ArraysEqual<T>(T[] a1, T[] a2)
+ {
+ if (ReferenceEquals(a1, a2))
+ return true;
- /// <summary>
- /// Compare two arrasy
- /// </summary>
- /// <typeparam name="T">Type</typeparam>
- /// <param name="a1">Array 1</param>
- /// <param name="a2">Array 2</param>
- /// <returns>Result</returns>
- public static bool ArraysEqual<T>(T[] a1, T[] a2)
- {
- if (ReferenceEquals(a1, a2))
- return true;
+ if (a1 == null || a2 == null)
+ return false;
- if (a1 == null || a2 == null)
- return false;
+ if (a1.Length != a2.Length)
+ return false;
- if (a1.Length != a2.Length)
+ var comparer = EqualityComparer<T>.Default;
+ for (var i = 0; i < a1.Length; i++)
+ if (!comparer.Equals(a1[i], a2[i]))
return false;
+ return true;
+ }
- var comparer = EqualityComparer<T>.Default;
- for (var i = 0; i < a1.Length; i++)
- {
- if (!comparer.Equals(a1[i], a2[i])) return false;
- }
+ /// <summary>
+ /// Check if type is simple
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ public static bool IsSimpleType(Type type)
+ {
+ if (type == null)
return true;
- }
-
- /// <summary>
- /// Check if type is simple
- /// </summary>
- /// <param name="type"></param>
- /// <returns></returns>
- public static bool IsSimpleType(Type type)
- {
- if (type == null)
- return true;
-
- return
- type.IsPrimitive ||
- new[] {
- typeof(string),
- typeof(decimal),
- typeof(DateTime),
- typeof(DateTimeOffset),
- typeof(TimeSpan),
- typeof(Guid)
- }.Contains(type) ||
- type.IsEnum ||
- Convert.GetTypeCode(type) != TypeCode.Object ||
- (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) && IsSimpleType(type.GetGenericArguments()[0]))
- ;
- }
- /// <summary>
- /// Converts a value to a destination type.
- /// </summary>
- /// <param name="value">The value to convert.</param>
- /// <param name="destinationType">The type to convert the value to.</param>
- /// <returns>The converted value.</returns>
- public static object To(object value, Type destinationType)
- {
- return To(value, destinationType, CultureInfo.InvariantCulture);
- }
- /// <summary>
- /// Converts a value to a destination type.
- /// </summary>
- /// <param name="value">The value to convert.</param>
- /// <param name="destinationType">The type to convert the value to.</param>
- /// <param name="culture">Culture</param>
- /// <returns>The converted value.</returns>
- public static object To(object value, Type destinationType, CultureInfo culture)
+ return
+ type.IsPrimitive ||
+ new[] {
+ typeof(string),
+ typeof(decimal),
+ typeof(DateTime),
+ typeof(DateTimeOffset),
+ typeof(TimeSpan),
+ typeof(Guid)
+ }.Contains(type) ||
+ type.IsEnum ||
+ Convert.GetTypeCode(type) != TypeCode.Object ||
+ (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) &&
+ IsSimpleType(type.GetGenericArguments()[0]))
+ ;
+ }
+
+ /// <summary>
+ /// Converts a value to a destination type.
+ /// </summary>
+ /// <param name="value">The value to convert.</param>
+ /// <param name="destinationType">The type to convert the value to.</param>
+ /// <returns>The converted value.</returns>
+ public static object To(object value, Type destinationType)
+ {
+ return To(value, destinationType, CultureInfo.InvariantCulture);
+ }
+
+ /// <summary>
+ /// Converts a value to a destination type.
+ /// </summary>
+ /// <param name="value">The value to convert.</param>
+ /// <param name="destinationType">The type to convert the value to.</param>
+ /// <param name="culture">Culture</param>
+ /// <returns>The converted value.</returns>
+ public static object To(object value, Type destinationType, CultureInfo culture)
+ {
+ if (value != null)
{
- if (value != null)
- {
- var sourceType = value.GetType();
+ var sourceType = value.GetType();
- var destinationConverter = TypeDescriptor.GetConverter(destinationType);
- if (destinationConverter.CanConvertFrom(value.GetType()))
- return destinationConverter.ConvertFrom(null, culture, value);
+ var destinationConverter = TypeDescriptor.GetConverter(destinationType);
+ if (destinationConverter.CanConvertFrom(value.GetType()))
+ return destinationConverter.ConvertFrom(null, culture, value);
- var sourceConverter = TypeDescriptor.GetConverter(sourceType);
- if (sourceConverter.CanConvertTo(destinationType))
- return sourceConverter.ConvertTo(null, culture, value, destinationType);
+ var sourceConverter = TypeDescriptor.GetConverter(sourceType);
+ if (sourceConverter.CanConvertTo(destinationType))
+ return sourceConverter.ConvertTo(null, culture, value, destinationType);
- if (destinationType.IsEnum && value is int)
- return Enum.ToObject(destinationType, (int)value);
+ if (destinationType.IsEnum && value is int)
+ return Enum.ToObject(destinationType, (int)value);
- if (!destinationType.IsInstanceOfType(value))
- return Convert.ChangeType(value, destinationType, culture);
- }
- return value;
+ if (!destinationType.IsInstanceOfType(value))
+ return Convert.ChangeType(value, destinationType, culture);
}
- /// <summary>
- /// Converts a value to a destination type.
- /// </summary>
- /// <param name="value">The value to convert.</param>
- /// <typeparam name="T">The type to convert the value to.</typeparam>
- /// <returns>The converted value.</returns>
- public static T To<T>(object value)
- {
- return (T)To(value, typeof(T));
- }
+ return value;
+ }
- /// <summary>
- /// Convert enum for front-end
- /// </summary>
- /// <param name="value">Enum value</param>
- /// <returns>Converted string</returns>
- public static string ConvertEnum<T>(T value) where T : struct
- {
- var str = value.ToString();
- if (string.IsNullOrEmpty(str)) return string.Empty;
- var result = string.Empty;
- foreach (var c in str)
- if (c.ToString() != c.ToString().ToLower())
- result += " " + c;
- else
- result += c.ToString();
- return result.TrimStart();
- }
+ /// <summary>
+ /// Converts a value to a destination type.
+ /// </summary>
+ /// <param name="value">The value to convert.</param>
+ /// <typeparam name="T">The type to convert the value to.</typeparam>
+ /// <returns>The converted value.</returns>
+ public static T To<T>(object value)
+ {
+ return (T)To(value, typeof(T));
+ }
+ /// <summary>
+ /// Convert enum for front-end
+ /// </summary>
+ /// <param name="value">Enum value</param>
+ /// <returns>Converted string</returns>
+ public static string ConvertEnum<T>(T value) where T : struct
+ {
+ var str = value.ToString();
+ if (string.IsNullOrEmpty(str)) return string.Empty;
+ var result = string.Empty;
+ foreach (var c in str)
+ if (c.ToString() != c.ToString().ToLower())
+ result += " " + c;
+ else
+ result += c.ToString();
+ return result.TrimStart();
+ }
- /// <summary>
- /// Get difference in years
- /// </summary>
- /// <param name="startDate"></param>
- /// <param name="endDate"></param>
- /// <returns></returns>
- public static int GetDifferenceInYears(DateTime startDate, DateTime endDate)
- {
- //source: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c
- //this assumes you are looking for the western idea of age and not using East Asian reckoning.
- var age = endDate.Year - startDate.Year;
- if (startDate > endDate.AddYears(-age))
- age--;
- return age;
- }
+ /// <summary>
+ /// Get difference in years
+ /// </summary>
+ /// <param name="startDate"></param>
+ /// <param name="endDate"></param>
+ /// <returns></returns>
+ public static int GetDifferenceInYears(DateTime startDate, DateTime endDate)
+ {
+ //source: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c
+ //this assumes you are looking for the western idea of age and not using East Asian reckoning.
+ var age = endDate.Year - startDate.Year;
+ if (startDate > endDate.AddYears(-age))
+ age--;
+ return age;
}
}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
index 831d5d1a0..5b60ada45 100644
--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
@@ -1,115 +1,115 @@
-namespace Grand.SharedKernel.Extensions
+namespace Grand.SharedKernel.Extensions;
+
+public static class CommonPath
{
- public static class CommonPath
+ public static string AppData => "App_Data";
+
+ /// <summary>
+ /// Extra parameter to path
+ /// </summary>
+ public static string Param { get; set; } = "";
+
+ /// <summary>
+ /// Maps a settings path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string DataProtectionKeysPath => Path.Combine(BaseDirectory, AppData, Param, "DataProtectionKeys");
+
+ /// <summary>
+ /// Maps a settings path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string SettingsPath => Path.Combine(BaseDirectory, AppData, Param, "Settings.cfg");
+
+ /// <summary>
+ /// Maps a theme path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string PluginsPath => Path.Combine(BaseDirectory, "Plugins");
+
+ /// <summary>
+ /// Maps a image path.
+ /// </summary>
+ /// <returns>The path.</returns>
+ public static string ImagePath => Path.Combine("assets", "images");
+
+ /// <summary>
+ /// Maps a image thumb path.
+ /// </summary>
+ /// <returns>The path.</returns>
+ public static string ImageThumbPath => Path.Combine("assets", "images", "thumbs");
+
+ /// <summary>
+ /// Maps a image upload path.
+ /// </summary>
+ /// <returns>The path.</returns>
+ public static string ImageUploadedPath => Path.Combine("assets", "images", "uploaded");
+
+
+ /// <summary>
+ /// Maps a installled plugins path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string InstalledPluginsFilePath =>
+ Path.Combine(BaseDirectory, AppData, Param, "InstalledPlugins.cfg");
+
+ /// <summary>
+ /// Maps a installled plugins path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string PluginsCopyPath => Path.Combine(BaseDirectory, PluginsPath, "bin");
+
+ /// <summary>
+ /// Maps a temp upload path to a physical disk path.
+ /// </summary>
+ /// <returns>The physical path.</returns>
+ public static string TmpUploadPath => Path.Combine(BaseDirectory, AppData, Param, "TempUploads");
+
+ /// <summary>
+ /// Gets or sets application base path
+ /// </summary>
+ public static string BaseDirectory { get; set; }
+
+ /// <summary>
+ /// Gets or sets web application content files
+ /// </summary>
+ public static string WebRootPath => Path.Combine(WebHostEnvironment, Param);
+
+ /// <summary>
+ /// Gets or sets web application content files
+ /// </summary>
+ public static string WebHostEnvironment { get; set; }
+
+ /// <summary>
+ /// Maps a path to a physical disk path.
+ /// </summary>
+ /// <param name="path">The path to map. E.g. "~/bin"</param>
+ /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\bin"</returns>
+ public static string MapPath(string path)
+ {
+ path = path.Replace("~/", "").TrimStart('/');
+ return Path.Combine(BaseDirectory, path);
+ }
+
+ /// <summary>
+ /// Maps a virtual path to a physical disk path (for tenants).
+ /// </summary>
+ /// <param name="path">The path to map. E.g. "~/bin"</param>
+ /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>
+ public static string WebMapPath(string path)
{
- public static string AppData => "App_Data";
- /// <summary>
- /// Extra parameter to path
- /// </summary>
- public static string Param { get; set; } = "";
-
- /// <summary>
- /// Maps a path to a physical disk path.
- /// </summary>
- /// <param name="path">The path to map. E.g. "~/bin"</param>
- /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\bin"</returns>
- public static string MapPath(string path)
- {
- path = path.Replace("~/", "").TrimStart('/');
- return Path.Combine(BaseDirectory, path);
- }
-
- /// <summary>
- /// Maps a settings path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string DataProtectionKeysPath => Path.Combine(BaseDirectory, AppData, Param, "DataProtectionKeys");
-
- /// <summary>
- /// Maps a settings path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string SettingsPath => Path.Combine(BaseDirectory, AppData, Param, "Settings.cfg");
-
- /// <summary>
- /// Maps a theme path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string PluginsPath => Path.Combine(BaseDirectory, "Plugins");
-
- /// <summary>
- /// Maps a image path.
- /// </summary>
- /// <returns>The path.</returns>
- public static string ImagePath => Path.Combine("assets", "images");
-
- /// <summary>
- /// Maps a image thumb path.
- /// </summary>
- /// <returns>The path.</returns>
- public static string ImageThumbPath => Path.Combine("assets", "images", "thumbs");
-
- /// <summary>
- /// Maps a image upload path.
- /// </summary>
- /// <returns>The path.</returns>
- public static string ImageUploadedPath => Path.Combine("assets", "images", "uploaded");
-
-
- /// <summary>
- /// Maps a installled plugins path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string InstalledPluginsFilePath => Path.Combine(BaseDirectory, AppData, Param, "InstalledPlugins.cfg");
-
- /// <summary>
- /// Maps a installled plugins path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string PluginsCopyPath => Path.Combine(BaseDirectory, PluginsPath, "bin");
-
- /// <summary>
- /// Maps a temp upload path to a physical disk path.
- /// </summary>
- /// <returns>The physical path.</returns>
- public static string TmpUploadPath => Path.Combine(BaseDirectory, AppData, Param, "TempUploads");
-
- /// <summary>
- /// Gets or sets application base path
- /// </summary>
- public static string BaseDirectory { get; set; }
-
- /// <summary>
- /// Maps a virtual path to a physical disk path (for tenants).
- /// </summary>
- /// <param name="path">The path to map. E.g. "~/bin"</param>
- /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>
- public static string WebMapPath(string path)
- {
- path = path.Replace("~/", "").TrimStart('/');
- return Path.Combine(WebRootPath, path);
- }
-
- /// <summary>
- /// Gets or sets web application content files
- /// </summary>
- public static string WebRootPath => Path.Combine(WebHostEnvironment, Param);
-
- /// <summary>
- /// Maps a virtual path to a physical disk path. (not for tenants)
- /// </summary>
- /// <param name="path">The path to map. E.g. "~/bin"</param>
- /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>
- public static string WebHostMapPath(string path)
- {
- path = path.Replace("~/", "").TrimStart('/');
- return Path.Combine(WebHostEnvironment, path);
- }
-
- /// <summary>
- /// Gets or sets web application content files
- /// </summary>
- public static string WebHostEnvironment { get; set; }
+ path = path.Replace("~/", "").TrimStart('/');
+ return Path.Combine(WebRootPath, path);
+ }
+ /// <summary>
+ /// Maps a virtual path to a physical disk path. (not for tenants)
+ /// </summary>
+ /// <param name="path">The path to map. E.g. "~/bin"</param>
+ /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>
+ public static string WebHostMapPath(string path)
+ {
+ path = path.Replace("~/", "").TrimStart('/');
+ return Path.Combine(WebHostEnvironment, path);
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Extensions/ExtendedLinq.cs b/src/Core/Grand.SharedKernel/Extensions/ExtendedLinq.cs
index ecd62d69d..0b4c11ee1 100644
--- a/src/Core/Grand.SharedKernel/Extensions/ExtendedLinq.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/ExtendedLinq.cs
@@ -1,46 +1,37 @@
-namespace Grand.SharedKernel.Extensions
+namespace Grand.SharedKernel.Extensions;
+
+public static class ExtendedLinq
{
- public static class ExtendedLinq
+ public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> values)
{
- public static bool ContainsAny<TSource>(this IEnumerable<TSource> source, IEnumerable<TSource> values)
- {
- return source.Any(s => values.Contains(s));
- }
+ return source.Any(s => values.Contains(s));
+ }
- public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(
- this IEnumerable<IEnumerable<T>> sequences)
- {
- IEnumerable<IEnumerable<T>> emptyProduct = new[] { Enumerable.Empty<T>() };
- return sequences.Aggregate(
- emptyProduct,
- (accumulator, sequence) =>
+ public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(
+ this IEnumerable<IEnumerable<T>> sequences)
+ {
+ IEnumerable<IEnumerable<T>> emptyProduct = new[] { Enumerable.Empty<T>() };
+ return sequences.Aggregate(
+ emptyProduct,
+ (accumulator, sequence) =>
from accseq in accumulator
from item in sequence
select accseq.Concat(new[] { item }));
- }
-
- public static async Task<bool> AllAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
- {
- foreach (var item in source)
- {
- if (!await predicate(item))
- {
- return false;
- }
- }
- return true;
- }
- public static async Task<bool> AnyAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
- {
- foreach (var item in source)
- {
- if (await predicate(item))
- {
- return true;
- }
- }
- return false;
- }
+ }
+ public static async Task<bool> AllAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
+ {
+ foreach (var item in source)
+ if (!await predicate(item))
+ return false;
+ return true;
+ }
+
+ public static async Task<bool> AnyAsync<T>(this IEnumerable<T> source, Func<T, Task<bool>> predicate)
+ {
+ foreach (var item in source)
+ if (await predicate(item))
+ return true;
+ return false;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/Extensions/FormatText.cs b/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
index 48fb93d32..a7e2f85ec 100644
--- a/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/FormatText.cs
@@ -1,20 +1,19 @@
using System.Net;
-namespace Grand.SharedKernel.Extensions
+namespace Grand.SharedKernel.Extensions;
+
+public static class FormatText
{
- public static class FormatText
+ public static string ConvertText(string text)
{
- public static string ConvertText(string text)
- {
- if (string.IsNullOrEmpty(text))
- return string.Empty;
+ if (string.IsNullOrEmpty(text))
+ return string.Empty;
- text = WebUtility.HtmlEncode(text);
+ text = WebUtility.HtmlEncode(text);
- text = text.Replace("\r\n", "<br />");
- text = text.Replace("\t", "&nbsp;&nbsp;");
+ text = text.Replace("\r\n", "<br />");
+ text = text.Replace("\t", "&nbsp;&nbsp;");
- return text;
- }
+ return text;
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/FieldSizeLimits.cs b/src/Core/Grand.SharedKernel/FieldSizeLimits.cs
index d67810a62..e1df6c3ac 100644
--- a/src/Core/Grand.SharedKernel/FieldSizeLimits.cs
+++ b/src/Core/Grand.SharedKernel/FieldSizeLimits.cs
@@ -4,4 +4,4 @@ public static class FieldSizeLimits
{
public const int NameMaxLength = 200;
public const int EmailMaxLength = 150;
-}
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/GrandException.cs b/src/Core/Grand.SharedKernel/GrandException.cs
index a7917edf6..1aded7d1b 100644
--- a/src/Core/Grand.SharedKernel/GrandException.cs
+++ b/src/Core/Grand.SharedKernel/GrandException.cs
@@ -1,26 +1,24 @@
-namespace Grand.SharedKernel
+namespace Grand.SharedKernel;
+
+/// <summary>
+/// Represents errors that occur during application execution
+/// </summary>
+[Serializable]
+public class GrandException : Exception
{
/// <summary>
- /// Represents errors that occur during application execution
+ /// Initializes a new instance of the Exception class.
/// </summary>
- [Serializable]
- public class GrandException : Exception
+ public GrandException()
{
- /// <summary>
- /// Initializes a new instance of the Exception class.
- /// </summary>
- public GrandException()
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the Exception class with a specified error message.
- /// </summary>
- /// <param name="message">The message that describes the error.</param>
- public GrandException(string message)
- : base(message)
- {
- }
+ }
+ /// <summary>
+ /// Initializes a new instance of the Exception class with a specified error message.
+ /// </summary>
+ /// <param name="message">The message that describes the error.</param>
+ public GrandException(string message)
+ : base(message)
+ {
}
-}
+}
\ No newline at end of file
diff --git a/src/Core/Grand.SharedKernel/IStartupBase.cs b/src/Core/Grand.SharedKernel/IStartupBase.cs
index 346a78aad..68a1f9c2c 100644
--- a/src/Core/Grand.SharedKernel/IStartupBase.cs
+++ b/src/Core/Grand.SharedKernel/IStartupBase.cs
@@ -1,15 +1,14 @@
-namespace Grand.SharedKernel
+namespace Grand.SharedKernel;
+
+public interface IStartupBase
{
- public interface IStartupBase
- {
- /// <summary>
- /// Execute
- /// </summary>
- void Execute();
+ /// <summary>
+ /// Priority
+ /// </summary>
+ int Priority { get; }
- /// <summary>
- /// Priority
- /// </summary>
- int Priority { get; }
- }
-}
+ /// <summary>
+ /// Execute
+ /// </summary>
+ void Execute();
+}
\ No newline at end of file