Saxonite - various
This commit is contained in:
@@ -288,7 +288,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public virtual bool ItemHasId { get { return true; } }
|
||||
public virtual bool ItemHasId { get; } = true;
|
||||
public SysId Id
|
||||
{
|
||||
get
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
@@ -8,16 +12,17 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
//[Serializable()]
|
||||
[JsonConverter(typeof(SysIdJsonConverter))]
|
||||
public class SysId
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private Int64 id = 0;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SysId () { }
|
||||
public SysId (Int64 id)
|
||||
public SysId() { }
|
||||
public SysId(Int64 id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
@@ -37,30 +42,30 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
public static bool IsValid (SysId sysId)
|
||||
public static bool IsValid(SysId sysId)
|
||||
{
|
||||
return (sysId != null && sysId.id != 0);
|
||||
}
|
||||
public static SysId InvalidOnNull (SysId sysId)
|
||||
public static SysId InvalidOnNull(SysId sysId)
|
||||
{
|
||||
return (sysId != null ? sysId : new SysId());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Comparison.
|
||||
public override bool Equals (object obj)
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
return Equals(obj as SysId);
|
||||
}
|
||||
public bool Equals (SysId sysId)
|
||||
public bool Equals(SysId sysId)
|
||||
{
|
||||
if (sysId == null) return false;
|
||||
// False if either value invalid.
|
||||
if (id == 0) return false;
|
||||
return ToInt().Equals(InvalidOnNull(sysId).ToInt());
|
||||
}
|
||||
public override int GetHashCode ()
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return id.GetHashCode();
|
||||
}
|
||||
@@ -75,11 +80,11 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
return ToInt(this);
|
||||
}
|
||||
public override String ToString ()
|
||||
public override String ToString()
|
||||
{
|
||||
return ToString(this);
|
||||
}
|
||||
public String ToString (String invalidValue)
|
||||
public String ToString(String invalidValue)
|
||||
{
|
||||
return ToString(this, invalidValue);
|
||||
}
|
||||
@@ -92,15 +97,43 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
return (IsValid(sysId) ? sysId.id : 0);
|
||||
}
|
||||
public static String ToString (SysId sysId)
|
||||
public static String ToString(SysId sysId)
|
||||
{
|
||||
return ToString(sysId, String.Empty);
|
||||
}
|
||||
public static String ToString (SysId sysId, String invalidValue)
|
||||
public static String ToString(SysId sysId, String invalidValue)
|
||||
{
|
||||
return (IsValid(sysId) ? sysId.id.ToString() : invalidValue);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// JSON Converter to serialise/deserialise SysId to/from simple integer value.
|
||||
/// </summary>
|
||||
class SysIdJsonConverter : JsonConverter<SysId>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, [AllowNull] SysId id, JsonSerializer serializer)
|
||||
{
|
||||
if (id == null) return;
|
||||
// Simply return the integer Id value.
|
||||
serializer.Serialize(writer, id.Id);
|
||||
}
|
||||
public override SysId ReadJson(JsonReader reader, Type objectType, [AllowNull] SysId existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Convert the integer value to a SysId.
|
||||
JValue jValue = new JValue(reader.Value);
|
||||
return new SysId() { Id = (long)jValue };
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Debug(GetType().Name + ".ReadJson " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
@@ -108,13 +141,13 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// List contents.
|
||||
public static int GetIdCount (this List<SysId> values, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
public static int GetIdCount(this List<SysId> values, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
{
|
||||
if (ignoreDuplicates)
|
||||
{
|
||||
values = values.Select(id => id).Distinct().ToList();
|
||||
// SysId.Equals treats invalid ids as inequal so 'Distinct' doesn't remove them.
|
||||
if (values.FindIndex(id => !SysId.IsValid(id)) >= 0)
|
||||
if (values.FindIndex(id => !SysId.IsValid(id)) >= 0)
|
||||
{
|
||||
// Remove all invalid entries and put one back to correct the count.
|
||||
values.RemoveAll(id => !SysId.IsValid(id));
|
||||
@@ -123,24 +156,24 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
}
|
||||
return values.Count(id => !ignoreInvalid || SysId.IsValid(id));
|
||||
}
|
||||
public static bool HasValidIds (this List<SysId> values)
|
||||
public static bool HasValidIds(this List<SysId> values)
|
||||
{
|
||||
return (values.Find(id => SysId.IsValid(id)) != null);
|
||||
}
|
||||
public static bool Equals (this List<SysId> values, List<SysId> values2)
|
||||
public static bool Equals(this List<SysId> values, List<SysId> values2)
|
||||
{
|
||||
return values.OrderBy(id => id.Id).SequenceEqual(values2.OrderBy(id => id.Id));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Populate list.
|
||||
public static void AddId (this List<SysId> values, SysId sysId, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
public static void AddId(this List<SysId> values, SysId sysId, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
{
|
||||
if (ignoreInvalid && !SysId.IsValid(sysId)) return;
|
||||
if (ignoreDuplicates && values.Contains(sysId)) return;
|
||||
values.Add(sysId);
|
||||
}
|
||||
public static void AddIds (this List<SysId> values, List<SysId> sysIds, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
public static void AddIds(this List<SysId> values, List<SysId> sysIds, bool ignoreInvalid = true, bool ignoreDuplicates = true)
|
||||
{
|
||||
foreach (SysId id in sysIds)
|
||||
values.AddId(id, ignoreInvalid, ignoreDuplicates);
|
||||
@@ -150,7 +183,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
// Extract from list.
|
||||
/// <summary>Remove specified number of entries from the list and return them.</summary>
|
||||
/// <returns></returns>
|
||||
public static List<SysId> ExtractIds (this List<SysId> values, int numberToRemove)
|
||||
public static List<SysId> ExtractIds(this List<SysId> values, int numberToRemove)
|
||||
{
|
||||
List<SysId> ids = new List<SysId>();
|
||||
while (values.Count > 0 && ids.Count < numberToRemove)
|
||||
@@ -170,7 +203,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
/// <param name="delimiter"></param>
|
||||
/// <param name="ignoreInvalid"></param>
|
||||
/// <returns></returns>
|
||||
public static String Concat (this List<SysId> values, String delimiter, bool ignoreInvalid = true)
|
||||
public static String Concat(this List<SysId> values, String delimiter, bool ignoreInvalid = true)
|
||||
{
|
||||
List<String> ids = new List<string>();
|
||||
foreach (SysId id in values.FindAll(id => !ignoreInvalid || SysId.IsValid(id)))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
@@ -49,12 +50,20 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public int ColumnCount
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return columns.Count();
|
||||
}
|
||||
}
|
||||
public List<DbDfnIndexColumn> Columns
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return new List<DbDfnIndexColumn>(columns);
|
||||
return columns.ToList();
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
@@ -29,6 +30,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public String Schema { get; set; } = String.Empty;
|
||||
public String Name { get; set; } = String.Empty;
|
||||
public String QualifiedName { get { return (!StringUtil.IsEmpty(Schema) ? Schema + "." : "") + Name; } }
|
||||
public String QuotedQualifiedName { get { return (!StringUtil.IsEmpty(Schema) ? "[" + Schema + "]." : "") + "[" + Name + "]"; } }
|
||||
public String Remarks { get; set; } = String.Empty;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -47,19 +49,26 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public bool HasColumnByName(String columnName)
|
||||
{
|
||||
lock (columns)
|
||||
return (columns != null && columns.Exists(col => col.Name.EqualsCI(columnName)));
|
||||
return columns.Exists(col => col.Name.EqualsCI(columnName));
|
||||
}
|
||||
public bool HasColumns()
|
||||
{
|
||||
lock (columns)
|
||||
return (columns != null && columns.Count > 0);
|
||||
return ColumnCount > 0;
|
||||
}
|
||||
public int ColumnCount
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return columns.Count;
|
||||
}
|
||||
}
|
||||
public List<DbDfnColumn> Columns
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return new List<DbDfnColumn>(columns);
|
||||
return columns.ToList();
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -97,19 +106,26 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public bool HasIndexByName(String indexName)
|
||||
{
|
||||
lock (indices)
|
||||
return (indices != null && indices.Exists(idx => idx.Name.EqualsCI(indexName)));
|
||||
return indices.Exists(idx => idx.Name.EqualsCI(indexName));
|
||||
}
|
||||
public bool HasIndices()
|
||||
{
|
||||
lock (indices)
|
||||
return (indices != null && indices.Count > 0);
|
||||
return IndexCount > 0;
|
||||
}
|
||||
public int IndexCount
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (indices)
|
||||
return indices.Count;
|
||||
}
|
||||
}
|
||||
public List<DbDfnIndex> Indices
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (indices)
|
||||
return new List<DbDfnIndex>(indices);
|
||||
return indices.ToList();
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Database schema.
|
||||
List<String> GetTableNames ();
|
||||
List<String> GetTableNames (bool refresh = false);
|
||||
List<DbDfnTable> GetTableDfns (bool refresh = false);
|
||||
DbDfnTable GetTableDfn (String name, bool refresh = false);
|
||||
bool TableExists (String tableName);
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Sarand.Net.Standard.Base.Helpers
|
||||
|
||||
public static void Fill(byte[] byteArray)
|
||||
{
|
||||
// ToDo RandomNumberGenerator.Fill(byteArray);
|
||||
RandomNumberGenerator.GetBytes(byteArray);
|
||||
RandomNumberGenerator.Fill(byteArray);
|
||||
//RandomNumberGenerator.GetBytes(byteArray);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -40,9 +40,9 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
||||
/// <para>followed by stack entries on separate lines.</para>
|
||||
/// </summary>
|
||||
public static String GetLogMessage (this Exception exc, int entries = 8)
|
||||
public static String GetLogMessage (this Exception exc, int entries = 8, String stackEntryDelim = "\n\t")
|
||||
{
|
||||
return exc.GetType().Name + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", "\n\t");
|
||||
return exc.GetType().Name + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", stackEntryDelim);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Xml
|
||||
namespace Sarand.Net.Standard.Base.Utils
|
||||
{
|
||||
//=======================================================================
|
||||
public enum SoapElementType
|
||||
+20
-1
@@ -7,7 +7,7 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Xml
|
||||
namespace Sarand.Net.Standard.Base.Utils
|
||||
{
|
||||
//=======================================================================
|
||||
public static class SacsXmlUtil
|
||||
@@ -145,6 +145,7 @@ namespace Sarand.Net.Standard.Base.Xml
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// System.Xml.Linq variation.
|
||||
/// <summary>Get text from first child that matches the node name.</summary>
|
||||
public static String GetChildText (this XElement element, String name)
|
||||
{
|
||||
@@ -153,9 +154,18 @@ namespace Sarand.Net.Standard.Base.Xml
|
||||
return child.Value;
|
||||
return String.Empty;
|
||||
}
|
||||
// System.Xml varations.
|
||||
public static String GetChildText(this XmlNode node, String name)
|
||||
{
|
||||
foreach (XmlNode child in node.ChildNodes)
|
||||
if (child.Name.EqualsCI(name))
|
||||
return child.InnerText;
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Append element to node.
|
||||
// System.Xml.Linq variation.
|
||||
public static XElement AppendElement (this XContainer container, XElement element)
|
||||
{
|
||||
container.Add(element);
|
||||
@@ -173,6 +183,15 @@ namespace Sarand.Net.Standard.Base.Xml
|
||||
container.Add(child);
|
||||
return child;
|
||||
}
|
||||
// System.Xml varations.
|
||||
public static XmlElement AppendElement(this XmlNode node, String name, String text = "")
|
||||
{
|
||||
XmlDocument doc = (node is XmlDocument ? node as XmlDocument : node.OwnerDocument);
|
||||
XmlElement child = (XmlElement)node.AppendChild(doc.CreateElement(name));
|
||||
if (!StringUtil.IsEmpty(text))
|
||||
child.AppendChild(doc.CreateTextNode(text));
|
||||
return child;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Utils
|
||||
{
|
||||
//=======================================================================
|
||||
public static class XmlUtil
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Convert XML document to string.
|
||||
public static String GetXml (this XDocument xmlDoc)
|
||||
{
|
||||
using (var stringWriter = new StringWriter())
|
||||
using (var xmlTextWriter = XmlWriter.Create(stringWriter))
|
||||
{
|
||||
xmlDoc.WriteTo(xmlTextWriter);
|
||||
xmlTextWriter.Flush();
|
||||
return stringWriter.GetStringBuilder().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Append element to node.
|
||||
public static XmlElement AppendElement (this XmlNode node, String name, String text = "")
|
||||
{
|
||||
XmlDocument doc = (node is XmlDocument ? node as XmlDocument : node.OwnerDocument);
|
||||
XmlElement child = (XmlElement)node.AppendChild(doc.CreateElement(name));
|
||||
if (!StringUtil.IsEmpty(text))
|
||||
child.AppendChild(doc.CreateTextNode(text));
|
||||
return child;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Get child text.
|
||||
public static String GetChildText (this XmlNode node, String name)
|
||||
{
|
||||
foreach (XmlNode child in node.ChildNodes)
|
||||
if (child.Name.EqualsCI(name))
|
||||
return child.InnerText;
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user