protected IAmazonTextract CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonTextractConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonTextractClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
예제 #2
0
        public override async Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAccessKey = (string)await v_AccessKey.EvaluateCode(engine);

            var vSecretKey = (string)await v_SecretKey.EvaluateCode(engine);

            var          ocrRequest = new DetectDocumentTextRequest();
            MemoryStream memStream  = new MemoryStream();

            if (v_ImageType == "Filepath")
            {
                string vFilePath = (string)await v_FilePath.EvaluateCode(engine);

                FileStream image = File.OpenRead(vFilePath);
                image.CopyTo(memStream);
            }
            else
            {
                Bitmap vBitmap = (Bitmap)await v_Bitmap.EvaluateCode(engine);

                vBitmap.Save(memStream, ImageFormat.Jpeg);
            }
            ocrRequest.Document       = new Document();
            ocrRequest.Document.Bytes = memStream;
            AmazonTextractConfig config = new AmazonTextractConfig();

            config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(v_AWSRegion);
            AmazonTextractClient       client  = new AmazonTextractClient(vAccessKey, vSecretKey, config);
            DetectDocumentTextResponse results = client.DetectDocumentText(ocrRequest);
            string readText = "";

            if (results.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                foreach (Block block in results.Blocks)
                {
                    if (block.BlockType.Value == "LINE")
                    {
                        readText += block.Text + "\n";
                    }
                }
            }
            else
            {
                throw new Exception("Call to AWS textract failed");
            }
            readText.SetVariableValue(engine, v_OutputUserVariableName);
        }