Exemple #1
0
        // private void CallVisionApi(String filename)
        //{
        //  CallVisionApiTask(filename);
        //}

        private async Task CallVisionApiTask(GoogleVisionApiSession sess)
        {
            await sess.PostAsync();

            var result = await sess.GetResult();

            if (result == null)
            {
                // XXX
                AppendErrorMessage("API session not finished");
            }
            else if (result.Succeeded)
            {
                String text = result.GetText();

                foreach (var line in text.Split(new Char[] { '\n' }))
                {
                    textBox1.AppendText(line);
                    textBox1.AppendText("\r\n");
                }
            }
            else if (result.Error != null)
            {
                AppendErrorMessage(String.Format("Http status={0} error code={1} status={2} message={3}",
                                                 result.HttpStatusCode,
                                                 result.Error.Code,
                                                 result.Error.Status,
                                                 result.Error.Message));
            }
            else
            {
                AppendErrorMessage(String.Format("Http error: {0}", result.HttpStatusCode));
                AppendDebugMessage(result.HttpErrorMessage);
            }
        }
        private async Task <GoogleVisionApiResult> ResultTest2(string apikey = null)
        {
            if (apikey == null)
            {
                apikey = ApiKey;
            }

            var sess = new GoogleVisionApiSession("small.png", apikey);
            await sess.PostAsync();

            Debug.WriteLine("status={0}", new Object[] { sess.HttpResponse.StatusCode });
            GoogleVisionApiResult result = await sess.GetResult();

            return(result);
        }