Saxonite 1.2.11.5, BusinessMgr.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
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? GetFieldDecimalNullable(DbDataReader dbDataReader, String name, Decimal? defaultValue);
|
||||
DateTime GetFieldDateTime (DbDataReader dbDataReader, String name, DateTime defaultValue);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -90,31 +90,61 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
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 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 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 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 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 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) { }
|
||||
@@ -125,16 +155,31 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
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 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 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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// D b D a t a I t e m
|
||||
@@ -258,6 +303,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Retrieve field values.
|
||||
|
||||
public String GetFieldString(DbDataReader dbDataReader, String columnName, String defaultValue)
|
||||
{
|
||||
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
|
||||
@@ -273,7 +319,13 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
return 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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,6 +527,7 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public byte[] GetFieldByteArray(DbDataReader dbDataReader, String columnName, byte[] defaultValue)
|
||||
{
|
||||
int columnIdx = GetColumnOrdinal(dbDataReader, columnName);
|
||||
@@ -454,20 +555,20 @@ namespace Sarand.Net.Standard.Dbas.Data
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -71,7 +71,8 @@ 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;
|
||||
@@ -508,6 +509,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
|
||||
// Item list.
|
||||
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;
|
||||
|
||||
@@ -72,7 +72,8 @@ 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;
|
||||
@@ -394,6 +395,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
|
||||
// Interface ProcessMessage list.
|
||||
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;
|
||||
|
||||
@@ -93,7 +93,8 @@ 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;
|
||||
@@ -632,6 +633,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces
|
||||
// Interface Process list.
|
||||
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;
|
||||
|
||||
@@ -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,8 +14,7 @@ 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>
|
||||
@@ -23,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
|
||||
/// </summary>
|
||||
public static bool Generate(String connectionString)
|
||||
{
|
||||
String fn = nameof(SaItemDataDbDfnGenerator) + ".Generate";
|
||||
String fn = className + ".Generate";
|
||||
|
||||
// Locate output folder:
|
||||
String directory = GetOutputFolder();
|
||||
@@ -42,7 +41,7 @@ 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;
|
||||
}
|
||||
@@ -77,31 +76,29 @@ namespace Sarand.Net.Standard.Dbas.ItemData
|
||||
//-------------------------------------------------------------------
|
||||
private static String GetOutputFolder()
|
||||
{
|
||||
String fn = nameof(SaItemDataDbDfnGenerator) + ".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\ItemData\' folder.
|
||||
directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "ItemData";
|
||||
// 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;
|
||||
|
||||
@@ -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;
|
||||
@@ -497,6 +498,7 @@ namespace Sarand.Net.Standard.Dbas.ItemData
|
||||
// Item Data list.
|
||||
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;
|
||||
|
||||
@@ -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,8 +18,7 @@ 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>
|
||||
@@ -27,7 +26,7 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
|
||||
/// </summary>
|
||||
public static bool Generate(String connectionString)
|
||||
{
|
||||
String fn = nameof(SaItemDocsDbDfnGenerator) + ".Generate";
|
||||
String fn = className + ".Generate";
|
||||
|
||||
// Locate output folder:
|
||||
String directory = GetOutputFolder();
|
||||
@@ -46,7 +45,7 @@ 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;
|
||||
}
|
||||
@@ -84,31 +83,29 @@ namespace Sarand.Net.Standard.Dbas.ItemDocs
|
||||
//-------------------------------------------------------------------
|
||||
private static String GetOutputFolder()
|
||||
{
|
||||
String fn = nameof(SaItemDocsDbDfnGenerator) + ".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\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,8 +14,7 @@ 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>
|
||||
@@ -23,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
|
||||
/// </summary>
|
||||
public static bool Generate(String connectionString)
|
||||
{
|
||||
String fn = nameof(SaUpdateLogDbDfnGenerator) + ".Generate";
|
||||
String fn = className + ".Generate";
|
||||
|
||||
// Locate output folder:
|
||||
String directory = GetOutputFolder();
|
||||
@@ -42,7 +41,7 @@ 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;
|
||||
}
|
||||
@@ -76,31 +75,29 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog
|
||||
//-------------------------------------------------------------------
|
||||
private static String GetOutputFolder()
|
||||
{
|
||||
String fn = nameof(SaUpdateLogDbDfnGenerator) + ".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\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;
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace Sarand.Net.Standard.Proc.Procs
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
protected DbUpdateInfo DbUpdateInfo { get { return config.DbUpdateInfo; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Utilities.
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user