using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.IO; using Abbyy.CloudOcrSdk;

namespace AbbeyOCR { public enum ProcessingModeEnum { SinglePage, MultiPage, ProcessTextField, ProcessFields, ProcessMrz, CaptureData };

public partial class Form1 : Form
{

    private RestServiceClient restClient;

    public Form1()
    {
        InitializeComponent();
    }

    public void Test()
    {
        restClient = new RestServiceClient();
        restClient.Proxy.Credentials = CredentialCache.DefaultCredentials;

        //!!! Please provide your application id and password here
        /*
        // Name of application you created
        restClient.ApplicationId = "<your application id>";
        // Password should be sent to your e-mail after application was created
        restClient.Password = "<your password>";
         */
        restClient.ApplicationId = "<Date Time Extraction>";
        restClient.Password = "<fI/wqmIPmAJigSG3RborMzTY>";

        // Display hint to provide credentials
        if (String.IsNullOrEmpty(restClient.ApplicationId) ||
            String.IsNullOrEmpty(restClient.Password))
        {
            throw new Exception("Please provide access credentials to Cloud OCR SDK service! See Test.cs file for details!");
        }

        //Console.WriteLine(String.Format("Application id: {0}\n", restClient.ApplicationId));

    }

    public void ProcessPath(string sourcePath, string outputPath,
        IProcessingSettings settings,
        ProcessingModeEnum processingMode)
    {
        List<string> sourceFiles = new List<string>();
        if (Directory.Exists(sourcePath))
        {
            sourceFiles.AddRange(Directory.GetFiles(sourcePath));
            sourceFiles.Sort();
        }
        else if (File.Exists(sourcePath))
        {
            sourceFiles.Add(sourcePath);
        }
        else
        {
            Console.WriteLine("Invalid source path");
            return;
        }

        if (!Directory.Exists(outputPath))
        {
            Directory.CreateDirectory(outputPath);
        }

        if (processingMode == ProcessingModeEnum.SinglePage ||
            (processingMode == ProcessingModeEnum.MultiPage && sourceFiles.Count == 1))
        {
            ProcessingSettings fullTextSettings = settings as ProcessingSettings;
            foreach (string filePath in sourceFiles)
            {
                string outputFileName = Path.GetFileNameWithoutExtension(filePath);
                string outputFilePath = Path.Combine(outputPath, outputFileName);

                Console.WriteLine("Processing " + Path.GetFileName(filePath));

                ProcessFile(filePath, outputFilePath, fullTextSettings);
            }
        }
        else if (processingMode == ProcessingModeEnum.MultiPage)
        {
            ProcessingSettings fullTextSettings = settings as ProcessingSettings;
            string outputFileName = "document";
            string outputFilePath = Path.Combine(outputPath, outputFileName);

            ProcessDocument(sourceFiles, outputFilePath, fullTextSettings);
        }
        else if (processingMode == ProcessingModeEnum.ProcessTextField)
        {
            TextFieldProcessingSettings fieldSettings = settings as TextFieldProcessingSettings;
            foreach (string filePath in sourceFiles)
            {
                string outputFileName = Path.GetFileNameWithoutExtension(filePath);
                string ext = ".xml";
                string outputFilePath = Path.Combine(outputPath, outputFileName + ext);

                Console.WriteLine("Processing " + Path.GetFileName(filePath));

                ProcessTextField(filePath, outputFilePath, fieldSettings);
            }
        }
        else if (processingMode == ProcessingModeEnum.ProcessMrz)
        {
            foreach (string filePath in sourceFiles)
            {
                string outputFileName = Path.GetFileNameWithoutExtension(filePath);
                string ext = ".xml";
                string outputFilePath = Path.Combine(outputPath, outputFileName + ext);

                Console.WriteLine("Processing " + Path.GetFileName(filePath));

                ProcessMrz(filePath, outputFilePath);
            }
        }
    }

    public void ProcessFile(string sourceFilePath, string outputFileBase, ProcessingSettings settings)
    {
        Console.WriteLine("Uploading..");
        Task task = restClient.ProcessImage(sourceFilePath, settings);

        TaskId taskId = task.Id;

        while (true)
        {
            task = restClient.GetTaskStatus(taskId);
            if (!Task.IsTaskActive(task.Status))
                break;

            Console.WriteLine(String.Format("Task status: {0}", task.Status));
            System.Threading.Thread.Sleep(1000);
        }

        if (task.Status == TaskStatus.Completed)
        {
            Console.WriteLine("Processing completed.");
            for (int i = 0; i < settings.OutputFormats.Count; i++)
            {
                var outputFormat = settings.OutputFormats[i];
                string ext = settings.GetOutputFileExt(outputFormat);
                restClient.DownloadUrl(task.DownloadUrls[i], outputFileBase + ext);
            }
            Console.WriteLine("Download completed.");
        }
        else if (task.Status ==   TaskStatus.NotEnoughCredits)
        {
            Console.WriteLine("Not enough credits to process the file. Please add more pages to your application balance.");
        }
        else
        {
            Console.WriteLine("Error while processing the task");
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}

}

The errors the main problem errors are on lines like:

else if (task.Status == TaskStatus.NotEnoughCredits)

First on TaskStatus im getting the error:

Error 10 'TaskStatus' is an ambiguous reference between 'System.Threading.Tasks.TaskStatus' and 'Abbyy.CloudOcrSdk.TaskStatus'

Second error im getting is:

Error 5 Cannot implicitly convert type 'Abbyy.CloudOcrSdk.Task' to 'System.Threading.Tasks.Task'

And:

Error 6 Cannot implicitly convert type 'int' to 'Abbyy.CloudOcrSdk.TaskId'

I copied this method from the console example and getting this errors. How can i solve them ?

asked 08 Sep '13, 21:16

Daniel%20Lip's gravatar image

Daniel Lip
112

closed 09 Sep '13, 15:54

Anastasia%20Galimova's gravatar image

Anastasia Ga... ♦♦
790112

The question has been closed for the following reason "Question is not relevant (about C# in general, not about ABBYY OCR SDK products)." by Anastasia Galimova 09 Sep '13, 15:54


The issue occurs because of the ambiguous references between 'System.Threading.Tasks.TaskStatus' and 'Abbyy.CloudOcrSdk.TaskStatus', and also between 'Abbyy.CloudOcrSdk.Task' and 'System.Threading.Tasks.Task.

We recommend to specify the classes directly (replace "TaskStatus" to "Abbyy.CloudOcrSdk.TaskStatus" and "Task" to "Abbyy.CloudOcrSdk.Task" where it is necessary).

link

answered 09 Sep '13, 15:53

Anastasia%20Galimova's gravatar image

Anastasia Ga... ♦♦
790112

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×28

Asked: 08 Sep '13, 21:16

Seen: 1,845 times

Last updated: 09 Sep '13, 15:54

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal