656 lines
34 KiB
C#
656 lines
34 KiB
C#
#region Namespace
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Security.Principal;
|
|
using System.ServiceProcess;
|
|
using System.Threading;
|
|
using Asm.As.Oib.Client;
|
|
using Asm.As.Oib.Client.CustomExtensions;
|
|
using Asm.As.Oib.SiplacePro.Contracts.Data.Business.Objects;
|
|
using Asm.As.Oib.SiplaceSetupCenter.Contracts.Data;
|
|
using com.itac.mes.proxy.business;
|
|
using com.itac.mes.proxy.sockets;
|
|
using com.itac.mes.tools;
|
|
using com.itac.oib;
|
|
using com.itac.oib.siplacepro.service;
|
|
using Itac.Oib;
|
|
#endregion
|
|
|
|
namespace com.itac.mes.proxy.winservice
|
|
{
|
|
|
|
public class WindowsService : ServiceBase
|
|
{
|
|
#region Fields
|
|
|
|
/// <summary>
|
|
/// Der Linienname ergibt sich aus der SetupCenter Konfiguration. Es darf nur eine Linie geben.
|
|
/// </summary>
|
|
private string _lineFullPath;
|
|
private SocketAdapter _socketAdapter;
|
|
private OIBEventHandler _eventHandler;
|
|
private OibClient _oibClient;
|
|
private static List<tools.KeyValue> versionList;
|
|
|
|
#endregion
|
|
|
|
#region Static Methods
|
|
|
|
private static string GetVersionNr()
|
|
{
|
|
var asm = Assembly.GetExecutingAssembly();
|
|
var asmName = asm.GetName();
|
|
|
|
object[] attribs = asm.GetCustomAttributes(typeof(AssemblyProductAttribute), true);
|
|
string productName = String.Empty;
|
|
|
|
if (attribs.Length > 0)
|
|
{
|
|
var asmProduct = attribs[0] as AssemblyProductAttribute;
|
|
productName = asmProduct.Product;
|
|
}
|
|
string aVersion = String.Format("{1}.{2}.{3}.{4}",
|
|
productName, asmName.Version.Major, asmName.Version.Minor, asmName.Version.Build, asmName.Version.Revision);
|
|
string vers = String.Format("{0} - Version: {1}", productName, aVersion);
|
|
return (vers);
|
|
}
|
|
|
|
private static string GetFileVersionNr()
|
|
{
|
|
var asm = Assembly.GetExecutingAssembly();
|
|
|
|
object[] attribs = asm.GetCustomAttributes(typeof(AssemblyProductAttribute), true);
|
|
string productName = String.Empty;
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
if (attribs.Length > 0)
|
|
{
|
|
var asmProduct = attribs[0] as AssemblyProductAttribute;
|
|
productName = asmProduct.Product;
|
|
}
|
|
|
|
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
// string version = fvi.ProductVersion;
|
|
versionList.Add(new KeyValue() { key = productName, value = fvi.ProductVersion });
|
|
string version = String.Format("{0} - FileVersion: {1}", productName, fvi.ProductVersion);
|
|
|
|
|
|
String[] xVersion = fvi.Comments.Split();
|
|
try
|
|
{
|
|
String[] mesVersion = xVersion[3].Split('=');
|
|
versionList.Add(new KeyValue() { key = mesVersion[0], value = mesVersion[1] });
|
|
String[] intfVersion = xVersion[4].Split('=');
|
|
versionList.Add(new KeyValue() { key = intfVersion[0], value = intfVersion[1] });
|
|
} catch (Exception )
|
|
{ }
|
|
return (version);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Public Constructor for WindowsService.
|
|
/// - Put all of your Initialization code here.
|
|
/// </summary>
|
|
public WindowsService()
|
|
{
|
|
ServiceName = Constants.SERVICE_NAME;
|
|
EventLog.Log = Constants.LOGGER;
|
|
|
|
// These Flags set whether or not to handle that specific
|
|
// type of event. Set to true if you need it, false otherwise.
|
|
CanHandlePowerEvent = true;
|
|
CanHandleSessionChangeEvent = true;
|
|
CanPauseAndContinue = true;
|
|
CanShutdown = true;
|
|
CanStop = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Main Thread: This is where your Service is Run.
|
|
/// </summary>
|
|
static void Main()
|
|
{
|
|
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
|
{
|
|
if (e.IsTerminating)
|
|
{
|
|
object o = e.ExceptionObject;
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "### general exception handling ###");
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, o.ToString());
|
|
}
|
|
};
|
|
|
|
|
|
var service = new WindowsService();
|
|
#if (SERVICE)
|
|
ServiceBase.Run(service);
|
|
#else
|
|
service.OnStart(null);
|
|
Console.ReadLine();
|
|
service.OnStop();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// OnStart(): Put startup code here
|
|
/// - Start threads, get inital data, etc.
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
protected override void OnStart(string[] args)
|
|
{
|
|
InitService();
|
|
base.OnStart(args);
|
|
}
|
|
|
|
/// <summary>
|
|
/// OnStop(): Put your stop code here
|
|
/// - Stop threads, set final data, etc.
|
|
/// </summary>
|
|
protected override void OnStop()
|
|
{
|
|
ShutdownService();
|
|
base.OnStop();
|
|
}
|
|
|
|
/// <summary>
|
|
/// OnShutdown(): Called when the System is shutting down
|
|
/// - Put code here when you need special handling
|
|
/// of code that deals with a system shutdown, such
|
|
/// as saving special data before shutdown.
|
|
/// </summary>
|
|
protected override void OnShutdown()
|
|
{
|
|
ShutdownService();
|
|
base.OnShutdown();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dieser Adapter übernimmt die Steuerung der Subscriptions und der Endpoints
|
|
/// </summary>
|
|
private readonly AdapterControl _adapterControl = new AdapterControl();
|
|
private StatisticWorker statisticWorker;
|
|
private Thread statisticThread;
|
|
|
|
private void InitService()
|
|
{
|
|
// Ausgabe hilfe für xml-Messages
|
|
var messageWriter = new MessageWriter();
|
|
|
|
var config = new AppSettingsReader();
|
|
//<add key="xmlExport" value="true"/>
|
|
bool xmlExport = (bool)config.GetValue("xmlExport", typeof(bool));
|
|
bool xmlLogging = (bool)config.GetValue("xmlLogging", typeof(bool));
|
|
|
|
messageWriter.init(xmlExport, xmlLogging);
|
|
|
|
//<!-- definieren, welche Messages ausgegeben werden sollen -->
|
|
if (xmlExport)
|
|
{
|
|
if ((bool)config.GetValue("TraceabilityData", typeof(bool))) { messageWriter.AddType("TraceabilityData"); }
|
|
if ((bool)config.GetValue("DownloadData", typeof(bool))) { messageWriter.AddType("DownloadData"); }
|
|
if ((bool)config.GetValue("CheckInData", typeof(bool))) { messageWriter.AddType("CheckInData"); }
|
|
if ((bool)config.GetValue("StationEventComposite", typeof(bool))) { messageWriter.AddType("StationEventComposite"); }
|
|
if ((bool)config.GetValue("PackagingUnitLocation", typeof(bool))) { messageWriter.AddType("PackagingUnitLocation"); }
|
|
if ((bool)config.GetValue("ExternalControlResult", typeof(bool))) { messageWriter.AddType("ExternalControlResult"); }
|
|
if ((bool)config.GetValue("MaterialMovedReport", typeof(bool))) { messageWriter.AddType("MaterialMovedReport"); }
|
|
if ((bool)config.GetValue("SetupChangedReport", typeof(bool))) { messageWriter.AddType("SetupChangedReport"); }
|
|
if ((bool)config.GetValue("FeederPlacedReport", typeof(bool))) { messageWriter.AddType("FeederPlacedReport"); }
|
|
if ((bool)config.GetValue("TablePlacedReport", typeof(bool))) { messageWriter.AddType("TablePlacedReport"); }
|
|
if ((bool)config.GetValue("TableRemovedReport", typeof(bool))) { messageWriter.AddType("TableRemovedReport"); }
|
|
if ((bool)config.GetValue("BoardProcessedData", typeof(bool))) { messageWriter.AddType("BoardProcessedData"); }
|
|
if ((bool)config.GetValue("FeederRemovedReport", typeof(bool))) { messageWriter.AddType("FeederRemovedReport"); }
|
|
if ((bool)config.GetValue("PackagingUnitConsumedReport", typeof(bool))) { messageWriter.AddType("PackagingUnitConsumedReport"); }
|
|
if ((bool)config.GetValue("PackagingUnitCreatedReport", typeof(bool))) { messageWriter.AddType("PackagingUnitCreatedReport"); }
|
|
if ((bool)config.GetValue("LockStateChangedReport", typeof(bool))) { messageWriter.AddType("LockStateChangedReport"); }
|
|
if ((bool)config.GetValue("LineChangeoverEvent", typeof(bool))) { messageWriter.AddType("LineChangeoverEventArgs"); }
|
|
if ((bool)config.GetValue("BoardRequestData", typeof(bool))) { messageWriter.AddType("BoardRequestData"); }
|
|
}
|
|
|
|
_eventHandler = new OIBEventHandler(_adapterControl, messageWriter);
|
|
|
|
try
|
|
{
|
|
#if (SERVICE)
|
|
TraceListener eventLogTraceListener = new EventLogTraceListener(Constants.SERVICE_NAME);
|
|
eventLogTraceListener.Filter = new EventTypeFilter(SourceLevels.Information);
|
|
LogHandler.addListener(eventLogTraceListener);
|
|
#endif
|
|
// Der Port an dem der Adapter auf eingehende Verbindungen des iTAC DataInterface lauscht
|
|
var listenPort = (int)config.GetValue("ListenPort", typeof(int));
|
|
|
|
// diese Werte werden alle benötigt...
|
|
var oibCoreComuputerName = (String)config.GetValue("OIBCoreHostName", typeof(String));
|
|
var siplaceProEventPort = (int)config.GetValue("SiplaceProEventPort", typeof(int));
|
|
var displayServiceEventPort = (int)config.GetValue("DisplayServiceEventPort", typeof(int));
|
|
var setupCenterNotifyPort = (int)config.GetValue("SetupCenterNotifyPort", typeof(int));
|
|
var setupCenterExternalControlPort = (int)config.GetValue("SetupCenterExternalControlPort", typeof(int));
|
|
var traceServicePort = (int)config.GetValue("TraceServicePort", typeof(int));
|
|
var monitoringReceiverPort = (int)config.GetValue("MonitoringReceiverPort", typeof(int));
|
|
var boardGateKeeperEventPort = (int)config.GetValue("BoardGateKeeperEventPort", typeof(int));
|
|
var isSetupStation = (bool)config.GetValue("isSetupStation", typeof(bool));
|
|
var isOfflineMode = (bool)config.GetValue("offlineMode", typeof(bool));
|
|
var configuredLineFullPath = (String)config.GetValue("LineName", typeof(String));
|
|
|
|
// check that the process is started as administrator or end process with message
|
|
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
|
WindowsPrincipal principal = new WindowsPrincipal(identity);
|
|
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, getHeadertext("iTAC.OIB.Adapter Startup Problem"));
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "");
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Insufficient privileges!");
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "This process needs to be started with administrative privileges.");
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Right click on the executable file and select \"Run As Administrator\"");
|
|
return;
|
|
}
|
|
|
|
_eventHandler.LineName = configuredLineFullPath;
|
|
versionList = new List<KeyValue>();
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("iTAC.OIB.Adapter"));
|
|
String version = GetVersionNr();
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, version);
|
|
String fileVersion = GetFileVersionNr();
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, fileVersion);
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "listening for incoming connections on port " + listenPort);
|
|
_adapterControl._isSetupStation = isSetupStation;
|
|
if (isSetupStation)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "running in SetupStation Mode");
|
|
}
|
|
|
|
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
|
|
foreach (Assembly assembly in loadedAssemblies)
|
|
{
|
|
if (assembly.FullName.StartsWith("AsmApi"))
|
|
{
|
|
AssemblyProductAttribute adAttr = (AssemblyProductAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyProductAttribute));
|
|
versionList.Add(new KeyValue() { key = "AsmApi", value = adAttr.Product });
|
|
Console.WriteLine("AsmApi" + adAttr.Product);
|
|
}
|
|
}
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("OIB Startup"));
|
|
_oibClient = new OibClient("iTac", "OibAdapter", oibCoreComuputerName, configuredLineFullPath);
|
|
String firstMachineInLine = "";
|
|
String lastMachineInLine = "";
|
|
_adapterControl.OibClient = _oibClient;
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Setup Center Access"));
|
|
var serviceImpl = new OIBServiceImpl(_adapterControl, messageWriter);
|
|
serviceImpl.OibSetupCenterAccess = _oibClient.GetOibSetupCenterAccess();
|
|
com.itac.oib.siplacesetupcenter.contracts.data.Configuration setupCenterConfig = null;
|
|
_eventHandler.serviceImpl = serviceImpl;
|
|
|
|
#region Check Setup Center Version and that the confiured line is also configured in setup center.
|
|
var stationFullPaths = new List<string>();
|
|
|
|
try
|
|
{
|
|
setupCenterConfig = serviceImpl.getConfiguration();
|
|
String scVersion = setupCenterConfig.ProductVersion;
|
|
if (scVersion == null)
|
|
{
|
|
// Der iTAC.OIB.Adapter muss eine SetupCenter Verbindung haben
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "iTAC OIB.Adapter can not work without SetupCenter connection");
|
|
Environment.Exit(-3);
|
|
}
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "SetupCenter connected, version = " + scVersion);
|
|
versionList.Add(new KeyValue() { key = "SetupCenter", value = scVersion });
|
|
|
|
// nur eine Linie erlaubt ...
|
|
if (!isSetupStation)
|
|
{
|
|
bool isLineConfiguredInSetupCenter = false;
|
|
foreach (var line in setupCenterConfig.LineConfigurations)
|
|
{
|
|
if (line.LinePath == configuredLineFullPath)
|
|
{
|
|
_lineFullPath = configuredLineFullPath;
|
|
isLineConfiguredInSetupCenter = true;
|
|
firstMachineInLine = line.MachineConfigurations[0].MachineLocator.MachineName;
|
|
lastMachineInLine = line.MachineConfigurations[line.MachineConfigurations.Length - 1].MachineLocator.MachineName;
|
|
// BoardGateKeeperMapper.machineName = firstMachineInLine;
|
|
foreach (var station in line.MachineConfigurations)
|
|
{
|
|
stationFullPaths.Add(station.MachineLocator.MachineName);
|
|
}
|
|
}
|
|
}
|
|
if (!isLineConfiguredInSetupCenter)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, string.Format("Line '{0}' is not configured in Setup Center. Adapter stops.", _lineFullPath));
|
|
Environment.Exit(-4);
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "use fix url extension '/SetupStation'");
|
|
_lineFullPath = "SetupStation";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "SetupCenter NOT connected, unable to get version information", ex);
|
|
Environment.Exit(-4);
|
|
}
|
|
serviceImpl.configuredLineFullPath = configuredLineFullPath;
|
|
serviceImpl.firstMachineInLine = firstMachineInLine;
|
|
serviceImpl.lastMachineInLine = lastMachineInLine;
|
|
|
|
#endregion
|
|
|
|
OperatorNotificationManager operatorNotificationManager = null;
|
|
|
|
OibDisplayServiceAccess oibDisplayServiceAccess = null;
|
|
SetupCenterExternalControlReceiver externalcontrolReceiver = null;
|
|
if (!isOfflineMode)
|
|
{
|
|
/// listener auf externalcontrol bauen
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("SetupCenterExternalControl"));
|
|
var oibSetupCenterExternalControlEvents = _oibClient.GetOibSetupCenterExternalControlEvents(setupCenterExternalControlPort, PortsharingMode.WithoutTcpPortsharing);
|
|
|
|
externalcontrolReceiver = new SetupCenterExternalControlReceiver(oibSetupCenterExternalControlEvents);
|
|
externalcontrolReceiver._eventHandler = _eventHandler;
|
|
_adapterControl.SetupCenterExternalControlReceiver = externalcontrolReceiver;
|
|
|
|
if (displayServiceEventPort > 0)
|
|
{
|
|
oibDisplayServiceAccess = initDisplayService(displayServiceEventPort, serviceImpl);
|
|
}
|
|
}
|
|
|
|
TraceabilityReceiver traceOibReceiver = null;
|
|
SiplacePro siplacePro = null;
|
|
if (!isSetupStation)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Setup Center Events"));
|
|
var oibSetupCenterEvents = _oibClient.GetOibSetupCenterEvents(new OibCoreSubscriptionParamters(SubscriptionType.Permanent, setupCenterNotifyPort, TimeSpan.FromMinutes(1), PortsharingMode.WithoutTcpPortsharing), stationFullPaths);
|
|
if (!isOfflineMode)
|
|
{
|
|
_adapterControl.SetupCenterReceiver = new SetupCenterReceiver(oibSetupCenterEvents, _oibClient.LineFullPath, isSetupStation);
|
|
_adapterControl.SetupCenterReceiver._eventHandler = _eventHandler;
|
|
}
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("SIPLACE Pro"));
|
|
OibSpiAccess oibSpiAccess = null;
|
|
if (!isOfflineMode)
|
|
{
|
|
oibSpiAccess = _oibClient.GetOibSpiAccess(siplaceProEventPort, PortsharingMode.WithoutTcpPortsharing);
|
|
var spiVersion = oibSpiAccess.Session.SPIVersion;
|
|
}
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Monitoring Events"));
|
|
if (!isOfflineMode)
|
|
{
|
|
var oibMonitoringEvents = _oibClient.GetOibMonitoringEvents(new OibCoreSubscriptionParamters(SubscriptionType.Permanent, monitoringReceiverPort, TimeSpan.FromMinutes(1), PortsharingMode.WithoutTcpPortsharing));
|
|
_adapterControl.MonitoringReceiver = new MonitoringReceiver(oibMonitoringEvents, _oibClient.LineFullPath);
|
|
_adapterControl.MonitoringReceiver._eventHandler = _eventHandler;
|
|
}
|
|
|
|
try
|
|
{
|
|
HashSet<string> versionKeySet = new HashSet<string>();
|
|
versionKeySet.Add("ConfigurationManager");
|
|
versionKeySet.Add("ServiceLocator");
|
|
versionKeySet.Add("DisplayService");
|
|
versionKeySet.Add("SIPLACE.SetupCenter.MaterialControl");
|
|
versionKeySet.Add("SIPLACE.Pro.LineControl");
|
|
versionKeySet.Add("SIPLACE.Monitoring");
|
|
versionKeySet.Add("SIPLACE.Pro.SPI");
|
|
var serviceLocator = _oibClient.GetSeriviceLocatorClient();
|
|
var allServices = serviceLocator.GetAllServices();
|
|
for (int i = 0; i < allServices.Length; i++)
|
|
{
|
|
var sd = allServices[i];
|
|
if (versionKeySet.Contains(sd.ServiceName) && sd.Configuration != null)
|
|
{
|
|
versionList.Add(new KeyValue() { key = sd.ServiceName, value = sd.ServiceVersion });
|
|
}
|
|
}
|
|
|
|
_adapterControl.productVersions = versionList;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
if (!isOfflineMode)
|
|
{
|
|
siplacePro = new SiplacePro();
|
|
siplacePro._eventHandler = _eventHandler;
|
|
siplacePro.oibSpiAccess = oibSpiAccess;
|
|
siplacePro.RegisterCallback();
|
|
serviceImpl.SiplacePro = siplacePro;
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Siplace Pro"));
|
|
versionList.Add(new KeyValue() { key = "SiplacePro", value = siplacePro.oibSpiAccess.Session.ProductVersion });
|
|
|
|
var oibSpiEvents = _oibClient.GetOibSpiEvents(oibSpiAccess);
|
|
oibSpiEvents.StartDownloadEvents();
|
|
var spiReceiver = new SpiReceiver(oibSpiEvents, _eventHandler);
|
|
_adapterControl.SpiReceiver = spiReceiver;
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Line Control"));
|
|
serviceImpl.OibLineControlAccess = _oibClient.GetOibLineControlAccess();
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "connect to Line Control: " + serviceImpl.OibLineControlAccess.OibServiceComputerName);
|
|
try
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "Line Control Database Id: " + serviceImpl.OibLineControlAccess.LineControlSession.DatabaseId);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Line Control Database Id not detected", e);
|
|
}
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "Line Control: " + serviceImpl.OibLineControlAccess.LineControlSession.ProductVersion);
|
|
versionList.Add(new KeyValue() { key = "LineControl", value = serviceImpl.OibLineControlAccess.LineControlSession.ProductVersion });
|
|
|
|
operatorNotificationManager = new OperatorNotificationManager(_oibClient, oibSpiAccess, serviceImpl.OibLineControlAccess, oibDisplayServiceAccess);
|
|
traceOibReceiver = initTraceability(traceServicePort, oibSpiAccess, serviceImpl.OibLineControlAccess, oibDisplayServiceAccess, operatorNotificationManager);
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Changeover Manager"));
|
|
// ab client 2.1.0.14 diesen Constructor nutzen
|
|
var changeoverManager = new ChangeoverManager(oibSpiAccess, oibSpiEvents, serviceImpl.OibSetupCenterAccess, oibSetupCenterEvents, serviceImpl.OibLineControlAccess, operatorNotificationManager, configuredLineFullPath);
|
|
|
|
var changeoverReceiver = new ChangeoverReceiver(changeoverManager);
|
|
changeoverReceiver._eventHandler = _eventHandler;
|
|
_adapterControl.ChangeoverReceiver = changeoverReceiver;
|
|
serviceImpl.ChangeoverReceiver = changeoverReceiver;
|
|
|
|
initBoardGateKeeper(boardGateKeeperEventPort, _eventHandler, _adapterControl, oibSpiAccess, oibSpiEvents, operatorNotificationManager, configuredLineFullPath);
|
|
}
|
|
}
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("iHap Connection"));
|
|
_socketAdapter = new SocketAdapter(listenPort, _adapterControl, serviceImpl);
|
|
|
|
String currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "current path = " + currentPath);
|
|
bool exists = System.IO.Directory.Exists(@"./xml");
|
|
if (exists)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "directory ./xml exists, start scanning for *.xml files");
|
|
DirectoryMonitor dirMonitor = new DirectoryMonitor();
|
|
dirMonitor.addType(typeof(com.itac.oib.siplacesetupcenter.contracts.data.MaterialMovedReport));
|
|
dirMonitor.addType(typeof(com.itac.oib.monitoring.contracts.data.StationEventComposite));
|
|
dirMonitor.addType(typeof(com.itac.oib.monitoring.contracts.data.BoardProcessedData));
|
|
dirMonitor.addType(typeof(FeederPlacedEvent));
|
|
dirMonitor.addType(typeof(PackagingUnitLocation));
|
|
dirMonitor.addType(typeof(TraceabilityData));
|
|
dirMonitor.addType(typeof(DownloadData));
|
|
dirMonitor.addType(typeof(PackagingUnitConsumedReport));
|
|
dirMonitor.addType(typeof(LineChangeoverEventArgs));
|
|
dirMonitor.addType(typeof(VirtualInkspotHandlerBoardRequest));
|
|
|
|
dirMonitor.deserializedObjectEvent += dispatchFileObject;
|
|
|
|
dirMonitor.Start();
|
|
}
|
|
var proxyVersions = _oibClient.GetOibProxyVersions();
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("OIB Proxy Versions"));
|
|
foreach (var keyValuePair in proxyVersions)
|
|
{
|
|
if (!keyValuePair.Key.Equals("AsmApi"))
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, string.Format("{0,-50} {1,10}", keyValuePair.Key, keyValuePair.Value));
|
|
}
|
|
}
|
|
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Statistic Thread"));
|
|
try
|
|
{
|
|
statisticWorker = new StatisticWorker();
|
|
statisticWorker.setVersionList(versionList);
|
|
statisticThread = new Thread(statisticWorker.DoWork);
|
|
statisticThread.Start();
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "Statistic thread started! ");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Statistic thread NOT started!", e);
|
|
}
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Initialization completed"));
|
|
if (!isOfflineMode)
|
|
{
|
|
_adapterControl.startMonitoringReceiver();
|
|
_adapterControl.startSetupCenterNotifyReceiver();
|
|
_adapterControl.startTraceReceiver();
|
|
_adapterControl.startBoardGateKeeper();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Initialization failed! " + e.Message, e);
|
|
}
|
|
}
|
|
|
|
private void dispatchFileObject(object sender, object deserializedObject)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Verbose, "deserialized obejct");
|
|
/* if (traceOibReceiver != null)
|
|
{
|
|
dirMonitor.setTraceReceiver(traceOibReceiver);
|
|
}
|
|
if (_adapterControl.MonitoringReceiver != null)
|
|
{
|
|
dirMonitor.setMonitoringReceiver(_adapterControl.MonitoringReceiver);
|
|
}
|
|
dirMonitor.setSetupCenterReceiver(_adapterControl.SetupCenterReceiver);
|
|
dirMonitor.setSetupCenterExternalControl(externalcontrolReceiver);
|
|
if (siplacePro != null)
|
|
{
|
|
dirMonitor.setSiplacePro(serviceImpl.SiplacePro);
|
|
}
|
|
dirMonitor.changeoverReceiver = _adapterControl.ChangeoverReceiver;
|
|
dirMonitor.boardGateKeeperReceiver = _adapterControl.BoardGateKeeperReceiver;*/
|
|
}
|
|
|
|
private OibDisplayServiceAccess initDisplayService(int displayServiceEventPort, OIBServiceImpl serviceImpl)
|
|
{
|
|
OibDisplayServiceAccess oibDisplayServiceAccess = null;
|
|
try
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("DisplayService"));
|
|
oibDisplayServiceAccess = _oibClient.GetOibDisplayServiceAccess(displayServiceEventPort, PortsharingMode.WithoutTcpPortsharing);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Warning, "DisplayService not initialized correctly, continue without DisplayService", e);
|
|
}
|
|
finally
|
|
{
|
|
serviceImpl.DisplayServiceAccess = oibDisplayServiceAccess;
|
|
}
|
|
return oibDisplayServiceAccess;
|
|
}
|
|
|
|
private TraceabilityReceiver initTraceability(int traceServicePort, OibSpiAccess oibSpiAccess, OibLineControlAccess oibLineControlAccess, OibDisplayServiceAccess oibDisplayServiceAccess, OperatorNotificationManager operatorNotificationManager)
|
|
{
|
|
TraceabilityReceiver traceOibReceiver = null;
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Traceability"));
|
|
if (traceServicePort > 0)
|
|
{
|
|
try
|
|
{
|
|
|
|
var oibTraceabilityEvents = _oibClient.GetOibTraceabilityEvents(traceServicePort, PortsharingMode.WithoutTcpPortsharing);
|
|
traceOibReceiver = new TraceabilityReceiver(oibTraceabilityEvents, _eventHandler, operatorNotificationManager);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "Traceability initialization failure", e);
|
|
}
|
|
finally
|
|
{
|
|
_adapterControl.TraceReceiver = traceOibReceiver;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "Traceability switched off by configuration (port is set to 0)");
|
|
}
|
|
return traceOibReceiver;
|
|
}
|
|
|
|
private void initBoardGateKeeper(int boardGateKeeperEventPort, OIBEventHandler _eventHandler, AdapterControl _adapterControl, OibSpiAccess oibSpiAccess, OibSpiEvents oibSpiEvents, OperatorNotificationManager operatorNotificationManager, String configuredLineFullPath)
|
|
{
|
|
BoardGateKeeperReceiver boardGateKeeperOibReceiver = null;
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("BoardGateKeeper"));
|
|
if (boardGateKeeperEventPort > 0)
|
|
{
|
|
try
|
|
{
|
|
var oibBoardGateKeeperEvents = _oibClient.GetOibBoardGateKeeperEvents(boardGateKeeperEventPort, PortsharingMode.WithoutTcpPortsharing);
|
|
boardGateKeeperOibReceiver = new BoardGateKeeperReceiver(oibBoardGateKeeperEvents, _eventHandler);
|
|
VirtualInkspotHandlerWrapper vx = new VirtualInkspotHandlerWrapper(oibSpiAccess, oibSpiEvents, oibBoardGateKeeperEvents, operatorNotificationManager, configuredLineFullPath);
|
|
vx.VirtualInkspotData = boardGateKeeperOibReceiver.virtualInkspotData;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Error, "BoardGateKeeper initialization failure", e);
|
|
}
|
|
finally
|
|
{
|
|
_adapterControl.BoardGateKeeperReceiver = boardGateKeeperOibReceiver;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "BoardGateKeeper switched off by configuration (port is set to 0)");
|
|
}
|
|
}
|
|
|
|
private string getHeadertext(string v)
|
|
{
|
|
String separator = "--------------------------------------------------------------------";
|
|
if (separator.Length < v.Length)
|
|
{
|
|
return separator.Substring(0, 10) + " " + v;
|
|
}
|
|
else
|
|
{
|
|
return separator.Substring(0, 10) + " " + v + " " + separator.Substring(0, separator.Length - v.Length);
|
|
}
|
|
}
|
|
|
|
|
|
private void ShutdownService()
|
|
{
|
|
statisticWorker.RequestStop();
|
|
statisticThread.Join();
|
|
_socketAdapter.Shutdown();
|
|
if (_oibClient != null)
|
|
_oibClient.Dispose();
|
|
if (_adapterControl != null)
|
|
_adapterControl.Dispose();
|
|
}
|
|
|
|
}
|
|
}
|