示例#1
0
        public override bool StartCard()
        {
            frontBitmap = null;
            backBitmap  = null;
            PrinterStatus ps = GetPrinterStatus();

            if (ps != PrinterStatus.Ready)
            {
                throw new Exception($"Printer {printerName} not ready");
            }
            JobId = GetNewJobID();
            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, Start Job {JobId}, Hopper {HopperID}");
            var startJob2In = new StartJob2Input
            {
                client        = ClientId,
                jobId         = JobId,
                settingsGroup = string.Empty,
                exceptionJob  = false
            };

            dpcl2Client.StartJob3(startJob2In);

            Pick((HopperID > 0) ? (uint)HopperID : (uint)1);
            //WaitForActionCompletion();
            return(JobId > 0);
        }
示例#2
0
 public override bool StopJob()
 {
     if (JobId > 0)
     {
         WaitForCompletion();
     }
     dpcl2Client?.Close();
     LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, Stop Job {JobId}");
     return(true);
 }
示例#3
0
 public override bool StartJob()
 {
     LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, Https = {Https}, Dpcl starting");
     try
     {
         dpcl2Client = CreateDPCL2Client(printerName, !Https, false, 50);
         GetPrinterStatus();
     }
     catch (EndpointNotFoundException ex)
     {
         return(true);
     }
     catch (Exception e)
     {
         SecurityProtocolTypeCurrent = SecurityProtocolType.Tls;
         LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName} trying tls protocol");
         dpcl2Client = CreateDPCL2Client(printerName, !Https, false, 50);
     }
     //LogClass.WriteToLog($"Dpcl: CardId = {cardId}, Printer = {printerName} connected");
     //проверяем что устройство доступно
     //return (GetPrinterStatus() == PrinterStatus.Ready);
     return(true);
 }
示例#4
0
        private void SubmitDataSigma(byte[] data)
        {
            StringBuilder req = new StringBuilder();

            req.Append(@"--qwertyqwerty" + Environment.NewLine);
            req.Append("Content-Type: application/soap+xml; charset=utf-8; type=\"application/soap+xml\"" + Environment.NewLine);
            req.Append(@"Content-Transfer-Encoding: binary" + Environment.NewLine);
            req.Append(@"Content-ID: <SOAP-ENV:Envelope>" + Environment.NewLine);
            req.Append(Environment.NewLine);
            req.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine);

            req.Append("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:SOAP-ENC=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:DPCLEmboss=\"urn:dpcl:emboss:2011-06-03\" xmlns:DPCLWheel=\"urn:dpcl:wheel:2011-06-03\" xmlns:DPCLMagStripe=\"urn:dpcl:magstripe:2010-01-19\" xmlns:DPCLSensors=\"urn:dpcl:sensors:2010-01-19\" xmlns:DPCLSettings=\"urn:dpcl:settings:2010-01-19\" xmlns:DPCLUpdate=\"urn:dpcl:update:2011-10-19\" xmlns:DPCLNetworkAccessList=\"urn:dpcl:nal:2012-05-30\" xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" xmlns:xenc=\"http://www.w3.org/2001/04/xmlenc#\" xmlns:xmime5=\"http://www.w3.org/2005/05/xmlmime\" xmlns:DPCL=\"urn:dpcl:wsdl:2010-01-19\" xmlns:DPCL2=\"urn:dpcl:wsdl:2011-09-02\"><SOAP-ENV:Body><DPCL2:SubmitData><SubmitDataInput><client>" + ClientId + "</client><jobId>" + JobId + "</jobId><actionId>" + LastAction + "</actionId><dataId>1</dataId><attachment xmime5:contentType=\"application/vnd.dpcl.emboss+xml\"><xop:Include href=\"cid:id6\"/></attachment><moreData>false</moreData></SubmitDataInput></DPCL2:SubmitData></SOAP-ENV:Body></SOAP-ENV:Envelope>" + Environment.NewLine);
            req.Append(Environment.NewLine);
            req.Append(@"--qwertyqwerty" + Environment.NewLine);
            req.Append(@"Content-Type: application/vnd.dpcl.emboss+xml" + Environment.NewLine);
            req.Append(@"Content-Transfer-Encoding: binary" + Environment.NewLine);
            req.Append(@"Content-ID: <id6>" + Environment.NewLine + Environment.NewLine);

            byte[] header = Encoding.UTF8.GetBytes(req.ToString());
            //Byte[] data1 = ASCIIEncoding.ASCII.GetBytes(req.ToString());
            //image

            // string foobar = @"--==filiMb0Hl4qGJpC5624Cjxmfapt+igWS0/5m/JextOjsohegdLCD/BHEPUFl==" + Environment.NewLine;
            string foobar = Environment.NewLine + @"--qwertyqwerty--";

            byte[] footer = Encoding.UTF8.GetBytes(foobar);
            //Byte[] data3 = Encoding.ASCII.GetBytes(foobar);

            byte[] dataToSend = new byte[header.Length + data.Length + footer.Length];
            Buffer.BlockCopy(header, 0, dataToSend, 0, header.Length);
            Buffer.BlockCopy(data, 0, dataToSend, header.Length, data.Length);
            Buffer.BlockCopy(footer, 0, dataToSend, header.Length + data.Length, footer.Length);

            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, SubmitDataSigma.Length = {data?.Length}");
            SendHttp(dataToSend);
        }
示例#5
0
        private void SubmitData(string contentType, byte[] data, Parameter[] parameters)
        {
            var submitDataIn = new SubmitDataInput
            {
                client   = ClientId,
                jobId    = JobId,
                actionId = LastAction,
                dataId   = 1
            };

            if (parameters != null)
            {
                submitDataIn.parameter = parameters;
            }

            var attachment = new Attachment();

            submitDataIn.attachment = attachment;
            attachment.contentType  = contentType;
            attachment.Item         = data;

            dpcl2Client.SubmitDataAsync(submitDataIn);
            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, SubmitData.Length = {data?.Length}");
        }
示例#6
0
        public void Start()
        {
            LogClass.ToConsole = true;
            _startDirectory    = System.AppDomain.CurrentDomain.BaseDirectory;
            _exeName           = System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName.Replace(".exe", "").Replace(".vshost", "");
            _xmlSettings       = new XmlDocument();
            try
            {
                _xmlSettings.Load($"{_startDirectory}{_exeName}.xml");
            }
            catch (Exception exc)
            {
                LogClass.WriteToLog($"Ошибка загрузки настроек: {exc.Message}");
                return;
            }
            _inDirectory = XmlClass.GetTag(_xmlSettings, "InputDirectory", null);
            _inMask      = XmlClass.GetAttribute(_xmlSettings, "InputDirectory", "Mask", "*", null);

            _xmlProducts = new XmlDocument();
            try
            {
                string prods = XmlClass.GetTag(_xmlSettings, "ProductsFile", null).Replace("..\\", _startDirectory);
                if (prods.Length == 0)
                {
                    prods = $"{_startDirectory}Products.xml";
                }
                _xmlProducts.Load(prods);
                int cnt = XmlClass.GetXmlNodeCount(_xmlProducts, "", null);
                _products.Clear();
                for (int i = 0; i < cnt; i++)
                {
                    ProductClass pc = new ProductClass();
                    XmlDocument  pr = XmlClass.GetXmlNode(_xmlProducts, "", i, null);
                    pc.ProductName = XmlClass.GetAttribute(pr, "", "Name", null);
                    pc.conditions  = new List <List <Condition> >();
                    int allConditionsCnt = XmlClass.GetXmlNodeCount(pr, "Conditions", null);
                    for (int k = 0; k < allConditionsCnt; k++)
                    {
                        pc.conditions.Add(new List <Condition>());
                        XmlDocument oneConditions = XmlClass.GetXmlNode(pr, "Conditions", k, null);
                        int         conditionCnt  = XmlClass.GetXmlNodeCount(oneConditions, "Condition", null);
                        for (int j = 0; j < conditionCnt; j++)
                        {
                            XmlDocument cn = XmlClass.GetXmlNode(oneConditions, "Condition", j, null);
                            pc.conditions[k].Add(new Condition()
                            {
                                Field = XmlClass.GetAttribute(cn, "", "Field", null), Type = XmlClass.GetAttribute(cn, "", "Type", null), Value = XmlClass.GetAttribute(cn, "", "Value", null)
                            });
                        }
                    }
                    XmlDocument addon = XmlClass.GetXmlNode(pr, "AdditionalProcessing", 0, null);
                    if (addon != null)
                    {
                        pc.AdditionalXml = addon.OuterXml;
                    }
                    pc.Ignore = XmlClass.GetAttribute(pr, "", "Ignore", "false", null).ToLower() == "true";
                    _products.Add(pc);
                }
            }
            catch (Exception exc)
            {
                LogClass.WriteToLog($"Ошибка загрузки файла продуктов: {exc.Message}");
                return;
            }


            if (!Directory.Exists(_inDirectory))
            {
                LogClass.WriteToLog($"Ошибка открытия входной директории: {_inDirectory}");
                return;
            }

            _mainTimer = new Timer {
                Interval = 5000, AutoReset = true
            };
            _mainTimer.Elapsed += _mainTimer_Elapsed;
        }
示例#7
0
        /// <summary>
        /// Waits for the job completion.
        /// </summary>
        private void WaitForCompletion()
        {
            var input = new WaitForStatus2Input
            {
                maxSeconds             = 2,
                matchConditionClient   = ClientId,
                matchConditionJobId    = JobId,
                minConditionSeverity   = ConditionSeverity.Notice,
                includeConditions      = true,
                includeCounters        = false,
                includeJobQueue        = false,
                includeNetworkAdapters = false,
                includeSensors         = false,
                includeSettings        = false,
                includeSupplies        = true,
                includeTunnels         = false
            };

            uint     currentConditionMarker = 0;
            uint?    startConditionMarker   = null;
            DateTime startTime = DateTime.Now;
            int      countWait = 0;

            while (true)
            {
                if ((DateTime.Now - startTime).Seconds > 15)
                {
                    LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, WaitForCompletion, ~15 sec passed");
                    startTime = DateTime.Now;
                    countWait++;
                }
                if (countWait > 20)
                {
                    throw new Exception($"CardId = { cardId }, Printer = { printerName}, WaitForCompletion, Error = too long");
                }
                input.minConditionMarker = currentConditionMarker;
                var output = dpcl2Client.WaitForStatus2(input);
                currentConditionMarker = output.nextConditionMarker;
                if (startConditionMarker == null)
                {
                    startConditionMarker = currentConditionMarker;
                }
                //LogClass.WriteToLog($"{currentConditionMarker}");
                if (isKiosk && (currentConditionMarker - startConditionMarker) >= 6)
                {
                    SendMessage(MessageType.CompleteStep, $"dispense:{cardId}");
                }

                if (output.status.condition == null)
                {
                    continue;
                }

                foreach (var c in output.status.condition.Where(c => c.client == ClientId))
                {
                    LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, WaitForCompletion = {c.code}");
                    if ((c.code == 0) || (c.code == 1))
                    {
                        return;
                    }

                    switch (c.severity)
                    {
                    case ConditionSeverity.Notice:
                        break;

                    default:
                        //break;
                        throw new Exception(GetErrorMessage(c.code));
                    }
                }
            }
        }
示例#8
0
        private void EmbossData(List <EmbossString> emboss_strings, Boolean TopperOn)
        {
            string actionName = (isKiosk) ? "EmbCardDataKiosk" : "EmbCardData";

            //применяется ли топпирование фольгой
            if (TopperOn)
            {
                SubmitAction(actionName, new[] { new Parameter {
                                                     name = "EmbossDataSource", value = "TopCard"
                                                 } });
            }
            else
            {
                SubmitAction(actionName, null);
            }
            string emm = "";

            using (var str = new MemoryStream())
            {
                var doc = new XmlTextWriter(str, Encoding.UTF8);
                doc.WriteStartDocument();
                doc.WriteStartElement("emboss");
                doc.WriteAttributeString("xmlns", "SOAP-ENV", null, "http://www.w3.org/2003/05/soap-envelope");
                doc.WriteAttributeString("xmlns", "SOAP-ENC", null, "http://www.w3.org/2003/05/soap-encoding");
                doc.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                doc.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
                doc.WriteAttributeString("xmlns", "DPCLEmboss", null, "urn:dpcl:emboss:2010-01-19");
                doc.WriteAttributeString("xsi", "type", null, "DPCLEmboss:Emboss");
                doc.WriteAttributeString("SOAP-ENV", "encodingStyle", null, "http://www.w3.org/2003/05/soap-encoding");

                foreach (EmbossString embs in emboss_strings)
                {
                    doc.WriteStartElement("line");
                    doc.WriteAttributeString("number", emboss_strings.IndexOf(embs).ToString());
                    doc.WriteElementString("font", embs.font.ToString());
                    doc.WriteElementString("horz", embs.x.ToString());
                    doc.WriteElementString("vert", embs.y.ToString());
                    doc.WriteElementString("stringData", embs.text);
                    doc.WriteEndElement();
                    emm += $"{embs.font},{embs.x},{embs.y},{embs.text.Length} chars;";
                }
                LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, EmbossData = {emm}");

                doc.WriteEndElement();
                doc.WriteEndDocument();
                doc.Flush();

                if (deviceType == ProcardWPF.DeviceType.CE)
                {
                    SubmitData("application/vnd.dpcl.emboss+xml", str.GetBuffer());
                }
                if (deviceType == ProcardWPF.DeviceType.Sigma)
                {
                    SubmitDataSigma(str.GetBuffer());
                }

                if (isKiosk)
                {
                    SubmitAction("Dispense", null);
                }
            }
        }
示例#9
0
        /// <summary>
        /// Submits an action to the printer.
        /// </summary>
        /// <param name="action">The action name.</param>
        /// <param name="parameters">The parameters of the action.</param>
        private void SubmitAction(string action, Parameter[] parameters)
        {
            if (action.ToLower() == "magstriperead")
            {
                action = action;
            }
            var submitActionIn = new SubmitActionInput
            {
                client    = ClientId,
                jobId     = JobId,
                actionId  = ++LastAction,
                type      = action,
                parameter = parameters
            };
            //Task<SubmitActionResponse> sa = dpcl2Client.SubmitActionAsync(submitActionIn);

            //var submitActionOut = sa.Result.output;
            string logstr = $"Client {submitActionIn.client}, Job {submitActionIn.jobId}, ActionId {submitActionIn.actionId}, Type {submitActionIn.type}, Parameters [";

            for (int i = 0; i < submitActionIn.parameter?.Length; i++)
            {
                logstr += $"[{submitActionIn.parameter[i].name}: {submitActionIn.parameter[i].value}] ";
            }
            logstr = logstr.Trim() + "]";
            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, SubmitActionIn: {logstr}");

            var submitActionOut = dpcl2Client.SubmitAction(submitActionIn);

            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, SubmitActionOut: Check {submitActionOut?.checkStatus}, Success {submitActionOut?.success}");
            //var parametersStringBuilder = new StringBuilder();
            //if (parameters != null && parameters.Length > 0)
            //{
            //    parametersStringBuilder.Append('(');
            //    var isFirst = true;
            //    foreach (var p in parameters)
            //    {
            //        if (isFirst)
            //        {
            //            isFirst = false;
            //        }
            //        else
            //        {
            //            parametersStringBuilder.Append(", ");
            //        }

            //        parametersStringBuilder.Append(p.name);
            //        parametersStringBuilder.Append('=');
            //        parametersStringBuilder.Append(p.value);
            //    }

            //    parametersStringBuilder.Append(')');
            //}

            // If there is an error detected, we need to wait for the completion of the action
            if (!submitActionOut.success)
            {
                if (submitActionOut.checkStatus)
                {
                    WaitForCompletion();
                }
                else
                {
                    throw new Exception($"Printer = {printerName}, Submit action failed unexpectedly");
                }
            }
        }
示例#10
0
        public override bool PrintCard()
        {
            try
            {
                if (!String.IsNullOrEmpty(magstripe[0]) || !String.IsNullOrEmpty(magstripe[1]) ||
                    !String.IsNullOrEmpty(magstripe[2]))
                {
                    //LogClass.WriteToLog($"Encode t1: {magstripe[0]}, t2: {magstripe[1]}, t3: {magstripe[2]}");
                    if (!String.IsNullOrEmpty(magstripe[0]) && magstripe[0].ToUpper().StartsWith("B") && magstripe[0].IndexOf("^") > 0)
                    {
                        string panFromMS = magstripe[0].Substring(1, magstripe[0].IndexOf("^") - 1);
                        if (panFromMS.Length >= 16)
                        {
                            panFromMS = panFromMS.Substring(0, 6).PadRight(panFromMS.Length - 4, '*') + panFromMS.Substring(panFromMS.Length - 4);
                            LogClass.WriteToLog($"CardId = {cardId}, Printer = {printerName}, Encode mag stripe, Pan = {panFromMS}");
                        }
                    }
                    EncodeMagstripe(2, magstripe[0].ToUpper(), magstripe[1], magstripe[2]);
                }

                if (frontBitmap != null)
                {
                    if (Color)
                    {
                        SubmitAction("Color", new[] { new Parameter {
                                                          name = "PageNumber", value = "1"
                                                      }, new Parameter {
                                                          name = "PrintColorResolution", value = "300x300"
                                                      } });
                    }
                    else
                    {
                        SubmitAction("Monochrome", new[] { new Parameter {
                                                               name = "PageNumber", value = "1"
                                                           }, new Parameter {
                                                               name = "PrintMonoResolution", value = "300x300"
                                                           },
                                                           new Parameter {
                                                               name = "MonochromePanelSelect", value = "Custom1"
                                                           } });
                    }

                    //GraphicsUnit gu = GraphicsUnit.Pixel;
                    //frontBitmap.SetResolution(300, 300);
                    //frontBitmap = frontBitmap.Clone(frontBitmap.GetBounds(ref gu), PixelFormat.Format1bppIndexed);
                    frontBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    MemoryStream ms = new MemoryStream();
                    frontBitmap.Save(ms, ImageFormat.Png);
                    byte[] data = ms.ToArray();
                    ms.Close();
                    var parameters = new List <Parameter>();
                    parameters.Add(new Parameter {
                        name = "Orientation", value = "Portrait"
                    });
                    parameters.Add(new Parameter {
                        name = "ImageContent", value = "Graphics"
                    });
                    parameters.Add(new Parameter {
                        name = "XOrigin", value = "0"
                    });
                    parameters.Add(new Parameter {
                        name = "YOrigin", value = "0"
                    });
                    //File.WriteAllBytes("111.png", data);
                    SubmitData("image/png", data, parameters.ToArray());
                }
                if (backBitmap != null)
                {
                    if (Color)
                    {
                        SubmitAction("Color", new[] { new Parameter {
                                                          name = "PageNumber", value = "2"
                                                      }, new Parameter {
                                                          name = "PrintColorResolution", value = "300x300"
                                                      } });
                    }
                    else
                    {
                        SubmitAction("Monochrome", new[] { new Parameter {
                                                               name = "PageNumber", value = "2"
                                                           }, new Parameter {
                                                               name = "PrintMonoResolution", value = "300x300"
                                                           },
                                                           new Parameter {
                                                               name = "MonochromePanelSelect", value = "Custom1"
                                                           } });
                    }

                    backBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    MemoryStream ms = new MemoryStream();
                    backBitmap.Save(ms, ImageFormat.Png);
                    byte[] data = ms.ToArray();
                    ms.Close();
                    var parameters = new List <Parameter>();
                    parameters.Add(new Parameter {
                        name = "Orientation", value = "Portrait"
                    });
                    parameters.Add(new Parameter {
                        name = "ImageContent", value = "Graphics"
                    });
                    parameters.Add(new Parameter {
                        name = "XOrigin", value = "0"
                    });
                    parameters.Add(new Parameter {
                        name = "YOrigin", value = "0"
                    });
                    SubmitData("image/png", data, parameters.ToArray());
                }


                if (embossData.Count > 0)
                {
                    EmbossData(embossData, !NoTopper);
                }
                else
                {
                    Eject();
                }
            }
            catch (Exception e)
            {
                CancelJob();
                EndJob();
                throw new Exception($"Printer = {printerName}, card print error: {e.Message}");
            }
            return(true);
        }