Saxonite 1.2.11.5, BusinessMgr.

This commit is contained in:
Andy Howard
2024-06-13 14:30:50 +01:00
parent ba5801b4dc
commit 14102d5164
44 changed files with 645 additions and 411 deletions
+5 -2
View File
@@ -85,6 +85,7 @@ namespace Sacs.Web.Components
WebAppHome,
WebAppHome_SessionExpired,
}
[NonAction]
public String GetRedirectLocation(RedirectLocation redirectLocation)
{
string protocol = Request.Scheme;
@@ -110,13 +111,13 @@ namespace Sacs.Web.Components
//-------------------------------------------------------------------
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuting" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
//if (DebugMode) SaLogger.Debug($"{SysUtil.Fn}" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
base.OnActionExecuting(filterContext);
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
//if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuted" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
//if (DebugMode) SaLogger.Debug($"{SysUtil.Fn}" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
base.OnActionExecuted(filterContext);
}
@@ -159,6 +160,7 @@ namespace Sacs.Web.Components
//-------------------------------------------------------------------
// Cookies.
//-------------------------------------------------------------------
[NonAction]
/// <summary>Retrieve the value from the named request cookie.</summary>
public String GetRequestCookie(String key)
{
@@ -166,6 +168,7 @@ namespace Sacs.Web.Components
return Request.Cookies[key];
return null;
}
[NonAction]
/// <summary>Set the value against the named response cookie.</summary>
public void SetResponseCookie(string key, string value, DateTime? expiresAt = null, bool isEssential = false)
{
@@ -79,7 +79,7 @@ namespace Sarand.Net.Standard.Accounts.QuickBooks.App
String sMsg = "Unsupported connection type: "+prmQbk.ConnectionType.ToString();
SetErrorState(sMsg);
if (SacsSystem.DebugMode)
SaLogger.Debug(GetType().Name + ".CreateApiConsole " + sMsg);
SaLogger.Debug($"{SysUtil.Fn} {sMsg}");
}
return null;
}
@@ -77,7 +77,7 @@ namespace Sarand.Net.Standard.Base.App
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".CTR Invalid process definition: " + exc.Message, true);
SaLogger.Warn($"{GetType().Name}.CTR Invalid process definition: {exc.Message}", true);
}
}
}
+47 -5
View File
@@ -165,49 +165,91 @@ namespace Sarand.Net.Standard.Base.Bus
protected void CheckChanged(SysId oldValue, SysId newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
// Compare by numeric value so that invalid values are equal.
Changed = SysId.ToInt(oldValue) != SysId.ToInt(newValue);
}
protected void CheckChanged(ItemId oldValue, ItemId newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = (oldValue.Type != newValue.Type) || (!oldValue.Id.Equals(newValue.Id));
}
protected void CheckChanged(String oldValue, String newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = !StringUtil.EmptyOnNull(oldValue).Equals(StringUtil.EmptyOnNull(newValue));
}
protected void CheckChanged(bool oldValue, bool newValue)
{
CheckChangedNullable(oldValue, newValue);
}
protected void CheckChangedNullable(bool? oldValue, bool? newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = (oldValue != newValue);
}
protected void CheckChangedEnum<T>(T oldValue, T newValue) where T : struct, IConvertible
{
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);
CheckChangedEnumNullable<T>(oldValue, newValue);
}
protected void CheckChangedEnumNullable<T>(T? oldValue, T? newValue) where T : struct, IConvertible
{
if (!(oldValue != null && oldValue is Enum) || !(newValue != null && newValue is Enum))
throw new ArgumentException($"{SysUtil.Fn}<T> Parameters must be enumerated types. Type supplied: {oldValue.GetType().Name}, {newValue.GetType().Name}.");
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = ((int)(oldValue as IConvertible) != (int)(newValue as IConvertible));
}
protected void CheckChanged(long oldValue, long newValue)
{
CheckChangedNullable(oldValue, newValue);
}
protected void CheckChangedNullable(long? oldValue, long? newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = (oldValue != newValue);
}
protected void CheckChanged(double oldValue, double newValue)
{
CheckChangedNullable(oldValue, newValue);
}
protected void CheckChangedNullable(double? oldValue, double? newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = (oldValue != newValue);
}
protected void CheckChanged(decimal oldValue, decimal newValue)
{
CheckChangedNullable(oldValue, newValue);
}
protected void CheckChangedNullable(decimal? oldValue, decimal? newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = (oldValue != newValue);
}
protected void CheckChanged(DateTime oldValue, DateTime newValue)
{
CheckChangedNullable(oldValue, newValue);
}
protected void CheckChangedNullable(DateTime? oldValue, DateTime? newValue)
{
if (Changed) return;
if ((oldValue == null) != (newValue == null)) Changed = true;
else if (oldValue != null && newValue != null)
Changed = !oldValue.Equals(newValue);
}
protected void CheckChanged(IEnumerable<String> oldValues, IEnumerable<String> newValues)
@@ -296,14 +338,14 @@ namespace Sarand.Net.Standard.Base.Bus
{
get
{
if (!ItemHasId) throw new NotSupportedException(GetType().Name + ".Id Item has no Id property");
if (!ItemHasId) throw new NotSupportedException($"{SysUtil.Fn}.get - Item has no Id property.");
return data.Id;
}
set
{
if (!ItemHasId && SysId.IsValid(data.Id)) throw new NotSupportedException(GetType().Name + ".Id Item has no Id property");
if (!ItemHasId && SysId.IsValid(data.Id)) throw new NotSupportedException($"{SysUtil.Fn}.set - Item has no Id property.");
if (SysId.IsValid(data.Id) && (!SysId.IsValid(value) || !data.Id.Equals(value)))
throw new NotSupportedException("SacsHierarchyItem.Id.set Id already has a valid value");
throw new NotSupportedException($"{SysUtil.Fn}.set - Id already has a valid value.");
data.Id = value;
}
}
+1 -1
View File
@@ -134,7 +134,7 @@ namespace Sarand.Net.Standard.Base.Bus
}
catch (Exception exc)
{
SaLogger.Debug(GetType().Name + ".ReadJson " + ExceptionUtil.GetErrorStateMessage(exc));
SaLogger.Debug($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}");
}
return null;
}
+11 -13
View File
@@ -197,23 +197,21 @@ namespace Sarand.Net.Standard.Base.Core
// Convert to specific type of data - fails if type is not correct:
if (dataType == DataType.Bool) return (bool)value;
if (dataType == DataType.Unknown) return false;
#if DEBUG
SaLogger.Debug(GetType().Name + ".AsBool Incorrect data type: " + dataType.ToString());
#endif
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return false;
}
public TriStateType AsTriState ()
{
if (dataType == DataType.TriState) return (TriStateType)value;
if (dataType == DataType.Unknown) return TriStateType.Unknown;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsTriState Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return TriStateType.Unknown;
}
public long AsLong ()
{
if (dataType == DataType.Long) return (long)value;
if (dataType == DataType.Unknown) return 0;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsLong Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0;
}
public double AsDouble ()
@@ -223,24 +221,24 @@ namespace Sarand.Net.Standard.Base.Core
// Aug-2018 Temporarily allow decimal values to be returned as double.
if (dataType == DataType.Decimal)
{
SaLogger.Warn(GetType().Name + ".AsDouble Data type: " + dataType.ToString());
SaLogger.Warn($"{SysUtil.Fn} Data type: {dataType.ToString()}.");
return (double)(decimal)value;
}
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsDouble Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0.0;
}
public decimal AsDecimal ()
{
if (dataType == DataType.Decimal) return (decimal)value;
if (dataType == DataType.Unknown) return 0.00m;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsDecimal Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return 0.00m;
}
public String AsString ()
{
if (dataType == DataType.String) return (String)value;
if (dataType == DataType.Unknown) return "";
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsString Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return "";
}
public DateTime AsDateTime ()
@@ -248,28 +246,28 @@ namespace Sarand.Net.Standard.Base.Core
// NB DateTime.Ticks is NotFiniteNumberException of 100-nanosecond intervals since beginning of 1st January 0001.
if (dataType == DataType.Date || dataType == DataType.Time || dataType == DataType.DateTime) return (DateTime)value;
if (dataType == DataType.Unknown) return DateTime.MinValue;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsDateTime Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
public DateTime AsDate ()
{
if (dataType == DataType.Date || dataType == DataType.DateTime) return ((DateTime)value).Date;
if (dataType == DataType.Unknown) return DateTime.MinValue;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsDate Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
public DateTime AsTime ()
{
if (dataType == DataType.Time || dataType == DataType.DateTime) return (DateTime)value;
if (dataType == DataType.Unknown) return DateTime.MinValue;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsTime Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return DateTime.MinValue;
}
public Byte[] AsBlob ()
{
if (dataType == DataType.Blob) return (Byte[])value;
if (dataType == DataType.Unknown) return null;
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AsBlob Incorrect data type: " + dataType.ToString());
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}.");
return null;
}
@@ -33,7 +33,7 @@ namespace Sarand.Net.Standard.Base.Core
// Ignore exception.
if (SacsSystem.DebugMode)
{
SaLogger.Debug(GetType().Name + ".Dispose " + ExceptionUtil.GetErrorStateMessage(exc));
SaLogger.Debug($"{SysUtil.Fn} {ExceptionUtil.GetErrorStateMessage(exc)}");
Debugger.Break();
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ namespace Sarand.Net.Standard.Base.Core
{
if (String.IsNullOrEmpty(name) || value == null)
{
if (SacsSystem.DebugMode) SaLogger.Debug(GetType().Name + ".AddValue Invalid named value. Name: " + StringUtil.EmptyOnNull(name) + ". Value: " + (value != null ? value.GetDataType().ToString() : "null"));
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Invalid named value. Name: {StringUtil.EmptyOnNull(name)}. Value: " + (value != null ? value.GetDataType().ToString() : "null"));
return false;
}
values[name] = value;
+1 -1
View File
@@ -42,7 +42,7 @@ namespace Sarand.Net.Standard.Base.Core
public virtual bool SetErrorState (String message)
{
if (StringUtil.IsEmpty(StringUtil.EmptyOnNull(message).Trim()))
throw new NotSupportedException(GetType().Name + ".SetErrorState Blank error message");
throw new NotSupportedException($"{SysUtil.Fn} Blank error message.");
this.ErrorState = new SacsErrorState(message);
return false;
}
+24
View File
@@ -78,6 +78,12 @@ namespace Sarand.Net.Standard.Base.Dbas
}
//-------------------------------------------------------------------
// Variable type and default - used in variable declaration.
/// <summary>
/// Column data type name as used in property names.
/// <para>- Binary represented as 'ByteArray'.</para>
/// <para>- Other data types represented by their variable type.</para>
/// </summary>
public String GetVariableTypeName()
{
switch (DataType)
@@ -87,6 +93,15 @@ namespace Sarand.Net.Standard.Base.Dbas
}
return GetVariableType();
}
/// <summary>
/// Column data type name as used in variable declarations.
/// <para>- VarChar represented as 'String'.</para>
/// <para>- Bit represented as 'Boolean'.</para>
/// <para>- TinyInt/SmallInt/BigInt represented as 'Int16/32/64'.</para>
/// <para>- Single/Double/Decimal/DateTime represented 'as-is'.</para>
/// <para>- Binary represented as 'Byte[]'.</para>
/// </summary>
public String GetVariableType()
{
switch (DataType)
@@ -116,6 +131,10 @@ namespace Sarand.Net.Standard.Base.Dbas
}
return String.Empty;
}
/// <summary>
/// Default value to be used in column value declarations.
/// </summary>
public String GetVariableDefault()
{
switch (DataType)
@@ -145,6 +164,11 @@ namespace Sarand.Net.Standard.Base.Dbas
}
return String.Empty;
}
/// <summary>
/// Method suffix to use for 'GetValue' calls.
/// <para>- Binary represented as 'ByteArray'.</para>
/// <para>- Other data types represented by their variable type.</para>
/// </summary>
public String GetGetFieldSuffix()
{
switch (DataType)
+1 -1
View File
@@ -186,7 +186,7 @@ namespace Sarand.Net.Standard.Base.Dbas
// Debugging.
public void Dump ()
{
SaLogger.Debug(GetType().Name + ".Dump");
SaLogger.Debug($"{SysUtil.Fn}");
SaLogger.Debug("\tType = " + GetJoinType(Type));
SaLogger.Debug("\tTable = " + Table.Concat(" AS "));
SaLogger.Debug("\tFilters = " + Filters.Concat("", "\t\t", "\n"));
+2 -1
View File
@@ -38,7 +38,8 @@ namespace Sarand.Net.Standard.Base.Dbas
Int64 GetFieldInt64 (DbDataReader dbDataReader, String name, Int64 defaultValue);
Single GetFieldSingle (DbDataReader dbDataReader, String name, Single defaultValue);
Double GetFieldDouble (DbDataReader dbDataReader, String name, Double defaultValue);
Decimal GetFieldDecimal (DbDataReader dbDataReader, String name, Decimal defaultValue);
Decimal GetFieldDecimal(DbDataReader dbDataReader, String name, Decimal defaultValue);
Decimal? GetFieldDecimalNullable(DbDataReader dbDataReader, String name, Decimal? defaultValue);
DateTime GetFieldDateTime (DbDataReader dbDataReader, String name, DateTime defaultValue);
//-------------------------------------------------------------------
+9 -5
View File
@@ -142,10 +142,10 @@ namespace Sarand.Net.Standard.Base.Utils
//-------------------------------------------------------------------------
// I n v a l i d
//-------------------------------------------------------------------------
public static DateTime OnInvalid(this DateTime value, DateTime defaultValue)
public static DateTime OnInvalid(this DateTime? value, DateTime defaultValue)
{
if (!IsValid(value)) return defaultValue;
return value;
return (DateTime)value;
}
//-------------------------------------------------------------------------
@@ -563,15 +563,19 @@ namespace Sarand.Net.Standard.Base.Utils
/// <param name="format"></param>
/// <returns></returns>
public static String Format(this DateTime value, String format, CultureInfo cultureInfo = null)
{
return Format((DateTime?)value, format, cultureInfo);
}
public static String Format(this DateTime? value, String format, CultureInfo cultureInfo = null)
{
if (!IsValid(value)) return String.Empty;
try
{
if (!String.IsNullOrEmpty(format))
{
return value.ToString(format, cultureInfo ?? CultureInfo.InvariantCulture);
return ((DateTime)value).ToString(format, cultureInfo ?? CultureInfo.InvariantCulture);
}
return value.ToString(cultureInfo ?? CultureInfo.InvariantCulture);
return ((DateTime)value).ToString(cultureInfo ?? CultureInfo.InvariantCulture);
}
catch (Exception exc)
{
@@ -616,7 +620,7 @@ namespace Sarand.Net.Standard.Base.Utils
//-------------------------------------------------------------------
/// <summary>Format suitable for parsing as javascript date: 'yyyy-MM-dd'</summary>
public static String FormatDateForJavascript(this DateTime value)
public static String FormatDateForJavascript(this DateTime? value)
{
return Format(value, Format_JavascriptDate);
}
@@ -23,6 +23,11 @@ namespace Sarand.Net.Standard.Base.Utils
// G e n e r i c G e t W i t h D e f a u l t
//-------------------------------------------------------------------
/// <summary>Safely get value from Dictionary with default if not defined.</summary>
public static TValue GetValue<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
{
return GetValue(dictionary as IDictionary<TKey, TValue>, key, defaultValue);
}
/// <summary>Safely get value from Dictionary with default if not defined.</summary>
public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
{
if (key == null) return defaultValue;
+1 -1
View File
@@ -23,7 +23,7 @@ namespace Sarand.Net.Standard.Base.Utils
return "";
}
/// <summary>Get calling code's fucntion name.</summary>
/// <summary>Get calling code's function name.</summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static string GetCallerMemberName([CallerMemberName] string memberName = "")
{
@@ -118,7 +118,7 @@ namespace Sarand.Net.Standard.Dbas.Base
// Clear files from output firectory.
if (Directory.EnumerateFiles(config.OutputDirectory, "*", SearchOption.TopDirectoryOnly).Count() > 0)
{
SaLogger.Info(GetType().Name + ".Generate Deleting existing files in output folders.");
SaLogger.Info($"{SysUtil.Fn} Deleting existing files in output folders.");
DirectoryInfo di = new DirectoryInfo(config.OutputDirectory);
foreach (FileInfo file in di.EnumerateFiles())
file.Delete();
@@ -178,16 +178,18 @@ namespace Sarand.Net.Standard.Dbas.Base
/// <summary>Intercept column variable type name to replace double/float with decimal where required.</summary>
private static String GetColumnVariableTypeName(DbDfnColumn columnDfn, bool treatDoubleFormatAsDecimal)
{
String typeName = columnDfn.GetVariableTypeName();
if (treatDoubleFormatAsDecimal)
{
switch (columnDfn.DataType)
{
case DbColumnDataType.Single:
case DbColumnDataType.Double:
return "Decimal";
typeName = "Decimal";
break;
}
}
return columnDfn.GetVariableTypeName();
return typeName;
}
//-------------------------------------------------------------------
@@ -199,16 +201,18 @@ namespace Sarand.Net.Standard.Dbas.Base
/// <summary>Intercept column variable type to replace double/float with decimal where required.</summary>
private static String GetColumnVariableType(DbDfnColumn columnDfn, bool treatDoubleFormatAsDecimal)
{
String typeName = columnDfn.GetVariableType();
if (treatDoubleFormatAsDecimal)
{
switch (columnDfn.DataType)
{
case DbColumnDataType.Single:
case DbColumnDataType.Double:
return "Decimal";
typeName = "Decimal";
break;
}
}
return columnDfn.GetVariableType();
return typeName;
}
//-------------------------------------------------------------------
@@ -220,16 +224,29 @@ namespace Sarand.Net.Standard.Dbas.Base
/// <summary>Intercept column 'Get Field Suffix' to replace double/float with decimal where required.</summary>
private static String GetColumnGetFieldSuffix(DbDfnColumn columnDfn, bool treatDoubleFormatAsDecimal)
{
String suffix = columnDfn.GetGetFieldSuffix();
if (treatDoubleFormatAsDecimal)
{
switch (columnDfn.DataType)
{
case DbColumnDataType.Single:
case DbColumnDataType.Double:
return "Decimal";
suffix = "Decimal";
break;
}
}
return columnDfn.GetGetFieldSuffix();
return suffix;
}
//-------------------------------------------------------------------
private static List<string> nullableDataTypes = new List<string>() { "Boolean", "Byte", "Int16", "Int32", "Int64", "Single", "Double", "Decimal", "DateTime" };
/// <summary>
/// Determine whether column should be treated as nullable.
/// <para>- This behaviour is restricted to selected data types.</para>
/// </summary>
private bool TreatColumnAsNullable(DbDfnColumn columnDfn)
{
return (nullableDataTypes.ContainsCI(columnDfn.GetVariableTypeName()) && columnDfn.IsNullable);
}
//-------------------------------------------------------------------
@@ -589,7 +606,10 @@ namespace Sarand.Net.Standard.Dbas.Base
file.WriteLine(tab2 + "public class ColumnsData");
file.WriteLine(tab2 + "{");
foreach (var columnDfn in tableDfn.Columns)
file.WriteLine(tab3 + "public ColumnData" + GetColumnVariableTypeName(columnDfn) + " _" + columnDfn.Name + " { get; } = new ColumnData" + GetColumnVariableTypeName(columnDfn) + "(\"" + columnDfn.Name + "\"" + (columnDfn.IsIdentity ? ", true" : "") + ");");
{
String columnDataClassName = "ColumnData" + GetColumnVariableTypeName(columnDfn) + (TreatColumnAsNullable(columnDfn) ? "Nullable" : "");
file.WriteLine(tab3 + "public " + columnDataClassName + " _" + columnDfn.Name + " { get; } = new " + columnDataClassName + "(\"" + columnDfn.Name + "\"" + (columnDfn.IsIdentity ? ", true" : "") + ");");
}
file.WriteLine(tab2 + "}");
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
file.WriteLine(tab2 + "// Data members.");
@@ -605,6 +625,10 @@ namespace Sarand.Net.Standard.Dbas.Base
file.WriteLine(tab2 + "{");
foreach (String columnName in primaryColumnNames) file.WriteLine(tab3 + "\"" + columnName + "\",");
file.WriteLine(tab2 + "};");
file.WriteLine(tab2 + "protected static List<String> fieldsNullable { get; } = new List<String>()");
file.WriteLine(tab2 + "{");
foreach (var columnDfn in tableDfn.Columns.FindAll(item => item.IsNullable)) file.WriteLine(tab3 + "\"" + columnDfn.Name + "\",");
file.WriteLine(tab2 + "};");
file.WriteLine(tab2 + "protected static List<String> fieldsIgnoreOnUpdate { get; } = new List<String>()");
file.WriteLine(tab2 + "{");
foreach (String columnName in columnsIgnoredOnUpdate) file.WriteLine(tab3 + "\"" + columnName + "\",");
@@ -644,7 +668,7 @@ namespace Sarand.Net.Standard.Dbas.Base
file.WriteLine(tab2 + "// Columns.");
file.WriteLine(tab2 + "public ColumnsData Cols { get; } = new ColumnsData();");
foreach (var columnDfn in tableDfn.Columns)
file.WriteLine(tab2 + "public " + GetColumnVariableType(columnDfn) + " _" + columnDfn.Name + " { get { return Cols._" + columnDfn.Name + ".Value; } set { Cols._" + columnDfn.Name + ".Value = value; } }");
file.WriteLine(tab2 + "public " + GetColumnVariableType(columnDfn) + (TreatColumnAsNullable(columnDfn) ? "?" : "") + " _" + columnDfn.Name + " { get { return Cols._" + columnDfn.Name + ".Value; } set { Cols._" + columnDfn.Name + ".Value = value; } }");
file.WriteLine(tab2 + "// Existing columns - confirmed on database if table exists.");
file.WriteLine(tab2 + "public List<String> ExistingColumnNames { get { return GetExistingColumnNames(Fields); } }");
file.WriteLine(tab2 + "public List<String> ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } }");
@@ -669,7 +693,7 @@ namespace Sarand.Net.Standard.Dbas.Base
file.WriteLine(tab2 + "public override void PopulateFrom (DbDataReader dbDataReader)");
file.WriteLine(tab2 + "{");
foreach (var columnDfn in tableDfn.Columns)
file.WriteLine(tab3 + "_" + columnDfn.Name + " = GetField" + GetColumnGetFieldSuffix(columnDfn) + "(dbDataReader, \"" + columnDfn.Name + "\", _" + columnDfn.Name + ");");
file.WriteLine(tab3 + "_" + columnDfn.Name + " = GetField" + GetColumnGetFieldSuffix(columnDfn) + (TreatColumnAsNullable(columnDfn) ? "Nullable" : "") + "(dbDataReader, \"" + columnDfn.Name + "\", _" + columnDfn.Name + ");");
file.WriteLine(tab2 + "}");
//-----------------------------------------------------------
@@ -698,11 +722,8 @@ namespace Sarand.Net.Standard.Dbas.Base
if (!String.IsNullOrEmpty(identityColumnName))
file.WriteLine(tab3 + "query += \"Output Inserted." + identityColumnName + " \";");
List<String> columnsValuesToInsertSql = new List<String>();
foreach (var columnDfn in tableDfn.Columns)
{
if (!columnDfn.IsIdentity)
foreach (var columnDfn in tableDfn.Columns.Where(col => !col.IsIdentity))
columnsValuesToInsertSql.Add("@" + columnDfn.Name);
}
file.WriteLine(tab3 + "if (dbCommand is SqlCommand)");
file.WriteLine(tab4 + "query += \"VALUES (\" + columnNames.Concat(\",\", \"@\", \"\") + \") \";");
file.WriteLine(tab3 + "else query += \"VALUES (\" + " + (config.SarandCommonVersion == SarandCommonVersion.VS2019 ? "StringListUtil" : "StringList") + ".CreateList(\"?\", columnNames.Count).Concat(\",\") + \") \";");
@@ -712,11 +733,8 @@ namespace Sarand.Net.Standard.Dbas.Base
file.WriteLine(tab3 + "Log(GetType().Name + \".ExecuteInsertCommand\", dbCommand.CommandText);");
file.WriteLine(tab3 + "// Populate parameters.");
file.WriteLine(tab3 + "dbCommand.Parameters.Clear();");
foreach (var columnDfn in tableDfn.Columns)
{
if (!columnDfn.IsIdentity)
foreach (var columnDfn in tableDfn.Columns.Where(col => !col.IsIdentity))
file.WriteLine(tab3 + "if (columnNames.ContainsCI(\"" + columnDfn.Name + "\")) AddCommandParameter(dbCommand, \"@" + columnDfn.Name + "\", _" + columnDfn.Name + ");");
}
file.WriteLine(tab3 + "// Execute insert command.");
file.WriteLine(tab3 + "bool commandSuccess = false;");
if (config.DbmsOutput == Dbms.SQL)
@@ -14,7 +14,7 @@ namespace Sarand.Net.Standard.Dbas.CodeType
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand Code Type Module database definition generator";
private static String className = nameof(SaCodeTypeDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
@@ -22,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.CodeType
/// </summary>
public static bool Generate(String connectionString)
{
String fn = nameof(SaCodeTypeDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -41,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.CodeType
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
@@ -81,31 +81,29 @@ namespace Sarand.Net.Standard.Dbas.CodeType
//-------------------------------------------------------------------
private static String GetOutputFolder()
{
String fn = nameof(SaCodeTypeDbDfnGenerator) + ".GetOutputFolder";
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: {directory}");
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\CodeTypes\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "CodeTypes";
SaLogger.Debug(fn + " Output folder: " + directory);
// Code files are generated to '..\Database\Generated\CodeTypes\' folder.
directory = Path.Combine(directory, "Database", "Generated", "CodeTypes");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -111,7 +111,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCodeType\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return codeType;
@@ -452,6 +453,7 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
public override List<SaCodeType> GetCodeTypeList (SaCodeType.Params prm)
{
ClearErrorState();
List<SaCodeType> codeTypes = new List<SaCodeType>();
DbQuery qry = CreateCodeTypeQuery(prm);
using (var dbConnection = Database.CreateConnection())
@@ -469,7 +471,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCodeTypeList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return codeTypes;
@@ -493,7 +496,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCodeTypeListAsync\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return codeTypes;
@@ -624,7 +628,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCode\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return code;
@@ -992,6 +997,7 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
public override List<SaCode> GetCodeList (SaCode.Params prm)
{
ClearErrorState();
List<SaCode> codes = new List<SaCode>();
DbQuery qry = CreateCodeQuery(prm);
// Query data.
@@ -1010,7 +1016,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCodeList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return codes;
@@ -1035,7 +1042,8 @@ namespace Sarand.Net.Standard.Dbas.CodeTypes
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCodeListAsync\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return codes;
+150 -49
View File
@@ -30,7 +30,7 @@ namespace Sarand.Net.Standard.Dbas.Data
private readonly List<DbDfnTable> tables;
private static readonly String defaultSchemaName = "dbo";
// Construction.
public DatabaseInfo (ISacsDatabase db)
public DatabaseInfo(ISacsDatabase db)
{
this.DatabaseName = db.DatabaseName;
this.tables = db.GetTableDfns();
@@ -39,7 +39,7 @@ namespace Sarand.Net.Standard.Dbas.Data
public String DatabaseName { get; }
public String Context { get { return StringUtil.OnEmpty(DatabaseName, "UnknownDb"); } }
// Database schema.
public DbDfnTable GetTableDefinition (String schemaName, String tableName)
public DbDfnTable GetTableDefinition(String schemaName, String tableName)
{
foreach (DbDfnTable table in tables.FindAll(item => item.Name.EqualsCI(tableName)))
{
@@ -48,17 +48,17 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return null;
}
public bool TableExists (String schemaName, String tableName)
public bool TableExists(String schemaName, String tableName)
{
return GetTableDefinition(schemaName, tableName) != null;
}
public bool ColumnExists (String schemaName, String tableName, String columnName)
public bool ColumnExists(String schemaName, String tableName, String columnName)
{
DbDfnTable table = GetTableDefinition(schemaName, tableName);
if (table == null) return false;
return table.HasColumnByName(columnName);
}
public List<DbDfnColumn> GetColumnsForTable (String schemaName, String tableName)
public List<DbDfnColumn> GetColumnsForTable(String schemaName, String tableName)
{
DbDfnTable table = GetTableDefinition(schemaName, tableName);
if (table != null) return table.Columns;
@@ -72,7 +72,7 @@ namespace Sarand.Net.Standard.Dbas.Data
/// <summary>Column data - column definition for DbDataItem.</summary>
public class ColumnData
{
protected ColumnData (String name, bool identity = false)
protected ColumnData(String name, bool identity = false)
{
Name = name;
Identity = identity;
@@ -82,57 +82,102 @@ namespace Sarand.Net.Standard.Dbas.Data
}
public class ColumnDataString : ColumnData
{
public ColumnDataString (String name, bool identity = false) : base(name, identity) { }
public ColumnDataString(String name, bool identity = false) : base(name, identity) { }
public String Value { get; set; } = String.Empty;
}
public class ColumnDataBoolean : ColumnData
{
public ColumnDataBoolean (String name, bool identity = false) : base(name, identity) { }
public ColumnDataBoolean(String name, bool identity = false) : base(name, identity) { }
public Boolean Value { get; set; } = false;
}
public class ColumnDataBooleanNullable : ColumnData
{
public ColumnDataBooleanNullable(String name, bool identity = false) : base(name, identity) { }
public Boolean? Value { get; set; } = null;
}
public class ColumnDataByte : ColumnData
{
public ColumnDataByte (String name, bool identity = false) : base(name, identity) { }
public ColumnDataByte(String name, bool identity = false) : base(name, identity) { }
public Byte Value { get; set; } = 0;
}
public class ColumnDataByteNullable : ColumnData
{
public ColumnDataByteNullable(String name, bool identity = false) : base(name, identity) { }
public Byte? Value { get; set; } = null;
}
public class ColumnDataInt16 : ColumnData
{
public ColumnDataInt16 (String name, bool identity = false) : base(name, identity) { }
public ColumnDataInt16(String name, bool identity = false) : base(name, identity) { }
public Int16 Value { get; set; } = 0;
}
public class ColumnDataInt16Nullable : ColumnData
{
public ColumnDataInt16Nullable(String name, bool identity = false) : base(name, identity) { }
public Int16? Value { get; set; } = null;
}
public class ColumnDataInt32 : ColumnData
{
public ColumnDataInt32 (String name, bool identity = false) : base(name, identity) { }
public ColumnDataInt32(String name, bool identity = false) : base(name, identity) { }
public Int32 Value { get; set; } = 0;
}
public class ColumnDataInt32Nullable : ColumnData
{
public ColumnDataInt32Nullable(String name, bool identity = false) : base(name, identity) { }
public Int32? Value { get; set; } = null;
}
public class ColumnDataInt64 : ColumnData
{
public ColumnDataInt64 (String name, bool identity = false) : base(name, identity) { }
public ColumnDataInt64(String name, bool identity = false) : base(name, identity) { }
public Int64 Value { get; set; } = 0;
}
public class ColumnDataInt64Nullable : ColumnData
{
public ColumnDataInt64Nullable(String name, bool identity = false) : base(name, identity) { }
public Int64? Value { get; set; } = null;
}
public class ColumnDataSingle : ColumnData
{
public ColumnDataSingle (String name, bool identity = false) : base(name, identity) { }
public ColumnDataSingle(String name, bool identity = false) : base(name, identity) { }
public Single Value { get; set; } = 0;
}
public class ColumnDataSingleNullable : ColumnData
{
public ColumnDataSingleNullable(String name, bool identity = false) : base(name, identity) { }
public Single? Value { get; set; } = null;
}
public class ColumnDataDouble : ColumnData
{
public ColumnDataDouble (String name, bool identity = false) : base(name, identity) { }
public ColumnDataDouble(String name, bool identity = false) : base(name, identity) { }
public Double Value { get; set; } = 0;
}
public class ColumnDataDecimal : ColumnData
{
public ColumnDataDecimal (String name, bool identity = false) : base(name, identity) { }
public ColumnDataDecimal(String name, bool identity = false) : base(name, identity) { }
public Decimal Value { get; set; } = 0;
}
public class ColumnDataDecimalNullable : ColumnData
{
public ColumnDataDecimalNullable(String name, bool identity = false) : base(name, identity) { }
public Decimal? Value { get; set; } = null;
}
public class ColumnDataDateTime : ColumnData
{
public ColumnDataDateTime (String name, bool identity = false) : base(name, identity) { }
public ColumnDataDateTime(String name, bool identity = false) : base(name, identity) { }
public DateTime Value { get; set; } = DateTime.MinValue;
}
public class ColumnDataDateTimeNullable : ColumnData
{
public ColumnDataDateTimeNullable(String name, bool identity = false) : base(name, identity) { }
public DateTime? Value { get; set; } = null;
}
public class ColumnDataByteArray : ColumnData
{
public ColumnDataByteArray (String name, bool identity = false) : base(name, identity) { }
public ColumnDataByteArray(String name, bool identity = false) : base(name, identity) { }
public Byte[] Value { get; set; } = null;
}
public class ColumnDataByteArrayNullable : ColumnData
{
public ColumnDataByteArrayNullable(String name, bool identity = false) : base(name, identity) { }
public Byte[] Value { get; set; } = null;
}
@@ -144,7 +189,7 @@ namespace Sarand.Net.Standard.Dbas.Data
//-------------------------------------------------------------------
// Construction.
protected DbDataItem (IDatabaseInfo dbInfo = null)
protected DbDataItem(IDatabaseInfo dbInfo = null)
{
DbInfo = dbInfo;
}
@@ -159,7 +204,7 @@ namespace Sarand.Net.Standard.Dbas.Data
//-------------------------------------------------------------------
/// <summary>Determine the table name used on the database which can differ if alternative names are available.</summary>
protected String GetActualTableName (String tableName)
protected String GetActualTableName(String tableName)
{
if (DbInfo != null)
{
@@ -172,18 +217,18 @@ namespace Sarand.Net.Standard.Dbas.Data
//-------------------------------------------------------------------
// Population.
public abstract void PopulateFrom (DbCommand dbCommand, String tableAlias, String filter);
public abstract void PopulateFrom (DbDataReader dbdataReader);
public abstract void PopulateFrom(DbCommand dbCommand, String tableAlias, String filter);
public abstract void PopulateFrom(DbDataReader dbdataReader);
//-------------------------------------------------------------------
// Database schema.
public bool ColumnExists (String columnName)
public bool ColumnExists(String columnName)
{
if (DbInfo != null)
return DbInfo.ColumnExists(SchemaName, TableName, columnName);
return true;
}
public List<String> GetExistingColumnNames (List<String> columnNames)
public List<String> GetExistingColumnNames(List<String> columnNames)
{
List<String> columnNamesExisting = new List<string>(columnNames);
if (existingColumnNamesFull == null)
@@ -192,7 +237,7 @@ namespace Sarand.Net.Standard.Dbas.Data
// NB The list will be empty if no DbInfo supplied or the table is not found on the database.
if (DbInfo != null)
{
List<DbDfnColumn> existingColumns = DbInfo.GetColumnsForTable(SchemaName,TableName);
List<DbDfnColumn> existingColumns = DbInfo.GetColumnsForTable(SchemaName, TableName);
existingColumnNamesFull = existingColumns.GetNames();
}
else existingColumnNamesFull = new List<string>();
@@ -211,9 +256,9 @@ namespace Sarand.Net.Standard.Dbas.Data
/// Get column index by name.
/// <para>Returns -1 if not found and logs message.</para>
/// </summary>
protected int GetColumnOrdinal (DbDataReader dbDataReader, String columnName)
protected int GetColumnOrdinal(DbDataReader dbDataReader, String columnName)
{
String fn = GetType().Name+".GetColumnOrdinal";
String fn = GetType().Name + ".GetColumnOrdinal";
// Identify whether the specified column name is in the list of columns in the results set.
// NB Efficient as doesn't load the table schema and avoids logging of exception.
// Ref. https://stackoverflow.com/questions/373230/check-for-column-name-in-a-sqldatareader-object
@@ -258,7 +303,8 @@ namespace Sarand.Net.Standard.Dbas.Data
//-------------------------------------------------------------------
// Retrieve field values.
public String GetFieldString (DbDataReader dbDataReader, String columnName, String defaultValue)
public String GetFieldString(DbDataReader dbDataReader, String columnName, String defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -273,7 +319,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Boolean GetFieldBoolean (DbDataReader dbDataReader, String columnName, Boolean defaultValue)
public Boolean GetFieldBoolean(DbDataReader dbDataReader, String columnName, Boolean defaultValue)
{
return GetFieldBooleanNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Boolean? GetFieldBooleanNullable(DbDataReader dbDataReader, String columnName, Boolean? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -288,7 +340,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Byte GetFieldByte (DbDataReader dbDataReader, String columnName, Byte defaultValue)
public Byte GetFieldByte(DbDataReader dbDataReader, String columnName, Byte defaultValue)
{
return GetFieldByteNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Byte? GetFieldByteNullable(DbDataReader dbDataReader, String columnName, Byte? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -303,7 +361,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Int16 GetFieldInt16 (DbDataReader dbDataReader, String columnName, Int16 defaultValue)
public Int16 GetFieldInt16(DbDataReader dbDataReader, String columnName, Int16 defaultValue)
{
return GetFieldInt16Nullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Int16? GetFieldInt16Nullable(DbDataReader dbDataReader, String columnName, Int16? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -318,7 +382,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Int32 GetFieldInt32 (DbDataReader dbDataReader, String columnName, Int32 defaultValue)
public Int32 GetFieldInt32(DbDataReader dbDataReader, String columnName, Int32 defaultValue)
{
return GetFieldInt32Nullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Int32? GetFieldInt32Nullable(DbDataReader dbDataReader, String columnName, Int32? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -335,7 +405,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Int64 GetFieldInt64 (DbDataReader dbDataReader, String columnName, Int64 defaultValue)
public Int64 GetFieldInt64(DbDataReader dbDataReader, String columnName, Int64 defaultValue)
{
return GetFieldInt64Nullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Int64? GetFieldInt64Nullable(DbDataReader dbDataReader, String columnName, Int64? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -354,7 +430,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Single GetFieldSingle (DbDataReader dbDataReader, String columnName, Single defaultValue)
public Single GetFieldSingle(DbDataReader dbDataReader, String columnName, Single defaultValue)
{
return GetFieldSingleNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Single? GetFieldSingleNullable(DbDataReader dbDataReader, String columnName, Single? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -369,7 +451,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Double GetFieldDouble (DbDataReader dbDataReader, String columnName, Double defaultValue)
public Double GetFieldDouble(DbDataReader dbDataReader, String columnName, Double defaultValue)
{
return GetFieldDoubleNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Double? GetFieldDoubleNullable(DbDataReader dbDataReader, String columnName, Double? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -388,7 +476,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public Decimal GetFieldDecimal (DbDataReader dbDataReader, String columnName, Decimal defaultValue)
public Decimal GetFieldDecimal(DbDataReader dbDataReader, String columnName, Decimal defaultValue)
{
return GetFieldDecimalNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public Decimal? GetFieldDecimalNullable(DbDataReader dbDataReader, String columnName, Decimal? defaultValue = null)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -412,7 +506,13 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public DateTime GetFieldDateTime (DbDataReader dbDataReader, String columnName, DateTime defaultValue)
public DateTime GetFieldDateTime(DbDataReader dbDataReader, String columnName, DateTime defaultValue)
{
return GetFieldDateTimeNullable(dbDataReader, columnName, defaultValue) ?? defaultValue;
}
public DateTime? GetFieldDateTimeNullable(DbDataReader dbDataReader, String columnName, DateTime? defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -427,7 +527,8 @@ namespace Sarand.Net.Standard.Dbas.Data
}
return defaultValue;
}
public byte[] GetFieldByteArray (DbDataReader dbDataReader, String columnName, byte[] defaultValue)
public byte[] GetFieldByteArray(DbDataReader dbDataReader, String columnName, byte[] defaultValue)
{
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
if (columnIdx < 0) return defaultValue;
@@ -449,25 +550,25 @@ namespace Sarand.Net.Standard.Dbas.Data
// Value is passed as a Typed parameter (rather than object) so that it's type is known
// even if the value is null, eg. to assign Db type for correct handling of null values,
// ref. byte[] -> VarBinary.
protected void AddCommandParameter<ValueType> (DbCommand dbCommand, String parameterName, ValueType value)
protected void AddCommandParameter<ValueType>(DbCommand dbCommand, String parameterName, ValueType value)
{
DbParameter dbParameter = dbCommand.CreateParameter();
dbParameter.ParameterName = parameterName;
dbParameter.Value = (Object)value ?? DBNull.Value;
if (typeof(ValueType) == typeof(Int16))
if (typeof(ValueType) == typeof(Int16) || typeof(ValueType) == typeof(Int16?))
{
dbParameter.DbType = System.Data.DbType.Int16;
}
else if (typeof(ValueType) == typeof(Int32))
else if (typeof(ValueType) == typeof(Int32) || typeof(ValueType) == typeof(Int32?))
{
dbParameter.DbType = System.Data.DbType.Int32;
}
else if (typeof(ValueType) == typeof(DateTime))
else if (typeof(ValueType) == typeof(DateTime) || typeof(ValueType) == typeof(DateTime?))
{
if (dbCommand is SqlCommand)
dbParameter.DbType = System.Data.DbType.DateTime2;
else dbParameter.DbType = System.Data.DbType.DateTime;
if ((DateTime)(Object)value == DateTime.MinValue)
if ((Object)value == null || (DateTime)(Object)value == DateTime.MinValue || (DateTime)(Object)value == DateTime.MaxValue)
dbParameter.Value = DBNull.Value;
else
{
@@ -489,17 +590,17 @@ namespace Sarand.Net.Standard.Dbas.Data
//-------------------------------------------------------------------
// Database updates via ODBC Command.
public abstract bool ExecuteInsertCommand (DbCommand dbCommand);
public abstract bool ExecuteUpdateCommand (DbCommand dbCommand);
public abstract bool ExecuteInsertCommand(DbCommand dbCommand);
public abstract bool ExecuteUpdateCommand(DbCommand dbCommand);
//public abstract bool ExecuteDeleteCommand (DbCommand dbCommand);
//-------------------------------------------------------------------
// Full list of all columns missing from database over life of application.
private static readonly List<String> columnsMissing = new List<string>();
// Missing columns are only logged on their initial discovery.
private void LogMissingColumn (String columnName)
private void LogMissingColumn(String columnName)
{
String columnIdentifier = DbInfo.Context+"."+(!StringUtil.IsEmpty(SchemaName)?SchemaName+".":"")+TableName+"."+columnName;
String columnIdentifier = DbInfo.Context + "." + (!StringUtil.IsEmpty(SchemaName) ? SchemaName + "." : "") + TableName + "." + columnName;
if (!columnsMissing.ContainsCI(columnIdentifier))
{
columnsMissing.Add(columnIdentifier);
@@ -512,9 +613,9 @@ namespace Sarand.Net.Standard.Dbas.Data
// Full list of all columns found with alternative data type in database over life of application.
private static readonly List<String> columnsAlternativeType = new List<string>();
// Missing columns are only logged on their initial discovery.
private void LogAlternativeTypeColumn (String columnName, Type typeExpected, Type typeFound)
private void LogAlternativeTypeColumn(String columnName, Type typeExpected, Type typeFound)
{
String columnIdentifier = DbInfo.Context+"."+(!StringUtil.IsEmpty(SchemaName)?SchemaName+".":"")+TableName+"."+columnName;
String columnIdentifier = DbInfo.Context + "." + (!StringUtil.IsEmpty(SchemaName) ? SchemaName + "." : "") + TableName + "." + columnName;
if (!columnsAlternativeType.ContainsCI(columnIdentifier))
{
columnsAlternativeType.Add(columnIdentifier);
@@ -527,7 +628,7 @@ namespace Sarand.Net.Standard.Dbas.Data
// Logging.
public static SaMessageLevel LoggingLevel { get; set; } = SaMessageLevel.None;
public static String LoggingPrefix { get; set; } = " ~~~ ";
protected void Log (String fn, String message, SaMessageLevel level = SaMessageLevel.Debug)
protected void Log(String fn, String message, SaMessageLevel level = SaMessageLevel.Debug)
{
if ((int)level > (int)LoggingLevel) return;
SaLogger.Log((fn + "\n\t" + message).Trim(), level);
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.Data
qry.Tables.Add(NextIdTable);
qry.Columns.Add(colNextId, colAliasNextId);
qry.Filters.Add(filter);
//SaLogger.Debug(GetType().Name + ".GetNextId Query: " + qry.BuildQuery());
//SaLogger.Debug($"{SysUtil.Fn} Query: {qry.BuildQuery()}");
DbResultSet_DataReader resultsSet = DbResultSet_DataReader.ExecuteQuery(this, qry.BuildQuery());
if (resultsSet != null && resultsSet.NextRecord())
{
@@ -101,7 +101,7 @@ namespace Sarand.Net.Standard.Dbas.Data
updateColumnValues.Add(DbCol_UpdateBy, SysId.IsValid(dbUpdateInfo.UserId) ? SysId.ToString(dbUpdateInfo.UserId) : "0");
}
String updateQry = "Update " + NextIdTable + " Set " + updateColumnValues.Concat("=").Concat(", ") + " Where " + filter;
//SaLogger.Debug(GetType().Name + ".GetNextId Update query: " + updateQry);
//SaLogger.Debug($"{SysUtil.Fn} Update query: {updateQry}");
using (var dbConnection = CreateConnection())
using (var dbCommand = dbConnection.CreateCommand())
{
@@ -133,7 +133,7 @@ namespace Sarand.Net.Standard.Dbas.Data
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(",") + ")";
SaLogger.Debug(GetType().Name + ".GetNextId Insert query: " + insertQry);
SaLogger.Debug($"{SysUtil.Fn} Insert query: {insertQry}");
using (var dbConnection = CreateConnection())
using (var dbCommand = dbConnection.CreateCommand())
{
@@ -157,7 +157,7 @@ namespace Sarand.Net.Standard.Dbas.Data
{
PopulateNextIdTableDfn();
throw new NotSupportedException(GetType().Name + ".SetMinNextId Not yet implemented");
throw new NotSupportedException($"{SysUtil.Fn} Not yet implemented.");
//return true;
}
@@ -323,7 +323,7 @@ namespace Sarand.Net.Standard.Dbas.Data
}
catch (Exception exc)
{
SaLogger.Error(GetType().Name + ".GetRowValue " + ExceptionUtil.GetLogMessage(exc) + "\n\tTable: " + tableName + ". Column: " + columnName + ". Filter: " + (!StringUtil.IsEmpty(filter) ? filter : "<none>"), true);
SaLogger.Error($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}\n\tTable: {tableName}. Column: {columnName}. Filter: " + (!StringUtil.IsEmpty(filter) ? filter : "<none>"), true);
SetErrorState(exc.Message);
}
return null;
@@ -654,7 +654,7 @@ namespace Sarand.Net.Standard.Dbas.Data
else if (colName.EqualsCI("SS_XML_SCHEMACOLLECTION_NAME")) { }
else if (colName.EqualsCI("SS_DATA_TYPE")) { }
// Unrecognised columns.
else SaLogger.Debug(GetType().Name + ".PopulateTableColumns Unrecognised Schema column name: " + colName + " [" + value + "]");
else SaLogger.Debug($"{SysUtil.Fn} Unrecognised Schema column name: {colName} [{value}]");
}
if (!StringUtil.IsEmpty(columnName))
{
@@ -20,18 +20,18 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
// I n t e r f a c e D a t a I t e m s
//*******************************************************************
// Create Item.
public override SaInterfaceDataItem CreateInterfaceDataItem (SysId interfaceId, SaInterfaceProcessDirection direction, ItemId itemId, String externalReference)
public override SaInterfaceDataItem CreateInterfaceDataItem(SysId interfaceId, SaInterfaceProcessDirection direction, ItemId itemId, String externalReference)
{
return new SaInterfaceDataItem_Dbas(null, interfaceId, direction, itemId, externalReference, 0);
}
private SaInterfaceDataItem CreateInterfaceDataItem (SaInterfaceDataItem_Db dbInterfaceDataItem)
private SaInterfaceDataItem CreateInterfaceDataItem(SaInterfaceDataItem_Db dbInterfaceDataItem)
{
ClearErrorState();
SaInterfaceDataItem interfaceDataItem = new SaInterfaceDataItem_Dbas(new SysId(dbInterfaceDataItem._Id), new SysId(dbInterfaceDataItem._InterfaceId), (SaInterfaceProcessDirection)dbInterfaceDataItem._Direction, new ItemId(dbInterfaceDataItem._ItemType, new SysId(dbInterfaceDataItem._ItemId)), dbInterfaceDataItem._ExternalRef, (ushort)dbInterfaceDataItem._Flags);
PopulateFrom(dbInterfaceDataItem, interfaceDataItem);
return interfaceDataItem;
}
private SaInterfaceDataItem CreateInterfaceDataItem (DbDataReader dataReader)
private SaInterfaceDataItem CreateInterfaceDataItem(DbDataReader dataReader)
{
SaInterfaceDataItem_Db dbInterfaceDataItem = new SaInterfaceDataItem_Db(DbInfo);
dbInterfaceDataItem.PopulateFrom(dataReader);
@@ -40,7 +40,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Item exists.
public override bool InterfaceDataItemExistsById (SysId id)
public override bool InterfaceDataItemExistsById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return false;
@@ -49,11 +49,11 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Get Item.
public override SaInterfaceDataItem GetInterfaceDataItem (SaInterfaceDataItem.Params prm)
public override SaInterfaceDataItem GetInterfaceDataItem(SaInterfaceDataItem.Params prm)
{
return GetInterfaceDataItem(GetInterfaceDataItemQueryFilter(prm).Concat(" AND ", "(", ")"));
}
private SaInterfaceDataItem GetInterfaceDataItem (String filter)
private SaInterfaceDataItem GetInterfaceDataItem(String filter)
{
ClearErrorState();
if (GetInterfaceDataItemCount(filter) != 1) return null;
@@ -71,12 +71,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceDataItem\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaceProcessDataItem;
}
public override SaInterfaceDataItem GetInterfaceDataItemById (SysId id)
public override SaInterfaceDataItem GetInterfaceDataItemById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return null;
@@ -85,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Validate Item properties.
public override bool IsValidInterfaceDataItemData (SaInterfaceDataItem.Data interfaceData, SaInterfaceDataItem.ErrField errField)
public override bool IsValidInterfaceDataItemData(SaInterfaceDataItem.Data interfaceData, SaInterfaceDataItem.ErrField errField)
{
ClearErrorState();
if (!base.IsValidInterfaceDataItemData(interfaceData, errField)) return false;
@@ -94,7 +95,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Insert Item.
public override bool InsertInterfaceDataItem (SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
public override bool InsertInterfaceDataItem(SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceDataItem(interfaceProcessDataItem)) return false;
@@ -122,7 +123,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Update Item.
public override bool UpdateInterfaceDataItem (SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
public override bool UpdateInterfaceDataItem(SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceDataItem(interfaceProcessDataItem)) return false;
@@ -147,13 +148,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Delete Item.
public override bool InterfaceDataItemCanBeDeleted (SaInterfaceDataItem interfaceProcessDataItem)
public override bool InterfaceDataItemCanBeDeleted(SaInterfaceDataItem interfaceProcessDataItem)
{
ClearErrorState();
if (!base.InterfaceDataItemCanBeDeleted(interfaceProcessDataItem)) return false;
return true;
}
public override bool DeleteInterfaceDataItem (SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
public override bool DeleteInterfaceDataItem(SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!InterfaceDataItemCanBeDeleted(interfaceProcessDataItem)) return false;
@@ -178,7 +179,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Copy data properties to and from database.
private void PopulateTo (SaInterfaceDataItem_Db dbInterfaceDataItem, SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
private void PopulateTo(SaInterfaceDataItem_Db dbInterfaceDataItem, SaInterfaceDataItem interfaceProcessDataItem, DbUpdateInfo dbUpdateInfo)
{
dbInterfaceDataItem._Id = interfaceProcessDataItem.Id.ToInt();
dbInterfaceDataItem._InterfaceId = SysId.ToInt(interfaceProcessDataItem.InterfaceId);
@@ -205,7 +206,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
dbInterfaceDataItem._UpdateBy = dbUpdateInfo.UserId.ToInt();
dbInterfaceDataItem._UpdateHost = dbUpdateInfo.Host;
}
private void PopulateFrom (SaInterfaceDataItem_Db dbInterfaceDataItem, SaInterfaceDataItem interfaceProcessDataItem)
private void PopulateFrom(SaInterfaceDataItem_Db dbInterfaceDataItem, SaInterfaceDataItem interfaceProcessDataItem)
{
//interface.Id = new SysId(dbInterfaceDataItem._Id);
//interfaceProcessDataItem.InterfaceId = new SysId(dbInterfaceDataItem._InterfaceId);
@@ -237,9 +238,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
alias = aliasInterfaceDataItem;
col.Set(caption, width, (int)dbCol, prefix + SaInterfaceDbDfn.GetColumnName(dbCol, false), SaInterfaceDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
}
public override ColumnDfn GetInterfaceDataItemColumnDfn (SaInterfaceDataItem.Column columnId, string caption = "", int width = 0)
public override ColumnDfn GetInterfaceDataItemColumnDfn(SaInterfaceDataItem.Column columnId, string caption = "", int width = 0)
{
ColumnDfn columnDfn = new ColumnDfn((int)columnId,caption,width);
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
switch (columnId)
{
case SaInterfaceDataItem.Column.Pos:
@@ -388,7 +389,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Query filter.
public override List<string> GetInterfaceDataItemQueryFilter (SaInterfaceDataItem.Params prm)
public override List<string> GetInterfaceDataItemQueryFilter(SaInterfaceDataItem.Params prm)
{
List<String> filter = new List<String>();
@@ -451,7 +452,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
return filter;
}
// Sort columns.
public List<String> GetInterfaceDataItemSortColumns (SaInterfaceDataItem.Params prm)
public List<String> GetInterfaceDataItemSortColumns(SaInterfaceDataItem.Params prm)
{
// Sort sequence:
List<String> sortColumnNames = new List<String>();
@@ -493,12 +494,12 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Item count.
private long GetInterfaceDataItemCount (String filter)
private long GetInterfaceDataItemCount(String filter)
{
ClearErrorState();
return Database.GetRowCount(TableName_InterfaceDataItem + " As " + aliasInterfaceDataItem, filter);
}
public override long GetInterfaceDataItemCount (SaInterfaceDataItem.Params prm)
public override long GetInterfaceDataItemCount(SaInterfaceDataItem.Params prm)
{
ClearErrorState();
return GetInterfaceDataItemCount(GetInterfaceDataItemQueryFilter(prm).Concat(" AND ", "(", ")"));
@@ -506,8 +507,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Item list.
public override List<SaInterfaceDataItem> GetInterfaceDataItemList (SaInterfaceDataItem.Params prm)
public override List<SaInterfaceDataItem> GetInterfaceDataItemList(SaInterfaceDataItem.Params prm)
{
ClearErrorState();
List<SaInterfaceDataItem> interfaces = new List<SaInterfaceDataItem>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_InterfaceDataItem, aliasInterfaceDataItem);
@@ -531,7 +533,8 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceDataItemList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaces;
@@ -539,7 +542,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Item query.
public override DbResultSet ExecuteInterfaceDataItemQuery (List<ColumnDfn> columns, SaInterfaceDataItem.Params prm)
public override DbResultSet ExecuteInterfaceDataItemQuery(List<ColumnDfn> columns, SaInterfaceDataItem.Params prm)
{
ClearErrorState();
@@ -20,19 +20,19 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
// I n t e r f a c e P r o c e s s M e s s a g e s
//*******************************************************************
// Create Item.
public override SaInterfaceProcessMessage CreateInterfaceProcessMessage (SysId interfaceProcessId)
public override SaInterfaceProcessMessage CreateInterfaceProcessMessage(SysId interfaceProcessId)
{
ClearErrorState();
return new SaInterfaceProcessMessage_Dbas(null, interfaceProcessId, 0);
}
private SaInterfaceProcessMessage CreateInterfaceProcessMessage (SaInterfaceProcessMessage_Db dbInterfaceProcessMessage)
private SaInterfaceProcessMessage CreateInterfaceProcessMessage(SaInterfaceProcessMessage_Db dbInterfaceProcessMessage)
{
ClearErrorState();
SaInterfaceProcessMessage interfaceProcessMessage = new SaInterfaceProcessMessage_Dbas(new SysId(dbInterfaceProcessMessage._Id), new SysId(dbInterfaceProcessMessage._ProcessId), (ushort)dbInterfaceProcessMessage._Flags);
PopulateFrom(dbInterfaceProcessMessage, interfaceProcessMessage);
return interfaceProcessMessage;
}
private SaInterfaceProcessMessage CreateInterfaceProcessMessage (DbDataReader dataReader)
private SaInterfaceProcessMessage CreateInterfaceProcessMessage(DbDataReader dataReader)
{
SaInterfaceProcessMessage_Db dbInterfaceProcessMessage = new SaInterfaceProcessMessage_Db(DbInfo);
dbInterfaceProcessMessage.PopulateFrom(dataReader);
@@ -41,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Item exists.
public override bool InterfaceProcessMessageExistsById (SysId id)
public override bool InterfaceProcessMessageExistsById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return false;
@@ -50,11 +50,11 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Get Item.
public override SaInterfaceProcessMessage GetInterfaceProcessMessage (SaInterfaceProcessMessage.Params prm)
public override SaInterfaceProcessMessage GetInterfaceProcessMessage(SaInterfaceProcessMessage.Params prm)
{
return GetInterfaceProcessMessage(GetInterfaceProcessMessageQueryFilter(prm).Concat(" AND ", "(", ")"));
}
private SaInterfaceProcessMessage GetInterfaceProcessMessage (String filter)
private SaInterfaceProcessMessage GetInterfaceProcessMessage(String filter)
{
ClearErrorState();
if (GetInterfaceProcessMessageCount(filter) != 1) return null;
@@ -72,12 +72,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceProcessMessage\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaceProcessMessage;
}
public override SaInterfaceProcessMessage GetInterfaceProcessMessageById (SysId id)
public override SaInterfaceProcessMessage GetInterfaceProcessMessageById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return null;
@@ -86,7 +87,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Validate Interface ProcessMessage.
public override bool IsValidInterfaceProcessMessageData (SaInterfaceProcessMessage.Data interfaceData, SaInterfaceProcessMessage.ErrField errField)
public override bool IsValidInterfaceProcessMessageData(SaInterfaceProcessMessage.Data interfaceData, SaInterfaceProcessMessage.ErrField errField)
{
ClearErrorState();
if (!base.IsValidInterfaceProcessMessageData(interfaceData, errField)) return false;
@@ -95,7 +96,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Insert Interface ProcessMessage.
public override bool InsertInterfaceProcessMessage (SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
public override bool InsertInterfaceProcessMessage(SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceProcessMessage(interfaceProcessMessage)) return false;
@@ -123,7 +124,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Update Interface ProcessMessage.
public override bool UpdateInterfaceProcessMessage (SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
public override bool UpdateInterfaceProcessMessage(SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceProcessMessage(interfaceProcessMessage)) return false;
@@ -148,13 +149,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Delete item.
public override bool InterfaceProcessMessageCanBeDeleted (SaInterfaceProcessMessage interfaceProcessMessage)
public override bool InterfaceProcessMessageCanBeDeleted(SaInterfaceProcessMessage interfaceProcessMessage)
{
ClearErrorState();
if (!base.InterfaceProcessMessageCanBeDeleted(interfaceProcessMessage)) return false;
return true;
}
public override bool DeleteInterfaceProcessMessage (SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
public override bool DeleteInterfaceProcessMessage(SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!InterfaceProcessMessageCanBeDeleted(interfaceProcessMessage)) return false;
@@ -179,7 +180,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Copy data properties to and from database.
private void PopulateTo (SaInterfaceProcessMessage_Db dbInterfaceProcessMessage, SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
private void PopulateTo(SaInterfaceProcessMessage_Db dbInterfaceProcessMessage, SaInterfaceProcessMessage interfaceProcessMessage, DbUpdateInfo dbUpdateInfo)
{
dbInterfaceProcessMessage._Id = interfaceProcessMessage.Id.ToInt();
dbInterfaceProcessMessage._ProcessId = SysId.ToInt(interfaceProcessMessage.InterfaceProcessId);
@@ -201,7 +202,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
dbInterfaceProcessMessage._UpdateBy = dbUpdateInfo.UserId.ToInt();
dbInterfaceProcessMessage._UpdateHost = dbUpdateInfo.Host;
}
private void PopulateFrom (SaInterfaceProcessMessage_Db dbInterfaceProcessMessage, SaInterfaceProcessMessage interfaceProcessMessage)
private void PopulateFrom(SaInterfaceProcessMessage_Db dbInterfaceProcessMessage, SaInterfaceProcessMessage interfaceProcessMessage)
{
//interface.Id = new SysId(dbInterfaceProcessMessage._Id);
//interfaceProcessMessage.InterfaceProcessId = new SysId(dbInterfaceProcessMessage._ProcessId);
@@ -231,9 +232,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
alias = aliasInterfaceProcessMessage;
col.Set(caption, width, (int)dbCol, prefix + SaInterfaceDbDfn.GetColumnName(dbCol, false), SaInterfaceDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
}
public override ColumnDfn GetInterfaceProcessMessageColumnDfn (SaInterfaceProcessMessage.Column columnId, string caption = "", int width = 0)
public override ColumnDfn GetInterfaceProcessMessageColumnDfn(SaInterfaceProcessMessage.Column columnId, string caption = "", int width = 0)
{
ColumnDfn columnDfn = new ColumnDfn((int)columnId,caption,width);
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
switch (columnId)
{
case SaInterfaceProcessMessage.Column.Pos:
@@ -305,7 +306,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface ProcessMessage query filter.
public override List<string> GetInterfaceProcessMessageQueryFilter (SaInterfaceProcessMessage.Params prm)
public override List<string> GetInterfaceProcessMessageQueryFilter(SaInterfaceProcessMessage.Params prm)
{
List<String> filter = new List<String>();
@@ -341,7 +342,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
return filter;
}
// Interface ProcessMessage sort columns.
public List<String> GetInterfaceProcessMessageSortColumns (SaInterfaceProcessMessage.Params prm)
public List<String> GetInterfaceProcessMessageSortColumns(SaInterfaceProcessMessage.Params prm)
{
// Sort sequence:
List<String> sortColumnNames = new List<String>();
@@ -379,12 +380,12 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface ProcessMessage count.
private long GetInterfaceProcessMessageCount (String filter)
private long GetInterfaceProcessMessageCount(String filter)
{
ClearErrorState();
return Database.GetRowCount(TableName_InterfaceProcessMessage + " As " + aliasInterfaceProcessMessage, filter);
}
public override long GetInterfaceProcessMessageCount (SaInterfaceProcessMessage.Params prm)
public override long GetInterfaceProcessMessageCount(SaInterfaceProcessMessage.Params prm)
{
ClearErrorState();
return GetInterfaceProcessMessageCount(GetInterfaceProcessMessageQueryFilter(prm).Concat(" AND ", "(", ")"));
@@ -392,8 +393,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface ProcessMessage list.
public override List<SaInterfaceProcessMessage> GetInterfaceProcessMessageList (SaInterfaceProcessMessage.Params prm)
public override List<SaInterfaceProcessMessage> GetInterfaceProcessMessageList(SaInterfaceProcessMessage.Params prm)
{
ClearErrorState();
List<SaInterfaceProcessMessage> interfaces = new List<SaInterfaceProcessMessage>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_InterfaceProcessMessage, aliasInterfaceProcessMessage);
@@ -417,7 +419,8 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceProcessMessageList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaces;
@@ -425,7 +428,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface ProcessMessage query.
public override DbResultSet ExecuteInterfaceProcessMessageQuery (List<ColumnDfn> columns, SaInterfaceProcessMessage.Params prm)
public override DbResultSet ExecuteInterfaceProcessMessageQuery(List<ColumnDfn> columns, SaInterfaceProcessMessage.Params prm)
{
ClearErrorState();
@@ -20,40 +20,40 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
// I n t e r f a c e P r o c e s s e s
//*******************************************************************
// Associated data.
public override int GetInterfaceProcessMessageCount (SysId id)
public override int GetInterfaceProcessMessageCount(SysId id)
{
String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcessMessage_ProcessId)+"="+SysId.ToString(id);
String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcessMessage_ProcessId) + "=" + SysId.ToString(id);
return (int)Database.GetRowCount(TableName_InterfaceProcessMessage, filter);
}
public override bool InterfaceProcessHasMessages (SysId id)
public override bool InterfaceProcessHasMessages(SysId id)
{
return (GetInterfaceProcessMessageCount(id) > 0);
}
public override int GetInterfaceProcessDataItemCount (SysId id)
public override int GetInterfaceProcessDataItemCount(SysId id)
{
String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcessDataItem_ProcessId)+"="+SysId.ToString(id);
String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcessDataItem_ProcessId) + "=" + SysId.ToString(id);
return (int)Database.GetRowCount(TableName_InterfaceProcessDataItem, filter);
}
public override bool InterfaceProcessHasDataItems (SysId id)
public override bool InterfaceProcessHasDataItems(SysId id)
{
return (GetInterfaceProcessDataItemCount(id) > 0);
}
//-------------------------------------------------------------------
// Create Interface Process.
public override SaInterfaceProcess CreateInterfaceProcess (SysId interfaceId, SaInterfaceProcessDirection direction, String reference, int sequence)
public override SaInterfaceProcess CreateInterfaceProcess(SysId interfaceId, SaInterfaceProcessDirection direction, String reference, int sequence)
{
ClearErrorState();
return new SaInterfaceProcess_Dbas(null, interfaceId, direction, reference, sequence, 0);
}
private SaInterfaceProcess CreateInterfaceProcess (SaInterfaceProcess_Db dbInterfaceProcess)
private SaInterfaceProcess CreateInterfaceProcess(SaInterfaceProcess_Db dbInterfaceProcess)
{
ClearErrorState();
SaInterfaceProcess interfaceProcess = new SaInterfaceProcess_Dbas(new SysId(dbInterfaceProcess._Id), new SysId(dbInterfaceProcess._InterfaceId), (SaInterfaceProcessDirection)dbInterfaceProcess._Direction, dbInterfaceProcess._ProcRef, dbInterfaceProcess._ProcSeq, (ushort)dbInterfaceProcess._Flags);
PopulateFrom(dbInterfaceProcess, interfaceProcess);
return interfaceProcess;
}
private SaInterfaceProcess CreateInterfaceProcess (DbDataReader dataReader)
private SaInterfaceProcess CreateInterfaceProcess(DbDataReader dataReader)
{
SaInterfaceProcess_Db dbInterfaceProcess = new SaInterfaceProcess_Db_Local(DbInfo);
dbInterfaceProcess.PopulateFrom(dataReader);
@@ -62,7 +62,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface Process exists.
public override bool InterfaceProcessExistsById (SysId id)
public override bool InterfaceProcessExistsById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return false;
@@ -71,11 +71,11 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Get Interface Process.
public override SaInterfaceProcess GetInterfaceProcess (SaInterfaceProcess.Params prm)
public override SaInterfaceProcess GetInterfaceProcess(SaInterfaceProcess.Params prm)
{
return GetInterfaceProcess(GetInterfaceProcessQueryFilter(prm).Concat(" AND ", "(", ")"));
}
private SaInterfaceProcess GetInterfaceProcess (String filter)
private SaInterfaceProcess GetInterfaceProcess(String filter)
{
ClearErrorState();
if (GetInterfaceProcessCount(filter) != 1) return null;
@@ -93,12 +93,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceProcess\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaceProcess;
}
public override SaInterfaceProcess GetInterfaceProcessById (SysId id)
public override SaInterfaceProcess GetInterfaceProcessById(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return null;
@@ -107,7 +108,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Validate Interface Process.
public override bool IsValidInterfaceProcessData (SaInterfaceProcess.Data interfaceData, SaInterfaceProcess.ErrField errField)
public override bool IsValidInterfaceProcessData(SaInterfaceProcess.Data interfaceData, SaInterfaceProcess.ErrField errField)
{
ClearErrorState();
if (!base.IsValidInterfaceProcessData(interfaceData, errField)) return false;
@@ -116,7 +117,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Insert Interface Process.
public override bool InsertInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
public override bool InsertInterfaceProcess(SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceProcess(interfaceProcess)) return false;
@@ -144,7 +145,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Update Interface Process.
public override bool UpdateInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
public override bool UpdateInterfaceProcess(SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidInterfaceProcess(interfaceProcess)) return false;
@@ -169,13 +170,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Delete Item.
public override bool InterfaceProcessCanBeDeleted (SaInterfaceProcess interfaceProcess)
public override bool InterfaceProcessCanBeDeleted(SaInterfaceProcess interfaceProcess)
{
ClearErrorState();
if (!base.InterfaceProcessCanBeDeleted(interfaceProcess)) return false;
return true;
}
public override bool ClearInterfaceProcessMessages (List<SysId> interfaceProcessIdsToClear, DbUpdateInfo dbUpdateInfo)
public override bool ClearInterfaceProcessMessages(List<SysId> interfaceProcessIdsToClear, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
using (var dbConnection = Database.CreateConnection())
@@ -201,7 +202,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
return !HasErrorState();
}
public override bool ClearInterfaceProcessDataItems (List<SysId> interfaceProcessIdsToClear, DbUpdateInfo dbUpdateInfo)
public override bool ClearInterfaceProcessDataItems(List<SysId> interfaceProcessIdsToClear, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
using (var dbConnection = Database.CreateConnection())
@@ -227,7 +228,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
return !HasErrorState();
}
public override bool DeleteInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
public override bool DeleteInterfaceProcess(SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!InterfaceProcessCanBeDeleted(interfaceProcess)) return false;
@@ -252,7 +253,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Copy data properties to and from database.
private void PopulateTo (SaInterfaceProcess_Db dbInterfaceProcess, SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
private void PopulateTo(SaInterfaceProcess_Db dbInterfaceProcess, SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo)
{
dbInterfaceProcess._Id = interfaceProcess.Id.ToInt();
dbInterfaceProcess._InterfaceId = SysId.ToInt(interfaceProcess.InterfaceId);
@@ -274,7 +275,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
dbInterfaceProcess._UpdateBy = dbUpdateInfo.UserId.ToInt();
dbInterfaceProcess._UpdateHost = dbUpdateInfo.Host;
}
private void PopulateFrom (SaInterfaceProcess_Db dbInterfaceProcess, SaInterfaceProcess interfaceProcess)
private void PopulateFrom(SaInterfaceProcess_Db dbInterfaceProcess, SaInterfaceProcess interfaceProcess)
{
//interface.Id = new SysId(dbInterfaceProcess._Id);
//interfaceProcess.InterfaceId = new SysId(dbInterfaceProcess._InterfaceId);
@@ -306,9 +307,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
alias = aliasInterfaceProcess;
col.Set(caption, width, (int)dbCol, prefix + SaInterfaceDbDfn.GetColumnName(dbCol, false), SaInterfaceDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
}
public override ColumnDfn GetInterfaceProcessColumnDfn (SaInterfaceProcess.Column columnId, string caption = "", int width = 0)
public override ColumnDfn GetInterfaceProcessColumnDfn(SaInterfaceProcess.Column columnId, string caption = "", int width = 0)
{
ColumnDfn columnDfn = new ColumnDfn((int)columnId,caption,width);
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
switch (columnId)
{
case SaInterfaceProcess.Column.Pos:
@@ -473,7 +474,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface Process query filter.
public override List<string> GetInterfaceProcessQueryFilter (SaInterfaceProcess.Params prm)
public override List<string> GetInterfaceProcessQueryFilter(SaInterfaceProcess.Params prm)
{
List<String> filter = new List<String>();
@@ -521,7 +522,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
else if (Database.ColumnExists(TableName_InterfaceProcess, "ProcDate"))
{
// Legacy database - ProcDate/Time (integer values) istead of ProcessAt (DateTime).
String colInterfaceProcess_ProcDate = aliasInterfaceProcess+".ProcDate";
String colInterfaceProcess_ProcDate = aliasInterfaceProcess + ".ProcDate";
if (DateUtil.IsValid(prm.ProcessedOn))
{
filter.Add(colInterfaceProcess_ProcDate + ">=" + DateUtil.DateToInt32(prm.ProcessedOn.Date));
@@ -562,7 +563,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
return filter;
}
// Interface Process sort columns.
public List<String> GetInterfaceProcessSortColumns (SaInterfaceProcess.Params prm)
public List<String> GetInterfaceProcessSortColumns(SaInterfaceProcess.Params prm)
{
// Sort sequence:
List<String> sortColumnNames = new List<String>();
@@ -617,12 +618,12 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface Process count.
private long GetInterfaceProcessCount (String filter)
private long GetInterfaceProcessCount(String filter)
{
ClearErrorState();
return Database.GetRowCount(TableName_InterfaceProcess + " As " + aliasInterfaceProcess, filter);
}
public override long GetInterfaceProcessCount (SaInterfaceProcess.Params prm)
public override long GetInterfaceProcessCount(SaInterfaceProcess.Params prm)
{
ClearErrorState();
return GetInterfaceProcessCount(GetInterfaceProcessQueryFilter(prm).Concat(" AND ", "(", ")"));
@@ -630,8 +631,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface Process list.
public override List<SaInterfaceProcess> GetInterfaceProcessList (SaInterfaceProcess.Params prm)
public override List<SaInterfaceProcess> GetInterfaceProcessList(SaInterfaceProcess.Params prm)
{
ClearErrorState();
List<SaInterfaceProcess> interfaces = new List<SaInterfaceProcess>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_InterfaceProcess, aliasInterfaceProcess);
@@ -655,7 +657,8 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceProcessList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaces;
@@ -663,7 +666,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
//-------------------------------------------------------------------
// Interface Process query.
public override DbResultSet ExecuteInterfaceProcessQuery (List<ColumnDfn> columns, SaInterfaceProcess.Params prm)
public override DbResultSet ExecuteInterfaceProcessQuery(List<ColumnDfn> columns, SaInterfaceProcess.Params prm)
{
ClearErrorState();
@@ -104,7 +104,8 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterface\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaceObj;
@@ -467,6 +468,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
// Item list.
public override List<SaInterface> GetInterfaceList (SaInterface.Params prm)
{
ClearErrorState();
List<SaInterface> interfaces = new List<SaInterface>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_Interface, aliasInterface);
@@ -490,7 +492,8 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetInterfaceList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return interfaces;
@@ -14,16 +14,15 @@ namespace Sarand.Net.Standard.Dbas.ItemData
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand Item Data Module database definition generator";
//private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;";
private static String className = nameof(SaItemDataDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
/// Generate database definitions.
/// </summary>
public static bool Generate (String connectionString)
public static bool Generate(String connectionString)
{
String fn = nameof(SaItemDataDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -42,13 +41,13 @@ namespace Sarand.Net.Standard.Dbas.ItemData
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
//-------------------------------------------------------------------
private static bool GenerateDatabaseDefinition (SacsDatabase database, String directory)
private static bool GenerateDatabaseDefinition(SacsDatabase database, String directory)
{
DatabaseDefinitionGenerator.Config config = new DatabaseDefinitionGenerator.Config()
{
@@ -75,33 +74,31 @@ namespace Sarand.Net.Standard.Dbas.ItemData
}
//-------------------------------------------------------------------
private static String GetOutputFolder ()
private static String GetOutputFolder()
{
String fn = nameof(SaItemDataDbDfnGenerator) + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof (DatabaseDefinitionGenerator)).Location));
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: {directory}");
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\ItemData\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "ItemData";
SaLogger.Debug(fn+" Output folder: " + directory);
// Code files are generated to '..\Database\Generated\ItemData\' folder.
directory = Path.Combine(directory, "Database", "Generated", "ItemData");
SaLogger.Debug(fn + " Output folder: " + directory);
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -25,13 +25,13 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Static initialisation.
static SaItemDataMgr_Dbas ()
static SaItemDataMgr_Dbas()
{
}
//-------------------------------------------------------------------
// Construction.
internal SaItemDataMgr_Dbas (SaItemDataConsole_Dbas itemDataConsole)
internal SaItemDataMgr_Dbas(SaItemDataConsole_Dbas itemDataConsole)
{
this.itemDataConsole = itemDataConsole;
DbInfo = new DbDataItem.DatabaseInfo(itemDataConsole.Database);
@@ -49,7 +49,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
// I t e m D a t a
//*******************************************************************
// Utilities.
public override bool ItemHasData (ItemId itemId, bool ignoreDeleted = true)
public override bool ItemHasData(ItemId itemId, bool ignoreDeleted = true)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return false;
@@ -58,7 +58,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
prmItemData.StatusCat = (ignoreDeleted ? SaItemData.StatusCat.NotDeleted : SaItemData.StatusCat.Any);
return (GetItemDataCount(prmItemData) > 0);
}
public override bool ItemHasData (ItemId itemId, String dataType, bool ignoreDeleted = true)
public override bool ItemHasData(ItemId itemId, String dataType, bool ignoreDeleted = true)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return false;
@@ -72,19 +72,19 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Create Item.
public override SaItemData CreateItemData (ItemId itemId)
public override SaItemData CreateItemData(ItemId itemId)
{
ClearErrorState();
return new SaItemData_Dbas(null, itemId, 0);
}
private SaItemData CreateItemData (SaItemData_Db dbItemData)
private SaItemData CreateItemData(SaItemData_Db dbItemData)
{
ClearErrorState();
SaItemData itemData = new SaItemData_Dbas(null, new ItemId(dbItemData._ItemType, new SysId(dbItemData._ItemId)), (ushort)dbItemData._Flags);
PopulateFrom(dbItemData, itemData);
return itemData;
}
private SaItemData CreateItemData (DbDataReader dataReader)
private SaItemData CreateItemData(DbDataReader dataReader)
{
SaItemData_Db dbItemData = new SaItemData_Db(DbInfo);
dbItemData.PopulateFrom(dataReader);
@@ -93,7 +93,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Item exists.
public override bool ItemDataExists (SysId id)
public override bool ItemDataExists(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return false;
@@ -102,7 +102,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
prmItemData.StatusCat = SaItemData.StatusCat.Any;
return (GetItemDataCount(prmItemData) > 0);
}
public override bool ItemDataExists (ItemId itemId, String dataType, bool ignoreDeleted = true)
public override bool ItemDataExists(ItemId itemId, String dataType, bool ignoreDeleted = true)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return false;
@@ -116,7 +116,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Get Item Data.
public override SaItemData GetItemData (SysId id)
public override SaItemData GetItemData(SysId id)
{
ClearErrorState();
if (!SysId.IsValid(id)) return null;
@@ -125,7 +125,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
prmItemData.StatusCat = SaItemData.StatusCat.Any;
return GetItemData(prmItemData);
}
public override SaItemData GetItemData (ItemId itemId, String dataType)
public override SaItemData GetItemData(ItemId itemId, String dataType)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return null;
@@ -136,11 +136,11 @@ namespace Sarand.Net.Standard.Dbas.ItemData
prmItemData.StatusCat = SaItemData.StatusCat.Any;
return GetItemData(prmItemData);
}
public override SaItemData GetItemData (SaItemData.Params prmItemData)
public override SaItemData GetItemData(SaItemData.Params prmItemData)
{
return GetItemData(GetItemDataQueryFilter(prmItemData).Concat(" And ", "(", ")"));
}
private SaItemData GetItemData (String filter)
private SaItemData GetItemData(String filter)
{
ClearErrorState();
if (GetItemDataCount(filter) != 1) return null;
@@ -158,7 +158,8 @@ namespace Sarand.Net.Standard.Dbas.ItemData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemData\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemData;
@@ -166,7 +167,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Validate ItemData.
public override bool IsValidItemDataData (SaItemData.Data itemDataData, SaItemData.ErrField errField)
public override bool IsValidItemDataData(SaItemData.Data itemDataData, SaItemData.ErrField errField)
{
ClearErrorState();
if (!base.IsValidItemDataData(itemDataData, errField)) return false;
@@ -175,7 +176,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Insert ItemData.
public override bool InsertItemData (SaItemData itemData, DbUpdateInfo dbUpdateInfo)
public override bool InsertItemData(SaItemData itemData, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidItemData(itemData)) return false;
@@ -203,7 +204,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Update item.
public override bool UpdateItemData (SaItemData itemData, DbUpdateInfo dbUpdateInfo)
public override bool UpdateItemData(SaItemData itemData, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!IsValidItemData(itemData)) return false;
@@ -228,13 +229,13 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Delete item.
public override bool ItemDataCanBeDeleted (SaItemData itemData)
public override bool ItemDataCanBeDeleted(SaItemData itemData)
{
ClearErrorState();
if (!base.ItemDataCanBeDeleted(itemData)) return false;
return true;
}
public override bool DeleteItemData (SaItemData itemData, DbUpdateInfo dbUpdateInfo)
public override bool DeleteItemData(SaItemData itemData, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!ItemDataCanBeDeleted(itemData)) return false;
@@ -256,19 +257,19 @@ namespace Sarand.Net.Standard.Dbas.ItemData
}
return !HasErrorState();
}
public override bool ClearItemData (ItemId itemId, DbUpdateInfo dbUpdateInfo)
public override bool ClearItemData(ItemId itemId, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return SetErrorState("Item Id must be specified");
String colItemType = SaItemDataDbDfn.GetColumnName(SaItemDataDbDfn.ColumnIdx.SaItemData_ItemType);
String colItemId = SaItemDataDbDfn.GetColumnName(SaItemDataDbDfn.ColumnIdx.SaItemData_ItemId);
String query = "Delete From "+TableName_ItemData+" WHERE "+colItemType+"="+itemId.Type.ToString()+" AND "+colItemId+"="+SysId.ToString(itemId.Id);
String query = "Delete From " + TableName_ItemData + " WHERE " + colItemType + "=" + itemId.Type.ToString() + " AND " + colItemId + "=" + SysId.ToString(itemId.Id);
Database.ExecuteNonQuery(query);
if (Database.HasErrorState())
SetErrorState("Failed to clear Item Data - " + Database.ErrorStateMessage);
return !HasErrorState();
}
public override bool ClearItemData (ItemId itemId, String dataType, DbUpdateInfo dbUpdateInfo)
public override bool ClearItemData(ItemId itemId, String dataType, DbUpdateInfo dbUpdateInfo)
{
ClearErrorState();
if (!ItemId.IsValid(itemId)) return SetErrorState("Item Id must be specified");
@@ -276,7 +277,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
String colItemType = SaItemDataDbDfn.GetColumnName(SaItemDataDbDfn.ColumnIdx.SaItemData_ItemType);
String colItemId = SaItemDataDbDfn.GetColumnName(SaItemDataDbDfn.ColumnIdx.SaItemData_ItemId);
String colDataType = SaItemDataDbDfn.GetColumnName(SaItemDataDbDfn.ColumnIdx.SaItemData_DataType);
String query = "Delete From " + TableName_ItemData + " WHERE " + colItemType + "=" + itemId.Type.ToString() + " AND " + colItemId + "=" + SysId.ToString(itemId.Id) + " AND " + colDataType + "='"+dataType+"';";
String query = "Delete From " + TableName_ItemData + " WHERE " + colItemType + "=" + itemId.Type.ToString() + " AND " + colItemId + "=" + SysId.ToString(itemId.Id) + " AND " + colDataType + "='" + dataType + "';";
Database.ExecuteNonQuery(query);
if (Database.HasErrorState())
SetErrorState("Failed to clear Item Data - " + Database.ErrorStateMessage);
@@ -285,7 +286,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Copy data properties to and from database.
private void PopulateTo (SaItemData_Db dbItemData, SaItemData itemData, DbUpdateInfo dbUpdateInfo)
private void PopulateTo(SaItemData_Db dbItemData, SaItemData itemData, DbUpdateInfo dbUpdateInfo)
{
dbItemData._ItemType = itemData.ItemId.Type;
dbItemData._ItemId = SysId.ToInt(itemData.ItemId.Id);
@@ -305,7 +306,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
dbItemData._UpdateBy = dbUpdateInfo.UserId.ToInt();
dbItemData._UpdateHost = dbUpdateInfo.Host;
}
private void PopulateFrom (SaItemData_Db dbItemData, SaItemData itemData)
private void PopulateFrom(SaItemData_Db dbItemData, SaItemData itemData)
{
//itemData.ItemId = new ItemId(dbItemData._ItemType, new SysId(dbItemData._ItemId));
itemData.DataType = dbItemData._DataType;
@@ -330,9 +331,9 @@ namespace Sarand.Net.Standard.Dbas.ItemData
alias = aliasItemData;
col.Set(caption, width, (int)dbCol, prefix + SaItemDataDbDfn.GetColumnName(dbCol, false), SaItemDataDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
}
public override ColumnDfn GetItemDataColumnDfn (SaItemData.Column columnId, string caption = "", int width = 0)
public override ColumnDfn GetItemDataColumnDfn(SaItemData.Column columnId, string caption = "", int width = 0)
{
ColumnDfn columnDfn = new ColumnDfn((int)columnId,caption,width);
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
switch (columnId)
{
case SaItemData.Column.Pos:
@@ -394,7 +395,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// ItemData query filter.
public override List<string> GetItemDataQueryFilter (SaItemData.Params prm)
public override List<string> GetItemDataQueryFilter(SaItemData.Params prm)
{
List<String> filter = new List<String>();
@@ -443,7 +444,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
return filter;
}
// ItemData sort columns.
public List<String> GetItemDataSortColumns (SaItemData.Params prm)
public List<String> GetItemDataSortColumns(SaItemData.Params prm)
{
// Sort sequence:
List<String> sortColumnNames = new List<String>();
@@ -482,12 +483,12 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// ItemData count.
private long GetItemDataCount (String filter)
private long GetItemDataCount(String filter)
{
ClearErrorState();
return Database.GetRowCount(SaItemDataDbDfn.GetTableName(SaItemDataDbDfn.TableIdx.SaItemData) + " As " + aliasItemData, filter);
}
public override long GetItemDataCount (SaItemData.Params prm)
public override long GetItemDataCount(SaItemData.Params prm)
{
ClearErrorState();
return GetItemDataCount(GetItemDataQueryFilter(prm).Concat(" AND ", "(", ")"));
@@ -495,8 +496,9 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Item Data list.
public override List<SaItemData> GetItemDataList (SaItemData.Params prm)
public override List<SaItemData> GetItemDataList(SaItemData.Params prm)
{
ClearErrorState();
List<SaItemData> itemDatas = new List<SaItemData>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_ItemData, aliasItemData);
@@ -520,7 +522,8 @@ namespace Sarand.Net.Standard.Dbas.ItemData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemDataList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemDatas;
@@ -528,7 +531,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
//-------------------------------------------------------------------
// Item Data query.
public override DbResultSet ExecuteItemDataQuery (List<ColumnDfn> columns, SaItemData.Params prm)
public override DbResultSet ExecuteItemDataQuery(List<ColumnDfn> columns, SaItemData.Params prm)
{
ClearErrorState();
@@ -136,7 +136,8 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemDoc\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemDoc;
@@ -533,6 +534,7 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
// Item list.
public override List<SaItemDoc> GetItemDocList (SaItemDoc.Params prm)
{
ClearErrorState();
List<SaItemDoc> itemDocs = new List<SaItemDoc>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_ItemDoc, aliasItemDoc);
@@ -556,7 +558,8 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemDocList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemDocs;
@@ -18,16 +18,15 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand Item Docs Module database definition generator";
//private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;";
private static String className = nameof(SaItemDocsDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
/// Generate database definitions.
/// </summary>
public static bool Generate (String connectionString)
public static bool Generate(String connectionString)
{
String fn = nameof(SaItemDocsDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -46,13 +45,13 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
//-------------------------------------------------------------------
private static bool GenerateDatabaseDefinition (SacsDatabase database, String directory)
private static bool GenerateDatabaseDefinition(SacsDatabase database, String directory)
{
DatabaseDefinitionGenerator.Config config = new DatabaseDefinitionGenerator.Config()
{
@@ -82,33 +81,31 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
return generator.Generate(config);
}
//-------------------------------------------------------------------
private static String GetOutputFolder ()
private static String GetOutputFolder()
{
String fn = nameof(SaItemDocsDbDfnGenerator) + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof (DatabaseDefinitionGenerator)).Location));
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: " + directory);
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\ItemDocs\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "ItemDocs";
SaLogger.Debug(fn + " Output folder: " + directory);
// Code files are generated to '..\Database\Generated\ItemDocs\' folder.
directory = Path.Combine(directory, "Database", "Generated", "ItemDocs");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -123,7 +123,8 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemOption\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemOption;
@@ -509,7 +510,8 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetItemOptionList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return itemOptions;
@@ -14,8 +14,7 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand Item Options Module database definition generator";
//private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;";
private static string className = nameof(SaItemOptionsDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
@@ -23,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
/// </summary>
public static bool Generate(String connectionString)
{
String fn = nameof(SaItemOptionsDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -42,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
@@ -80,31 +79,29 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions
//-------------------------------------------------------------------
private static String GetOutputFolder()
{
String fn = nameof(SaItemOptionsDbDfnGenerator) + ".GetOutputFolder";
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: {directory}");
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\ItemOptions\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "ItemOptions";
SaLogger.Debug(fn + " Output folder: " + directory);
// Code files are generated to '..\Database\Generated\ItemOptions\' folder.
directory = Path.Combine(directory, "Database", "Generated", "ItemOptions");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -14,8 +14,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand ReferenceData Module database definition generator";
//private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;";
private static string className = nameof(SaReferenceDataDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
@@ -23,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
/// </summary>
public static bool Generate(String connectionString)
{
String fn = nameof(SaReferenceDataDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -42,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
@@ -84,31 +83,29 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
//-------------------------------------------------------------------
private static String GetOutputFolder()
{
String fn = nameof(SaReferenceDataDbDfnGenerator) + ".GetOutputFolder";
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: {directory}");
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\ReferenceData\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "ReferenceData";
SaLogger.Debug(fn + " Output folder: " + directory);
directory = Path.Combine(directory, "Database", "Generated", "ReferenceData");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
catch (Exception exc)
{
SetErrorState("Database query exception");
SaLogger.Warn(GetType().Name + ".GetCurrency\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return currency;
@@ -426,6 +426,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
// Currency list.
public override List<SaCurrency> GetCurrencyList (SaCurrency.Params prm)
{
ClearErrorState();
List<SaCurrency> currencies = new List<SaCurrency>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(ReferenceDataConsole.TableName_Currency, aliasCurrency);
@@ -451,7 +452,8 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetCurrencyList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return currencies;
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
catch (Exception exc)
{
SetErrorState("Database query exception");
SaLogger.Warn(GetType().Name + ".GetLanguage\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return language;
@@ -434,6 +434,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
// Language list.
public override List<SaLanguage> GetLanguageList (SaLanguage.Params prm)
{
ClearErrorState();
List<SaLanguage> languages = new List<SaLanguage>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(ReferenceDataConsole.TableName_Language, aliasLanguage);
@@ -457,7 +458,8 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetLanguageList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return languages;
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
catch (Exception exc)
{
SetErrorState("Database query exception");
SaLogger.Warn(GetType().Name + ".GetRegion\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return region;
@@ -413,6 +413,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
// Region list.
public override List<SaRegion> GetRegionList (SaRegion.Params prm)
{
ClearErrorState();
List<SaRegion> regions = new List<SaRegion>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(ReferenceDataConsole.TableName_Region, aliasRegion);
@@ -436,7 +437,8 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetRegionList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return regions;
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
catch (Exception exc)
{
SetErrorState("Database query exception");
SaLogger.Warn(GetType().Name + ".GetTaxCode\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return taxCode;
@@ -454,6 +454,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
// TaxCode list.
public override List<SaTaxCode> GetTaxCodeList (SaTaxCode.Params prm)
{
ClearErrorState();
List<SaTaxCode> taxCodes = new List<SaTaxCode>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(ReferenceDataConsole.TableName_TaxCode, aliasTaxCode);
@@ -477,7 +478,8 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetTaxCodeList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return taxCodes;
@@ -86,7 +86,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
catch (Exception exc)
{
SetErrorState("Database query exception");
SaLogger.Warn(GetType().Name + ".GetUnitMeasure\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return unitMeasure;
@@ -463,6 +463,7 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
// UnitMeasure list.
public override List<SaUnitMeasure> GetUnitMeasureList (SaUnitMeasure.Params prm)
{
ClearErrorState();
List<SaUnitMeasure> unitMeasures = new List<SaUnitMeasure>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(ReferenceDataConsole.TableName_UnitMeasure, aliasUnitMeasure);
@@ -486,7 +487,8 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetUnitMeasureList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return unitMeasures;
@@ -188,20 +188,19 @@ namespace Sarand.Net.Standard.Dbas.Security
//-------------------------------------------------------------------
public override bool LoginUser(SysId userId, bool recordLastLogin = true)
{
String fn = GetType().Name + ".LoginUser";
ClearErrorState();
using (SaSecurityItem secItemUser = securityMgr.GetSecurityItemById(userId))
{
if (secItemUser == null || secItemUser.ItemType != SaSecurity.ItemType.User || !secItemUser.IsStatusEnabled)
{
SaLogger.Error(fn + " Failed to retrieve user for login. Id: " + SysId.ToString(userId) + " - " + securityMgr.ErrorStateMessage, true);
SaLogger.Error($"{SysUtil.Fn}Failed to retrieve user for login. Id: {SysId.ToString(userId)} - {securityMgr.ErrorStateMessage}", true);
return SetErrorState("Invalid credentials supplied");
}
if (recordLastLogin)
{
secItemUser.LastLogin = DateTime.Now;
if (!securityMgr.UpdateSecurityItem(secItemUser, new DbUpdateInfo(secItemUser.Id, secItemUser.Description, SacsSystem.ComputerName)))
SaLogger.Error(fn + " Failed to update user on login. Id: " + SysId.ToString(userId) + "' - " + securityMgr.ErrorStateMessage, true);
SaLogger.Error($"{SysUtil.Fn}Failed to update user on login. Id: {SysId.ToString(userId)}' - {securityMgr.ErrorStateMessage}", true);
}
OnLogin(secItemUser != null ? secItemUser.Id : null);
}
@@ -209,7 +208,6 @@ namespace Sarand.Net.Standard.Dbas.Security
}
public override bool LoginAuthenticatedUser()
{
String fn = GetType().Name + ".LoginAuthenticatedUser";
ClearErrorState();
String userCode = System.Environment.UserName;
@@ -218,7 +216,7 @@ namespace Sarand.Net.Standard.Dbas.Security
{
secItem.LastLogin = DateTime.Now;
if (!securityMgr.UpdateSecurityItem(secItem, new DbUpdateInfo(secItem.Id, secItem.Description, SacsSystem.ComputerName)))
SaLogger.Error(fn + " Failed to update user '" + userCode + "' - " + securityMgr.ErrorStateMessage, true);
SaLogger.Error($"{SysUtil.Fn}Failed to update user '{userCode}' - {securityMgr.ErrorStateMessage}", true);
}
else
{
@@ -230,7 +228,7 @@ namespace Sarand.Net.Standard.Dbas.Security
secItem.AuthenticatedUser = true;
if (!securityMgr.InsertSecurityItem(secItem, new DbUpdateInfo(new SysId(), secItem.Description, SacsSystem.ComputerName)))
{
SaLogger.Error(fn + " Failed to create user '" + userCode + "' - " + securityMgr.ErrorStateMessage, true);
SaLogger.Error($"{SysUtil.Fn}Failed to create user '{userCode}' - {securityMgr.ErrorStateMessage}", true);
secItem = null;
}
}
@@ -270,9 +268,8 @@ namespace Sarand.Net.Standard.Dbas.Security
}
private SaSecurityProfile GetSecurityProfile(SaSecurityItem secItem)
{
String fn = GetType().Name + ".PopulateSecurityProfile";
if (secItem == null || !SysId.IsValid(secItem.Id)) return null;
if (LogSecurityProfile) SaLogger.Info(fn + " Populating security profile for user " + secItem.Code + " '" + secItem.Description + "'");
if (LogSecurityProfile) SaLogger.Info($"{SysUtil.Fn}Populating security profile for user {secItem.Code} '{secItem.Description}'");
// Retrieve Group links associated with the Item.
SaSecurityLink.Params prmSecLinkGroups = new SaSecurityLink.Params();
@@ -301,10 +298,10 @@ namespace Sarand.Net.Standard.Dbas.Security
SaSecurityItem secGroup = secItems.Find(item => item.Id.Equals(secGroupLink.ItemIdTarget) && item.ItemType == SaSecurity.ItemType.Group);
if (secGroup == null)
{
SaLogger.Warn(fn + " Failed to retrieve security group. Id: " + SysId.ToString(secGroupLink.ItemIdTarget));
SaLogger.Warn($"{SysUtil.Fn}Failed to retrieve security group. Id: {SysId.ToString(secGroupLink.ItemIdTarget)}.");
continue;
}
if (LogSecurityProfile) SaLogger.Info(fn + " Adding group to profile: " + secGroup.Code + " '" + secGroup.Description + "'");
if (LogSecurityProfile) SaLogger.Info($"{SysUtil.Fn}Adding group to profile: {secGroup.Code} '{secGroup.Description}'");
// Retrieve rights for group.
List<SaSecurityProfile.RightData> profileGroupRights = new List<SaSecurityProfile.RightData>();
@@ -314,17 +311,17 @@ namespace Sarand.Net.Standard.Dbas.Security
SaSecurityItem secRight = secItems.Find(item => item.Id.Equals(secRightLink.ItemIdTarget) && item.ItemType == SaSecurity.ItemType.Right);
if (secRight == null)
{
SaLogger.Warn(fn + " Failed to retrieve security group right. Id: " + SysId.ToString(secRightLink.ItemIdTarget));
SaLogger.Warn($"{SysUtil.Fn}Failed to retrieve security group right. Id: {SysId.ToString(secRightLink.ItemIdTarget)}.");
continue;
}
bool rightGranted = (secRightLink.Status == SaStatus.Granted);
if (LogSecurityProfile) SaLogger.Info(fn + " Adding group right to profile: " + secRight.Code + " '" + secRight.Description + "' [" + (rightGranted ? "Granted" : "Denied") + "]");
if (LogSecurityProfile) SaLogger.Info($"{SysUtil.Fn}Adding group right to profile: {secRight.Code} '{secRight.Description}' [" + (rightGranted ? "Granted" : "Denied") + "]");
try
{
SaSecurityProfile.RightData rightData = new SaSecurityProfile.RightData(secRight, secRightLink);
profileGroupRights.Add(rightData);
}
catch (Exception exc) { SaLogger.Warn(fn + " " + exc.Message); }
catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {exc.Message}"); }
}
try
@@ -332,7 +329,7 @@ namespace Sarand.Net.Standard.Dbas.Security
SaSecurityProfile.GroupData groupData = new SaSecurityProfile.GroupData(secGroup, profileGroupRights);
profileGroups.Add(groupData);
}
catch (Exception exc) { SaLogger.Warn(fn + " " + exc.Message); }
catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {exc.Message}"); }
}
// Add the Rights to the profile.
@@ -343,17 +340,17 @@ namespace Sarand.Net.Standard.Dbas.Security
SaSecurityItem secRight = secItems.Find(item => item.Id.Equals(secRightLink.ItemIdTarget) && item.ItemType == SaSecurity.ItemType.Right);
if (secRight == null)
{
SaLogger.Warn(fn + " Failed to retrieve security right. Id: " + SysId.ToString(secRightLink.ItemIdTarget));
SaLogger.Warn($"{SysUtil.Fn}Failed to retrieve security right. Id: {SysId.ToString(secRightLink.ItemIdTarget)}.");
continue;
}
bool rightGranted = (secRightLink.Status == SaStatus.Granted);
if (LogSecurityProfile) SaLogger.Info(fn + " Adding right to profile: " + secRight.Code + " '" + secRight.Description + "' [" + (rightGranted ? "Granted" : "Denied") + "]");
if (LogSecurityProfile) SaLogger.Info($"{SysUtil.Fn}Adding right to profile: {secRight.Code} '{secRight.Description}' [" + (rightGranted ? "Granted" : "Denied") + "]");
try
{
SaSecurityProfile.RightData rightData = new SaSecurityProfile.RightData(secRight, secRightLink);
profileRights.Add(rightData);
}
catch (Exception exc) { SaLogger.Warn(fn + " " + exc.Message); }
catch (Exception exc) { SaLogger.Warn($"{SysUtil.Fn} {exc.Message}"); }
}
// Create security profile.
@@ -14,7 +14,7 @@ namespace Sarand.Net.Standard.Dbas.Security
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand Security Module database definition generator";
private static string className = nameof(SaSecurityDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
@@ -22,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.Security
/// </summary>
public static bool Generate(String connectionString)
{
String fn = nameof(SaSecurityDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -41,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.Security
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
@@ -84,31 +84,29 @@ namespace Sarand.Net.Standard.Dbas.Security
//-------------------------------------------------------------------
private static String GetOutputFolder()
{
String fn = nameof(SaSecurityDbDfnGenerator) + ".GetOutputFolder";
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: {directory}");
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\Security\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "Security";
SaLogger.Debug(fn + " Output folder: " + directory);
// Code files are generated to '..\Database\Generated\Security\' folder.
directory = Path.Combine(directory, "Database", "Generated", "Security");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -19,6 +19,21 @@ namespace Sarand.Net.Standard.Dbas.Security
//*******************************************************************
// S e c u r i t y I t e m
//*******************************************************************
//-------------------------------------------------------------------
// Utilities.
private List<StringPair> GetLogProperties(SaSecurityItem securityItem)
{
return new List<StringPair>()
{
new StringPair("Id",SysId.ToString(securityItem.Id)),
new StringPair("Code",securityItem.Code),
new StringPair("Description",securityItem.Description),
new StringPair("Status",securityItem.StatusCode)
};
}
//-------------------------------------------------------------------
// Associated data.
public override bool SecurityItemIsSourceOfLinks(SysId securityItemId)
{
@@ -85,7 +100,8 @@ namespace Sarand.Net.Standard.Dbas.Security
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetSecurityItem\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return securityItem;
@@ -158,7 +174,6 @@ namespace Sarand.Net.Standard.Dbas.Security
// Insert item.
public override bool InsertSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo)
{
String fn = GetType().Name + ".InsertSecurityItem";
ClearErrorState();
if (!IsValidSecurityItem(securityItem)) return false;
if (SysId.IsValid(securityItem.Id)) return SetErrorState(ErrorMessage.ValiditemId);
@@ -178,7 +193,7 @@ namespace Sarand.Net.Standard.Dbas.Security
dbSecurityItem.ExecuteInsertCommand(dbCommand);
securityItem.Id = new SysId(dbSecurityItem._Id);
securityItem.Changed = false;
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Inserted.\n\tId: " + SysId.ToString(securityItem.Id) + "\n\tCode: " + securityItem.Code + "\n\tDescription: " + securityItem.Description + "\n\tStatus: " + securityItem.StatusCode);
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn}Inserted. {GetLogProperties(securityItem).Concat(": ").Concat("", "\n\t")}");
}
catch (Exception exc) { SetErrorState(exc.Message); }
}
@@ -189,13 +204,12 @@ namespace Sarand.Net.Standard.Dbas.Security
// Update item.
public override bool UpdateSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo)
{
String fn = GetType().Name + ".UpdateSecurityItem";
ClearErrorState();
if (!IsValidSecurityItem(securityItem)) return false;
if (!SysId.IsValid(securityItem.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
if (!securityItem.Changed)
{
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Data not changed.\n\tId: " + SysId.ToString(securityItem.Id) + "\n\tCode: " + securityItem.Code + "\n\tDescription: " + securityItem.Description + "\n\tStatus: " + securityItem.StatusCode);
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn}Data not changed. {GetLogProperties(securityItem).Concat(": ").Concat("", "\n\t")}");
return true;
}
using (var dbConnection = Database.CreateConnection())
@@ -212,7 +226,7 @@ namespace Sarand.Net.Standard.Dbas.Security
PopulateTo(dbSecurityItem, securityItem, dbUpdateInfo);
dbSecurityItem.ExecuteUpdateCommand(dbCommand);
securityItem.Changed = false;
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Updated.\n\tId: " + SysId.ToString(securityItem.Id) + "\n\tCode: " + securityItem.Code + "\n\tDescription: " + securityItem.Description + "\n\tStatus: " + securityItem.StatusCode);
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn}Updated. {GetLogProperties(securityItem).Concat(": ").Concat("", "\n\t")}");
// Record updates.
updateLogMonitor.RecordUpdatedValues(securityItem);
updateLogMonitor.LogUpdates();
@@ -232,7 +246,6 @@ namespace Sarand.Net.Standard.Dbas.Security
}
public override bool DeleteSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo)
{
String fn = GetType().Name + ".DeleteSecurityItem";
ClearErrorState();
if (!SecurityItemCanBeDeleted(securityItem)) return false;
using (var dbConnection = Database.CreateConnection())
@@ -248,7 +261,7 @@ namespace Sarand.Net.Standard.Dbas.Security
dbCommand.CommandType = System.Data.CommandType.Text;
dbCommand.CommandText = "DELETE FROM " + TableName_SecItem + " WHERE Id=" + SysId.ToString(securityItem.Id) + ";";
dbCommand.ExecuteNonQuery();
if (SacsSystem.DebugMode) SaLogger.Debug(fn + " Deleted.\n\tId: " + SysId.ToString(securityItem.Id) + "\n\tCode: " + securityItem.Code + "\n\tDescription: " + securityItem.Description + "\n\tStatus: " + securityItem.StatusCode);
if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn}Deleted. {GetLogProperties(securityItem).Concat(": ").Concat("", "\n\t")}");
}
catch (Exception exc) { SetErrorState(exc.Message); }
}
@@ -512,6 +525,7 @@ namespace Sarand.Net.Standard.Dbas.Security
// Security Item list.
public override List<SaSecurityItem> GetSecurityItemList(SaSecurityItem.Params prm)
{
ClearErrorState();
List<SaSecurityItem> secItems = new List<SaSecurityItem>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_SecItem, aliasSecurityItem);
@@ -540,7 +554,8 @@ namespace Sarand.Net.Standard.Dbas.Security
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetSecurityItemList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return secItems;
@@ -57,7 +57,8 @@ namespace Sarand.Net.Standard.Dbas.Security
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetSecurityLink\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return securityLink;
@@ -400,6 +401,7 @@ namespace Sarand.Net.Standard.Dbas.Security
// Security Link list.
public override List<SaSecurityLink> GetSecurityLinkList (SaSecurityLink.Params prm)
{
ClearErrorState();
List<SaSecurityLink> secLinks = new List<SaSecurityLink>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_SecLink, aliasSecurityLink);
@@ -429,7 +431,8 @@ namespace Sarand.Net.Standard.Dbas.Security
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetSecurityLinkList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return secLinks;
@@ -14,16 +14,15 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
{
//-------------------------------------------------------------------
// Data members.
//private static string messageBoxTitle = "Sarand UpdateLog Module database definition generator";
//private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;";
private static string className = nameof(SaUpdateLogDbDfnGenerator);
//-------------------------------------------------------------------
/// <summary>
/// Generate database definitions.
/// </summary>
public static bool Generate (String connectionString)
public static bool Generate(String connectionString)
{
String fn = nameof(SaUpdateLogDbDfnGenerator) + ".Generate";
String fn = className + ".Generate";
// Locate output folder:
String directory = GetOutputFolder();
@@ -42,13 +41,13 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
}
catch (Exception exc)
{
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating database definition")}");
}
return false;
}
//-------------------------------------------------------------------
private static bool GenerateDatabaseDefinition (SacsDatabase database, String directory)
private static bool GenerateDatabaseDefinition(SacsDatabase database, String directory)
{
DatabaseDefinitionGenerator.Config config = new DatabaseDefinitionGenerator.Config()
{
@@ -74,33 +73,31 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
return generator.Generate(config);
}
//-------------------------------------------------------------------
private static String GetOutputFolder ()
private static String GetOutputFolder()
{
String fn = nameof(SaUpdateLogDbDfnGenerator) + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof (DatabaseDefinitionGenerator)).Location));
String fn = className + ".GetOutputFolder";
String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location));
String directory = assemblyDirectory;
SaLogger.Debug(fn + " Assembly folder: " + directory);
SaLogger.Debug($"{fn} Assembly folder: " + directory);
// Locate the parent of the 'Workspace' solution root folder.
String projectFolder = "Workspace";
while (!String.IsNullOrEmpty(directory))
{
if (FileUtil.IsDirectory(directory + Path.DirectorySeparatorChar + projectFolder))
{
if (FileUtil.IsDirectory(Path.Combine(directory, projectFolder)))
break;
}
directory = FileUtil.GetParentDirectory(directory);
}
if (String.IsNullOrEmpty(directory))
{
SaLogger.Error(fn + " Failed to find '" + projectFolder + "' solution root folder in assembly path:\n\t" + assemblyDirectory);
SaLogger.Error($"{fn} Failed to find '{projectFolder}' solution root folder in assembly path: {assemblyDirectory}");
return String.Empty;
}
// Code files are generated to '..\Dbas\Generated\UpdateLog\' folder.
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "UpdateLog";
SaLogger.Debug(fn + " Output folder: " + directory);
directory = Path.Combine(directory, "Database", "Generated", "UpdateLog");
SaLogger.Debug($"{fn} Output folder: {directory}");
if (!FileUtil.ValidateDirectory(directory, true))
{
SaLogger.Error(fn + " Output folder not found:\n\n" + directory);
SaLogger.Error($"{fn} Output folder not found: {directory}");
return String.Empty;
}
return directory;
@@ -99,7 +99,8 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetUpdateLog\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return logEntry;
@@ -215,7 +216,7 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
{
foreach (String query in updateLogQueries)
{
SaLogger.Debug(GetType().Name + ".LogUpdates Query: " + query);
SaLogger.Debug($"{SysUtil.Fn} Query: {query}");
Database.ExecuteNonQuery(query);
if (Database.HasErrorState())
SetErrorState("Failed to insert update log entries - " + Database.ErrorStateMessage);
@@ -224,7 +225,7 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
else
{
String query = updateLogQueries.Concat(";");
SaLogger.Debug(GetType().Name + ".LogUpdates Query: " + query);
SaLogger.Debug($"{SysUtil.Fn} Query: {query}");
Database.ExecuteNonQuery(query);
if (Database.HasErrorState())
SetErrorState("Failed to insert update log entries - " + Database.ErrorStateMessage);
@@ -560,6 +561,7 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
// Update Log Entry list.
public override List<SaUpdateLogEntry> GetLogEntryList (SaUpdateLogEntry.Params prm)
{
ClearErrorState();
List<SaUpdateLogEntry> logEntries = new List<SaUpdateLogEntry>();
DbQuery qry = new DbQuery(Database.DbmsType);
qry.Tables.Add(TableName_UpdateLog, aliasUpdateLog);
@@ -589,7 +591,8 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".GetLogEntryList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
SetErrorState("Database query exception");
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
}
}
return logEntries;
+1
View File
@@ -43,6 +43,7 @@ namespace Sarand.Net.Standard.Proc.Procs
//-------------------------------------------------------------------
// Properties.
protected DbUpdateInfo DbUpdateInfo { get { return config.DbUpdateInfo; } }
//-------------------------------------------------------------------
// Utilities.
+4 -4
View File
@@ -50,7 +50,7 @@ namespace Sarand.Net.Standard.Proc.Zip
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".OpenArchive " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}");
return SetErrorState(ExceptionUtil.GetErrorStateMessage(exc));
}
return !HasErrorState();
@@ -69,7 +69,7 @@ namespace Sarand.Net.Standard.Proc.Zip
}
catch (Exception exc)
{
SaLogger.Warn(GetType().Name + ".OpenArchive " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}");
return SetErrorState(ExceptionUtil.GetErrorStateMessage(exc));
}
return !HasErrorState();
@@ -89,7 +89,7 @@ namespace Sarand.Net.Standard.Proc.Zip
catch (Exception exc)
{
SetErrorState(ExceptionUtil.GetErrorStateMessage(exc));
SaLogger.Warn(GetType().Name + ".CloseArchive " + ExceptionUtil.GetLogMessage(exc));
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}");
}
zipArchive = null;
return !HasErrorState();
@@ -103,7 +103,7 @@ namespace Sarand.Net.Standard.Proc.Zip
if (!IsArchiveOpen()) return null;
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
//SaLogger.Debug(GetType().Name + ".GetFile Entry: " + entry.FullName);
//SaLogger.Debug($"{SysUtil.Fn} Entry: {entry.FullName}");
if (entry.FullName.EqualsCI(filename) || entry.Name.EqualsCI(filename))
{
using (Stream entryStream = entry.Open())