128 lines
4.8 KiB
C#
128 lines
4.8 KiB
C#
#region Namespace
|
|
using System;
|
|
using System.Diagnostics;
|
|
using Asm.As.Oib.Client.CustomExtensions;
|
|
using com.itac.mes.tools;
|
|
using Constants = com.itac.mes.tools.Constants;
|
|
using com.itac.mes.proxy.business;
|
|
using com.itac.oib.traceability.contracts.data;
|
|
using OibClient = Asm.As.Oib.Client;
|
|
using SiplaceNS = www.siplace.com.OIB._2012._03.Traceability.Contracts.Data;
|
|
#endregion
|
|
|
|
namespace Itac.Oib
|
|
{
|
|
/// <summary>
|
|
/// Receiver class for the TraceService events
|
|
/// </summary>
|
|
public class TraceabilityReceiver : IDisposable, IReceiver
|
|
{
|
|
#region Fields
|
|
|
|
OIBEventHandler _eventHandler;
|
|
readonly OibClient.OibTraceabilityEvents _oibTraceabilityEvents;
|
|
readonly OperatorNotificationManager _operatorNotificationManager;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public TraceabilityReceiver(OibClient.OibTraceabilityEvents oibTraceEvents, OIBEventHandler eventHandler, OperatorNotificationManager operatorNotificationManager)
|
|
{
|
|
if (oibTraceEvents == null) throw new ArgumentNullException("oibTraceEvents");
|
|
if (eventHandler == null) throw new ArgumentNullException("eventHandler");
|
|
if (operatorNotificationManager == null) throw new ArgumentNullException("operatorNotificationManager");
|
|
|
|
_oibTraceabilityEvents = oibTraceEvents;
|
|
_eventHandler = eventHandler;
|
|
_operatorNotificationManager = operatorNotificationManager;
|
|
|
|
oibTraceEvents.TraceabilityData = TraceDataReceived;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Start/Stop
|
|
|
|
public void Start()
|
|
{
|
|
_oibTraceabilityEvents.Start();
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_oibTraceabilityEvents.Stop();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Handling of events
|
|
|
|
|
|
public SiplaceNS.BoardProducedResponse TraceDataReceived(SiplaceNS.TraceabilityData traceabilityData)
|
|
{
|
|
SiplaceNS.BoardProducedResponse response = new SiplaceNS.BoardProducedResponse();
|
|
try
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "ITraceabilityOibService.NewTraceabilityData");
|
|
if (_eventHandler != null)
|
|
{
|
|
|
|
TraceabilityData itacTraceData = TraceabilityDataMapper.get(traceabilityData);
|
|
BoardProducedResponse result = _eventHandler.boardProduced(itacTraceData);
|
|
if (result.BoardValidationResult == 2)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "received the RC_TRCDATA_REJECTED return code");
|
|
try
|
|
{
|
|
_operatorNotificationManager.TraceDataRejected("Die letzte Station wurde gestoppt, da iTac die Tracedaten als fehlerhaft erkannt hat.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "calling OperatorNotificationManager failed", ex);
|
|
}
|
|
}
|
|
else if (result.BoardValidationReason.StartsWith("RC_TRCDATA_REJECTED:"))
|
|
{
|
|
string message = result.BoardValidationReason.Replace("RC_TRCDATA_REJECTED:", "");
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "received the RC_TRCDATA_REJECTED return code with additional l message text " + message);
|
|
try
|
|
{
|
|
_operatorNotificationManager.TraceDataRejected(message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "calling OperatorNotificationManager failed", ex);
|
|
}
|
|
}
|
|
response.BoardValidationResult = 2;
|
|
return response;
|
|
}
|
|
else
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Warning, "calling ITraceabilityOibService.NewTraceabilityData not performed");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// der letzte Aufruf schlug fehl!!
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "calling NewTraceabilityData in eventHandler failed", e);
|
|
}
|
|
response.BoardValidationResult = 1;
|
|
return response;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IDisposeable
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_oibTraceabilityEvents != null)
|
|
_oibTraceabilityEvents.Dispose();
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |