BusinessMgr 3.0.2 .Net8

This commit is contained in:
Andy Howard
2025-11-20 17:17:40 +00:00
parent e3cb2b26fe
commit 796dd7cc2b
24 changed files with 142 additions and 136 deletions
+7 -9
View File
@@ -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<string>.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;
@@ -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)}");
+8 -7
View File
@@ -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)
{
@@ -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();
+16 -16
View File
@@ -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
/// <param name="path">The path of a file or directory.</param>
/// <returns>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.</returns>
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.
/// <para>Avoiding Exception thrown when network path isn't valid.</para>
/// </summary>
public static IEnumerable<String> EnumerateDirectories (String path)
public static IEnumerable<String> 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<String>();
}
@@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.IO
/// Retrieve list of files in directory.
/// <para>Avoiding Exception thrown when network path isn't valid.</para>
/// </summary>
public static IEnumerable<String> EnumerateFiles (String path)
public static IEnumerable<String> 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<String>();
}
@@ -91,7 +91,7 @@ namespace Sarand.Net.Standard.Base.IO
/// Retrieve list of files in directory.
/// <para>Avoiding Exception thrown when network path isn't valid.</para>
/// </summary>
public static IEnumerable<String> EnumerateFiles (String path, String searchPattern)
public static IEnumerable<String> 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<String>();
}
@@ -108,7 +108,7 @@ namespace Sarand.Net.Standard.Base.IO
/// Retrieve list of files in directory.
/// <para>Avoiding Exception thrown when network path isn't valid.</para>
/// </summary>
public static IEnumerable<String> EnumerateFiles (String path, String searchPattern, SearchOption searchOption)
public static IEnumerable<String> 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<String>();
}
@@ -128,7 +128,7 @@ namespace Sarand.Net.Standard.Base.IO
/// Create Directory in the specified path.
/// <para>Avoiding Exception thrown when network path isn't valid.</para>
/// </summary>
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, "[\\\\/]+$", "");
}
+9 -10
View File
@@ -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];
}
+2 -5
View File
@@ -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;
}
@@ -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);
}
+2 -5
View File
@@ -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)];
+1 -1
View File
@@ -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;
}
@@ -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
/// <returns>The copied object.</returns>
public static T DeepCopy<T>(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>(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.
+2 -4
View File
@@ -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;
}
+1 -1
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Sarand.Net.Standard</RootNamespace>
</PropertyGroup>