Beispiel #1
0
        /// <summary>
        /// repeatedly check job status until the job is complete - failed or not.
        /// </summary>
        public static void PollForJobCompletion(BidiSplWrap bidiSpl, int printerJobID)
        {
            const int pollSleepMilliseconds = 2000;

            while (true)
            {
                string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES);
                PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

                if ((0 != printerStatusValues._errorCode) && (printerJobID == printerStatusValues._printerJobID))
                {
                    string message = string.Format("{0} severity: {1}", printerStatusValues._errorString, printerStatusValues._errorSeverity);
                    throw new BidiException(message, printerStatusValues._printerJobID, printerStatusValues._errorCode);
                }

                string          jobStatusRequest = strings.JOB_STATUS_XML;
                string          jobInfoXML       = string.Format(jobStatusRequest, printerJobID);
                string          jobStatusXML     = bidiSpl.GetPrinterData(strings.JOB_STATUS, jobInfoXML);
                JobStatusValues jobStatusValues  = Util.ParseJobStatusXML(jobStatusXML);

                Console.WriteLine("Printer job ID: {0} {1}", printerJobID, jobStatusValues._jobState);

                if (strings.JOB_ACTIVE != jobStatusValues._jobState)
                {
                    return;
                }

                Thread.Sleep(pollSleepMilliseconds);
            }
        }
Beispiel #2
0
        public static void EncodeMagstripe(BidiSplWrap bidiSpl, bool jisRequest, String track1, String track2, String track3)
        {
            // Hardcoded XML to encode all 3 tracks in IAT mode.
            // track 1 = "TRACK1", track 2 = "1122", track 3 = "321"
            string trackDataXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                                  + "<magstripe>"
                                  + "<track number=\"1\"><base64Data>" + Convert.ToBase64String(Encoding.ASCII.GetBytes(track1)) + "</base64Data></track>"
                                  + "<track number=\"2\"><base64Data>" + Convert.ToBase64String(Encoding.ASCII.GetBytes(track2)) + "</base64Data></track>"
                                  + "<track number=\"3\"><base64Data>" + Convert.ToBase64String(Encoding.ASCII.GetBytes(track3)) + "</base64Data></track>"
                                  + "</magstripe>";

            if (jisRequest)
            {
                // JIS only allows track 3 = "321"
                //trackDataXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                //+ "<magstripe>"
                //+ "<track number=\"1\"><base64Data></base64Data></track>"
                //+ "<track number=\"2\"><base64Data></base64Data></track>"
                //+ "<track number=\"3\"><base64Data>MzIx</base64Data></track>"
                //+ "</magstripe>";
            }

            // replace schema string MAGSTRIPE_ENCODE to MAGSTRIPE_ENCODE_FRONT for front side encode
            string printerStatusXML = bidiSpl.SetPrinterData(strings.MAGSTRIPE_ENCODE, trackDataXML);
            PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

            if (0 != printerStatusValues._errorCode)
            {
                throw new BidiException(printerStatusValues._errorString, printerStatusValues._printerJobID, printerStatusValues._errorCode);
            }

            bidiSpl.SetPrinterData(strings.ENDJOB);
        }
Beispiel #3
0
        public static String[] ReadMagstripe(BidiSplWrap bidiSpl, bool jisRequest)
        {
            String[] magData = new String[3];
            // replace schema string MAGSTRIPE_READ to MAGSTRIPE_READ_FRONT for front side read
            string printerStatusXML = bidiSpl.GetPrinterData(strings.MAGSTRIPE_READ);

            PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

            if (0 == printerStatusValues._errorCode)
            {
                // Console.WriteLine("Magstripe data read successfully; printer job id: " + printerStatusValues._printerJobID);



                string track1 = "";
                string track2 = "";
                string track3 = "";

                Util.ParseMagstripeStrings(printerStatusXML, ref track1, ref track2, ref track3, jisRequest);

                bidiSpl.SetPrinterData(strings.ENDJOB);
                if (track1.Length != 0)
                {
                    // Convert the Base64 UUEncoded output.
                    byte[] binaryData = System.Convert.FromBase64String(track1);
                    string str        = System.Text.Encoding.UTF8.GetString(binaryData);
                    magData[0] = str;
                }

                if (track2.Length != 0)
                {
                    // Convert the Base64 UUEncoded output.
                    byte[] binaryData = System.Convert.FromBase64String(track2);
                    string str        = System.Text.Encoding.UTF8.GetString(binaryData);
                    magData[1] = str;
                }

                if (track3.Length != 0)
                {
                    // Convert the Base64 UUEncoded output.
                    byte[] binaryData = System.Convert.FromBase64String(track3);
                    string str        = System.Text.Encoding.UTF8.GetString(binaryData);
                    magData[2] = str;
                }
            }
            else
            {
                throw new BidiException(printerStatusValues._errorString, printerStatusValues._printerJobID, printerStatusValues._errorCode);
            }

            return(magData);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// Issue an IBidi StartJob with xml markup to start an IBidi print job.
        ///
        /// We do this to have the printer check for supplies, or, just to obtain the
        /// printerJobID for job completion polling later.
        ///
        /// If the printer is out of supplies, throw an exception.
        ///
        /// </summary>
        public static int StartJob(
            BidiSplWrap bidiSpl,
            bool checkSupplies,
            string hopperID)
        {
            const int pollSleepMilliseconds = 2000;

            int printerJobID = 0;

            do
            {
                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);

                int checkPrintRibbon    = (printerOptionsValues._printHead == "Installed") ? 1 : 0;
                int checkEmbossSupplies = printerOptionsValues._moduleEmbosser == "None" ? 0 : 1;

                string startJobXml = string.Format(
                    strings.STARTJOB_XML,
                    hopperID,
                    checkPrintRibbon,
                    checkEmbossSupplies);

                string printerStatusXML = bidiSpl.SetPrinterData(strings.STARTJOB, startJobXml);
                PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

                if (506 == printerStatusValues._errorCode)
                {
                    // Printer cannot accept another job as it is busy. Try again.
                    Console.WriteLine("StartJob(): {0} Trying again.", printerStatusValues._errorString);

                    // let the current card process in the printer:
                    Thread.Sleep(pollSleepMilliseconds);
                }
                else if (0 != printerStatusValues._errorCode)
                {
                    var message = string.Format("StartJob(): {0} {1}",
                                                printerStatusValues._errorCode,
                                                printerStatusValues._errorString);
                    throw new BidiException(message, printerStatusValues._printerJobID, printerStatusValues._errorCode);
                }
                else
                {
                    Console.WriteLine("Printer job ID: {0} started.", printerStatusValues._printerJobID);
                    printerJobID = printerStatusValues._printerJobID;
                }
            } while (0 == printerJobID);

            return(printerJobID);
        }
Beispiel #5
0
        /// <summary>
        /// sample xml printer status xml:
        ///
        ///     <!--Printer status xml file.-->
        ///     <PrinterStatus>
        ///         <ClientID>fellmadwin7x64_{8CB9F232-7136-42BC-B0FA-EF7D734EAEAD}</ClientID>
        ///         <DataFromPrinter><![CDATA[  ]]></DataFromPrinter>
        ///         <ErrorCode>0</ErrorCode>
        ///         <ErrorSeverity>0</ErrorSeverity>
        ///         <ErrorString></ErrorString>
        ///         <PrinterJobID>792</PrinterJobID>
        ///         <WindowsJobID>0</WindowsJobID>
        ///     </PrinterStatus>
        ///
        /// </summary>
        public static PrinterStatusValues ParsePrinterStatusXML(string printerStatusXML)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(printerStatusXML);

            PrinterStatusValues printerStatusValues = new PrinterStatusValues();

            printerStatusValues._printerJobID    = IntFromXml(doc, "PrinterStatus/PrinterJobID");
            printerStatusValues._clientID        = StringFromXml(doc, "PrinterStatus/ClientID");
            printerStatusValues._dataFromPrinter = StringFromXml(doc, "PrinterStatus/DataFromPrinter");
            printerStatusValues._errorCode       = IntFromXml(doc, "PrinterStatus/ErrorCode");
            printerStatusValues._errorSeverity   = IntFromXml(doc, "PrinterStatus/ErrorSeverity");
            printerStatusValues._errorString     = StringFromXml(doc, "PrinterStatus/ErrorString");
            printerStatusValues._windowsJobID    = IntFromXml(doc, "PrinterStatus/WindowsJobID");

            return(printerStatusValues);
        }