Saxonite v1.2.3
This commit is contained in:
@@ -20,8 +20,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution files", "Solution
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SacsStandardAccounts", "SacsStandardAccounts\SacsStandardAccounts.csproj", "{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SacsStandardAccounts", "SacsStandardAccounts\SacsStandardAccounts.csproj", "{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusMgrCoreProcs", "..\..\BusinessMgr\Workspace\SaBusMgrCoreProcs\SaBusMgrCoreProcs.csproj", "{452FC874-81D6-4858-A6F4-0337AA656D23}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -52,10 +50,6 @@ Global
|
|||||||
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C62999E2-1947-4EB7-82D2-A0EDB67D2F10}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{452FC874-81D6-4858-A6F4-0337AA656D23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{452FC874-81D6-4858-A6F4-0337AA656D23}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{452FC874-81D6-4858-A6F4-0337AA656D23}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{452FC874-81D6-4858-A6F4-0337AA656D23}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Sarand.Net.Standard.Base.Helpers;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sacs.UnitTests.Net.Standard.Base.Helpers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
[TestClass]
|
||||||
|
public class SacsRandomHelper_Tester
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Random Helper.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Fill byte array.
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_ByteArray()
|
||||||
|
{
|
||||||
|
int dataLength = 10;
|
||||||
|
byte[] data = new byte[dataLength];
|
||||||
|
Assert.IsNotNull(data);
|
||||||
|
|
||||||
|
// Initial values should be zero.
|
||||||
|
for (int i = 0; i < dataLength; i++)
|
||||||
|
Assert.AreEqual(0, data[i]);
|
||||||
|
|
||||||
|
SacsRandomHelper.Fill(data);
|
||||||
|
|
||||||
|
// Sum of data values should no longer be zero.
|
||||||
|
int total = 0;
|
||||||
|
for (int i = 0; i < dataLength; i++)
|
||||||
|
total += data[i];
|
||||||
|
Assert.AreNotEqual(0, total);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
[TestMethod]
|
||||||
|
public void GetInt32_ToExclusive()
|
||||||
|
{
|
||||||
|
for (int i = 1; i < 1000; i++)
|
||||||
|
{
|
||||||
|
int value = SacsRandomHelper.GetInt32(i);
|
||||||
|
Assert.IsTrue(value >= 0);
|
||||||
|
Assert.IsTrue(value < i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
[TestMethod]
|
||||||
|
public void GetInt32_FromInclusive_ToExclusive()
|
||||||
|
{
|
||||||
|
for (int i = -100; i < 101; i++)
|
||||||
|
{
|
||||||
|
for (int j = i + 1; j < i + 100; j++)
|
||||||
|
{
|
||||||
|
int value = SacsRandomHelper.GetInt32(i, j);
|
||||||
|
//Debug.WriteLine("Value: "+value);
|
||||||
|
Assert.IsTrue(value >= i);
|
||||||
|
Assert.IsTrue(value < j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
[TestMethod]
|
||||||
|
public void GetInt32_getRandomLengthNumber()
|
||||||
|
{
|
||||||
|
for (ushort i = 1; i < 13; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 10; j++)
|
||||||
|
{
|
||||||
|
String value = SacsRandomHelper.getRandomLengthNumber(i);
|
||||||
|
//Debug.WriteLine("Value: " + value);
|
||||||
|
Assert.IsTrue(value.Length > 0);
|
||||||
|
Assert.IsTrue(value.Length < i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -77,12 +77,12 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>Get flag value - position 1 - 16</summary>
|
/// <summary>Get flag value - position 1 - 16</summary>
|
||||||
public bool GetFlag (Byte flagPos)
|
public bool GetFlag(Byte flagPos)
|
||||||
{
|
{
|
||||||
return SacsHierarchyItem.GetFlag(Flags, flagPos);
|
return SacsHierarchyItem.GetFlag(Flags, flagPos);
|
||||||
}
|
}
|
||||||
/// <summary>Set flag value - position 1 - 16</summary>
|
/// <summary>Set flag value - position 1 - 16</summary>
|
||||||
public void SetFlag (Byte flagPos, bool value)
|
public void SetFlag(Byte flagPos, bool value)
|
||||||
{
|
{
|
||||||
CheckChanged(GetFlag(flagPos), value);
|
CheckChanged(GetFlag(flagPos), value);
|
||||||
Flags = SacsHierarchyItem.SetFlag(Flags, flagPos, value);
|
Flags = SacsHierarchyItem.SetFlag(Flags, flagPos, value);
|
||||||
@@ -126,7 +126,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Population.
|
// Population.
|
||||||
/// <summary>Copy common properties to this object.</summary>
|
/// <summary>Copy common properties to this object.</summary>
|
||||||
protected void PopulateFrom (Data sourceData)
|
protected void PopulateFrom(Data sourceData)
|
||||||
{
|
{
|
||||||
Id = sourceData.Id;
|
Id = sourceData.Id;
|
||||||
Notes = sourceData.Notes;
|
Notes = sourceData.Notes;
|
||||||
@@ -136,7 +136,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
UpdateStamp = sourceData.UpdateStamp;
|
UpdateStamp = sourceData.UpdateStamp;
|
||||||
}
|
}
|
||||||
/// <summary>Copy comon properties to the target object.</summary>
|
/// <summary>Copy comon properties to the target object.</summary>
|
||||||
internal void PopulateTo (Data targetData)
|
internal void PopulateTo(Data targetData)
|
||||||
{
|
{
|
||||||
targetData.PopulateFrom(this);
|
targetData.PopulateFrom(this);
|
||||||
}
|
}
|
||||||
@@ -155,30 +155,30 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>Clear 'Changed' flag.</summary>
|
/// <summary>Clear 'Changed' flag.</summary>
|
||||||
public void AcceptChanges ()
|
public void AcceptChanges()
|
||||||
{
|
{
|
||||||
Changed = false;
|
Changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Compare old and new property values and set 'Changed' if different.
|
// Compare old and new property values and set 'Changed' if different.
|
||||||
protected void CheckChanged (SysId oldValue, SysId newValue)
|
protected void CheckChanged(SysId oldValue, SysId newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
// Compare by numeric value so that invalid values are equal.
|
// Compare by numeric value so that invalid values are equal.
|
||||||
Changed = SysId.ToInt(oldValue) != SysId.ToInt(newValue);
|
Changed = SysId.ToInt(oldValue) != SysId.ToInt(newValue);
|
||||||
}
|
}
|
||||||
protected void CheckChanged (ItemId oldValue, ItemId newValue)
|
protected void CheckChanged(ItemId oldValue, ItemId newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = (oldValue.Type != newValue.Type) || (!oldValue.Id.Equals(newValue.Id));
|
Changed = (oldValue.Type != newValue.Type) || (!oldValue.Id.Equals(newValue.Id));
|
||||||
}
|
}
|
||||||
protected void CheckChanged (String oldValue, String newValue)
|
protected void CheckChanged(String oldValue, String newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = !StringUtil.EmptyOnNull(oldValue).Equals(StringUtil.EmptyOnNull(newValue));
|
Changed = !StringUtil.EmptyOnNull(oldValue).Equals(StringUtil.EmptyOnNull(newValue));
|
||||||
}
|
}
|
||||||
protected void CheckChanged (bool oldValue, bool newValue)
|
protected void CheckChanged(bool oldValue, bool newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = (oldValue != newValue);
|
Changed = (oldValue != newValue);
|
||||||
@@ -186,44 +186,45 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
protected void CheckChangedEnum<T>(T oldValue, T newValue) where T : struct, IConvertible
|
protected void CheckChangedEnum<T>(T oldValue, T newValue) where T : struct, IConvertible
|
||||||
{
|
{
|
||||||
if (!(oldValue is Enum) || !(newValue is Enum))
|
if (!(oldValue is Enum) || !(newValue is Enum))
|
||||||
throw new ArgumentException(GetType().Name+ ".CheckChangedEnum<T> Parameters must be enumerated types. Type supplied: " + oldValue.GetType().Name + ", " + newValue.GetType().Name);
|
throw new ArgumentException(GetType().Name + ".CheckChangedEnum<T> Parameters must be enumerated types. Type supplied: " + oldValue.GetType().Name + ", " + newValue.GetType().Name);
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = ((int)(oldValue as IConvertible) != (int)(newValue as IConvertible));
|
Changed = ((int)(oldValue as IConvertible) != (int)(newValue as IConvertible));
|
||||||
}
|
}
|
||||||
protected void CheckChanged (long oldValue, long newValue)
|
protected void CheckChanged(long oldValue, long newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = (oldValue != newValue);
|
Changed = (oldValue != newValue);
|
||||||
}
|
}
|
||||||
protected void CheckChanged (double oldValue, double newValue)
|
protected void CheckChanged(double oldValue, double newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = (oldValue != newValue);
|
Changed = (oldValue != newValue);
|
||||||
}
|
}
|
||||||
protected void CheckChanged (decimal oldValue, decimal newValue)
|
protected void CheckChanged(decimal oldValue, decimal newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = (oldValue != newValue);
|
Changed = (oldValue != newValue);
|
||||||
}
|
}
|
||||||
protected void CheckChanged (DateTime oldValue, DateTime newValue)
|
protected void CheckChanged(DateTime oldValue, DateTime newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = !oldValue.Equals(newValue);
|
Changed = !oldValue.Equals(newValue);
|
||||||
}
|
}
|
||||||
protected void CheckChanged (List<String> oldValues, List<String> newValues)
|
protected void CheckChanged(IEnumerable<String> oldValues, IEnumerable<String> newValues)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
Changed = !oldValues.ContentEquals(newValues);
|
Changed = !oldValues.ContentEquals(newValues);
|
||||||
}
|
}
|
||||||
protected void CheckChanged<T> (List<T> oldValues, List<T> newValues)
|
protected void CheckChanged<T>(IEnumerable<T> oldValues, IEnumerable<T> newValues)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
if (oldValues.Count() != newValues.Count()) Changed = true;
|
if (oldValues.Count() != newValues.Count()) Changed = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < oldValues.Count(); idx++)
|
var combinedValues = oldValues.Zip(newValues, Tuple.Create);
|
||||||
|
foreach (var combinedValue in combinedValues)
|
||||||
{
|
{
|
||||||
if (!oldValues[idx].Equals(newValues[idx]))
|
if (!combinedValue.Item1.Equals(combinedValue.Item2))
|
||||||
{
|
{
|
||||||
Changed = true;
|
Changed = true;
|
||||||
return;
|
return;
|
||||||
@@ -231,7 +232,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected void CheckChanged (byte[] oldValue, byte[] newValue)
|
protected void CheckChanged(byte[] oldValue, byte[] newValue)
|
||||||
{
|
{
|
||||||
if (Changed) return;
|
if (Changed) return;
|
||||||
if ((oldValue == null) != (newValue != null)) Changed = true;
|
if ((oldValue == null) != (newValue != null)) Changed = true;
|
||||||
@@ -271,17 +272,17 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SacsHierarchyItem ()
|
protected SacsHierarchyItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
protected SacsHierarchyItem (SysId id)
|
protected SacsHierarchyItem(SysId id)
|
||||||
{
|
{
|
||||||
data.Id = id;
|
data.Id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Disposal.
|
// Disposal.
|
||||||
protected override void Dispose (bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
@@ -344,7 +345,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
protected set { data.Flags = value; }
|
protected set { data.Flags = value; }
|
||||||
}
|
}
|
||||||
/// <summary>Flags are positioned from 1, up to 16 allowed.</summary>
|
/// <summary>Flags are positioned from 1, up to 16 allowed.</summary>
|
||||||
public static bool GetFlag (UInt16 flags, Byte flagPos)
|
public static bool GetFlag(UInt16 flags, Byte flagPos)
|
||||||
{
|
{
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
if (flagPos > 0 && flagPos <= 16)
|
if (flagPos > 0 && flagPos <= 16)
|
||||||
@@ -352,12 +353,12 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
/// <summary>Flags are positioned from 1, up to 16 allowed.</summary>
|
/// <summary>Flags are positioned from 1, up to 16 allowed.</summary>
|
||||||
public bool GetFlag (Byte flagPos)
|
public bool GetFlag(Byte flagPos)
|
||||||
{
|
{
|
||||||
return GetFlag(data.Flags, flagPos);
|
return GetFlag(data.Flags, flagPos);
|
||||||
}
|
}
|
||||||
/// <summary>Set flag value - position 1 - 16</summary>
|
/// <summary>Set flag value - position 1 - 16</summary>
|
||||||
public static UInt16 SetFlag (UInt16 flags, Byte flagPos, bool value)
|
public static UInt16 SetFlag(UInt16 flags, Byte flagPos, bool value)
|
||||||
{
|
{
|
||||||
if (flagPos > 0 && flagPos <= 16)
|
if (flagPos > 0 && flagPos <= 16)
|
||||||
{
|
{
|
||||||
@@ -370,7 +371,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
/// <summary>Set flag value - position 1 - 16</summary>
|
/// <summary>Set flag value - position 1 - 16</summary>
|
||||||
public void SetFlag (Byte flagPos, bool value)
|
public void SetFlag(Byte flagPos, bool value)
|
||||||
{
|
{
|
||||||
data.Flags = SetFlag(data.Flags, flagPos, value);
|
data.Flags = SetFlag(data.Flags, flagPos, value);
|
||||||
}
|
}
|
||||||
@@ -378,14 +379,14 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Update stamps.
|
// Update stamps.
|
||||||
public UpdateStamp CreateStamp { get { return data.CreateStamp; } }
|
public UpdateStamp CreateStamp { get { return data.CreateStamp; } }
|
||||||
public void SetCreateStamp (DateTime on, SysId by, String host)
|
public void SetCreateStamp(DateTime on, SysId by, String host)
|
||||||
{
|
{
|
||||||
CreateStamp.On = on;
|
CreateStamp.On = on;
|
||||||
CreateStamp.By = by;
|
CreateStamp.By = by;
|
||||||
CreateStamp.Host = host;
|
CreateStamp.Host = host;
|
||||||
}
|
}
|
||||||
public UpdateStamp UpdateStamp { get { return data.UpdateStamp; } }
|
public UpdateStamp UpdateStamp { get { return data.UpdateStamp; } }
|
||||||
public void SetUpdateStamp (DateTime on, SysId by, String host)
|
public void SetUpdateStamp(DateTime on, SysId by, String host)
|
||||||
{
|
{
|
||||||
UpdateStamp.On = on;
|
UpdateStamp.On = on;
|
||||||
UpdateStamp.By = by;
|
UpdateStamp.By = by;
|
||||||
@@ -394,7 +395,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Populate data item - only once on construction.
|
// Populate data item - only once on construction.
|
||||||
protected void SetData (Data data)
|
protected void SetData(Data data)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".SetData";
|
String fn = GetType().Name + ".SetData";
|
||||||
// Can only be replaced if currently internal class.
|
// Can only be replaced if currently internal class.
|
||||||
@@ -422,14 +423,14 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>Clear the 'Changed' flag to indicate that no changes have been made.</summary>
|
/// <summary>Clear the 'Changed' flag to indicate that no changes have been made.</summary>
|
||||||
public void AcceptChanges ()
|
public void AcceptChanges()
|
||||||
{
|
{
|
||||||
Changed = false;
|
Changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Format value for display.
|
// Format value for display.
|
||||||
public static String FormatForDisplay (String value, int maxLength = 0)
|
public static String FormatForDisplay(String value, int maxLength = 0)
|
||||||
{
|
{
|
||||||
if (StringUtil.IsEmpty(value)) return String.Empty;
|
if (StringUtil.IsEmpty(value)) return String.Empty;
|
||||||
// Replace non-display characters.
|
// Replace non-display characters.
|
||||||
@@ -450,7 +451,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
|||||||
public class Params
|
public class Params
|
||||||
{
|
{
|
||||||
// Construction.
|
// Construction.
|
||||||
protected Params ()
|
protected Params()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
/// <summary>Primary table alias to use if different from default.</summary>
|
/// <summary>Primary table alias to use if different from default.</summary>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Sarand.Net.Standard.Base.Core
|
|||||||
{
|
{
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
public sealed class DisposableCollection<T> : Collection<T>, IDisposable
|
public sealed class DisposableCollection<T> : Collection<T>, IDisposable
|
||||||
where T : IDisposable
|
where T : class, IDisposable
|
||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -47,10 +47,31 @@ namespace Sarand.Net.Standard.Base.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public new void Add(T item)
|
public new void Add(T item)
|
||||||
{
|
{
|
||||||
if (item != null)
|
if (item != null && !Contains(item))
|
||||||
base.Add(item);
|
base.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add list of items to the collection.
|
||||||
|
/// <para>Null items are ignored.</para>
|
||||||
|
/// <para>Items that can't be cast to the required object type cause a debug break.</para>
|
||||||
|
/// </summary>
|
||||||
|
public void AddRange<O>(List<O> items) where O : class, IDisposable
|
||||||
|
{
|
||||||
|
if (items != null && !items.IsEmpty())
|
||||||
|
{
|
||||||
|
foreach (O item in items)
|
||||||
|
{
|
||||||
|
if (item == null) continue;
|
||||||
|
T obj = item as T;
|
||||||
|
if (obj != null)
|
||||||
|
Add(obj);
|
||||||
|
else if (SacsSystem.DebugMode)
|
||||||
|
Debugger.Break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.Net.Standard.Base.Core
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Dictionary with items queued as if in FIFO list.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="K">Type of key</typeparam>
|
||||||
|
/// <typeparam name="V">Type of value</typeparam>
|
||||||
|
public class SacsQueueDictionary<K, V>
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data memners.
|
||||||
|
private readonly Queue<K> queue = new Queue<K>();
|
||||||
|
private readonly Dictionary<K, V> dictionary = new Dictionary<K, V>();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public int Count { get { lock (dictionary) return queue.Count; } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Is the KLey defined in the queue dictionary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns>True if found, else false.</returns>
|
||||||
|
public bool HasValue(K key)
|
||||||
|
{
|
||||||
|
lock (dictionary)
|
||||||
|
{
|
||||||
|
return dictionary.ContainsKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the value determined by the key.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns>Corresponding value if present, else default value.</returns>
|
||||||
|
public V GetValue(K key)
|
||||||
|
{
|
||||||
|
V value = default(V);
|
||||||
|
lock (dictionary)
|
||||||
|
{
|
||||||
|
dictionary.TryGetValue(key, out value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public bool SetEntry(K key, V value)
|
||||||
|
{
|
||||||
|
if (key == null || value == null) return false;
|
||||||
|
lock (dictionary)
|
||||||
|
{
|
||||||
|
if (dictionary.ContainsKey(key))
|
||||||
|
{
|
||||||
|
// Existsing key.
|
||||||
|
// Replace value in dictionary.
|
||||||
|
dictionary[key] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// New Key.
|
||||||
|
// Add to queue and set value in dictionary.
|
||||||
|
queue.Enqueue(key);
|
||||||
|
dictionary[key] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (SacsSystem.DebugMode) Validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the top n entries from the queue dictionary.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="maxEntries"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<KeyValuePair<K, V>> RemoveTopEntries(int maxEntries)
|
||||||
|
{
|
||||||
|
List<KeyValuePair<K, V>> entries = new List<KeyValuePair<K, V>>();
|
||||||
|
lock (dictionary)
|
||||||
|
{
|
||||||
|
while (queue.Count > 0 && entries.Count < maxEntries)
|
||||||
|
{
|
||||||
|
K key = queue.Dequeue();
|
||||||
|
V value = dictionary[key];
|
||||||
|
entries.Add(new KeyValuePair<K, V>(key, value));
|
||||||
|
dictionary.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SacsSystem.DebugMode) Validate();
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Internal utilities.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private void Validate()
|
||||||
|
{
|
||||||
|
lock (dictionary)
|
||||||
|
{
|
||||||
|
if (queue.Count != dictionary.Count)
|
||||||
|
throw new NotSupportedException("SacsQueueDictionary.Validate Inconsistent entry counts. Quete: " + queue.Count + ". Dictionary: " + dictionary.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
|||||||
/// <returns>the name of an ODBC driver for Microsoft SQL Server, if one is present; null, otherwise.</returns>
|
/// <returns>the name of an ODBC driver for Microsoft SQL Server, if one is present; null, otherwise.</returns>
|
||||||
public static string GetOdbcSqlDriverName ()
|
public static string GetOdbcSqlDriverName ()
|
||||||
{
|
{
|
||||||
List<string> driverPrecedence = new List<string>() { "SQL Server Native Client 14.0", "SQL Server Native Client 13.0", "SQL Server Native Client 12.0", "SQL Server Native Client 11.0", "SQL Server Native Client 10.0", "SQL Server Native Client 9.0", "SQL Server" };
|
List<string> driverPrecedence = new List<string>() { "ODBC Driver 17 for SQL Server", "ODBC Driver 13 for SQL Server", "ODBC Driver 11 for SQL Server", "SQL Server Native Client 11.0", "SQL Server Native Client 10.0", "SQL Server Native Client 9.0", "SQL Server" };
|
||||||
string[] availableOdbcDrivers = GetOdbcDriverNames();
|
string[] availableOdbcDrivers = GetOdbcDriverNames();
|
||||||
string driverName = null;
|
string driverName = null;
|
||||||
if (availableOdbcDrivers != null)
|
if (availableOdbcDrivers != null)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -49,6 +50,20 @@ namespace Sarand.Net.Standard.Base.Helpers
|
|||||||
//return Random.Next(fromInclusive, toExclusive);
|
//return Random.Next(fromInclusive, toExclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static String getRandomLengthNumber(ushort maxLength=4)
|
||||||
|
{
|
||||||
|
String value = "";
|
||||||
|
int len = GetInt32(1, maxLength + 1);
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
value += GetInt32(0,10);
|
||||||
|
if (StringUtil.IsEmpty(value))
|
||||||
|
throw new NotSupportedException("getRandomLengthNumber Generated blank value");
|
||||||
|
if (value.Length > maxLength)
|
||||||
|
throw new NotSupportedException("getRandomLengthNumber Generated excess length value");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Sarand.Net.Standard.Base.Utils
|
namespace Sarand.Net.Standard.Base.Utils
|
||||||
@@ -40,7 +42,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
// S t r i n g - I n t U t i l i t i e s
|
// S t r i n g - I n t U t i l i t i e s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Increment the count against the specified key by the supplied value, creating the key's entry if needed.</summary>
|
/// <summary>Increment the count against the specified key by the supplied value, creating the key's entry if needed.</summary>
|
||||||
public static void Increment (this IDictionary<String, int> dictionary, String key, int increment = 1)
|
public static void Increment(this IDictionary<String, int> dictionary, String key, int increment = 1)
|
||||||
{
|
{
|
||||||
if (!dictionary.ContainsKey(key))
|
if (!dictionary.ContainsKey(key))
|
||||||
dictionary[key] = increment;
|
dictionary[key] = increment;
|
||||||
@@ -52,14 +54,14 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
// A d d T o L i s t V a l u e
|
// A d d T o L i s t V a l u e
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Add key:object to dictionary where each value is a list of objects.</summary>
|
/// <summary>Add key:object to dictionary where each value is a list of objects.</summary>
|
||||||
public static void Add<TKey, TValue> (this Dictionary<TKey, List<TValue>> dict, TKey key, TValue value)
|
public static void Add<TKey, TValue>(this Dictionary<TKey, List<TValue>> dict, TKey key, TValue value)
|
||||||
{
|
{
|
||||||
if (!dict.ContainsKey(key))
|
if (!dict.ContainsKey(key))
|
||||||
dict[key] = new List<TValue>();
|
dict[key] = new List<TValue>();
|
||||||
dict[key].Add(value);
|
dict[key].Add(value);
|
||||||
}
|
}
|
||||||
/// <summary>Add key:objects to dictionary where each value is a list of objects.</summary>
|
/// <summary>Add key:objects to dictionary where each value is a list of objects.</summary>
|
||||||
public static void Add<TKey, TValue> (this Dictionary<TKey, List<TValue>> dict, TKey key, IEnumerable<TValue> values)
|
public static void Add<TKey, TValue>(this Dictionary<TKey, List<TValue>> dict, TKey key, IEnumerable<TValue> values)
|
||||||
{
|
{
|
||||||
if (!dict.ContainsKey(key))
|
if (!dict.ContainsKey(key))
|
||||||
dict[key] = new List<TValue>();
|
dict[key] = new List<TValue>();
|
||||||
@@ -70,11 +72,36 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
// A d d R a n g e
|
// A d d R a n g e
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Add entries from another dictionary.</summary>
|
/// <summary>Add entries from another dictionary.</summary>
|
||||||
public static void AddRange<TKey, TValue> (this Dictionary<TKey, TValue> dict, Dictionary<TKey, TValue> dictToAdd)
|
public static void AddRange<TKey, TValue>(this Dictionary<TKey, TValue> dict, Dictionary<TKey, TValue> dictToAdd)
|
||||||
{
|
{
|
||||||
dictToAdd.ForEach(x => dict.Add(x.Key, x.Value));
|
dictToAdd.ForEach(x => dict.Add(x.Key, x.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Orderd Dictionary
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static DictionaryEntry GetElementAt(this OrderedDictionary dictionary, int index)
|
||||||
|
{
|
||||||
|
return dictionary.Cast<DictionaryEntry>().ElementAt(index);
|
||||||
|
}
|
||||||
|
public static K GetKeyAt<K>(this OrderedDictionary dictionary, int index)
|
||||||
|
{
|
||||||
|
return (K)dictionary.GetElementAt(index).Key;
|
||||||
|
}
|
||||||
|
public static V GetValue<K, V>(this OrderedDictionary dictionary, K key)
|
||||||
|
{
|
||||||
|
if (dictionary == null || key == null)
|
||||||
|
return default(V);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (V)dictionary.Cast<DictionaryEntry>().AsQueryable().Single(kvp => ((K)kvp.Key).Equals(key)).Value;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return default(V);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
/// <para>- \r\n replaced with \n</para>
|
/// <para>- \r\n replaced with \n</para>
|
||||||
/// <para>- Duplicate lines removed.</para>
|
/// <para>- Duplicate lines removed.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String GetMessage (this Exception exc)
|
public static String GetMessage(this Exception exc)
|
||||||
{
|
{
|
||||||
List<String> messageLines = new List<string>();
|
List<String> messageLines = new List<string>();
|
||||||
foreach (String messageLine in (StringUtil.EmptyOnNull(exc?.Message) ?? "").Trim().ReplaceAll("\r\n", "\n").Split('\n'))
|
foreach (String messageLine in (StringUtil.EmptyOnNull(exc?.Message) ?? "").Trim().ReplaceAll("\r\n", "\n").Split('\n'))
|
||||||
@@ -29,7 +29,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
||||||
/// <para>followed by stack entries on separate lines.</para>
|
/// <para>followed by stack entries on separate lines.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String GetErrorStateMessage (this Exception exc, bool includeExceptionType = true)
|
public static String GetErrorStateMessage(this Exception exc, bool includeExceptionType = true)
|
||||||
{
|
{
|
||||||
return (includeExceptionType ? exc.GetType().Name + ": " : "") + GetMessage(exc);
|
return (includeExceptionType ? exc.GetType().Name + ": " : "") + GetMessage(exc);
|
||||||
}
|
}
|
||||||
@@ -40,14 +40,23 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
/// <para>[ExceptionType]: [ExceptionMessage]</para>
|
||||||
/// <para>followed by stack entries on separate lines.</para>
|
/// <para>followed by stack entries on separate lines.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static String GetLogMessage (this Exception exc, int entries = 8, String stackEntryDelim = "\n\t")
|
public static String GetLogMessage(this Exception exc, int entries = 8, String stackEntryDelim = "\n\t")
|
||||||
{
|
{
|
||||||
return exc.GetType().Name + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", stackEntryDelim);
|
return exc.GetLogMessage("", entries, stackEntryDelim);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Generate standard exception log message.
|
||||||
|
/// <para>[ExceptionType] [message]: [ExceptionMessage]</para>
|
||||||
|
/// <para>followed by stack entries on separate lines.</para>
|
||||||
|
/// </summary>
|
||||||
|
public static String GetLogMessage(this Exception exc, String message, int entries = 8, String stackEntryDelim = "\n\t")
|
||||||
|
{
|
||||||
|
return (exc.GetType().Name + " " + message + ": " + GetMessage(exc) + exc.GetStackEntries(entries).Concat("", stackEntryDelim)).TrimAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Retrieve stack entries, up to maximum number.</summary>
|
/// <summary>Retrieve stack entries, up to maximum number.</summary>
|
||||||
public static List<String> GetStackEntries (this Exception exc, int entries = 0)
|
public static List<String> GetStackEntries(this Exception exc, int entries = 0)
|
||||||
{
|
{
|
||||||
List<String> stackEntries = new List<string>();
|
List<String> stackEntries = new List<string>();
|
||||||
stackEntries.AddRange(exc.StackTrace.Split(new String[] { "\r\n" }, (entries > 0 ? entries : 999), StringSplitOptions.None));
|
stackEntries.AddRange(exc.StackTrace.Split(new String[] { "\r\n" }, (entries > 0 ? entries : 999), StringSplitOptions.None));
|
||||||
@@ -63,19 +72,19 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
// File handling exceptions.
|
// File handling exceptions.
|
||||||
public class FileException : Exception
|
public class FileException : Exception
|
||||||
{
|
{
|
||||||
public FileException (string message) :
|
public FileException(string message) :
|
||||||
base(message)
|
base(message)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
public class ArchiveFileException : FileException
|
public class ArchiveFileException : FileException
|
||||||
{
|
{
|
||||||
public ArchiveFileException (string message) :
|
public ArchiveFileException(string message) :
|
||||||
base(message)
|
base(message)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
public class FileExistsException : FileException
|
public class FileExistsException : FileException
|
||||||
{
|
{
|
||||||
public FileExistsException (string message) :
|
public FileExistsException(string message) :
|
||||||
base(message)
|
base(message)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,18 +42,18 @@ namespace Sarand.Net.Standard.Base.Utils
|
|||||||
// C o m p a r i s o n
|
// C o m p a r i s o n
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Compare lists to verify that they contain the same value in the corresponding position.</summary>
|
/// <summary>Compare lists to verify that they contain the same value in the corresponding position.</summary>
|
||||||
public static bool ContentEquals (this List<String> values, List<String> target)
|
public static bool ContentEquals (this IEnumerable<String> values, IEnumerable<String> target)
|
||||||
{
|
{
|
||||||
if (values.Count != target.Count) return false;
|
if (values.Count() != target.Count()) return false;
|
||||||
var combinedValues = values.Zip(target, Tuple.Create);
|
var combinedValues = values.Zip(target, Tuple.Create);
|
||||||
foreach (var combinedValue in combinedValues)
|
foreach (var combinedValue in combinedValues)
|
||||||
if (!combinedValue.Item1.Equals(combinedValue.Item2)) return false;
|
if (!combinedValue.Item1.Equals(combinedValue.Item2)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>Compare lists to verify that they contain the same case-insensitive value in the corresponding position.</summary>
|
/// <summary>Compare lists to verify that they contain the same case-insensitive value in the corresponding position.</summary>
|
||||||
public static bool ContentEqualsCI (this List<String> values, List<String> target)
|
public static bool ContentEqualsCI (this IEnumerable<String> values, IEnumerable<String> target)
|
||||||
{
|
{
|
||||||
if (values.Count != target.Count) return false;
|
if (values.Count() != target.Count()) return false;
|
||||||
var combinedValues = values.Zip(target, Tuple.Create);
|
var combinedValues = values.Zip(target, Tuple.Create);
|
||||||
foreach (var combinedValue in combinedValues)
|
foreach (var combinedValue in combinedValues)
|
||||||
if (!combinedValue.Item1.EqualsCI(combinedValue.Item2)) return false;
|
if (!combinedValue.Item1.EqualsCI(combinedValue.Item2)) return false;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SacsDatabaseOdbc (DbmsType dbms, String databaseName, String connectionString) : base(dbms, databaseName, connectionString)
|
public SacsDatabaseOdbc(DbmsType dbms, String databaseName, String connectionString) : base(dbms, databaseName, connectionString)
|
||||||
{
|
{
|
||||||
if (dbms == DbmsType.MsSql)
|
if (dbms == DbmsType.MsSql)
|
||||||
sqlConnectionString = connectionString;
|
sqlConnectionString = connectionString;
|
||||||
@@ -50,16 +50,16 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Connection.
|
// Connection.
|
||||||
public override void OnConnectionChanged ()
|
public override void OnConnectionChanged()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public override DbConnection CreateConnection (bool forceOdbc = false)
|
public override DbConnection CreateConnection(bool forceOdbc = false)
|
||||||
{
|
{
|
||||||
if (!forceOdbc && DbmsType == DbmsType.MsSql && !StringUtil.IsEmpty(sqlConnectionString))
|
if (!forceOdbc && DbmsType == DbmsType.MsSql && !StringUtil.IsEmpty(sqlConnectionString))
|
||||||
return new SqlConnection(sqlConnectionString);
|
return new SqlConnection(sqlConnectionString);
|
||||||
return new OdbcConnection(ConnectionString);
|
return new OdbcConnection(ConnectionString);
|
||||||
}
|
}
|
||||||
public override DbDataAdapter CreateDataAdapter ()
|
public override DbDataAdapter CreateDataAdapter()
|
||||||
{
|
{
|
||||||
return new OdbcDataAdapter();
|
return new OdbcDataAdapter();
|
||||||
}
|
}
|
||||||
@@ -68,17 +68,17 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
// I d e n t i t y G e n e r a t i o n
|
// I d e n t i t y G e n e r a t i o n
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
private DbDfnTable nextIdTableDfn = null;
|
private DbDfnTable nextIdTableDfn = null;
|
||||||
public override SysId GetNextId (String objectName, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id")
|
public override SysId GetNextId(String objectName, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id")
|
||||||
{
|
{
|
||||||
PopulateNextIdTableDfn();
|
PopulateNextIdTableDfn();
|
||||||
|
|
||||||
// Next Id database definitions.
|
// Next Id database definitions.
|
||||||
String colObject = NextIdTable+"."+NextIdColumn_Object;
|
String colObject = NextIdTable + "." + NextIdColumn_Object;
|
||||||
String colNextId = NextIdTable+"."+NextIdColumn_NextId;
|
String colNextId = NextIdTable + "." + NextIdColumn_NextId;
|
||||||
String colAliasNextId = "NxtId";
|
String colAliasNextId = "NxtId";
|
||||||
String filter = "("+colObject+")='"+objectName+"'";
|
String filter = "(" + colObject + ")='" + objectName + "'";
|
||||||
bool hasCreateCols = (nextIdTableDfn.HasColumnByName (DbCol_CreateOn) && nextIdTableDfn.HasColumnByName (DbCol_CreateBy));
|
bool hasCreateCols = (nextIdTableDfn.HasColumnByName(DbCol_CreateOn) && nextIdTableDfn.HasColumnByName(DbCol_CreateBy));
|
||||||
bool hasUpdateCols = (nextIdTableDfn.HasColumnByName (DbCol_UpdateOn) && nextIdTableDfn.HasColumnByName (DbCol_UpdateBy));
|
bool hasUpdateCols = (nextIdTableDfn.HasColumnByName(DbCol_UpdateOn) && nextIdTableDfn.HasColumnByName(DbCol_UpdateBy));
|
||||||
|
|
||||||
// Query the data.
|
// Query the data.
|
||||||
int nextIdValue = 1;
|
int nextIdValue = 1;
|
||||||
@@ -87,7 +87,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
qry.Columns.Add(colNextId, colAliasNextId);
|
qry.Columns.Add(colNextId, colAliasNextId);
|
||||||
qry.Filters.Add(filter);
|
qry.Filters.Add(filter);
|
||||||
//SaLogger.Debug(GetType().Name + ".GetNextId Query: " + qry.BuildQuery());
|
//SaLogger.Debug(GetType().Name + ".GetNextId Query: " + qry.BuildQuery());
|
||||||
DbResultSet_DataReader resultsSet = DbResultSet_DataReader.ExecuteQuery(this,qry.BuildQuery());
|
DbResultSet_DataReader resultsSet = DbResultSet_DataReader.ExecuteQuery(this, qry.BuildQuery());
|
||||||
if (resultsSet != null && resultsSet.NextRecord())
|
if (resultsSet != null && resultsSet.NextRecord())
|
||||||
{
|
{
|
||||||
NamedValue.Map values = resultsSet.GetRecordValues();
|
NamedValue.Map values = resultsSet.GetRecordValues();
|
||||||
@@ -132,7 +132,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
insertColumnValues.Add(DbCol_UpdateOn, DbQuery.FormatDateTimeForCondition(DateTime.Now));
|
insertColumnValues.Add(DbCol_UpdateOn, DbQuery.FormatDateTimeForCondition(DateTime.Now));
|
||||||
insertColumnValues.Add(DbCol_UpdateBy, SysId.IsValid(dbUpdateInfo.UserId) ? SysId.ToString(dbUpdateInfo.UserId) : "0");
|
insertColumnValues.Add(DbCol_UpdateBy, SysId.IsValid(dbUpdateInfo.UserId) ? SysId.ToString(dbUpdateInfo.UserId) : "0");
|
||||||
}
|
}
|
||||||
String insertQry = "Insert Into " + NextIdTable + " (" + insertColumnValues.GetValues(StringPair.Value.Value1).Concat(",") + ") Values (" +insertColumnValues.GetValues(StringPair.Value.Value2).Concat(",") + ")";
|
String insertQry = "Insert Into " + NextIdTable + " (" + insertColumnValues.GetValues(StringPair.Value.Value1).Concat(",") + ") Values (" + insertColumnValues.GetValues(StringPair.Value.Value2).Concat(",") + ")";
|
||||||
SaLogger.Debug(GetType().Name + ".GetNextId Insert query: " + insertQry);
|
SaLogger.Debug(GetType().Name + ".GetNextId Insert query: " + insertQry);
|
||||||
using (var dbConnection = CreateConnection())
|
using (var dbConnection = CreateConnection())
|
||||||
using (var dbCommand = dbConnection.CreateCommand())
|
using (var dbCommand = dbConnection.CreateCommand())
|
||||||
@@ -153,7 +153,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
return Math.Max(0, (int)maxId.AsLong()) + 1;
|
return Math.Max(0, (int)maxId.AsLong()) + 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
public override bool SetMinNextId (String objectName, SysId id, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id", bool force = false)
|
public override bool SetMinNextId(String objectName, SysId id, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id", bool force = false)
|
||||||
{
|
{
|
||||||
PopulateNextIdTableDfn();
|
PopulateNextIdTableDfn();
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//return true;
|
//return true;
|
||||||
}
|
}
|
||||||
private void PopulateNextIdTableDfn ()
|
private void PopulateNextIdTableDfn()
|
||||||
{
|
{
|
||||||
if (nextIdTableDfn != null && nextIdTableDfn.Name.Equals(NextIdTable)) return;
|
if (nextIdTableDfn != null && nextIdTableDfn.Name.Equals(NextIdTable)) return;
|
||||||
nextIdTableDfn = GetTableDfn(NextIdTable);
|
nextIdTableDfn = GetTableDfn(NextIdTable);
|
||||||
@@ -171,7 +171,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
// Q u e r y D a t a b a s e
|
// Q u e r y D a t a b a s e
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Query records.
|
// Query records.
|
||||||
public override IDbDataTable ExecuteQuery (String query)
|
public override IDbDataTable ExecuteQuery(String query)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".ExecuteQuery";
|
String fn = GetType().Name + ".ExecuteQuery";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -198,7 +198,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Execute a non-query statement and return the row count.</summary>
|
/// <summary>Execute a non-query statement and return the row count.</summary>
|
||||||
public override int ExecuteNonQuery (string query)
|
public override int ExecuteNonQuery(string query)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".ExecuteNonQuery";
|
String fn = GetType().Name + ".ExecuteNonQuery";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -223,7 +223,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Compile and execute an insert statement and return the row count.</summary>
|
/// <summary>Compile and execute an insert statement and return the row count.</summary>
|
||||||
public override int ExecuteInsert (String tableName, List<StringPair> columnNameValues)
|
public override int ExecuteInsert(String tableName, List<StringPair> columnNameValues)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".ExecuteInsert";
|
String fn = GetType().Name + ".ExecuteInsert";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -252,7 +252,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Compile and execute an update statement and return the row count.</summary>
|
/// <summary>Compile and execute an update statement and return the row count.</summary>
|
||||||
public override int ExecuteUpdate (String tableName, List<StringPair> columnNameValues, String filter)
|
public override int ExecuteUpdate(String tableName, List<StringPair> columnNameValues, String filter)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".ExecuteUpdate";
|
String fn = GetType().Name + ".ExecuteUpdate";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -282,7 +282,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Compile and execute a delete statement and return the row count.</summary>
|
/// <summary>Compile and execute a delete statement and return the row count.</summary>
|
||||||
public override int ExecuteDelete (String tableName, String filter)
|
public override int ExecuteDelete(String tableName, String filter)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".ExecuteDelete";
|
String fn = GetType().Name + ".ExecuteDelete";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -311,13 +311,13 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Retrieve specific row value.</summary>
|
/// <summary>Retrieve specific row value.</summary>
|
||||||
public override DataValue GetRowValue (String tableName, String columnName, String filter)
|
public override DataValue GetRowValue(String tableName, String columnName, String filter)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String colAlias = "DataValue";
|
String colAlias = "DataValue";
|
||||||
String query = "SELECT "+columnName+" '"+colAlias+"' FROM "+tableName+(!StringUtil.IsEmpty(filter)?" WHERE "+filter:"");
|
String query = "SELECT " + columnName + " '" + colAlias + "' FROM " + tableName + (!StringUtil.IsEmpty(filter) ? " WHERE " + filter : "");
|
||||||
using (DbResultSet dbResultSet = DbResultSet_DataReader.ExecuteQuery(this, query))
|
using (DbResultSet dbResultSet = DbResultSet_DataReader.ExecuteQuery(this, query))
|
||||||
{
|
{
|
||||||
if (dbResultSet.NextRecord())
|
if (dbResultSet.NextRecord())
|
||||||
@@ -336,7 +336,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Get row count from Table applying optional filter.</summary>
|
/// <summary>Get row count from Table applying optional filter.</summary>
|
||||||
public override long GetRowCount (String tableName, String filter)
|
public override long GetRowCount(String tableName, String filter)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
DataValue dataValue = GetRowValue(tableName, "Count(*)", filter);
|
DataValue dataValue = GetRowValue(tableName, "Count(*)", filter);
|
||||||
@@ -346,7 +346,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
/// <summary>Get calculated value from table - Sum, Min or Max.</summary>
|
/// <summary>Get calculated value from table - Sum, Min or Max.</summary>
|
||||||
public override DataValue GetRowValue (String tableName, String columnName, String filter, DbGetValueType getValueType)
|
public override DataValue GetRowValue(String tableName, String columnName, String filter, DbGetValueType getValueType)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
String fn = "";
|
String fn = "";
|
||||||
@@ -364,7 +364,9 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// NB Always use ODBC connection for querying schema.
|
// NB Always use ODBC connection for querying schema.
|
||||||
// eg. SQL Connection GetSchema('Indices') doesn't return index columns.
|
// eg. SQL Connection GetSchema('Indices') doesn't return index columns.
|
||||||
public override List<String> GetTableNames (bool refresh = false)
|
public override List<String> GetTableNames(bool refresh = false)
|
||||||
|
{
|
||||||
|
lock (tables)
|
||||||
{
|
{
|
||||||
// Only populate table names if not previously done.
|
// Only populate table names if not previously done.
|
||||||
if (tables.Count < 1 || refresh)
|
if (tables.Count < 1 || refresh)
|
||||||
@@ -378,7 +380,10 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
return tables.GetNames();
|
return tables.GetNames();
|
||||||
}
|
}
|
||||||
public override List<DbDfnTable> GetTableDfns (bool refresh = false)
|
}
|
||||||
|
public override List<DbDfnTable> GetTableDfns(bool refresh = false)
|
||||||
|
{
|
||||||
|
lock (tables)
|
||||||
{
|
{
|
||||||
if (refresh) ClearTableDfns();
|
if (refresh) ClearTableDfns();
|
||||||
// Only populate table names and/or table schemas where not previously done.
|
// Only populate table names and/or table schemas where not previously done.
|
||||||
@@ -402,11 +407,15 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
return tables.ToList();
|
return tables.ToList();
|
||||||
}
|
}
|
||||||
public void ClearTableDfns ()
|
}
|
||||||
|
public void ClearTableDfns()
|
||||||
{
|
{
|
||||||
|
lock (tables)
|
||||||
tables.Clear();
|
tables.Clear();
|
||||||
}
|
}
|
||||||
public override DbDfnTable GetTableDfn (String tableName, bool refresh = false)
|
public override DbDfnTable GetTableDfn(String tableName, bool refresh = false)
|
||||||
|
{
|
||||||
|
lock (tables)
|
||||||
{
|
{
|
||||||
if (!tables.GetNames().Contains(tableName) || refresh)
|
if (!tables.GetNames().Contains(tableName) || refresh)
|
||||||
{
|
{
|
||||||
@@ -431,13 +440,16 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
return tables.GetTableByName(tableName);
|
return tables.GetTableByName(tableName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
private void PopulateTableNames (DbConnection dbConnection, String tableNameRestriction = null)
|
private void PopulateTableNames(DbConnection dbConnection, String tableNameRestriction = null)
|
||||||
|
{
|
||||||
|
lock (tables)
|
||||||
{
|
{
|
||||||
if (StringUtil.IsEmpty(tableNameRestriction) && tables.Count > 0) return;
|
if (StringUtil.IsEmpty(tableNameRestriction) && tables.Count > 0) return;
|
||||||
if (!StringUtil.IsEmpty(tableNameRestriction) && tables.Exists(item => item.Name.Equals(tableNameRestriction))) return;
|
if (!StringUtil.IsEmpty(tableNameRestriction) && tables.Exists(item => item.Name.Equals(tableNameRestriction))) return;
|
||||||
String fn = GetType().Name+".PopulateTableNames";
|
String fn = GetType().Name + ".PopulateTableNames";
|
||||||
if (SacsSystem.DebugMode) SaLogger.Debug(fn + (!StringUtil.IsEmpty(tableNameRestriction) ? " Table: " + tableNameRestriction : " "));
|
if (SacsSystem.DebugMode) SaLogger.Debug(fn + (!StringUtil.IsEmpty(tableNameRestriction) ? " Table: " + tableNameRestriction : " "));
|
||||||
String[] restrictions = new String[] { null, null, tableNameRestriction }; // database, owner, table name, type
|
String[] restrictions = new String[] { null, null, tableNameRestriction }; // database, owner, table name, type
|
||||||
using (DataTable tableSchema = dbConnection.GetSchema(OdbcMetaDataCollectionNames.Tables, restrictions))
|
using (DataTable tableSchema = dbConnection.GetSchema(OdbcMetaDataCollectionNames.Tables, restrictions))
|
||||||
@@ -496,11 +508,12 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
tables.Clear();
|
tables.Clear();
|
||||||
tables.AddRange(tablesUnsorted.OrderBy(item => item.Name).ToList());
|
tables.AddRange(tablesUnsorted.OrderBy(item => item.Name).ToList());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
private void PopulateTableColumns (DbConnection dbConnection, DbDfnTable table)
|
private void PopulateTableColumns(DbConnection dbConnection, DbDfnTable table)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name+".PopulateTableColumns";
|
String fn = GetType().Name + ".PopulateTableColumns";
|
||||||
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Table: " + table.Name);
|
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Table: " + table.Name);
|
||||||
short columnPos = 0;
|
short columnPos = 0;
|
||||||
String[] restrictions = new String[] { null, table.Schema, table.Name, null }; // database, owner, table name, column name
|
String[] restrictions = new String[] { null, table.Schema, table.Name, null }; // database, owner, table name, column name
|
||||||
@@ -703,9 +716,9 @@ namespace Sarand.Net.Standard.Dbas.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
private void PopulateTableIndices (DbConnection dbConnection, DbDfnTable table)
|
private void PopulateTableIndices(DbConnection dbConnection, DbDfnTable table)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name+".PopulateTableIndices";
|
String fn = GetType().Name + ".PopulateTableIndices";
|
||||||
String[] restrictions = new String[] { null, table.Schema, table.Name }; // database, owner, table name
|
String[] restrictions = new String[] { null, table.Schema, table.Name }; // database, owner, table name
|
||||||
using (DataTable columnSchema = dbConnection.GetSchema(OdbcMetaDataCollectionNames.Indexes, restrictions))
|
using (DataTable columnSchema = dbConnection.GetSchema(OdbcMetaDataCollectionNames.Indexes, restrictions))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user