From 796dd7cc2b576fe0e331d92f61b5872690bb4d77 Mon Sep 17 00:00:00 2001 From: Andy Howard Date: Thu, 20 Nov 2025 17:17:40 +0000 Subject: [PATCH] BusinessMgr 3.0.2 .Net8 --- SacsCoreUnitTests/SacsCoreUnitTests.csproj | 2 +- SacsCoreWeb/SacsCoreWeb.csproj | 2 +- SacsCoreWeb/Web/Components/SaController.cs | 81 +++++++++++++------ SacsMobileMaui/Maui/Layouts/SamWrapLayout.cs | 14 +--- SacsMobileMaui/SacsMobileMaui.csproj | 12 +-- SacsMobileXamarin/SacsMobileXamarin.csproj | 2 +- .../SacsStandardAccounts.csproj | 2 +- SacsStandardBase/Base/App/SacsVersion.cs | 16 ++-- .../Base/Data/SacsAesIvCrypter.cs | 15 ++-- SacsStandardBase/Base/Dbas/DbResultSet.cs | 15 ++-- .../Base/Helpers/SacsHttpClientHelper.cs | 8 +- SacsStandardBase/Base/IO/DirectoryUtil.cs | 32 ++++---- SacsStandardBase/Base/IO/FileUtil.cs | 19 +++-- SacsStandardBase/Base/Net/SacsHttpClient.cs | 7 +- SacsStandardBase/Base/Procs/SaProcess_Base.cs | 6 +- SacsStandardBase/Base/Utils/AssemblyUtil.cs | 7 +- SacsStandardBase/Base/Utils/DateUtil.cs | 2 +- .../Base/Utils/SerializableUtil.cs | 6 -- SacsStandardBase/Base/Utils/StringUtil.cs | 6 +- SacsStandardBase/SacsStandardBase.csproj | 2 +- .../Dbas/Data/DbResultSet_DataTableReader.cs | 12 +-- SacsStandardDbas/SacsStandardDbas.csproj | 2 +- .../Proc/Excel/SaMsSpreadsheet_OpenXml.cs | 6 +- SacsStandardProc/SacsStandardProc.csproj | 2 +- 24 files changed, 142 insertions(+), 136 deletions(-) diff --git a/SacsCoreUnitTests/SacsCoreUnitTests.csproj b/SacsCoreUnitTests/SacsCoreUnitTests.csproj index 63a75b7..ba3c657 100644 --- a/SacsCoreUnitTests/SacsCoreUnitTests.csproj +++ b/SacsCoreUnitTests/SacsCoreUnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false diff --git a/SacsCoreWeb/SacsCoreWeb.csproj b/SacsCoreWeb/SacsCoreWeb.csproj index d1418d1..08fede0 100644 --- a/SacsCoreWeb/SacsCoreWeb.csproj +++ b/SacsCoreWeb/SacsCoreWeb.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Sacs diff --git a/SacsCoreWeb/Web/Components/SaController.cs b/SacsCoreWeb/Web/Components/SaController.cs index 8b703ae..6f02431 100644 --- a/SacsCoreWeb/Web/Components/SaController.cs +++ b/SacsCoreWeb/Web/Components/SaController.cs @@ -14,12 +14,13 @@ using System.Collections.Specialized; using System.Globalization; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Web; namespace Sacs.Web.Components { //======================================================================= - public class SaController : Controller + public class SaController : Controller, ISacsStateItem { //------------------------------------------------------------------- /// @@ -246,7 +247,7 @@ namespace Sacs.Web.Components public AjaxResponse_Base SetSessionExpired(String title, String text) { SessionExpired = true; - return SetMessage(title, text); + return SetPopupMessage(title, text); } public AjaxResponse_Base SetGoHome() { @@ -256,21 +257,53 @@ namespace Sacs.Web.Components public AjaxResponse_Base SetGoHome(String title, String text) { GoHome = true; - return SetMessage(title, text); + return SetPopupMessage(title, text); } - // Message - displays alert popup. + + // Inline message - to display on view. + public class InlineMessageData + { + public String Text { get; init; } + public bool? Warning { get { return Level == SaMessageLevel.Warning ? true : null; } } + public bool? Error { get { return Level == SaMessageLevel.Error ? true : null; } } + [JsonIgnore] + public SaMessageLevel Level { get; init; } = SaMessageLevel.Info; + } + public InlineMessageData InlineMessage { get; private set; } + public AjaxResponse_Base SetInfoMessage(String message) + { + if (!StringUtil.IsBlank(message)) + InlineMessage = new() { Text = message }; + if (InlineMessage is not null) throw new NotSupportedException("Inline message already populated"); + return this; + } + public AjaxResponse_Base SetWarningMessage(String message) + { + if (!StringUtil.IsBlank(message)) + InlineMessage = new() { Text = message, Level = SaMessageLevel.Warning }; + return this; + } + public AjaxResponse_Base SetErrorMessage(String message) + { + if (!StringUtil.IsBlank(message)) + InlineMessage = new() { Text = message, Level = SaMessageLevel.Error }; + return this; + } + + // Popup Message - displays in modal popup. public class MessageData { public String Title { get; set; } public String Text { get; set; } } - public MessageData Message { get; private set; } - public AjaxResponse_Base SetMessage(String title, String text) + public MessageData PopupMessage { get; private set; } + public AjaxResponse_Base SetPopupMessage(String title, String text) { if (!StringUtil.IsBlank(text)) - Message = new MessageData() { Title = title, Text = text }; + PopupMessage = new MessageData() { Title = title, Text = text }; return this; } + // Confirmation message - to query user. public class ConfirmMessageData : MessageData { @@ -284,6 +317,20 @@ namespace Sacs.Web.Components return this; } public bool? HasConfirmMessage { get { return ConfirmMessage != null ? true : null; } } + + // Notify message - briefly displays after response received. + public class NotifyMessageData + { + public String Title { get; set; } + public String Message { get; set; } + } + public NotifyMessageData NotifyMessage { get; private set; } + public AjaxResponse_Base SetNotifyMessage(String title, String message) + { + NotifyMessage = new NotifyMessageData() { Title = title, Message = message }; + return this; + } + } //------------------------------------------------------------------- @@ -295,15 +342,15 @@ namespace Sacs.Web.Components { if (model.ErrorMessages.Any()) { - SetMessage(StringUtil.OnBlank(messageTitle, model.GetText("label.error", "Error")), model.ErrorMessages.Concat("", "\n")); + SetPopupMessage(StringUtil.OnBlank(messageTitle, model.GetText("label.error", "Error")), model.ErrorMessages.Concat("", "\n")); } else if (model.WarningMessages.Any()) { - SetMessage(StringUtil.OnBlank(messageTitle, model.GetText("label.warning", "Warning")), model.WarningMessages.Concat("", "\n")); + SetPopupMessage(StringUtil.OnBlank(messageTitle, model.GetText("label.warning", "Warning")), model.WarningMessages.Concat("", "\n")); } else if (model.InfoMessages.Any()) { - SetNotification(StringUtil.OnBlank(messageTitle, model.GetText("label.notification", "Notificaton")), model.InfoMessages.Concat("", "\n")); + SetNotifyMessage(StringUtil.OnBlank(messageTitle, model.GetText("label.notification", "Notificaton")), model.InfoMessages.Concat("", "\n")); } } @@ -491,20 +538,6 @@ namespace Sacs.Web.Components return false; } - //--------------------------------------------------------------- - // Notification - briefly displays after response received. - public class NotificationData - { - public String Title { get; set; } - public String Message { get; set; } - } - public NotificationData Notification { get; private set; } - public AjaxResponse_Data SetNotification(String title, String message) - { - Notification = new NotificationData() { Title = title, Message = message }; - return this; - } - //--------------------------------------------------------------- // Paged data. public class PagingData diff --git a/SacsMobileMaui/Maui/Layouts/SamWrapLayout.cs b/SacsMobileMaui/Maui/Layouts/SamWrapLayout.cs index 3b03a75..b1903d6 100644 --- a/SacsMobileMaui/Maui/Layouts/SamWrapLayout.cs +++ b/SacsMobileMaui/Maui/Layouts/SamWrapLayout.cs @@ -1,10 +1,4 @@ using Microsoft.Maui.Controls.Compatibility; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Sarand.Net.Mobile.Maui.Layouts { @@ -139,7 +133,7 @@ namespace Sarand.Net.Mobile.Maui.Layouts var size = child.Measure(widthConstraint, heightConstraint); var itemWidth = (double)columnsSize; - var itemHeight = size.Request.Height; + var itemHeight = size.Height; if (IsSquare) { @@ -201,8 +195,8 @@ namespace Sarand.Net.Mobile.Maui.Layouts { var child = childBlock.current.child; var size = childBlock.current.size; - var itemWidth = size.Request.Width; - var itemHeight = size.Request.Height; + var itemWidth = size.Width; + var itemHeight = size.Height; rowHeight = Math.Max(rowHeight, itemHeight + SpacingY); rowWidth += itemWidth + SpacingX; @@ -224,7 +218,7 @@ namespace Sarand.Net.Mobile.Maui.Layouts } xPos += itemWidth + SpacingX; - var nextWitdh = childBlock.next.size.Request.Width; + var nextWitdh = childBlock.next.size.Width; if (xPos + nextWitdh - x > widthConstraint) { diff --git a/SacsMobileMaui/SacsMobileMaui.csproj b/SacsMobileMaui/SacsMobileMaui.csproj index 114683f..b53d120 100644 --- a/SacsMobileMaui/SacsMobileMaui.csproj +++ b/SacsMobileMaui/SacsMobileMaui.csproj @@ -1,8 +1,8 @@ - net8.0-android;net8.0-ios;net8.0-maccatalyst - $(TargetFrameworks);net8.0-windows10.0.19041.0 + net9.0-android;net9.0-ios;net9.0-maccatalyst18.0 + $(TargetFrameworks);net9.0-windows10.0.19041.0 true @@ -10,9 +10,9 @@ enable enable - 15.4 + 14.5 13.1 - 21.0 + 32.0 10.0.17763.0 10.0.17763.0 6.3 @@ -20,8 +20,8 @@ - - + + diff --git a/SacsMobileXamarin/SacsMobileXamarin.csproj b/SacsMobileXamarin/SacsMobileXamarin.csproj index 4189384..8bfc545 100644 --- a/SacsMobileXamarin/SacsMobileXamarin.csproj +++ b/SacsMobileXamarin/SacsMobileXamarin.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Sarand.Net.Mobile diff --git a/SacsStandardAccounts/SacsStandardAccounts.csproj b/SacsStandardAccounts/SacsStandardAccounts.csproj index 6109294..357193e 100644 --- a/SacsStandardAccounts/SacsStandardAccounts.csproj +++ b/SacsStandardAccounts/SacsStandardAccounts.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Sarand.Net.Standard diff --git a/SacsStandardBase/Base/App/SacsVersion.cs b/SacsStandardBase/Base/App/SacsVersion.cs index 51bb70f..106a1aa 100644 --- a/SacsStandardBase/Base/App/SacsVersion.cs +++ b/SacsStandardBase/Base/App/SacsVersion.cs @@ -1,8 +1,6 @@ -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; -using System.Text; namespace Sarand.Net.Standard.Base.App { @@ -11,7 +9,7 @@ namespace Sarand.Net.Standard.Base.App { //------------------------------------------------------------------- // Construction. - public SacsVersion (String name, String version, DateTime buildAt) + public SacsVersion(String name, String version, DateTime buildAt) { Name = name; Version = version; @@ -27,7 +25,7 @@ namespace Sarand.Net.Standard.Base.App } catch (Exception exc) { - SaLogger.Warn(GetType().Name + " " + exc.GetType().Name + " on parsing version: " + exc.Message); + SaLogger.Warn($"{GetType().Name} {exc.GetType().Name} on parsing version: {ExceptionUtil.GetMessage(exc)}"); } VersionInt = Ver1 << 48 + Ver2 << 32 + Ver3 << 16 + Ver4; } @@ -45,24 +43,24 @@ namespace Sarand.Net.Standard.Base.App //------------------------------------------------------------------- // Comparison. - public override bool Equals (object obj) + public override bool Equals(object obj) { if (obj is SacsVersion) return Equals(obj as SacsVersion); return base.Equals(obj); } - public override int GetHashCode () + public override int GetHashCode() { var hashCode = 2121240903; hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Version); hashCode = hashCode * -1521134295 + VersionInt.GetHashCode(); return hashCode; } - public bool Equals (SacsVersion version) + public bool Equals(SacsVersion version) { if (VersionInt == version.VersionInt) return true; return false; } - public int CompareTo (SacsVersion version, bool includeName = false) + public int CompareTo(SacsVersion version, bool includeName = false) { int versionCompare = VersionInt.CompareTo(version.VersionInt); if (!includeName || versionCompare != 0) return versionCompare; diff --git a/SacsStandardBase/Base/Data/SacsAesIvCrypter.cs b/SacsStandardBase/Base/Data/SacsAesIvCrypter.cs index eee4a7b..6892ce0 100644 --- a/SacsStandardBase/Base/Data/SacsAesIvCrypter.cs +++ b/SacsStandardBase/Base/Data/SacsAesIvCrypter.cs @@ -1,10 +1,7 @@ using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; using System; -using System.Collections.Generic; using System.IO; using System.Security.Cryptography; -using System.Text; namespace Sarand.Net.Standard.Base.Data { @@ -23,11 +20,11 @@ namespace Sarand.Net.Standard.Base.Data // Either generate a 32 byte key or use any string and convert it into a key with CreateKey. // NB The salt will remain the same here for each key generated - it does not need to be randomized as with hashing. //------------------------------------------------------------------- - private static byte[] CreateKey (string password, int keyBytes = 32) + private static byte[] CreateKey(string password, int keyBytes = 32) { byte[] salt = new byte[] { 80, 70, 60, 50, 40, 30, 20, 10 }; int iterations = 300; - DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt, iterations); + DeriveBytes keyGenerator = new Rfc2898DeriveBytes(password, salt, iterations, HashAlgorithmName.SHA256); return keyGenerator.GetBytes(keyBytes); } @@ -37,7 +34,7 @@ namespace Sarand.Net.Standard.Base.Data // In AES, the IV is a randomizer, making sure that no two identical messages ever give the same encrypted output. // The IV can be public and does not need to be hidden. //------------------------------------------------------------------- - public static string Encrypt (this string clearValue, string encryptionKey) + public static string Encrypt(this string clearValue, string encryptionKey) { using (Aes aes = Aes.Create()) { @@ -48,7 +45,7 @@ namespace Sarand.Net.Standard.Base.Data } } //------------------------------------------------------------------- - public static byte[] Encrypt (string plainText, byte[] key, byte[] iv) + public static byte[] Encrypt(string plainText, byte[] key, byte[] iv) { if (plainText == null || plainText.Length <= 0) throw new ArgumentNullException($"{nameof(plainText)}"); if (key == null || key.Length <= 0) throw new ArgumentNullException($"{nameof(key)}"); @@ -79,7 +76,7 @@ namespace Sarand.Net.Standard.Base.Data // assume that the IV is at the end of the string passed in. // To decrypt a message encrypted by another function, the IV will have to be passed explicitly. //------------------------------------------------------------------- - public static string Decrypt (this string encryptedValue, string encryptionKey) + public static string Decrypt(this string encryptedValue, string encryptionKey) { String[] valueParts = encryptedValue.Split(new String[] { AesIvDelimiter }, StringSplitOptions.None); if (valueParts.Length != 2) @@ -91,7 +88,7 @@ namespace Sarand.Net.Standard.Base.Data return Decrypt(Convert.FromBase64String(valueParts[0]), CreateKey(encryptionKey), Convert.FromBase64String(valueParts[1])); } //------------------------------------------------------------------- - public static string Decrypt (byte[] cipherText, byte[] key, byte[] iv) + public static string Decrypt(byte[] cipherText, byte[] key, byte[] iv) { if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException($"{nameof(cipherText)}"); if (key == null || key.Length <= 0) throw new ArgumentNullException($"{nameof(key)}"); diff --git a/SacsStandardBase/Base/Dbas/DbResultSet.cs b/SacsStandardBase/Base/Dbas/DbResultSet.cs index 9795e6a..259627d 100644 --- a/SacsStandardBase/Base/Dbas/DbResultSet.cs +++ b/SacsStandardBase/Base/Dbas/DbResultSet.cs @@ -1,7 +1,8 @@ -using System; -using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Utils; +using System; namespace Sarand.Net.Standard.Base.Dbas { @@ -54,7 +55,7 @@ namespace Sarand.Net.Standard.Base.Dbas // Get Field Value. public DataValue GetFieldValue(String columnName) { - String fn = GetType().Name + ".GetFieldValue('" + columnName + "')"; + String fn = $"{GetType().Name}.GetFieldValue('{columnName}')"; DataValue dataValue = null; try { @@ -62,7 +63,7 @@ namespace Sarand.Net.Standard.Base.Dbas } catch (Exception exc) { - SaLogger.Warn(fn + " Exception: " + exc.Message); + SaLogger.Warn($"{fn} {ExceptionUtil.GetErrorStateMessage(exc)}"); } return dataValue; } @@ -71,7 +72,7 @@ namespace Sarand.Net.Standard.Base.Dbas #endif public DataValue GetFieldValue(int columnIdx) { - String fn = GetType().Name + ".GetFieldValue(" + columnIdx + ")"; + String fn = $"{GetType().Name}.GetFieldValue('{columnIdx}')"; if (IsDbNull(columnIdx)) return null; String columnDataType = ""; DataValue dataValue = null; @@ -136,7 +137,7 @@ namespace Sarand.Net.Standard.Base.Dbas } catch (Exception exc) { - SaLogger.Warn(fn + " Data type: " + columnDataType + ". Exception: " + exc.Message /*+ "\n" + exc.ToString()*/); + SaLogger.Warn($"{fn} Data type: {columnDataType}. {ExceptionUtil.GetErrorStateMessage(exc)}"); #if DEBUG if (!handlingGetFieldValueException) { diff --git a/SacsStandardBase/Base/Helpers/SacsHttpClientHelper.cs b/SacsStandardBase/Base/Helpers/SacsHttpClientHelper.cs index c3484c8..192a8fb 100644 --- a/SacsStandardBase/Base/Helpers/SacsHttpClientHelper.cs +++ b/SacsStandardBase/Base/Helpers/SacsHttpClientHelper.cs @@ -1,12 +1,10 @@ -using Microsoft.Net.Http.Headers; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Net; using Sarand.Net.Standard.Base.Tasks; using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; -using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -179,8 +177,8 @@ namespace Sarand.Net.Standard.Base.Helpers { exc = exc.InnerException; } - String msg = exc.GetType().Name + ": " + exc.Message; - SaLogger.Warn(SysUtil.Fn + " " + msg + ExceptionUtil.GetStackEntries(exc, 6).Concat("", "\n\t")); + String msg = ExceptionUtil.GetErrorStateMessage(exc); + SaLogger.Warn($"{SysUtil.Fn} {msg}{ExceptionUtil.GetStackEntries(exc, 6).Concat("", "\n\t")}"); responseData.ErrorStateMessage = msg; } requestData.ThrowIfCancellationRequested(); diff --git a/SacsStandardBase/Base/IO/DirectoryUtil.cs b/SacsStandardBase/Base/IO/DirectoryUtil.cs index 3bb3952..c0ac1cb 100644 --- a/SacsStandardBase/Base/IO/DirectoryUtil.cs +++ b/SacsStandardBase/Base/IO/DirectoryUtil.cs @@ -1,9 +1,9 @@ -using System; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Utils; +using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; namespace Sarand.Net.Standard.Base.IO { @@ -13,7 +13,7 @@ namespace Sarand.Net.Standard.Base.IO //------------------------------------------------------------------- // D i r e c t o r y E x i s t s //------------------------------------------------------------------- - public static bool DirectoryExists (String directory) + public static bool DirectoryExists(String directory) { try { @@ -32,7 +32,7 @@ namespace Sarand.Net.Standard.Base.IO /// The path of a file or directory. /// Directory information for path, or null if path denotes a root directory or is /// null. Returns System.String.Empty if path does not contain directory information. - public static String GetDirectoryName (String path) + public static String GetDirectoryName(String path) { try { @@ -54,7 +54,7 @@ namespace Sarand.Net.Standard.Base.IO /// Retrieve list of sub directories in directory. /// Avoiding Exception thrown when network path isn't valid. /// - public static IEnumerable EnumerateDirectories (String path) + public static IEnumerable EnumerateDirectories(String path) { try { @@ -62,7 +62,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Error("DirectoryUtil.EnumerateDirectories " + exc.GetType().Name + ": " + exc.Message + ". Path: '" + path + "'"); + SaLogger.Error($"DirectoryUtil.EnumerateDirectories {ExceptionUtil.GetErrorStateMessage(exc)}. Path: '{path}'"); } return new List(); } @@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.IO /// Retrieve list of files in directory. /// Avoiding Exception thrown when network path isn't valid. /// - public static IEnumerable EnumerateFiles (String path) + public static IEnumerable EnumerateFiles(String path) { try { @@ -82,7 +82,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Error("DirectoryUtil.EnumerateFiles " + exc.GetType().Name + ": " + exc.Message + ". Path: '" + path + "'"); + SaLogger.Error($"DirectoryUtil.EnumerateFiles {ExceptionUtil.GetErrorStateMessage(exc)}. Path: '{path}'"); } return new List(); } @@ -91,7 +91,7 @@ namespace Sarand.Net.Standard.Base.IO /// Retrieve list of files in directory. /// Avoiding Exception thrown when network path isn't valid. /// - public static IEnumerable EnumerateFiles (String path, String searchPattern) + public static IEnumerable EnumerateFiles(String path, String searchPattern) { try { @@ -99,7 +99,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Error("DirectoryUtil.EnumerateFiles " + exc.GetType().Name + ": " + exc.Message + ". Path: '" + path + "'. Pattern: " + searchPattern); + SaLogger.Error($"DirectoryUtil.EnumerateFiles {ExceptionUtil.GetErrorStateMessage(exc)}. Path: '{path}'. Pattern: {searchPattern}"); } return new List(); } @@ -108,7 +108,7 @@ namespace Sarand.Net.Standard.Base.IO /// Retrieve list of files in directory. /// Avoiding Exception thrown when network path isn't valid. /// - public static IEnumerable EnumerateFiles (String path, String searchPattern, SearchOption searchOption) + public static IEnumerable EnumerateFiles(String path, String searchPattern, SearchOption searchOption) { try { @@ -116,7 +116,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Error("DirectoryUtil.EnumerateFiles " + exc.GetType().Name + ": " + exc.Message + ". Path: '" + path + "'. Pattern: " + searchPattern + ". Option: " + searchOption.ToString()); + SaLogger.Error($"DirectoryUtil.EnumerateFiles {ExceptionUtil.GetErrorStateMessage(exc)}. Path: '{path}'. Pattern: {searchPattern}. Option: {searchOption}"); } return new List(); } @@ -128,7 +128,7 @@ namespace Sarand.Net.Standard.Base.IO /// Create Directory in the specified path. /// Avoiding Exception thrown when network path isn't valid. /// - public static DirectoryInfo CreateDirectory (String path) + public static DirectoryInfo CreateDirectory(String path) { try { @@ -136,7 +136,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Error("DirectoryUtil.CreateDirectory " + exc.GetType().Name + ": " + exc.Message + ". Path: '" + path + "'"); + SaLogger.Error($"DirectoryUtil.CreateDirectory {ExceptionUtil.GetErrorStateMessage(exc)}. Path: '{path}'"); } return null; } @@ -144,7 +144,7 @@ namespace Sarand.Net.Standard.Base.IO //------------------------------------------------------------------- // Utilities. - public static String TrimTrailingSlashes (String path) + public static String TrimTrailingSlashes(String path) { return Regex.Replace(path, "[\\\\/]+$", ""); } diff --git a/SacsStandardBase/Base/IO/FileUtil.cs b/SacsStandardBase/Base/IO/FileUtil.cs index 655b269..a2fa9a4 100644 --- a/SacsStandardBase/Base/IO/FileUtil.cs +++ b/SacsStandardBase/Base/IO/FileUtil.cs @@ -1,11 +1,10 @@ -using System; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Utils; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Base.IO { @@ -57,7 +56,7 @@ namespace Sarand.Net.Standard.Base.IO // Default method. return Directory.Exists(directoryPath); } - catch (Exception exc) { SaLogger.Debug("FileUtil.IsDirectory " + exc.GetType().Name + ": " + exc.Message); } + catch (Exception exc) { SaLogger.Debug($"FileUtil.IsDirectory {ExceptionUtil.GetErrorStateMessage(exc)}"); } return false; } public delegate String DirectoryGetParentFn(String filepath); @@ -74,7 +73,7 @@ namespace Sarand.Net.Standard.Base.IO if (parentDirectoryInfo != null) return parentDirectoryInfo.FullName; } - catch (Exception exc) { SaLogger.Debug("FileUtil.GetParentDirectory " + exc.GetType().Name + ": " + exc.Message); } + catch (Exception exc) { SaLogger.Debug($"FileUtil.GetParentDirectory {ExceptionUtil.GetErrorStateMessage(exc)}"); } return String.Empty; } public delegate bool DirectoryCreateDirectoryFn(String filepath); @@ -90,7 +89,7 @@ namespace Sarand.Net.Standard.Base.IO DirectoryInfo info = Directory.CreateDirectory(directoryPath); return info.Exists; } - catch (Exception exc) { SaLogger.Debug("FileUtil.CreateDirectory " + exc.GetType().Name + ": " + exc.Message); } + catch (Exception exc) { SaLogger.Debug($"FileUtil.CreateDirectory {ExceptionUtil.GetErrorStateMessage(exc)}"); } return false; } public static bool ValidateDirectory(String directoryPath, bool allowCreation = false) @@ -116,7 +115,7 @@ namespace Sarand.Net.Standard.Base.IO } catch (Exception exc) { - SaLogger.Warn(typeof(FileUtil).Name + ".GetFileLastWriteTime " + exc.GetType().Name + ": " + exc.Message); + SaLogger.Warn($"{typeof(FileUtil).Name}.GetFileLastWriteTime {ExceptionUtil.GetErrorStateMessage(exc)}"); } return DateTime.MinValue; } @@ -139,7 +138,7 @@ namespace Sarand.Net.Standard.Base.IO // Default method. return File.Exists(filePath); } - catch (Exception exc) { SaLogger.Debug("FileUtil.IsFile " + exc.GetType().Name + ": " + exc.Message); } + catch (Exception exc) { SaLogger.Debug($"FileUtil.IsFile {ExceptionUtil.GetErrorStateMessage(exc)}"); } return false; } @@ -161,7 +160,7 @@ namespace Sarand.Net.Standard.Base.IO // Default method. return File.ReadAllLines(filePath); } - catch (Exception exc) { SaLogger.Debug("FileUtil.ReadAllFileLines " + exc.GetType().Name + ": " + exc.Message); } + catch (Exception exc) { SaLogger.Debug($"FileUtil.ReadAllFileLines {ExceptionUtil.GetErrorStateMessage(exc)}"); } return new String[0]; } diff --git a/SacsStandardBase/Base/Net/SacsHttpClient.cs b/SacsStandardBase/Base/Net/SacsHttpClient.cs index 8e1ebc3..02582c1 100644 --- a/SacsStandardBase/Base/Net/SacsHttpClient.cs +++ b/SacsStandardBase/Base/Net/SacsHttpClient.cs @@ -1,8 +1,6 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.Net.Http.Headers; +using Microsoft.Net.Http.Headers; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Helpers; using Sarand.Net.Standard.Base.Tasks; using Sarand.Net.Standard.Base.Utils; using System; @@ -14,7 +12,6 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using System.Reflection.Metadata; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -262,7 +259,7 @@ namespace Sarand.Net.Standard.Base.Net { exc = exc.InnerException; } - String msg = exc.GetType().Name + ": " + exc.Message; + String msg = ExceptionUtil.GetErrorStateMessage(exc); SaLogger.Warn(SysUtil.Fn + " " + msg + ExceptionUtil.GetStackEntries(exc, 6).Concat("", "\n\t")); responseData.ErrorStateMessage = msg; } diff --git a/SacsStandardBase/Base/Procs/SaProcess_Base.cs b/SacsStandardBase/Base/Procs/SaProcess_Base.cs index db41438..ceac103 100644 --- a/SacsStandardBase/Base/Procs/SaProcess_Base.cs +++ b/SacsStandardBase/Base/Procs/SaProcess_Base.cs @@ -306,7 +306,7 @@ namespace Sarand.Net.Standard.Base.Procs } catch (Exception exc) { - String msg = exc.GetType().Name + ": " + exc.Message; + String msg = ExceptionUtil.GetErrorStateMessage(exc); AddErrorMessage(msg); SaLogger.Error($"{SysUtil.Fn} ProcessStarting: {msg}{exc.GetStackEntries(6).Concat("", "\n\tat ")}", true); } @@ -319,7 +319,7 @@ namespace Sarand.Net.Standard.Base.Procs } catch (Exception exc) { - String msg = exc.GetType().Name + ": " + exc.Message; + String msg = ExceptionUtil.GetErrorStateMessage(exc); AddErrorMessage(msg); SaLogger.Error($"{SysUtil.Fn} " + msg + exc.GetStackEntries(6).Concat("", "\n\tat "), true); } @@ -340,7 +340,7 @@ namespace Sarand.Net.Standard.Base.Procs } catch (Exception exc) { - String msg = exc.GetType().Name + ": " + exc.Message; + String msg = ExceptionUtil.GetErrorStateMessage(exc); AddErrorMessage(msg); SaLogger.Error($"{SysUtil.Fn} ProcessCompleted: {msg}{exc.GetStackEntries(6).Concat("", "\n\tat ")}", true); } diff --git a/SacsStandardBase/Base/Utils/AssemblyUtil.cs b/SacsStandardBase/Base/Utils/AssemblyUtil.cs index 8909520..9408f4d 100644 --- a/SacsStandardBase/Base/Utils/AssemblyUtil.cs +++ b/SacsStandardBase/Base/Utils/AssemblyUtil.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; namespace Sarand.Net.Standard.Base.Utils { @@ -27,10 +25,9 @@ namespace Sarand.Net.Standard.Base.Utils #pragma warning restore CS0649 }; - public static DateTime GetBuildDateTime (this Assembly assembly) + public static DateTime GetBuildDateTime(this Assembly assembly) { - // Not available until .Net Standard 1.5. - var path = assembly.GetName().CodeBase; + var path = assembly.Location; if (File.Exists(path)) { var buffer = new byte[Math.Max(Marshal.SizeOf(typeof(_IMAGE_FILE_HEADER)), 4)]; diff --git a/SacsStandardBase/Base/Utils/DateUtil.cs b/SacsStandardBase/Base/Utils/DateUtil.cs index e806376..7e406ca 100644 --- a/SacsStandardBase/Base/Utils/DateUtil.cs +++ b/SacsStandardBase/Base/Utils/DateUtil.cs @@ -579,7 +579,7 @@ namespace Sarand.Net.Standard.Base.Utils } catch (Exception exc) { - SaLogger.Debug("DateUtil.Format Exception: " + exc.Message); + SaLogger.Debug($"DateUtil.Format {ExceptionUtil.GetErrorStateMessage(exc)}"); } return String.Empty; } diff --git a/SacsStandardBase/Base/Utils/SerializableUtil.cs b/SacsStandardBase/Base/Utils/SerializableUtil.cs index 5e35e73..c697927 100644 --- a/SacsStandardBase/Base/Utils/SerializableUtil.cs +++ b/SacsStandardBase/Base/Utils/SerializableUtil.cs @@ -1,8 +1,6 @@ using Newtonsoft.Json; using System; using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Xml.Serialization; @@ -20,9 +18,6 @@ namespace Sarand.Net.Standard.Base.Utils /// The copied object. public static T DeepCopy(T source) { - if (!typeof(T).IsSerializable) - throw new ArgumentException("The type must be serializable.", "source"); - // Don't serialize a null object, simply return the default for that object if (Object.ReferenceEquals(source, null)) return default(T); @@ -40,7 +35,6 @@ namespace Sarand.Net.Standard.Base.Utils // Serialize using JSON. public static String ToJson(T source) { - if (!typeof(T).IsSerializable) throw new ArgumentException("The type must be serializable.", "source"); // Don't serialize a null object, simply return the default for that object if (Object.ReferenceEquals(source, null)) return ""; // Serialise to JSON String. diff --git a/SacsStandardBase/Base/Utils/StringUtil.cs b/SacsStandardBase/Base/Utils/StringUtil.cs index 9273dc7..bdb5396 100644 --- a/SacsStandardBase/Base/Utils/StringUtil.cs +++ b/SacsStandardBase/Base/Utils/StringUtil.cs @@ -1,6 +1,4 @@ using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Core; using System; using System.Collections.Generic; using System.Globalization; @@ -665,7 +663,7 @@ namespace Sarand.Net.Standard.Base.Utils } catch (Exception exc) { - SaLogger.Debug("StringUtil.FormatNumeric(double) " + exc.GetType().Name + ": " + exc.Message); + SaLogger.Debug($"StringUtil.FormatNumeric(double) {ExceptionUtil.GetErrorStateMessage(exc)}"); } return value; } @@ -681,7 +679,7 @@ namespace Sarand.Net.Standard.Base.Utils } catch (Exception exc) { - SaLogger.Debug("StringUtil.FormatNumeric(decimal) " + exc.GetType().Name + ": " + exc.Message); + SaLogger.Debug($"StringUtil.FormatNumeric(decimal) {ExceptionUtil.GetErrorStateMessage(exc)}"); } return value; } diff --git a/SacsStandardBase/SacsStandardBase.csproj b/SacsStandardBase/SacsStandardBase.csproj index 39958b8..f9dab15 100644 --- a/SacsStandardBase/SacsStandardBase.csproj +++ b/SacsStandardBase/SacsStandardBase.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Sarand.Net.Standard diff --git a/SacsStandardDbas/Dbas/Data/DbResultSet_DataTableReader.cs b/SacsStandardDbas/Dbas/Data/DbResultSet_DataTableReader.cs index acb43bb..f518d11 100644 --- a/SacsStandardDbas/Dbas/Data/DbResultSet_DataTableReader.cs +++ b/SacsStandardDbas/Dbas/Data/DbResultSet_DataTableReader.cs @@ -1,11 +1,11 @@ -using System; -using System.Data; -using System.Data.Common; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Base; +using System; +using System.Data; +using System.Data.Common; namespace Sarand.Net.Standard.Dbas.Data { @@ -48,8 +48,8 @@ namespace Sarand.Net.Standard.Dbas.Data } catch (Exception exc) { - SetErrorState(exc.GetType().Name + ": " + exc.Message); - SaLogger.Warn(SysUtil.Fn + " " + exc.GetType().Name + ": " + exc.Message + "\n\t Query: " + query, true); + SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); + SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}\n\t Query: " + query, true); } } //------------------------------------------------------------------- diff --git a/SacsStandardDbas/SacsStandardDbas.csproj b/SacsStandardDbas/SacsStandardDbas.csproj index c2f7185..0799354 100644 --- a/SacsStandardDbas/SacsStandardDbas.csproj +++ b/SacsStandardDbas/SacsStandardDbas.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Sarand.Net.Standard diff --git a/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs index 364f53a..070dc82 100644 --- a/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs @@ -101,7 +101,7 @@ namespace Sarand.Net.Standard.Proc.Excel workbook.MemoryStream = new MemoryStream(); workbook.Document = SpreadsheetDocument.Create(workbook.MemoryStream, SpreadsheetDocumentType.Workbook); } - catch (Exception exc) { SaLogger.Warn(exc.GetType().Name + ".CreateWorkbook " + ExceptionUtil.GetErrorStateMessage(exc)); } + catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}"); } return (workbook != null); } public override bool OpenWorkbook(String filePath) @@ -113,7 +113,7 @@ namespace Sarand.Net.Standard.Proc.Excel workbook = new WorkbookData(); workbook.Document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook); } - catch (Exception exc) { SaLogger.Warn(exc.GetType().Name + ".OpenWorkbook " + ExceptionUtil.GetErrorStateMessage(exc)); } + catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}"); } return (workbook != null); } public override bool CleanseWorkbook() @@ -153,7 +153,7 @@ namespace Sarand.Net.Standard.Proc.Excel workbook = null; } } - catch (Exception exc) { SaLogger.Warn(exc.GetType().Name + ".CloseWorkbook " + ExceptionUtil.GetErrorStateMessage(exc)); } + catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}"); } workbook = null; return OK; } diff --git a/SacsStandardProc/SacsStandardProc.csproj b/SacsStandardProc/SacsStandardProc.csproj index 9837ce7..b49affa 100644 --- a/SacsStandardProc/SacsStandardProc.csproj +++ b/SacsStandardProc/SacsStandardProc.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 Sarand.Net.Standard