188 lines
5.1 KiB
C#
188 lines
5.1 KiB
C#
using Icoel.Soap.SizerService;
|
|
using System;
|
|
using System.Runtime.Serialization;
|
|
using System.ServiceModel;
|
|
|
|
namespace Icoel.Soap.Compac
|
|
{
|
|
public class ComClient
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Oggetto client comunicazione con sizer ICOEL per invio/recupero informazioni di
|
|
/// produzione (batch)
|
|
/// </summary>
|
|
/// <param name="sizerIp">Indirizzo IP del server SIZER</param>
|
|
/// <param name="port">Porta di connessione del sizer (def: 8001)</param>
|
|
public ComClient(string sizerIp, string port)
|
|
{
|
|
var url = "http://" + sizerIp + ":" + port + "/SizerService/";
|
|
var epa = new EndpointAddress(new Uri(url));
|
|
SSClient = new SizerServiceClient("WSHttpBinding_ISizerService", epa);
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Status di connessione del client
|
|
/// </summary>
|
|
public bool connected
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (SSClient != null)
|
|
{
|
|
answ = SSClient.State == CommunicationState.Opened;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Effettua chiusura del proxy di comunicazione
|
|
/// </summary>
|
|
public void Close()
|
|
{
|
|
if (SSClient.State != CommunicationState.Closed)
|
|
{
|
|
SSClient.Close();
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Internal Methods
|
|
|
|
/// <summary>
|
|
/// Elenco dei layout attivi della varietà
|
|
/// </summary>
|
|
/// <param name="VarietyId">Guid della varietà</param>
|
|
/// <returns></returns>
|
|
internal Layout GetActiveLayout(Guid VarietyId)
|
|
{
|
|
return SSClient.GetActiveLayout(VarietyId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco varietà attive
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal Variety[] GetActiveVarieties()
|
|
{
|
|
return SSClient.GetActiveVarieties();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera il batch corrente (se monolinea)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal Batch GetCurrentBatch()
|
|
{
|
|
return SSClient.GetCurrentBatch();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera il batch corrente data la linea
|
|
/// </summary>
|
|
/// <param name="lineNum">Numero della linea 1=sx/2=dx</param>
|
|
/// <returns></returns>
|
|
internal Batch GetCurrentBatchByLane(int lineNum)
|
|
{
|
|
return SSClient.GetCurrentBatchByLane(lineNum);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco dei layout della varietà
|
|
/// </summary>
|
|
/// <param name="VarietyId">Guid della varietà</param>
|
|
/// <returns></returns>
|
|
internal Layout[] GetLayouts(Guid VarietyId)
|
|
{
|
|
return SSClient.GetLayouts(VarietyId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua chiamata per mettere in coda il lotto richiesto
|
|
/// </summary>
|
|
/// <param name="batch">Oggetto Batch completamente popolato da accodare in richiesta</param>
|
|
internal void MettiLottoInCoda(Batch batch)
|
|
{
|
|
SSClient.AddBatch(batch);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica del grower da codice/nome
|
|
/// </summary>
|
|
/// <param name="growerCode">Codice del produttore</param>
|
|
/// <param name="growerName">Denominazione del produttore</param>
|
|
internal void VerificaEsistenzaGrower(string growerCode, string growerName)
|
|
{
|
|
var grower = SSClient.GetGrower(growerCode);
|
|
|
|
if (grower == null)
|
|
{
|
|
var nuovo = new Grower() { Code = growerCode, Name = growerName };
|
|
|
|
SSClient.AddGrower(nuovo);
|
|
}
|
|
}
|
|
|
|
#endregion Internal Methods
|
|
|
|
#region Private Properties
|
|
|
|
/// <summary>
|
|
/// Client che inoltra le richieste al Sizer
|
|
/// </summary>
|
|
private SizerServiceClient SSClient { get; set; }
|
|
|
|
#endregion Private Properties
|
|
}
|
|
|
|
[Serializable]
|
|
internal class IcoelSizerException : Exception
|
|
{
|
|
#region Public Constructors
|
|
|
|
public IcoelSizerException()
|
|
{
|
|
}
|
|
|
|
public IcoelSizerException(Exception ex)
|
|
{
|
|
this.ex = ex;
|
|
}
|
|
|
|
public IcoelSizerException(string message) : base(message)
|
|
{
|
|
}
|
|
|
|
public IcoelSizerException(string message, Exception innerException) : base(message, innerException)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Constructors
|
|
|
|
protected IcoelSizerException(SerializationInfo info, StreamingContext context) : base(info, context)
|
|
{
|
|
}
|
|
|
|
#endregion Protected Constructors
|
|
|
|
#region Private Fields
|
|
|
|
private Exception ex;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |