313 lines
9.8 KiB
C#
313 lines
9.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static GenesisCordonelInterface.API.InterfaceOutsideToGCI;
|
|
using static Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.GenesisMeter;
|
|
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
|
|
|
namespace GenesisCordonelInterface.API
|
|
{
|
|
/// <summary>
|
|
/// Public data contract layer for the Genesis Cordonel Interface (GCI).
|
|
///
|
|
/// This class defines all Data Transfer Objects (DTOs) that are exposed
|
|
/// to external consumers (e.g. TBF, UI, or other integration layers).
|
|
///
|
|
/// Responsibilities:
|
|
/// - Provide stable, dependency-free models for external usage
|
|
/// - Decouple internal GCI implementation (GenesisMeter, Xylem libraries)
|
|
/// from external systems
|
|
/// - Define request/response contracts for all supported operations
|
|
/// - Contain mapping methods between public DTOs and internal domain models
|
|
///
|
|
/// Architecture:
|
|
/// External world (TBF / UI)
|
|
/// ↓
|
|
/// GciPublicModels (this layer)
|
|
/// ↓
|
|
/// Internal GCI API (InterfaceGCIToLaatzen, GenesisMeter, etc.)
|
|
///
|
|
/// Notes:
|
|
/// - Public models must NOT expose internal types (e.g. GenesisMeter, IPort, etc.)
|
|
/// - All mapping between internal and external representations must be done here
|
|
/// - DTOs are designed to be simple, serializable, and stable over time
|
|
/// - Any change in internal implementation should not affect these models
|
|
///
|
|
/// Pattern:
|
|
/// Each operation follows a consistent structure:
|
|
/// Request → Operation → Result
|
|
///
|
|
/// Example:
|
|
/// GciInitSlotRequest → InitSlot → GciInitSlotResult
|
|
/// GetSlot → GciSlotInfo
|
|
/// GetPcbId → GciGetPcbIdResult
|
|
///
|
|
/// This layer acts as a boundary between domain logic and integration logic.
|
|
/// </summary>
|
|
public class GciPublicModels
|
|
{
|
|
/// <summary>
|
|
/// Public DTOs exposed to external systems.
|
|
/// These models represent the contract of the GCI API.
|
|
/// They must remain stable and independent of internal implementation.
|
|
/// </summary>
|
|
#region ================================== PUBLIC MODELS ===========================================
|
|
|
|
public class GciSlotInfo
|
|
{
|
|
public int SlotId { get; set; }
|
|
|
|
public bool Exists { get; set; }
|
|
public bool Success { get; set; }
|
|
public string Message { get; set; }
|
|
public string PcbId { get; set; }
|
|
|
|
public GciConfigSource ConfigSource { get; set; }
|
|
public GciPasswordSource PasswordSource { get; set; }
|
|
|
|
public GciPortConfig RequestPort { get; set; }
|
|
public GciPortConfig StreamingPort { get; set; }
|
|
}
|
|
|
|
public class Result
|
|
{
|
|
public int SlotId { get; set; }
|
|
public bool Success { get; set; }
|
|
public string Message { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"SlotId={0}, Success={1}, Message={2}",
|
|
SlotId,
|
|
Success,
|
|
Message);
|
|
}
|
|
}
|
|
|
|
public enum GciPasswordSource
|
|
{
|
|
RestApi = 0,
|
|
OfflineFile = 1,
|
|
InterfaceInputPassword = 2,
|
|
}
|
|
public enum GciConfigSource
|
|
{
|
|
FileConfig = 0,
|
|
InterfaceInputConfig = 1,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Collection of port settings
|
|
/// </summary>
|
|
public class GciPortConfig
|
|
{
|
|
public string PortName { get; set; }
|
|
public string Type { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("PortName={0}, Type={1}", PortName, Type);
|
|
}
|
|
}
|
|
|
|
public class GciInitSlotRequest
|
|
{
|
|
public int SlotId { get; set; }
|
|
public GciConfigSource ConfigSource { get; set; }
|
|
public GciPasswordSource PasswordSource { get; set; }
|
|
public GciPortConfig RequestPort { get; set; }
|
|
public GciPortConfig StreamingPort { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"SlotId={0}, GciConfigSource={1}, PasswordSource={2}, RequestPort={3}, StreamingPort={4}",
|
|
SlotId,
|
|
ConfigSource,
|
|
PasswordSource,
|
|
RequestPort,
|
|
StreamingPort);
|
|
}
|
|
}
|
|
|
|
public class GciInitSlotResult
|
|
{
|
|
public int SlotId { get; set; }
|
|
|
|
public bool Success { get; set; }
|
|
|
|
public string Message { get; set; }
|
|
|
|
public string PcbId { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"SlotId={0}, Success={1}, Message={2}, PcbId={3}",
|
|
SlotId,
|
|
Success,
|
|
Message,
|
|
PcbId);
|
|
}
|
|
}
|
|
|
|
public class GciCleanSlotsResult
|
|
{
|
|
public bool Success { get; set; }
|
|
public string Message { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"Success={0}, Message={1}",
|
|
Success,
|
|
Message);
|
|
}
|
|
}
|
|
|
|
public class GciGetPcbIdResult
|
|
{
|
|
public int SlotId { get; set; }
|
|
|
|
public bool Success { get; set; }
|
|
|
|
public string PcbId { get; set; }
|
|
|
|
public string Message { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"SlotId={0}, Success={1}, PcbId={2}, Message={3}",
|
|
SlotId,
|
|
Success,
|
|
PcbId,
|
|
Message);
|
|
}
|
|
}
|
|
public class GciConnectResult
|
|
{
|
|
public int SlotId { get; set; }
|
|
public bool Success { get; set; }
|
|
public string PcbId { get; set; }
|
|
public bool IsLoggedOn { get; set; }
|
|
public string FwVersion { get; set; }
|
|
public string InterfaceVersion { get; set; }
|
|
public bool InterfaceSupportsFwVersion { get; set; }
|
|
public List<GciRegisterSnapshot> Registers { get; set; } = new List<GciRegisterSnapshot>();
|
|
public string Message { get; set; }
|
|
}
|
|
|
|
public class GciRegisterSnapshot
|
|
{
|
|
public string Name { get; set; }
|
|
public string Type { get; set; }
|
|
public string RawValue { get; set; }
|
|
public string Min { get; set; }
|
|
public string Max { get; set; }
|
|
public string Description { get; set; }
|
|
public string Version { get; set; }
|
|
public string IsAvailable { get; set; }
|
|
public string Privilege { get; set; }
|
|
}
|
|
|
|
public class GciDisconnectResult
|
|
{
|
|
public int SlotId { get; set; }
|
|
public bool Success { get; set; }
|
|
public string Message { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format(
|
|
"SlotId={0}, Success={1}, Message={2}",
|
|
SlotId,
|
|
Success,
|
|
Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Mapping methods between public DTOs and internal GCI models.
|
|
/// Ensures separation between external contracts and internal domain objects.
|
|
/// </summary>
|
|
#region ================================== OUTERN/INTERN and back models mapping ==================================
|
|
public static PasswordSource MapPasswordSource(GciPasswordSource src)
|
|
{
|
|
return (PasswordSource)src;
|
|
}
|
|
|
|
public static ConfigSource MapConfigSource(GciConfigSource src)
|
|
{
|
|
return (ConfigSource)src;
|
|
}
|
|
|
|
public static Xylem.Common.Hardware.Interfaces.Ports.PortCore.PortConfig? MapPort(GciPortConfig port)
|
|
{
|
|
if (port == null)
|
|
return null;
|
|
|
|
Xylem.Common.Hardware.Interfaces.Ports.PortCore.PortConfig result = new Xylem.Common.Hardware.Interfaces.Ports.PortCore.PortConfig();
|
|
|
|
result.PortName = port.PortName;
|
|
result.Type = port.Type;
|
|
|
|
return result;
|
|
}
|
|
|
|
public static GciInitSlotResult MapInitResult(GciInitSlotResult result)
|
|
{
|
|
if (result == null)
|
|
return null;
|
|
|
|
return new GciInitSlotResult
|
|
{
|
|
SlotId = result.SlotId,
|
|
Success = result.Success,
|
|
Message = result.Message
|
|
};
|
|
}
|
|
|
|
public static GciPasswordSource MapPasswordSourceBack(PasswordSource src)
|
|
{
|
|
return (GciPasswordSource)src;
|
|
}
|
|
|
|
public static GciConfigSource MapConfigSourceBack(ConfigSource src)
|
|
{
|
|
return (GciConfigSource)src;
|
|
}
|
|
|
|
public static GciPortConfig MapPortBack(PortConfig? port)
|
|
{
|
|
if (!port.HasValue)
|
|
return null;
|
|
|
|
PortConfig value = port.Value;
|
|
|
|
return new GciPortConfig
|
|
{
|
|
PortName = value.PortName,
|
|
Type = value.Type
|
|
};
|
|
}
|
|
|
|
public static GciPortConfig MapPortBack(IPort port)
|
|
{
|
|
if (port == null)
|
|
return null;
|
|
|
|
return new GciPortConfig
|
|
{
|
|
PortName = port.GetPortName(),
|
|
Type = port.GetType().Name
|
|
};
|
|
}
|
|
#endregion
|
|
}
|
|
}
|