Core item disposability
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SacsDisposableStateItem : SacsStateItem, ISacsDisposable
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private bool disposed = false;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SacsDisposableStateItem()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Disposal.
|
||||
~SacsDisposableStateItem()
|
||||
{
|
||||
Dispose(!disposed);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
Dispose(true);
|
||||
disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
public bool Disposed { get { return disposed; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
public class SacsHierarchyItem : SaErrorStateItem
|
||||
public class SacsHierarchyItem : SacsStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
@@ -333,15 +333,6 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
data.Id = id;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Disposal.
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
/// <summary>By default, all hierarchy itrems have an Id.<br/>Override and return false where this is not the case.</summary>
|
||||
|
||||
@@ -9,7 +9,7 @@ using Sarand.Net.Standard.Base.Utils;
|
||||
namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SacsItemMgr : SaErrorStateItem
|
||||
public abstract class SacsItemMgr : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
+8
-10
@@ -5,7 +5,10 @@ using Sarand.Net.Standard.Base.Utils;
|
||||
namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaErrorStateItem : SacsDisposable, ISacsStateItem
|
||||
/// <summary>
|
||||
/// State Item - allows business component to record and report error message.
|
||||
/// </summary>
|
||||
public abstract class SacsStateItem : ISacsStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
@@ -32,21 +35,15 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Static initialisation.
|
||||
static SaErrorStateItem()
|
||||
static SacsStateItem()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SaErrorStateItem()
|
||||
protected SacsStateItem()
|
||||
{
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
@@ -79,7 +76,8 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
/// </summary>
|
||||
public bool SetErrorState(String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(message)) return true;
|
||||
if (StringUtil.IsBlank(message))
|
||||
return false;
|
||||
this.errorState = new SacsErrorState(message);
|
||||
return false;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace Sarand.Net.Standard.Base.CodeTypes
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaCodeTypeConsole : SaErrorStateItem
|
||||
public abstract class SaCodeTypeConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Core
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>State Item interface.</summary>
|
||||
public interface ISacsStateItem
|
||||
{
|
||||
bool HasErrorState();
|
||||
SacsErrorState ErrorState { get; }
|
||||
String ErrorStateMessage { get; }
|
||||
bool SetErrorState(String message);
|
||||
void ClearErrorState();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -3,7 +3,18 @@
|
||||
namespace Sarand.Net.Standard.Base.Core
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SacsDisposable : IDisposable
|
||||
/// <summary>
|
||||
/// Disposable class.
|
||||
/// <br/>- Override 'protecetd void Dispose(bool disposing)' to dispose resources when flag is true.
|
||||
/// </summary>
|
||||
public interface ISacsDisposable : IDisposable
|
||||
{
|
||||
/// <summary>Returns flag to indicate whether object has been disposed.</summary>
|
||||
bool Disposed { get; }
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
public abstract class SacsDisposable : ISacsDisposable
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
@@ -11,24 +22,24 @@ namespace Sarand.Net.Standard.Base.Core
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
protected SacsDisposable ()
|
||||
protected SacsDisposable()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Disposal.
|
||||
~SacsDisposable ()
|
||||
~SacsDisposable()
|
||||
{
|
||||
Dispose(!disposed);
|
||||
}
|
||||
public void Dispose ()
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
Dispose(true);
|
||||
disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
protected abstract void Dispose (bool disposing);
|
||||
protected abstract void Dispose(bool disposing);
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Core
|
||||
{
|
||||
//=======================================================================
|
||||
/// <summary>State Item interface.</summary>
|
||||
public interface ISacsStateItem
|
||||
{
|
||||
bool HasErrorState();
|
||||
SacsErrorState ErrorState { get; }
|
||||
String ErrorStateMessage { get; }
|
||||
bool SetErrorState(String message);
|
||||
void ClearErrorState();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
/// <summary>
|
||||
/// State Item - allows business component to record and report error message.
|
||||
/// </summary>
|
||||
public class SacsStateItem : ISacsStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data items.
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction - use derived classes.
|
||||
protected SacsStateItem() { }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Poperties.
|
||||
|
||||
/// <summary>OK - No error state message.</summary>
|
||||
public bool OK { get { return !HasErrorState(); } }
|
||||
|
||||
// Error state.
|
||||
public SacsErrorState ErrorState { get; private set; }
|
||||
public bool HasErrorState()
|
||||
{
|
||||
return ErrorState != null;
|
||||
}
|
||||
public String ErrorStateMessage
|
||||
{
|
||||
get { return (ErrorState != null ? ErrorState.Message : String.Empty); }
|
||||
}
|
||||
// Update properties.
|
||||
public virtual bool SetErrorState(String message)
|
||||
{
|
||||
if (StringUtil.IsEmpty(StringUtil.EmptyOnNull(message).Trim()))
|
||||
throw new NotSupportedException($"{SysUtil.Fn} Blank error message.");
|
||||
this.ErrorState = new SacsErrorState(message);
|
||||
return false;
|
||||
}
|
||||
public void ClearErrorState()
|
||||
{
|
||||
ErrorState = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Sarand.Net.Standard.Base.App;
|
||||
namespace Sarand.Net.Standard.Base.Dbas
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class DbResultSet : SaErrorStateItem, IDbResultSet
|
||||
public abstract class DbResultSet : SacsDisposableStateItem, IDbResultSet
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
|
||||
@@ -4,7 +4,7 @@ using Sarand.Net.Standard.Base.Core;
|
||||
namespace Sarand.Net.Standard.Base.Dbas
|
||||
{
|
||||
//=======================================================================
|
||||
interface IDbResultSet : IDisposable
|
||||
interface IDbResultSet : ISacsDisposable
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Navigation.
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Text;
|
||||
namespace Sarand.Net.Standard.Base.Diary
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaDiaryConsole : SaErrorStateItem
|
||||
public abstract class SaDiaryConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Collections.Generic;
|
||||
namespace Sarand.Net.Standard.Base.Interfaces
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaInterfaceConsole : SaErrorStateItem
|
||||
public abstract class SaInterfaceConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Interface definition.
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Text;
|
||||
namespace Sarand.Net.Standard.Base.ItemData
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaItemDataConsole : SaErrorStateItem
|
||||
public abstract class SaItemDataConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Text;
|
||||
namespace Sarand.Net.Standard.Base.ItemDocs
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaItemDocConsole : SaErrorStateItem
|
||||
public abstract class SaItemDocConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -9,7 +9,7 @@ using Sarand.Net.Standard.Base.UpdateLog;
|
||||
namespace Sarand.Net.Standard.Base.ItemOptions
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaItemOptionConsole : SaErrorStateItem
|
||||
public abstract class SaItemOptionConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -5,7 +5,7 @@ using Sarand.Net.Standard.Base.Bus;
|
||||
namespace Sarand.Net.Standard.Base.Procs
|
||||
{
|
||||
//=======================================================================
|
||||
public abstract class SaReport_Base : SaErrorStateItem
|
||||
public abstract class SaReport_Base : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Sarand.Net.Standard.Base.ReferenceData
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
public abstract partial class SaReferenceDataConsole : SaErrorStateItem
|
||||
public abstract partial class SaReferenceDataConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Sarand.Net.Standard.Base.Security
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
public abstract class SaSecurityConsole : SaErrorStateItem
|
||||
public abstract class SaSecurityConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Sarand.Net.Standard.Base.UpdateLog
|
||||
// Definitions.
|
||||
|
||||
//=======================================================================
|
||||
public abstract class SaUpdateLogConsole : SaErrorStateItem
|
||||
public abstract class SaUpdateLogConsole : SacsDisposableStateItem
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Definitions.
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CsvHelper" Version="19.0.0" />
|
||||
<PackageReference Include="MailKit" Version="4.11.0" />
|
||||
<PackageReference Include="MailKit" Version="4.13.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.3.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
|
||||
<PackageReference Include="ZstdNet" Version="1.4.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user