298 lines
9.3 KiB
C#
298 lines
9.3 KiB
C#
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.Net.Standard.Base.Interfaces
|
|
{
|
|
//=======================================================================
|
|
public class SaInterfaceProcess : SacsHierarchyItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Columns.
|
|
public enum Column
|
|
{
|
|
Pos = 0,
|
|
Id,
|
|
// Interface.
|
|
InterfaceId,
|
|
Interface_Context,
|
|
Interface_Category,
|
|
Interface_Category_Desc,
|
|
Interface_Type,
|
|
Interface_Type_Desc,
|
|
Interface_Code,
|
|
Interface_Caption,
|
|
// Interface process.
|
|
ProcessDirection,
|
|
ProcessDirection_Desc,
|
|
ProcessReference,
|
|
ProcessSequence,
|
|
ProcessAt,
|
|
ProcessAt_Date,
|
|
ProcessAt_Time,
|
|
BatchAt,
|
|
BatchAt_Date,
|
|
BatchAt_Time,
|
|
Elapsed_Secs,
|
|
Elapsed_Fmt,
|
|
// Derived properties.
|
|
Message_Count,
|
|
Message_Status_Desc,
|
|
Message_Status_Ind,
|
|
DataItem_Count,
|
|
// Common properties.
|
|
Notes,
|
|
Status,
|
|
Status_Desc,
|
|
Status_Ind,
|
|
CreateOn_Date,
|
|
UpdateOn_Date,
|
|
UpdateHost,
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Properties other than common.</summary>
|
|
public class DataProperties
|
|
{
|
|
public SysId InterfaceId { get; set; } = null;
|
|
public SaInterfaceProcessDirection Direction { get; set; } = SaInterfaceProcessDirection.Unknown;
|
|
public String Reference { get; set; } = String.Empty;
|
|
public int Sequence { get; set; } = 0;
|
|
public DateTime? ProcessAt { get; set; } = DateTime.MinValue;
|
|
public DateTime? BatchAt { get; set; } = DateTime.MinValue;
|
|
public int ElapseSecs { get; set; } = 0;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data.
|
|
public new class Data : SacsHierarchyItem.Data
|
|
{
|
|
// Data members.
|
|
private readonly DataProperties data = new DataProperties();
|
|
// Construction.
|
|
public Data()
|
|
{
|
|
Status = DefaultStatus;
|
|
}
|
|
// Properties.
|
|
public SysId InterfaceId
|
|
{
|
|
get { return data.InterfaceId; }
|
|
set { CheckChanged(data.InterfaceId, value); data.InterfaceId = value; }
|
|
}
|
|
public SaInterfaceProcessDirection Direction
|
|
{
|
|
get { return data.Direction; }
|
|
set { CheckChanged((int)data.Direction, (int)value); data.Direction = value; }
|
|
}
|
|
public String Reference
|
|
{
|
|
get { return data.Reference; }
|
|
set { CheckChanged(data.Reference, value); data.Reference = value; }
|
|
}
|
|
public int Sequence
|
|
{
|
|
get { return data.Sequence; }
|
|
set { CheckChanged(data.Sequence, value); data.Sequence = value; }
|
|
}
|
|
public DateTime? ProcessAt
|
|
{
|
|
get { return data.ProcessAt; }
|
|
set { CheckChangedNullable(data.ProcessAt, value); data.ProcessAt = value; }
|
|
}
|
|
public DateTime? BatchAt
|
|
{
|
|
get { return data.BatchAt; }
|
|
set { CheckChangedNullable(data.BatchAt, value); data.BatchAt = value; }
|
|
}
|
|
public int ElapseSecs
|
|
{
|
|
get { return data.ElapseSecs; }
|
|
set { CheckChanged(data.ElapseSecs, value); data.ElapseSecs = value; }
|
|
}
|
|
// Population.
|
|
internal void PopulateFrom(Data data)
|
|
{
|
|
InterfaceId = data.InterfaceId;
|
|
Direction = data.Direction;
|
|
Reference = data.Reference;
|
|
Sequence = data.Sequence;
|
|
ProcessAt = data.ProcessAt;
|
|
BatchAt = data.BatchAt;
|
|
ElapseSecs = data.ElapseSecs;
|
|
base.PopulateFrom(data);
|
|
}
|
|
public Data Clone()
|
|
{
|
|
Data data = new Data();
|
|
data.PopulateFrom(this);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Error field - identify properties with validation error.
|
|
public new class ErrField : SacsHierarchyItem.ErrField
|
|
{
|
|
// Identifies the field that has invalid data.
|
|
public ValidValue InterfaceId { get; set; } = ValidValue.Valid;
|
|
public ValidValue Direction { get; set; } = ValidValue.Valid;
|
|
public ValidValue Reference { get; set; } = ValidValue.Valid;
|
|
public ValidValue Sequence { get; set; } = ValidValue.Valid;
|
|
public ValidValue ProcessedAt { get; set; } = ValidValue.Valid;
|
|
public ValidValue BatchAt { get; set; } = ValidValue.Valid;
|
|
public ValidValue ElapseSecs { get; set; } = ValidValue.Valid;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly Data data = new Data();
|
|
// Flags.
|
|
public static readonly Byte Flag_ = 0x01;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaInterfaceProcess(SysId id, SysId interfaceId, SaInterfaceProcessDirection direction, String reference, int sequence) :
|
|
base(id)
|
|
{
|
|
base.SetData(data);
|
|
InterfaceId = interfaceId;
|
|
Direction = direction;
|
|
Reference = reference;
|
|
Sequence = sequence;
|
|
Status = DefaultStatus;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Statuses.
|
|
private static readonly List<SaStatus> validStatuses = new List<SaStatus>()
|
|
{
|
|
SaStatus.Awaiting,
|
|
SaStatus.InProgress,
|
|
SaStatus.Completed,
|
|
SaStatus.Cancelled
|
|
};
|
|
public static SaStatus DefaultStatus { get { return AwaitingStatus; } }
|
|
public static SaStatus AwaitingStatus { get { return SaStatus.Awaiting; } }
|
|
public static SaStatus InProgressStatus { get { return SaStatus.InProgress; } }
|
|
public static SaStatus CompletedStatus { get { return SaStatus.Completed; } }
|
|
public static SaStatus CancelledStatus { get { return SaStatus.Cancelled; } }
|
|
public static List<SaStatus> ValidStatuses { get { return new List<SaStatus>(validStatuses); } }
|
|
public static DataValue.TriStateType GetStatusTriState(SaStatus status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case SaStatus.Awaiting:
|
|
return Core.DataValue.TriStateType.Amber;
|
|
case SaStatus.InProgress:
|
|
return Core.DataValue.TriStateType.Blue;
|
|
case SaStatus.Completed:
|
|
return Core.DataValue.TriStateType.Green;
|
|
case SaStatus.Cancelled:
|
|
return Core.DataValue.TriStateType.Red;
|
|
case SaStatus.Deleted:
|
|
return Core.DataValue.TriStateType.Purple;
|
|
}
|
|
return Core.DataValue.TriStateType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public Data GetData() { return data.Clone(); }
|
|
public void SetData(Data data)
|
|
{
|
|
// Properties that cannot be changed if previously specified.
|
|
if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Id cannot be changed");
|
|
if (SysId.IsValid(InterfaceId) && SysId.ToInt(InterfaceId) != SysId.ToInt(data.InterfaceId))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Interface cannot be changed");
|
|
if ((int)Direction > 0 && (int)Direction != (int)data.Direction)
|
|
throw new NotSupportedException($"{SysUtil.Fn} Direction cannot be changed");
|
|
if (!StringUtil.IsEmpty(Reference) && !Reference.Equals(data.Reference))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Reference cannot be changed");
|
|
if (Sequence > 0 && Sequence != data.Sequence)
|
|
throw new NotSupportedException($"{SysUtil.Fn} Sequence cannot be changed");
|
|
// Populate individual properties to ensure that 'Changed' indicator is kept up to date.
|
|
this.data.PopulateFrom(data);
|
|
}
|
|
public SysId InterfaceId
|
|
{
|
|
get { return data.InterfaceId; }
|
|
protected set { data.InterfaceId = value; }
|
|
}
|
|
public SaInterfaceProcessDirection Direction
|
|
{
|
|
get { return data.Direction; }
|
|
protected set { data.Direction = value; }
|
|
}
|
|
public String Reference
|
|
{
|
|
get { return data.Reference; }
|
|
protected set { data.Reference = value; }
|
|
}
|
|
public int Sequence
|
|
{
|
|
get { return data.Sequence; }
|
|
protected set { data.Sequence = value; }
|
|
}
|
|
public DateTime? ProcessAt
|
|
{
|
|
get { return data.ProcessAt; }
|
|
set { data.ProcessAt = value; }
|
|
}
|
|
public DateTime? BatchAt
|
|
{
|
|
get { return data.BatchAt; }
|
|
set { data.BatchAt = value; }
|
|
}
|
|
public int ElapseSecs
|
|
{
|
|
get { return data.ElapseSecs; }
|
|
set { data.ElapseSecs = value; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Flags.
|
|
|
|
//-------------------------------------------------------------------
|
|
// List parameters.
|
|
public enum StatusCat
|
|
{
|
|
Any,
|
|
AwaitingOnly,
|
|
InProgressOnly,
|
|
CompletedOnly,
|
|
}
|
|
/// <summary>
|
|
/// Item list parameters.
|
|
/// </summary>
|
|
public new class Params : SacsHierarchyItem.Params
|
|
{
|
|
public HashSet<SysId> IdsIncluded { get; } = new HashSet<SysId>();
|
|
public HashSet<SysId> IdsExcluded { get; } = new HashSet<SysId>();
|
|
public SysId InterfaceId { get; set; }
|
|
public SaInterfaceProcessDirection Direction { get; set; } = SaInterfaceProcessDirection.Unknown;
|
|
public String Reference { get; set; }
|
|
public String ReferencePartial { get; set; }
|
|
public DateTime ProcessedOn { get; set; } = DateTime.MinValue;
|
|
public DateTime ProcessedFrom { get; set; } = DateTime.MinValue;
|
|
public DateTime ProcessedTo { get; set; } = DateTime.MinValue;
|
|
public String MessageText { get; set; }
|
|
public String MessageTextPartial { get; set; }
|
|
public StatusCat StatusCat { get; set; } = StatusCat.Any;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// L i s t
|
|
//-------------------------------------------------------------------
|
|
public class List : List<SaInterfaceProcess>
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|