initialize
This commit is contained in:
@@ -0,0 +1,686 @@
|
||||
#region Namespace
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading;
|
||||
using com.itac.mes.proxy.business;
|
||||
using com.itac.mes.proxy.sockets;
|
||||
using com.itac.oib;
|
||||
using com.itac.oib.siplacepro.service;
|
||||
using Itac.Oib;
|
||||
using Asm.As.Oib.Client;
|
||||
using Asm.As.Oib.Client.CustomExtensions;
|
||||
using System.Security.Principal;
|
||||
using com.itac.mes.tools;
|
||||
using com.itac.oib.siplacesetupcenter.contracts.data;
|
||||
using com.itac.oib.linecontrol.data;
|
||||
#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 SocketAdapter _socketAdapter;
|
||||
private OIBEventHandler _eventHandler;
|
||||
private OibClient _oibClient;
|
||||
private static List<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();
|
||||
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] });
|
||||
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);
|
||||
|
||||
_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
|
||||
// this is the port the oib adapter listens for incoming connections from the data interface application
|
||||
var listenPort = (int)config.GetValue("ListenPort", typeof(int));
|
||||
|
||||
// store all configuration values in the configuration instance
|
||||
Asm.As.Oib.Client.Configuration.OibClientConfiguration oibClientconfiguration = new Asm.As.Oib.Client.Configuration.OibClientConfiguration();
|
||||
// PRE: _oibClient = new OibClient("iTac", "OibAdapter", oibCoreComuputerName, configuredLineFullPath);
|
||||
oibClientconfiguration.ApplicationName = "OibAdapter";
|
||||
oibClientconfiguration.CompanyName = "iTac";
|
||||
oibClientconfiguration.FactoryElementPath = "Enterprise"; // this is probably not necessary to set
|
||||
|
||||
oibClientconfiguration.EventNotificationProtocol = new Asm.As.Oib.Client.Configuration.EventNotificationProtocol();
|
||||
oibClientconfiguration.OibClientMode = Asm.As.Oib.Client.Configuration.OibClientMode.Line;
|
||||
|
||||
oibClientconfiguration.TcpPortSharingEnabled = true;
|
||||
oibClientconfiguration.UnsubscribeCoreEventsOnShutdown = true;
|
||||
|
||||
oibClientconfiguration.CoreComputerName = (String)config.GetValue("OIBCoreHostName", typeof(String));
|
||||
oibClientconfiguration.LineControlMesInterceptorCallbackPort = (int)config.GetValue("LinecontrolMesInterceptorPort", typeof(int)); // new from OIB5.3
|
||||
oibClientconfiguration.OibSpiCallbackPort = (int)config.GetValue("SiplaceProEventPort", typeof(int));
|
||||
oibClientconfiguration.DisplayServiceCallbackPort = (int)config.GetValue("DisplayServiceEventPort", typeof(int));
|
||||
oibClientconfiguration.SetupCenterEventsCallbackPort = (int)config.GetValue("SetupCenterNotifyPort", typeof(int));
|
||||
oibClientconfiguration.SetupCenterExternalControlCallbackPort = (int)config.GetValue("SetupCenterExternalControlPort", typeof(int));
|
||||
oibClientconfiguration.TraceabilitySynchronousCallbackPort = (int)config.GetValue("TraceServicePort", typeof(int));
|
||||
oibClientconfiguration.MonitoringEventsCallbackPort = (int)config.GetValue("MonitoringReceiverPort", typeof(int));
|
||||
oibClientconfiguration.BoardGateKeeperCallbackPort = (int)config.GetValue("BoardGateKeeperEventPort", typeof(int));
|
||||
oibClientconfiguration.DekPrinterExternalControlCallbackPort = (int)config.GetValue("DekPrinterExternalControlPort", typeof(int)); // new from OIB5.3
|
||||
oibClientconfiguration.ConfigurationManagerCallbackPort = (int)config.GetValue("ConfigurationManagerCallbackPort", typeof(int)); // new from OIB5.3
|
||||
|
||||
oibClientconfiguration.LineFullPath = (String)config.GetValue("LineName", typeof(String));
|
||||
|
||||
var isSetupStation = (bool)config.GetValue("isSetupStation", typeof(bool));
|
||||
var isOfflineMode = (bool)config.GetValue("offlineMode", typeof(bool));
|
||||
|
||||
// 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 = oibClientconfiguration.LineFullPath;
|
||||
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 });
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "AsmApi Version: " + adAttr.Product);
|
||||
}
|
||||
}
|
||||
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("OIB Startup"));
|
||||
|
||||
|
||||
|
||||
|
||||
_oibClient = new OibClient(oibClientconfiguration);
|
||||
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();
|
||||
Asm.As.Oib.SiplaceSetupCenter.Contracts.Data.Configuration setupCenterConfig = serviceImpl.OibSetupCenterAccess.GetConfiguration();
|
||||
_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 == oibClientconfiguration.LineFullPath)
|
||||
{
|
||||
isLineConfiguredInSetupCenter = true;
|
||||
firstMachineInLine = line.MachineConfigurations[0].MachineLocator.MachineName;
|
||||
lastMachineInLine = line.MachineConfigurations[line.MachineConfigurations.Count - 1].MachineLocator.MachineName;
|
||||
BoardGateKeeperReceiver.DefaultMachineFullPath = firstMachineInLine;
|
||||
foreach (var station in line.MachineConfigurations)
|
||||
{
|
||||
stationFullPaths.Add(station.MachineLocator.MachineName);
|
||||
}
|
||||
|
||||
foreach (var station in line.PrinterConfigurations)
|
||||
{
|
||||
stationFullPaths.Add(station.PrinterPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isLineConfiguredInSetupCenter)
|
||||
{
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Critical, string.Format("Line '{0}' is not configured in Setup Center. Adapter stops.", oibClientconfiguration.LineFullPath));
|
||||
Environment.Exit(-4);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "use fix url extension '/SetupStation'");
|
||||
// HOW TO HANDLE THE SETUP_STATION
|
||||
// _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 = oibClientconfiguration.LineFullPath;
|
||||
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();
|
||||
|
||||
externalcontrolReceiver = new SetupCenterExternalControlReceiver(oibSetupCenterExternalControlEvents);
|
||||
externalcontrolReceiver._eventHandler = _eventHandler;
|
||||
_adapterControl.SetupCenterExternalControlReceiver = externalcontrolReceiver;
|
||||
|
||||
if (oibClientconfiguration.DisplayServiceCallbackPort > 0)
|
||||
{
|
||||
oibDisplayServiceAccess = initDisplayService(serviceImpl);
|
||||
}
|
||||
}
|
||||
|
||||
TraceabilityReceiver traceOibReceiver = null;
|
||||
SiplacePro siplacePro = null;
|
||||
if (!isSetupStation)
|
||||
{
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Setup Center Events"));
|
||||
var oibSetupCenterEvents = _oibClient.GetOibSetupCenterEvents(stationFullPaths);
|
||||
if (!isOfflineMode)
|
||||
{
|
||||
_adapterControl.SetupCenterReceiver = new SetupCenterReceiver(oibSetupCenterEvents, oibClientconfiguration.LineFullPath, isSetupStation);
|
||||
_adapterControl.SetupCenterReceiver._eventHandler = _eventHandler;
|
||||
}
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("SIPLACE Pro"));
|
||||
OibSpiAccess oibSpiAccess = null;
|
||||
if (!isOfflineMode)
|
||||
{
|
||||
oibSpiAccess = _oibClient.GetOibSpiAccess();
|
||||
var spiVersion = oibSpiAccess.Session.SPIVersion;
|
||||
}
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Monitoring Events"));
|
||||
if (!isOfflineMode)
|
||||
{
|
||||
var oibMonitoringEvents = _oibClient.GetOibMonitoringEvents();
|
||||
_adapterControl.MonitoringReceiver = new MonitoringReceiver(oibMonitoringEvents, oibClientconfiguration.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.Get.GetServiceRegistration();
|
||||
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);
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, "connect to Line Control: " + serviceImpl.OibLineControlAccess.DisplayName);
|
||||
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 });
|
||||
|
||||
Asm.As.Oib.Client.CustomExtensions.Configuration.OperatorNotificationManagerConfiguration operatorNotificationManagerConfiguration = new Asm.As.Oib.Client.CustomExtensions.Configuration.OperatorNotificationManagerConfiguration();
|
||||
|
||||
operatorNotificationManagerConfiguration.ShowMessageOnVihDataRejected = true;
|
||||
operatorNotificationManagerConfiguration.StopLineOnTraceDataRejected = true;
|
||||
operatorNotificationManagerConfiguration.StopStationOnVihDataRejected = true;
|
||||
|
||||
// NO specific configuration right now
|
||||
operatorNotificationManager = new OperatorNotificationManager(_oibClient, oibSpiAccess, serviceImpl.OibLineControlAccess, oibDisplayServiceAccess, operatorNotificationManagerConfiguration);
|
||||
traceOibReceiver = initTraceability(oibClientconfiguration.TraceabilitySynchronousCallbackPort, oibSpiAccess, serviceImpl.OibLineControlAccess, oibDisplayServiceAccess, operatorNotificationManager);
|
||||
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Changeover Manager"));
|
||||
Asm.As.Oib.Client.CustomExtensions.Configuration.OibChangeoverManagerConfiguration changeoverManagerConfiguration = new Asm.As.Oib.Client.CustomExtensions.Configuration.OibChangeoverManagerConfiguration();
|
||||
// ab client 2.1.0.14 diesen Constructor nutzen
|
||||
changeoverManagerConfiguration.LineFullPath = oibClientconfiguration.LineFullPath;
|
||||
changeoverManagerConfiguration.ChangeoverIncompleteRepeatWarningSeconds = 120;
|
||||
changeoverManagerConfiguration.ChangeoverIncompleteWarningSeconds = 120;
|
||||
|
||||
var changeoverManager = new ChangeoverManager(oibSpiAccess, oibSpiEvents, serviceImpl.OibSetupCenterAccess, oibSetupCenterEvents, serviceImpl.OibLineControlAccess, operatorNotificationManager, changeoverManagerConfiguration);
|
||||
|
||||
var changeoverReceiver = new ChangeoverReceiver(changeoverManager);
|
||||
changeoverReceiver._eventHandler = _eventHandler;
|
||||
_adapterControl.ChangeoverReceiver = changeoverReceiver;
|
||||
serviceImpl.ChangeoverReceiver = changeoverReceiver;
|
||||
|
||||
initBoardGateKeeper(oibClientconfiguration.BoardGateKeeperCallbackPort, _eventHandler, _adapterControl, oibSpiAccess, oibSpiEvents, operatorNotificationManager, oibClientconfiguration.LineFullPath);
|
||||
|
||||
|
||||
OibDekPrinterExtenalControlEvents dekReceiver = _oibClient.GetOibDekPrinterExtenalControlEvents();
|
||||
var dekExternalControlReceiver = new DekPrinterExternalControlReceiver(dekReceiver);
|
||||
_adapterControl.DekPrinterExternalControlReceiver = dekExternalControlReceiver;
|
||||
|
||||
OibLineControlMesInterceptorEvents mesLineControlInterceptorEvents = _oibClient.GetOibLineControlMesInterceptorEvents();
|
||||
var lineControlMesInterceptorReceiver = new LineControlMesInterceptorReceiver(mesLineControlInterceptorEvents, _eventHandler);
|
||||
_adapterControl.MesLineControlMesInterceptorReceiver = lineControlMesInterceptorReceiver;
|
||||
|
||||
// starting health checks when a port number is given
|
||||
if (_oibClient.Configuration.ConfigurationManagerCallbackPort > 0)
|
||||
{
|
||||
_oibClient.GetOibHealthCheckCallbacks().Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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");
|
||||
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;
|
||||
}
|
||||
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(OIBServiceImpl serviceImpl)
|
||||
{
|
||||
OibDisplayServiceAccess oibDisplayServiceAccess = null;
|
||||
try
|
||||
{
|
||||
LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("DisplayService"));
|
||||
oibDisplayServiceAccess = _oibClient.GetOibDisplayServiceAccess();
|
||||
}
|
||||
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();
|
||||
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();
|
||||
boardGateKeeperOibReceiver = new BoardGateKeeperReceiver(oibBoardGateKeeperEvents, _eventHandler);
|
||||
Asm.As.Oib.Client.CustomExtensions.Configuration.VirtualInkspotHandlerConfiguration virtualInkspotHandlerConfiguration = new Asm.As.Oib.Client.CustomExtensions.Configuration.VirtualInkspotHandlerConfiguration();
|
||||
virtualInkspotHandlerConfiguration.LineFullPath = configuredLineFullPath;
|
||||
VirtualInkspotHandlerWrapper vx = new VirtualInkspotHandlerWrapper(oibSpiAccess, oibSpiEvents, oibBoardGateKeeperEvents, operatorNotificationManager, virtualInkspotHandlerConfiguration);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user