using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.Reflection; using System.Text; using System.Windows.Forms; using Asm.As.Oib.Client; using com.itac.mes.proxy; using com.itac.mes.proxy.business; using com.itac.mes.proxy.sockets; using com.itac.oib; using com.itac.oib.displayservice.contracts.data; using com.itac.oib.linecontrol.contracts.data; using com.itac.oib.monitoring.contracts.data; using com.itac.oib.siplacesetupcenter.contracts.data; using com.itac.oib.traceability.contracts.data; namespace oib5._1.GUI { public partial class Form1 : Form { public Form1() { InitializeComponent(); InitService(); } private SocketAdapter _socketAdapter; private OIBEventHandler _eventHandler; private static List versionList; /// /// Dieser Adapter übernimmt die Steuerung der Subscriptions und der Endpoints /// private readonly AdapterControl _adapterControl = new AdapterControl(); private void InitService() { // Ausgabe hilfe für xml-Messages var messageWriter = new MessageWriter(); messageWriter.init(); _eventHandler = new OIBEventHandler(_adapterControl, messageWriter); var config = new AppSettingsReader(); try { #if (SERVICE) TraceListener eventLogTraceListener = new EventLogTraceListener(Constants.SERVICE_NAME); eventLogTraceListener.Filter = new EventTypeFilter(SourceLevels.Information); LogHandler.addListener(eventLogTraceListener); #endif // create configuration with some default values (not configurable) // This is the port where the oib adapter listens for new incoming connections from the data interface var listenPort = (int)config.GetValue("ListenPort", typeof(int)); // all required configuration values string LineFullPath = (String)config.GetValue("LineName", typeof(String)); _eventHandler.LineName = LineFullPath; versionList = new List(); 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); 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); } } String firstMachineInLine = ""; String lastMachineInLine = ""; LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Setup Center Access")); var serviceImpl = new OIBServiceImpl(_adapterControl, messageWriter); _eventHandler.serviceImpl = serviceImpl; #region Check Setup Center Version and that the configured line is also configured in setup center. var stationFullPaths = new List(); serviceImpl.configuredLineFullPath = LineFullPath; serviceImpl.firstMachineInLine = firstMachineInLine; serviceImpl.lastMachineInLine = lastMachineInLine; #endregion /// listener auf externalcontrol bauen LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("SetupCenterExternalControl")); LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Setup Center Events")); LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("SIPLACE Pro")); try { HashSet versionKeySet = new HashSet(); 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; } LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Siplace Pro")); LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Line Control")); // LogHandler.log(Constants.LOGGER, TraceEventType.Information, "connect to Line Control: " + serviceImpl.OibLineControlAccess.LineControlSession.EndpointAddress OibServiceComputerName); LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Changeover Manager")); // ab client 2.1.0.14 diesen Constructor nutzen LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("iHap Connection")); _socketAdapter = new SocketAdapter(listenPort, _adapterControl, serviceImpl); LogHandler.log(Constants.LOGGER, TraceEventType.Information, getHeadertext("Initialization completed")); } catch (Exception e) { LogHandler.log(Constants.LOGGER, TraceEventType.Critical, "Initialization failed! " + e.Message, e); } } 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 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); } private void printerCoverOpened_Click(object sender, EventArgs e) { PrinterCoverOpenedReport coverOpenedReport = new PrinterCoverOpenedReport(); coverOpenedReport.Machine = getMachinelocator(); coverOpenedReport.SetupPath = "setupPath"; _eventHandler.printerCoverOpened(coverOpenedReport); } private MachineLocator getMachinelocator() { MachineLocator machinelocator = new MachineLocator(); machinelocator.LinePath = "DekLine"; machinelocator.MachineId = "01234"; machinelocator.MachineName = "DekNeoHorizon"; machinelocator.MachineType = "DEK NeoHorizon 03 iX"; return machinelocator; } private void printerCoverClosed_Click(object sender, EventArgs e) { PrinterCoverClosedReport coverClosedReport = new PrinterCoverClosedReport(); coverClosedReport.Machine = getMachinelocator(); coverClosedReport.SetupPath = "setupPath"; _eventHandler.printerCoverClosed(coverClosedReport); } private void PrinterMaterialVerified_Click(object sender, EventArgs e) { PrinterMaterialVerifiedReport report = new PrinterMaterialVerifiedReport(); _eventHandler.printerMaterialVerified(report); } private void PrinterMaterialUnverified_Click(object sender, EventArgs e) { PrinterMaterialUnverifiedReport report = new PrinterMaterialUnverifiedReport(); _eventHandler.printerMaterialUnverified(report); } private void PrinterToolVerified_Click(object sender, EventArgs e) { PrinterToolVerifiedReport report = new PrinterToolVerifiedReport(); _eventHandler.printerToolVerified(report); } private void PrinterToolUnverified_Click(object sender, EventArgs e) { PrinterToolUnverifiedReport report = new PrinterToolUnverifiedReport(); _eventHandler.printerToolUnverified(report); } private void printerCapabilitiesChanged_Click(object sender, EventArgs e) { PrinterCapabilitiesChangedReport report = new PrinterCapabilitiesChangedReport(); _eventHandler.printerCapabilitiesChanged(report); } private void printerconsumablesUpdate_click(object sender, EventArgs e) { PrinterConsumablesUpdatedReport report = new PrinterConsumablesUpdatedReport(); _eventHandler.printerConsumablesUpdated(report); } private void printerDeviceStateChange_Click(object sender, EventArgs e) { } private void feederPlaced_Click(object sender, EventArgs e) { FeederPlacedReport args = new FeederPlacedReport(); _eventHandler.feederPlaced(args); } private void feederRemoved_click(object sender, EventArgs e) { FeederRemovedReport args = new FeederRemovedReport(); _eventHandler.feederRemoved(args); } private void tablePlaced_Click(object sender, EventArgs e) { TablePlacedReport args = new TablePlacedReport(); _eventHandler.tablePlaced(args); } private void PackquantityChanged_Click(object sender, EventArgs e) { PackagingQuantityChangedReport args = new PackagingQuantityChangedReport(); _eventHandler.packagingQuantityChanged(args); } private void loclStateChanged_Click(object sender, EventArgs e) { LockStateChangedReport args = new LockStateChangedReport(); _eventHandler.lockStateChanged(args); } private void spliceChainSplit_Click(object sender, EventArgs e) { SpliceChainSplitReport args = new SpliceChainSplitReport(); _eventHandler.spliceChainSplit(args); } private void tableRemoved_Click(object sender, EventArgs e) { TableRemovedReport args = new TableRemovedReport(); _eventHandler.tableRemoved(args); } private void button18_Click(object sender, EventArgs e) { MaterialMovedReport a = new MaterialMovedReport(); _eventHandler.materialMoved(a); } private void boardProduced_Click(object sender, EventArgs e) { // Message from text com.itac.oib.traceability.contracts.data.TraceabilityData trcData = new com.itac.oib.traceability.contracts.data.TraceabilityData(); _eventHandler.boardProduced(trcData); } private void verifyPrinterMaterial_click(object sender, EventArgs e) { VerifyPrinterMaterialRequest requestData = new VerifyPrinterMaterialRequest(); requestData.PrinterMaterial = new com.itac.oib.siplacesetupcenter.contracts.data.PrinterMaterial(); requestData.PrinterMaterial.Barcode = printerMaterialBinNumber.Text; requestData.PrinterMaterial.Machine = getMachinelocator(); requestData.PrinterMaterial.Message = ""; requestData.PrinterMaterial.Name = ""; requestData.PrinterMaterial.PrinterValidationStatus = 0; requestData.PrinterMaterial.ProductInfo = new ProductInfo(); requestData.PrinterMaterial.ProductInfo.ConveyorLane = 0; //??? requestData.PrinterMaterial.ProductInfo.DateModified = DateTime.Now; requestData.PrinterMaterial.ProductInfo.ProductId = tbMateriaProductNumber.Text; requestData.PrinterMaterial.ProductInfo.ProductName = tbMateriaProductNumber.Text; requestData.PrinterMaterial.SetupPath = "setup_here"; requestData.PrinterMaterial.VerificationItemId = "PrintMedium"; requestData.PrinterMaterial.VerificationRequired = printerMaterialVerifyRequired.Checked ? 1 : 0; VerifyPrinterMaterialResponse response = _eventHandler.verifyPrinterMaterial(requestData); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(requestData); v.Append(serializer.serialize(response)); DekExtControlResult.Text = v.ToString(); } private void verifyPrinterTool_Click(object sender, EventArgs e) { VerifyPrinterToolRequest requestData = new VerifyPrinterToolRequest(); requestData.PrinterTool = new com.itac.oib.siplacesetupcenter.contracts.data.PrinterTool(); requestData.PrinterTool.Machine = getMachinelocator(); requestData.PrinterTool.Barcode = tbToolIdentification.Text; requestData.PrinterTool.Message = ""; requestData.PrinterTool.Name = ""; requestData.PrinterTool.PrinterValidationStatus = 0; requestData.PrinterTool.ProductInfo = new ProductInfo(); requestData.PrinterTool.ProductInfo.ConveyorLane = 1; requestData.PrinterTool.ProductInfo.DateModified = DateTime.Now; requestData.PrinterTool.ProductInfo.ProductId = tbToolPartNumber.Text; requestData.PrinterTool.ProductInfo.ProductName = tbToolPartNumber.Text; requestData.PrinterTool.SetupPath = "setup_here"; requestData.PrinterTool.VerificationItemId = "Screen"; requestData.PrinterTool.VerificationRequired = toolVerify.Checked ? 1 : 0; VerifyPrinterToolResponse response = _eventHandler.verifyPrinterTool(requestData); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(requestData); v.Append(serializer.serialize(response)); DekExtControlResult.Text = v.ToString(); } private void button29_Click(object sender, EventArgs e) { com.itac.oib.linecontrol.contracts.data.VerifyPcbForAutoProgramDownloadRequest k = new com.itac.oib.linecontrol.contracts.data.VerifyPcbForAutoProgramDownloadRequest(); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(k); var x = _eventHandler.verifyPcbForAutoProgramDownload(k); v.Append(serializer.serialize(x)); mesInterceptorText.Text = v.ToString(); } private void button30_Click(object sender, EventArgs e) { com.itac.oib.linecontrol.contracts.data.VerifyRecipeActivationOnDekPrinterRequest k = new com.itac.oib.linecontrol.contracts.data.VerifyRecipeActivationOnDekPrinterRequest(); // set Values k.DeviceLocator = new DeviceLocator(); k.DeviceLocator.LineName = "DekLine"; k.DeviceLocator.MachineId = "0"; k.DeviceLocator.MachineName = "DekNeoHorizon"; k.DeviceLocator.MachineType = "DEK NeoHorizon 03 iX"; k.DekPrinterRecipeVerificationData = new DekPrinterRecipeVerificationData(); k.DekPrinterRecipeVerificationData.ConveyorLane = 0; k.DekPrinterRecipeVerificationData.DateModified = DateTime.Now.ToString(); k.DekPrinterRecipeVerificationData.ProductId = "product"; k.DekPrinterRecipeVerificationData.ProductName = "SXCPP_TESTA"; ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(k); var x = _eventHandler.verifyRecipeActivationOnDekPrinter(k); v.Append(serializer.serialize(x)); mesInterceptorText.Text = v.ToString(); } private void button31_Click(object sender, EventArgs e) { com.itac.oib.linecontrol.contracts.data.VerifyRecipeDownloadRequest k = new com.itac.oib.linecontrol.contracts.data.VerifyRecipeDownloadRequest(); k.LineName = "LineName"; k.DownloadVerificationData = new DownloadVerificationData[1]; k.DownloadVerificationData[0] = new DownloadVerificationData(); k.DownloadVerificationData[0].Lane = 1; k.DownloadVerificationData[0].OrderId = "dekOrderNo"; k.DownloadVerificationData[0].ProductionSchedule = "ProductionSchedule"; k.DownloadVerificationData[0].ProductionScheduleElementId = "-1"; k.DownloadVerificationData[0].Recipe = "Recipe"; ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(k); var x = _eventHandler.verifyRecipeDownload(k); v.Append(serializer.serialize(x)); mesInterceptorText.Text = v.ToString(); } private void button32_Click(object sender, EventArgs e) { com.itac.oib.linecontrol.contracts.data.VerifyRecipeForAutoProgramDownloadRequest k = new com.itac.oib.linecontrol.contracts.data.VerifyRecipeForAutoProgramDownloadRequest(); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(k); var x = _eventHandler.verifyRecipeForAutoProgramDownload(k); v.Append(serializer.serialize(x)); mesInterceptorText.Text = v.ToString(); } private void button33_Click(object sender, EventArgs e) { com.itac.oib.linecontrol.contracts.data.VerifyRecipeForAutoProgramDownloadRequest k = new com.itac.oib.linecontrol.contracts.data.VerifyRecipeForAutoProgramDownloadRequest(); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(k); var x = _eventHandler.verifyStartAutoProgramDownload(k); v.Append(serializer.serialize(x)); mesInterceptorText.Text = v.ToString(); } private void printerTraceData_Click(object sender, EventArgs e) { // Message from text com.itac.oib.traceability.contracts.data.TraceabilityData trcData = new com.itac.oib.traceability.contracts.data.TraceabilityData(); trcData.Line = getMachinelocator().LinePath; trcData.Station = getMachinelocator().MachineName; trcData.Lane = ConveyorLanes.RIGHT.ToString(); trcData.PrePlacement = new PrePlacement(); PrinterData printerData = new PrinterData(); trcData.PrePlacement.Printers = new PrinterData[] { printerData }; printerData.BoardsSinceLastClean = 4; printerData.BoardsSincePasteReplenish = 3; printerData.BoardState = 0; printerData.Conditions = new PrinterEnvironmentalConditions(); printerData.Conditions.Humidity = 45.5; printerData.Conditions.Temperature = 22.6; printerData.DateTime = DateTime.Now; printerData.IdleTime = 14.5; printerData.Individual = new PrinterBoardIndividual(); printerData.Individual.BatchID = "batch"; printerData.Individual.BoardBarcode = "serial"; printerData.Individual.BoardNo = 1; printerData.Individual.BoardWhisperGuid = "whisperGuid"; printerData.MachineID = ""; com.itac.oib.traceability.contracts.data.PrinterMaterial printerMaterial = new com.itac.oib.traceability.contracts.data.PrinterMaterial(); printerData.Materials = new com.itac.oib.traceability.contracts.data.PrinterMaterial[] { printerMaterial }; // Paste... printerMaterial.Barcode = "GutePaste"; printerMaterial.Name = "Paste1"; printerMaterial.VerificationItemId = "PRINT_MEDIUM"; printerData.OperatorID = "operator"; printerData.PostSPCData = new PrinterPostSPCData(); printerData.PreSPCData = new PrinterPreSPCData(); printerData.PrintDirection = 0; printerData.ProcessData = new PrinterPrintProcess(); printerData.Recipe = new PrinterRecipe(); printerData.SqueegeePrintDistance = 4; com.itac.oib.traceability.contracts.data.PrinterTool printerTool = new com.itac.oib.traceability.contracts.data.PrinterTool(); com.itac.oib.traceability.contracts.data.PrinterTool printerTool2 = new com.itac.oib.traceability.contracts.data.PrinterTool(); printerData.Tools = new com.itac.oib.traceability.contracts.data.PrinterTool[] { printerTool, printerTool2 }; printerTool.Barcode = "SiebSXCPPTestA2"; printerTool.Name = "Sieb"; printerTool.VerificationItemId = "SCREEN"; printerTool2.Barcode = "RakelSxCppTestA"; printerTool2.Name = "Rakel"; printerTool2.VerificationItemId = "SQUEEGEE"; switch (cbTrace.SelectedIndex) { case 1: trcData.PrePlacement.Printers = new PrinterData[] { }; break; case 2: trcData.PrePlacement.Printers[0].MachineID = null; break; } BoardProducedResponse response = _eventHandler.boardProduced(trcData); ItacXmlSerializer serializer = new ItacXmlSerializer(); StringBuilder v = serializer.serialize(trcData); v.Append("\n"); v.Append(serializer.serialize(response)); traceResponse.Text = v.ToString(); } private void button34_Click(object sender, EventArgs e) { ConfirmationReceivedRequest confirmationReceivedRequest = new ConfirmationReceivedRequest(); confirmationReceivedRequest.Answer = new Answer(); confirmationReceivedRequest.Answer.AnswerText = "200002 | Top | SXCPPTestA | LEITERPLATTE REFLOW-GR Einseitig"; confirmationReceivedRequest.SubAnswer = new SubAnswer(); confirmationReceivedRequest.SubAnswer.SubAnswerText = "DekLine:DekNeoHorizon:BOTH:product"; _eventHandler.confirmationReceivedEvent(confirmationReceivedRequest); } private void button35_Click(object sender, EventArgs e) { StationEventComposite sec = new StationEventComposite(); sec.BoardNumber = 2; // sec.completionStatusType = CompletionStatusType.MESSAGECOMPLETE; sec.Conveyor = ConveyorType.LEFT; sec.FactoryLayoutPath = "factLayPath"; // sec.gantryStates = null; // sec.processingLocationStates = null; sec.Station = new Station(); sec.Station.ComputerAddress = "localhost"; sec.Station.FullPath = "fullPath"; sec.Station.LineFullPath = "lineFullPath"; sec.Station.LineName = "lineName"; sec.Station.Name = "DekHorizon"; sec.StationTime = DateTime.Now; sec.StateTransitions = new StateTransition[] { new StateTransition() }; _eventHandler.stationEventReceived(sec); } private void button36_Click(object sender, EventArgs e) { com.itac.oib.client.customextensions.VirtualInkspotHandlerBoardRequest evt = new com.itac.oib.client.customextensions.VirtualInkspotHandlerBoardRequest(); com.itac.oib.boardgatekeeper.contracts.data.BoardRequestData brd = new com.itac.oib.boardgatekeeper.contracts.data.BoardRequestData(); brd.Board = new com.itac.oib.boardgatekeeper.contracts.data.BoardData(); brd.Board.Barcode = "SMT004578"; brd.Board.BoardTime = DateTime.Now; evt.RecipeFullPath = "system\\SXCPP_TESTA-TOP"; evt.BoardRequestData = brd; _eventHandler.virtualInkspotBoardRequest(evt); } private void button22_Click(object sender, EventArgs e) { PackagingUnitCreatedReport pucr = new PackagingUnitCreatedReport(); pucr.FactoryLocation = ""; pucr.TimeStamp = DateTime.Now; PackagingUnitManagementData pumd = new PackagingUnitManagementData(); pumd.Date = DateTime.Now; pumd.Source = 2; pumd.PackagingUnit = new com.itac.oib.siplacesetupcenter.contracts.data.PackagingUnit(); pucr.PackagingUnitManagementDataList = new PackagingUnitManagementData[] { pumd }; _eventHandler.packagingUnitCreated(pucr); } } }