Ejemplo n.º 1
0
        /// <summary>
        /// Upload a file to service synchronously and start processing
        /// </summary>
        /// <param name="filePath">Path to an image to process</param>
        /// <param name="settings">Language and output format</param>
        /// <returns>Id of the task. Check task status to see if you have enough units to process the task</returns>
        /// <exception cref="ProcessingErrorException">thrown when something goes wrong</exception>
        public OcrSdkTask ProcessImage(string filePath, ProcessingSettings settings)
        {
            string url = String.Format("{0}processReceipt?{1}", ServerUrl, settings.AsUrlParams);

            try
            {
                // Build post request
                WebRequest request = createPostRequest(url);
                writeFileToRequest(filePath, request);

                XDocument  response = performRequest(request);
                OcrSdkTask task     = ServerXml.GetTaskStatus(response);

                return(task);
            }
            catch (System.Net.WebException e)
            {
                String friendlyMessage = retrieveFriendlyMessage(e);
                if (friendlyMessage != null)
                {
                    throw new ProcessingErrorException(friendlyMessage, e);
                }
                throw new ProcessingErrorException("Cannot upload file", e);
            }
        }
Ejemplo n.º 2
0
        public OcrSdkTask GetTaskStatus(TaskId task)
        {
            string url = String.Format("{0}getTaskStatus?taskId={1}", ServerUrl,
                                       Uri.EscapeDataString(task.ToString()));

            WebRequest request    = createGetRequest(url);
            XDocument  response   = performRequest(request);
            OcrSdkTask serverTask = ServerXml.GetTaskStatus(response);

            return(serverTask);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Upload image of a multipage document to server.
        /// </summary>
        /// <param name="filePath">Path to an image to process</param>
        /// <param name="taskToAddFile">Id of multipage document. If null, a new document is created</param>
        /// <returns>Id of document to which image was added</returns>
        public OcrSdkTask UploadAndAddFileToTask(string filePath, TaskId taskToAddFile)
        {
            string url = String.Format("{0}submitImage", ServerUrl);

            if (taskToAddFile != null)
            {
                url = url + "?taskId=" + Uri.EscapeDataString(taskToAddFile.ToString());
            }

            // Build post request
            WebRequest request = createPostRequest(url);

            writeFileToRequest(filePath, request);

            XDocument  response = performRequest(request);
            OcrSdkTask task     = ServerXml.GetTaskStatus(response);

            return(task);
        }