Exemplo n.º 1
0
        // Convert XML Document to a IJPMessage
        public IJPMessage BuildMessage()
        {
            IJPMessage m       = null;
            bool       success = true;

            // Need a XML Document to continue
            if (xmlDoc == null)
            {
                return(m);
            }
            try {
                m = new IJPMessage();

                XmlNode prnt = xmlDoc.SelectSingleNode("Label/Printer");
                if (success && prnt != null)
                {
                    success = LoadPrinterSettings(m, prnt);       // Send printer wide settings
                }

                XmlNode msg = xmlDoc.SelectSingleNode("Label/Message");
                if (success && msg != null)
                {
                    m.Nickname = GetXmlAttr(msg, "Name");
                    success    = AllocateRowsColumns(m, msg.ChildNodes); // Allocate rows and columns
                }

                // Send it to the printer (Maybe)
                if (ijp != null)
                {
                    ijp.SetMessage(m);
                }
            } catch (Exception e1) {
                EventArgs e = new EventArgs();
                Log(this, $"XML To Msg Failed == {e1}");
                success = false;
            } finally {
            }

            return(m);
        }
Exemplo n.º 2
0
        // 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); }));
            }
        }