Saxonite 1.2.11.4. BusinessMgr.

This commit is contained in:
Andy Howard
2024-06-04 16:14:45 +01:00
parent 7748941680
commit ba5801b4dc
33 changed files with 595 additions and 219 deletions
+6 -3
View File
@@ -59,9 +59,12 @@ namespace Sarand.Net.Standard.Base.Utils
public static List<String> GetStackEntries(this Exception exc, int entries = 0)
{
List<String> stackEntries = new List<string>();
stackEntries.AddRange(exc.StackTrace.Split(new String[] { "\r\n" }, (entries > 0 ? entries : 999), StringSplitOptions.None));
for (int idx = 0; idx < stackEntries.Count; idx++)
stackEntries[idx] = stackEntries[idx].Replace(" at ", "");
if (exc.StackTrace != null)
{
stackEntries.AddRange(exc.StackTrace.Split(new String[] { "\r\n" }, (entries > 0 ? entries : 999), StringSplitOptions.None));
for (int idx = 0; idx < stackEntries.Count; idx++)
stackEntries[idx] = stackEntries[idx].Replace(" at ", "");
}
return stackEntries;
}
+23 -2
View File
@@ -9,7 +9,7 @@ namespace Sarand.Net.Standard.Base.Utils
public static class ListUtil
{
//-------------------------------------------------------------------
public static void ClearAndDispose<T> (this IList<T> values) where T : IDisposable
public static void ClearAndDispose<T>(this IList<T> values) where T : IDisposable
{
while (values.Count > 0)
{
@@ -50,7 +50,12 @@ namespace Sarand.Net.Standard.Base.Utils
/// <summary>Unique values only - ignores number of instances of each value.</summary>
UniqueValuesOnly = 0x02,
}
public static bool Equals<T> (this IList<T> sourceList, IList<T> targetList, Equality equality)
/// <summary>
/// Compare content of two lists.
/// <para>- Exact ensures precise number and sequence of elements.</para>
/// <para>- Unique allows any number and sequence as long as each item is present in both lists.</para>
/// </summary>
public static bool Equals<T>(this IList<T> sourceList, IList<T> targetList, Equality equality)
{
bool sameLength = (sourceList.Count == targetList.Count);
if (equality == Equality.Exact)
@@ -69,6 +74,22 @@ namespace Sarand.Net.Standard.Base.Utils
return true;
}
//-------------------------------------------------------------------
/// <summary>
/// Remove the specified range of items from the list to a new list.
/// </summary>
public static List<T> ExtractRange<T>(this List<T> values, int index, int count)
{
List<T> extractedValues = new List<T>();
if (values.Any())
{
count = Math.Min(values.Count(), count);
extractedValues.AddRange(values.GetRange(index, count));
values.RemoveRange(index, count);
}
return extractedValues;
}
//-------------------------------------------------------------------
}
//=======================================================================
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace Sarand.Net.Standard.Base.Utils
{
//=======================================================================
public static class NewtonsoftJsonUtil
{
//-------------------------------------------------------------------
// Extracting.
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Parsing.
//-------------------------------------------------------------------
/// <summary>Parse data as JSON Token.</summary>
public static JToken ParseJsonToken(string jsonData)
{
return JToken.Parse(jsonData);
}
/// <summary>Parse data as JSON Token.</summary>
public static JToken ParseJsonToken(string jsonData, out Exception excOut)
{
excOut = null;
try
{
return JToken.Parse(jsonData);
}
catch (Exception exc)
{
excOut = exc;
}
return null;
}
//-------------------------------------------------------------------
/// <summary>Parse data as JSON Object.</summary>
public static JObject ParseJsonObject(string jsonData)
{
return JObject.Parse(jsonData);
}
/// <summary>Parse data as JSON Object.</summary>
public static JObject ParseJsonObject(string jsonData, out Exception excOut)
{
excOut = null;
try
{
return JObject.Parse(jsonData);
}
catch (Exception exc)
{
excOut = exc;
}
return null;
}
//-------------------------------------------------------------------
/// <summary>Parse data as JSON Object.</summary>
public static JArray ParseJsonArray(string jsonData)
{
return JArray.Parse(jsonData);
}
/// <summary>Parse data as JSON Object.</summary>
public static JArray ParseJsonArray(string jsonData, out Exception excOut)
{
excOut = null;
try
{
return JArray.Parse(jsonData);
}
catch (Exception exc)
{
excOut = exc;
}
return null;
}
//-------------------------------------------------------------------
}
//=======================================================================
}
+62 -8
View File
@@ -66,7 +66,7 @@ namespace Sarand.Net.Standard.Base.Utils
// Regular expressions.
//-------------------------------------------------------------------
/// <summary>
/// Create Regex from (quoted) expression and apply Regex.Match to String value and return Match.Success.
/// Apply Regex.Match to String value and return Match.Success.
/// <para>- Case sensitive.</para>
/// </summary>
public static bool Match(this String value, String expression)
@@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.Utils
return value.Match(expression, RegexOptions.None);
}
/// <summary>
/// Create Regex from (quoted) expression and apply Regex.Match to String value and return Match.Success.
/// Apply Regex.Match to String value and return Match.Success, ignoring case.
/// <para>- Case insensitive.</para>
/// </summary>
public static bool MatchCI(this String value, String expression)
@@ -82,12 +82,11 @@ namespace Sarand.Net.Standard.Base.Utils
return value.Match(expression, RegexOptions.IgnoreCase);
}
/// <summary>
/// Create Regex from (quoted) expression and apply Regex.Match to String value and return Match.Success.
/// <para>- Supply options as required.</para>
/// Apply Regex.Match to String value and return Match.Success.
/// </summary>
public static bool Match(this String value, String expression, RegexOptions options)
{
return new Regex(Regex.Escape(expression), options).Match(value).Success;
return Regex.Match(value, expression, options).Success;
}
/// <summary>
/// Apply Regex.Match to String value and return Match.Success.
@@ -96,12 +95,67 @@ namespace Sarand.Net.Standard.Base.Utils
{
return re.Match(value).Success;
}
/// <summary>
/// Apply Regex.Matches to String value and return true if any matches found.
/// Apply Regex.IsMatch to String value.
/// <para>- Case sensitive.</para>
/// </summary>
public static bool Matches(this String value, Regex re)
public static bool IsMatch(this String value, String expression)
{
return re.Matches(value).Count < 1;
return value.IsMatch(expression, RegexOptions.None);
}
/// <summary>
/// Apply Regex.IsMatch to String value, ignoring case.
/// <para>- Case insensitive.</para>
/// </summary>
public static bool IsMatchCI(this String value, String expression)
{
return value.IsMatch(new Regex(Regex.Escape(expression), RegexOptions.IgnoreCase));
}
/// <summary>
/// Apply Regex.IsMatch to String value.
/// </summary>
public static bool IsMatch(this String value, String expression, RegexOptions options)
{
return Regex.IsMatch(value, expression, options);
}
/// <summary>
/// Apply Regex.IsMatch to String value.
/// </summary>
public static bool IsMatch(this String value, Regex re)
{
return re.IsMatch(value);
}
/// <summary>
/// Apply Regex.Matches to String value and return number of matches found.
/// <para>- Case sensitive.</para>
/// </summary>
public static int MatchCount(this String value, String expression)
{
return value.MatchCount(expression, RegexOptions.None);
}
/// <summary>
/// Apply Regex.Matches to String value and return number of matches found.
/// <para>- Case insensitive.</para>
/// </summary>
public static int MatchCountCI(this String value, String expression)
{
return value.MatchCount(expression, RegexOptions.IgnoreCase);
}
/// <summary>
/// Apply Regex.Matches to String value and return number of matches found.
/// </summary>
public static int MatchCount(this String value, String expression, RegexOptions options)
{
return Regex.Matches(value, expression, options).Count;
}
/// <summary>
/// Apply Regex.Matches to String value and return number of matches found.
/// </summary>
public static int MatchCount(this String value, Regex re)
{
return re.Matches(value).Count;
}
//-------------------------------------------------------------------
-45
View File
@@ -1,45 +0,0 @@
using Sarand.Net.Standard.Base.Core;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
namespace Sarand.Net.Standard.Base.Utils
{
public static class WebUtil
{
//-------------------------------------------------------------------
// H T M L E n c o d i n g
//-------------------------------------------------------------------
/// <summary>Converts a string to an HTML-encoded string.</summary>
public static String HtmlEncode (this String value)
{
if (StringUtil.IsEmpty(value)) return value;
return WebUtility.HtmlEncode(value);
}
/// <summary>Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.</summary>
public static String HtmlDecode (this String value)
{
if (StringUtil.IsEmpty(value)) return value;
return WebUtility.HtmlDecode(value);
}
//-------------------------------------------------------------------
// U R L E n c o d i n g
//-------------------------------------------------------------------
/// <summary>Converts a string to an HTML-encoded string.</summary>
public static String UrlEncode (this String value)
{
if (StringUtil.IsEmpty(value)) return value;
return WebUtility.UrlEncode(value);
}
/// <summary>Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.</summary>
public static String UrlDecode (this String value)
{
if (StringUtil.IsEmpty(value)) return value;
return WebUtility.UrlDecode(value);
}
//-------------------------------------------------------------------
}
}