Esempio n. 1
0
        public Processor(string ApplicationId, string password, IProcessingCallback proc)
        {
            this.Processing = proc;
            Processing.ReportMessage("Starting Receipt processing!");

            restClient = new RestServiceClient();
            restClient.Proxy.Credentials = CredentialCache.DefaultCredentials;

            //!!! Please provide your application id and password in Config.txt
            // To create an application and obtain a password,
            // register at http://cloud.ocrsdk.com/Account/Register
            // More info on getting your application id and password at
            // http://ocrsdk.com/documentation/faq/#faq3

            // Name of application you created
            restClient.ApplicationId = ApplicationId;
            // Password should be sent to your e-mail after application was created
            restClient.Password = password;

            // Display hint to provide credentials
            if (String.IsNullOrEmpty(restClient.ApplicationId) ||
                String.IsNullOrEmpty(restClient.Password))
            {
                Processing.ReportError("Please provide access credentials to Cloud OCR SDK service!");
                throw new Exception("Please provide access credentials to Cloud OCR SDK service!");
            }

            Console.WriteLine(String.Format("Application id: {0}\n", restClient.ApplicationId));
        }
Esempio n. 2
0
        public Export(IDocument document, IProcessingCallback callback)
        {
            if (callback != null)
            {
                log = callback;
            }
            else
            {
                throw new ArgumentNullException("callback", "The IProcessingCallback can not be empty.");
            }

            if (document != null)
            {
                doc = document;
            }
            else
            {
                log.ReportError("The IDocument can not be empty.");
                throw new ArgumentNullException("document", "The IDocument can not be empty.");
            }
        }
Esempio n. 3
0
        public Receipt(string data, IProcessingCallback pc)
        {
            callback = pc;

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(data);

            if (doc.DocumentElement.ChildNodes.Count > 1)
            {
                callback.ReportError("Only one receipt per image is supported");
                throw new Exception("Only one receipt per image is supported");
            }
            foreach (XmlNode node in doc.DocumentElement.ChildNodes[0].ChildNodes)
            {
                if (node.Name == "vendor")
                {
                    foreach (XmlNode vendorNode in node.ChildNodes)
                    {
                        if (vendorNode.Name == "name")
                        {
                            // classifiedValue has more priority
                            if (String.IsNullOrEmpty(vendorNode["classifiedValue"].InnerText))
                            {
                                XmlNode vendorNameNode = vendorNode["recognizedValue"];
                                this.Vendor = vendorNameNode["text"].InnerText;
                            }
                            else
                            {
                                this.Vendor = vendorNode["classifiedValue"].InnerText;
                            }
                        }
                        else if (vendorNode.Name == "address")
                        {
                            //addressLabel.Text = vendorNode["text"].InnerText.Replace("\n", " ");
                        }
                        else if (vendorNode.Name == "phone")
                        {
                            //phoneFaxLabel.Text = vendorNode["normalizedValue"].InnerText;
                        }
                        else if (vendorNode.Name == "purchaseType")
                        {
                            //purchaseTypeLabel.Text = vendorNode.InnerText;
                        }
                    }
                }
                else if (node.Name == "date")
                {
                    this.Date = node["normalizedValue"].InnerText;
                }
                else if (node.Name == "time")
                {
                    this.Date += " / " + node["normalizedValue"].InnerText;
                }
                else if (node.Name == "subTotal")
                {
                    //subtotalLabel.Text = node["normalizedValue"].InnerText;
                }
                else if (node.Name == "total")
                {
                    this.Total = node["normalizedValue"].InnerText;
                }
                else if (node.Name == "tax")
                {
                    if (node.Attributes["total"].Value == "true")
                    {
                        this.TotalTax = node["normalizedValue"].InnerText;
                    }
                }
                else if (node.Name == "payment")
                {
                    this.Payment = node.Attributes["type"].InnerText;
                }
            }
        }