Beispiel #1
0
        public Processor()
        {
            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 = "";
            // Password should be sent to your e-mail after application was created
            restClient.Password = "";
            string configFileName = "..\\..\\Config.txt";

            if (File.Exists(configFileName))
            {
                string[] lines = System.IO.File.ReadAllLines(configFileName);
                foreach (string line in lines)
                {
                    if (line.Contains("ApplicationId"))
                    {
                        restClient.ApplicationId = getValueByKey(line, "ApplicationId");
                    }
                    else if (line.Contains("Password"))
                    {
                        restClient.Password = getValueByKey(line, "Password");
                    }
                }
            }

            // 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 in Config.txt!");
            }

            Console.WriteLine(String.Format("Application id: {0}\n", restClient.ApplicationId));
        }
        public Processor()
        {
            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 https://cloud.ocrsdk.com/Account/Register
            // More info on getting your application id and password at
            // https://ocrsdk.com/documentation/faq/#faq3

            // Name of application you created
            restClient.ApplicationId = "";
            // Password should be sent to your e-mail after application was created
            restClient.Password = "";
            var    currentModuleLocation = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string configFilePath        = Path.Combine(currentModuleLocation, "Config.txt");

            if (File.Exists(configFilePath))
            {
                string[] lines = System.IO.File.ReadAllLines(configFilePath);
                foreach (string line in lines)
                {
                    const String appIdKey      = "ApplicationId";
                    const String passwordKey   = "Password";
                    const String serviceUrlKey = "ServiceUrl";
                    if (line.StartsWith("//"))
                    {
                        continue;
                    }
                    if (line.StartsWith(appIdKey))
                    {
                        restClient.ApplicationId = getValueByKey(line, appIdKey);
                    }
                    else if (line.StartsWith(passwordKey))
                    {
                        restClient.Password = getValueByKey(line, passwordKey);
                    }
                    else if (line.StartsWith(serviceUrlKey))
                    {
                        var serviceUrl = getValueByKey(line, serviceUrlKey);
                        serviceUrl           = checkAndNormalizeServiceUrl(serviceUrl);
                        restClient.ServerUrl = serviceUrl;
                    }
                }
            }
            else
            {
                throw new Exception(
                          String.Format("Configuration file not found at path {0}", configFilePath));
            }

            // 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 in Config.txt!");
            }

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