コード例 #1
0
 private void onUploadFileCompleted(object sender, UploadCompletedEventArgs e)
 {
     if (UploadFileCompleted != null)
     {
         UploadFileCompleted(sender, e);
     }
 }
コード例 #2
0
 private void UploadCompleted(object sender, UploadCompletedEventArgs e)
 {
     Dispatcher.BeginInvoke(() =>
    {
        displayMessage("Upload completed. Processing..");
    }
    );
 }
コード例 #3
0
        private void processFieldWorker(string filePath, IProcessingSettings settings,
                                        AsyncOperation asyncOp)
        {
            Exception e = null;

            Task task = new Task();

            try
            {
                if (settings is TextFieldProcessingSettings)
                {
                    task.Id = _syncClient.ProcessTextField(filePath, settings as TextFieldProcessingSettings);
                }
                else if (settings is BarcodeFieldProcessingSettings)
                {
                    task.Id = _syncClient.ProcessBarcodeField(filePath, settings as BarcodeFieldProcessingSettings);
                }
                else if (settings is CheckmarkFieldProcessingSettings)
                {
                    task.Id = _syncClient.ProcessCheckmarkField(filePath, settings as CheckmarkFieldProcessingSettings);
                }
                else
                {
                    throw new ArgumentException("Invalid type of processing settings");
                }

                // Notify that upload was completed
                Task uploadedTask = new Task(task.Id, TaskStatus.Submitted);
                UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState);
                asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs);

                // Wait until task finishes
                startTaskMonitorIfNecessary();

                _taskList.AddTask(task);
                task = waitUntilTaskFinishes(task);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            lock (processJobs.SyncRoot)
            {
                processJobs.Remove(asyncOp.UserSuppliedState);
            }

            bool canceled = false;

            // Package the results of the operation in EventArgs
            TaskEventArgs ev = new TaskEventArgs(task, e, canceled, asyncOp.UserSuppliedState);

            // End the task. The asyncOp object is responsible
            // for marshaling the call.
            asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, ev);
        }
コード例 #4
0
        // This method performs the actual prime number computation.
        // It is executed on the worker thread.
        private void processFileWorker(string filePath, IProcessingSettings settings,
                                       AsyncOperation asyncOp)
        {
            Exception e = null;

            // Check that the task is still active.
            // The operation may have been canceled before
            // the thread was scheduled.

            Task task = null;

            try
            {
                if (settings is ProcessingSettings)
                {
                    task = _syncClient.ProcessImage(filePath, settings as ProcessingSettings);
                }
                else if (settings is BusCardProcessingSettings)
                {
                    task = _syncClient.ProcessBusinessCard(filePath, settings as BusCardProcessingSettings);
                }
                else if (settings is CaptureDataSettings)
                {
                    string templateName = (settings as CaptureDataSettings).TemplateName;
                    task = _syncClient.CaptureData(filePath, templateName);
                }

                // Notify subscriber that upload completed
                Task uploadedTask = new Task(task.Id, TaskStatus.Submitted);
                UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState);
                asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs);

                startTaskMonitorIfNecessary();

                _taskList.AddTask(task);

                task = waitUntilTaskFinishes(task); // task is modified on server
            }
            catch (Exception ex)
            {
                e = ex;
            }

            processCompletionMethod(task, e, false, asyncOp);
        }
コード例 #5
0
        /// <summary>
        /// Submit and process image asynchronously.
        /// Performs callbacks:
        ///   UploadFileCompleted
        ///   TaskProcessingCompleted
        /// </summary>
        /// <param name="filePath">Path to file in isolated storage</param>
        /// <param name="settings"></param>
        /// <param name="userState"></param>
        public void ProcessImageAsync(string filePath, ProcessingSettings settings, object userState)
        {
            BackgroundWorker w = new BackgroundWorker();

            w.DoWork += new DoWorkEventHandler((sender, e) =>
            {
                OcrSdkTask task = null;
                try
                {
                    task = _syncClient.ProcessImage(filePath, settings);
                    UploadCompletedEventArgs uploadArgs = new UploadCompletedEventArgs(task, userState);
                    onUploadFileCompleted(sender, uploadArgs);

                    // Wait until task finishes
                    while (true)
                    {
                        task = _syncClient.GetTaskStatus(task.Id);
                        if (!task.IsTaskActive())
                        {
                            break;
                        }
                        Thread.Sleep(1000);
                    }

                    if (task.Status == TaskStatus.NotEnoughCredits)
                    {
                        throw new Exception("Not enough credits to process image. Please add more pages to your application's account.");
                    }

                    TaskEventArgs taskArgs = new TaskEventArgs(task, null, false, userState);

                    onProcessingCompleted(sender, taskArgs);
                }
                catch (Exception ex)
                {
                    TaskEventArgs taskArgs = new TaskEventArgs(task, ex, false, userState);
                    onProcessingCompleted(sender, taskArgs);
                }
            }
                                               );

            w.RunWorkerAsync();
        }
コード例 #6
0
        /// <summary>
        /// Submit and process image asynchronously. 
        /// Performs callbacks:
        ///   UploadFileCompleted
        ///   TaskProcessingCompleted
        /// </summary>
        /// <param name="filePath">Path to file in isolated storage</param>
        /// <param name="settings"></param>
        /// <param name="userState"></param>
        public void ProcessImageAsync(string filePath, ProcessingSettings settings, object userState)
        {
            BackgroundWorker w = new BackgroundWorker();
            w.DoWork += new DoWorkEventHandler((sender, e) =>
                {
                    Task task = null;
                    try
                    {
                        task = _syncClient.ProcessImage(filePath, settings);
                        UploadCompletedEventArgs uploadArgs = new UploadCompletedEventArgs(task, userState);
                        onUploadFileCompleted(sender, uploadArgs);

                        // Wait until task finishes
                        while (true)
                        {
                            task = _syncClient.GetTaskStatus(task.Id);
                            if (!task.IsTaskActive())
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }

                        if (task.Status == TaskStatus.NotEnoughCredits)
                        {
                            throw new Exception("Not enough credits to process image. Please add more pages to your application's account.");
                        }

                        TaskEventArgs taskArgs = new TaskEventArgs(task, null, false, userState);

                        onProcessingCompleted(sender, taskArgs);
                    }
                    catch (Exception ex)
                    {
                        TaskEventArgs taskArgs = new TaskEventArgs(task, ex, false, userState);
                        onProcessingCompleted(sender, taskArgs);
                    }
                }
            );

            w.RunWorkerAsync();
        }
コード例 #7
0
ファイル: Window1.xaml.cs プロジェクト: peters/ocrsdk.com
        private void UploadCompleted(object sender, UploadCompletedEventArgs e)
        {
            UserTask task = e.UserState as UserTask;
            task.TaskStatus = "Processing";

            task.TaskId = e.Result.Id.ToString();
        }
コード例 #8
0
 private void onUploadFileCompleted(object sender, UploadCompletedEventArgs e)
 {
     if (UploadFileCompleted != null)
     {
         UploadFileCompleted(sender, e);
     }
 }
コード例 #9
0
        private void processFieldWorker(string filePath, IProcessingSettings settings,
            AsyncOperation asyncOp)
        {
            Exception e = null;

            Task task = new Task();
            try
            {
                if (settings is TextFieldProcessingSettings)
                {
                    task = _syncClient.ProcessTextField(filePath, settings as TextFieldProcessingSettings);
                }
                else if (settings is BarcodeFieldProcessingSettings)
                {
                    task = _syncClient.ProcessBarcodeField(filePath, settings as BarcodeFieldProcessingSettings);
                }
                else if (settings is CheckmarkFieldProcessingSettings)
                {
                    task = _syncClient.ProcessCheckmarkField(filePath, settings as CheckmarkFieldProcessingSettings);
                }
                else
                {
                    throw new ArgumentException("Invalid type of processing settings");
                }

                // Notify that upload was completed
                Task uploadedTask = new Task(task.Id, TaskStatus.Submitted);
                UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState);
                asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs);

                // Wait until task finishes
                startTaskMonitorIfNecessary();

                _taskList.AddTask(task);
                task = waitUntilTaskFinishes(task);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            lock (processJobs)
            {
                processJobs.Remove(asyncOp.UserSuppliedState);
            }

            bool canceled = false;

            // Package the results of the operation in EventArgs
            TaskEventArgs ev = new TaskEventArgs(task, e, canceled, asyncOp.UserSuppliedState);

            // End the task. The asyncOp object is responsible 
            // for marshaling the call.
            asyncOp.PostOperationCompleted(onProcessingCompleteDelegate, ev);
        }
コード例 #10
0
        // This method performs the actual file processing.
        // It is executed on the worker thread.
        private void processFileWorker(string filePath, IProcessingSettings settings,
            AsyncOperation asyncOp)
        {
            Exception e = null;

            // Check that the task is still active.
            // The operation may have been canceled before
            // the thread was scheduled.

            Task task = null;
            try
            {
                if (settings is ProcessingSettings)
                {
                    task = _syncClient.ProcessImage(filePath, settings as ProcessingSettings);
                }
                else if (settings is BusCardProcessingSettings)
                {
                    task = _syncClient.ProcessBusinessCard(filePath, settings as BusCardProcessingSettings);
                }
                else if (settings is CaptureDataSettings)
                {
                    string templateName = (settings as CaptureDataSettings).TemplateName;
                    task = _syncClient.CaptureData(filePath, templateName);
                }

                // Notify subscriber that upload completed
                Task uploadedTask = new Task(task.Id, TaskStatus.Submitted);
                UploadCompletedEventArgs uploadCompletedEventArgs = new UploadCompletedEventArgs(uploadedTask, asyncOp.UserSuppliedState);
                asyncOp.Post(onUploadCompletedDelegate, uploadCompletedEventArgs);

                startTaskMonitorIfNecessary();

                _taskList.AddTask(task);

                task = waitUntilTaskFinishes(task); // task is modified on server
            }
            catch (Exception ex)
            {
                e = ex;
            }

            processCompletionMethod(task, e, false, asyncOp);
        }
コード例 #11
0
        // This method is invoked via the AsyncOperation object,
        // so it is guaranteed to be executed on the correct thread.
        private void uploadCompleted(object operationState)
        {
            UploadCompletedEventArgs e = operationState as UploadCompletedEventArgs;

            onUploadFileCompleted(null, e);
        }