// Main processing loop private void ProcessTasks() { while (true) { pkt = Tasks.Take(); if (pkt.Type == ReqType.Exit) { break; } parent.BeginInvoke(new EventHandler(delegate { Log(this, pkt.ToString() + " Starting!"); })); IX_EventArgs evArgs = new IX_EventArgs(pkt.Type); MsgToXml mtx = null; string indentedView = string.Empty; TreeNode treeNode = null; ObjectDumper od = null; try { switch (pkt.Type) { case ReqType.Connect: Connect(pkt); break; case ReqType.Disconnect: Disconnect(pkt); break; case ReqType.ClearMessage: message = null; break; case ReqType.NewMessage: message = new IJPMessage(); break; case ReqType.GetMessage: message = (IJPMessage)ijp.GetMessage(); break; case ReqType.GetXML: if (message != null) { mtx = new MsgToXml(); string xml = mtx.RetrieveXML(message, ijp, pkt.MessageInfo); ProcessLabel(xml, out string IndentedXML, out TreeNode tnXML); evArgs.Indented = IndentedXML; evArgs.TreeNode = tnXML; } break; case ReqType.GetXMLOnly: if (message != null) { mtx = new MsgToXml(); evArgs.Indented = mtx.RetrieveXML(message, ijp, pkt.MessageInfo); } break; case ReqType.GetObjectSettings: if (message != null) { od = new ObjectDumper(2); od.Dump(message, out indentedView, out treeNode); evArgs.Indented = indentedView; evArgs.TreeNode = treeNode; } break; case ReqType.GetDirectory: evArgs.Mi = ijp.ListMessage(pkt.Start, pkt.End); break; case ReqType.GetSettings: message = (IJPMessage)ijp.GetMessage(); break; case ReqType.SetXML: XmlToMsg xtm = new XmlToMsg(pkt.XML, ijp); message = xtm.BuildMessage(); break; case ReqType.SetComStatus: ijp.SetComPort(pkt.ComStatus); break; case ReqType.SetMessage: if (message != null) { ijp.SetMessage(message); } break; case ReqType.CallMessage: ijp.CallMessage(pkt.MessageNumber); break; case ReqType.SaveMessage: ijp.SaveMessage(pkt.MessageInfo); break; case ReqType.RenameMessage: ijp.RenameMessage(pkt.MessageNumber, pkt.MessageName); break; case ReqType.GetAlarms: evArgs.AlarmHistory = ijp.GetAlarmHistory(pkt.Start, pkt.End); break; case ReqType.GetMisc: object Misc = null; switch (pkt.SubType) { case ReqSubType.UnitInformation: Misc = ijp.GetUnitInformation(); break; case ReqSubType.OperationManagement: Misc = ijp.GetOperationManagement(); break; case ReqSubType.ServiceManagement: Misc = ijp.GetServiceManagement(); break; case ReqSubType.Status: Misc = ijp.GetStatus(); break; case ReqSubType.ComEnvironment: Misc = ijp.GetCommunicationEnvironmentSetup(); break; case ReqSubType.DispEnvironment: Misc = ijp.GetDisplayEnvironmentSetup(); break; case ReqSubType.CircControl: Misc = ijp.GetCirculationControl(); break; case ReqSubType.SoftwareVersion: Misc = ijp.GetSoftwareVersion(); break; default: break; } od = new ObjectDumper(2); od.Dump(Misc, out indentedView, out treeNode); evArgs.Indented = indentedView; evArgs.TreeNode = treeNode; evArgs.SubType = pkt.SubType; break; } } catch (Exception e) { parent.BeginInvoke(new EventHandler(delegate { Log(this, $"IJP_XML: {e.Message} \n{e.StackTrace}"); })); } parent.BeginInvoke(new EventHandler(delegate { Complete(this, evArgs); })); } }