/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.Textract;
using Amazon.Textract.Model;
namespace Amazon.PowerShell.Cmdlets.TXT
{
///
/// Starts the asynchronous analysis of invoices or receipts for data like contact information,
/// items purchased, and vendor names.
///
///
/// StartExpenseAnalysis
can analyze text in documents that are in JPEG,
/// PNG, and PDF format. The documents must be stored in an Amazon S3 bucket. Use the
/// DocumentLocation parameter to specify the name of your S3 bucket and the name
/// of the document in that bucket.
/// StartExpenseAnalysis
returns a job identifier (JobId
) that
/// you will provide to GetExpenseAnalysis
to retrieve the results of the
/// operation. When the analysis of the input invoices/receipts is finished, Amazon Textract
/// publishes a completion status to the Amazon Simple Notification Service (Amazon SNS)
/// topic that you provide to the NotificationChannel
. To obtain the results
/// of the invoice and receipt analysis operation, ensure that the status value published
/// to the Amazon SNS topic is SUCCEEDED
. If so, call GetExpenseAnalysis,
/// and pass the job identifier (JobId
) that was returned by your call to
/// StartExpenseAnalysis
.
///
/// For more information, see Analyzing
/// Invoices and Receipts.
///
///
[Cmdlet("Start", "TXTExpenseAnalysis", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the Amazon Textract StartExpenseAnalysis API operation.", Operation = new[] {"StartExpenseAnalysis"}, SelectReturnType = typeof(Amazon.Textract.Model.StartExpenseAnalysisResponse))]
[AWSCmdletOutput("System.String or Amazon.Textract.Model.StartExpenseAnalysisResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.Textract.Model.StartExpenseAnalysisResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class StartTXTExpenseAnalysisCmdlet : AmazonTextractClientCmdlet, IExecutor
{
#region Parameter S3Object_Bucket
///
///
/// The name of the S3 bucket. Note that the # character is not valid in the file name.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("DocumentLocation_S3Object_Bucket")]
public System.String S3Object_Bucket { get; set; }
#endregion
#region Parameter ClientRequestToken
///
///
/// The idempotent token that's used to identify the start request. If you use the same
/// token with multiple StartDocumentTextDetection
requests, the same JobId
/// is returned. Use ClientRequestToken
to prevent the same job from being
/// accidentally started more than once. For more information, see Calling
/// Amazon Textract Asynchronous Operations
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientRequestToken { get; set; }
#endregion
#region Parameter JobTag
///
///
/// An identifier you specify that's included in the completion notification published
/// to the Amazon SNS topic. For example, you can use JobTag
to identify
/// the type of document that the completion notification corresponds to (such as a tax
/// form or a receipt).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String JobTag { get; set; }
#endregion
#region Parameter KMSKeyId
///
///
/// The KMS key used to encrypt the inference results. This can be in either Key ID or
/// Key Alias format. When a KMS key is provided, the KMS key will be used for server-side
/// encryption of the objects in the customer bucket. When this parameter is not enabled,
/// the result will be encrypted server side,using SSE-S3.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String KMSKeyId { get; set; }
#endregion
#region Parameter S3Object_Name
///
///
/// The file name of the input document. Synchronous operations can use image files that
/// are in JPEG or PNG format. Asynchronous operations also support PDF and TIFF format
/// files.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("DocumentLocation_S3Object_Name")]
public System.String S3Object_Name { get; set; }
#endregion
#region Parameter NotificationChannel_RoleArn
///
///
/// The Amazon Resource Name (ARN) of an IAM role that gives Amazon Textract publishing
/// permissions to the Amazon SNS topic.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String NotificationChannel_RoleArn { get; set; }
#endregion
#region Parameter OutputConfig_S3Bucket
///
///
/// The name of the bucket your output will go to.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String OutputConfig_S3Bucket { get; set; }
#endregion
#region Parameter OutputConfig_S3Prefix
///
///
/// The prefix of the object key that the output will be saved to. When not enabled, the
/// prefix will be “textract_output".
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String OutputConfig_S3Prefix { get; set; }
#endregion
#region Parameter NotificationChannel_SNSTopicArn
///
///
/// The Amazon SNS topic that Amazon Textract posts the completion status to.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String NotificationChannel_SNSTopicArn { get; set; }
#endregion
#region Parameter S3Object_Version
///
///
/// If the bucket has versioning enabled, you can specify the object version.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("DocumentLocation_S3Object_Version")]
public System.String S3Object_Version { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'JobId'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Textract.Model.StartExpenseAnalysisResponse).
/// Specifying the name of a property of type Amazon.Textract.Model.StartExpenseAnalysisResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "JobId";
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = string.Empty;
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Start-TXTExpenseAnalysis (StartExpenseAnalysis)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
}
context.ClientRequestToken = this.ClientRequestToken;
context.S3Object_Bucket = this.S3Object_Bucket;
context.S3Object_Name = this.S3Object_Name;
context.S3Object_Version = this.S3Object_Version;
context.JobTag = this.JobTag;
context.KMSKeyId = this.KMSKeyId;
context.NotificationChannel_RoleArn = this.NotificationChannel_RoleArn;
context.NotificationChannel_SNSTopicArn = this.NotificationChannel_SNSTopicArn;
context.OutputConfig_S3Bucket = this.OutputConfig_S3Bucket;
context.OutputConfig_S3Prefix = this.OutputConfig_S3Prefix;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.Textract.Model.StartExpenseAnalysisRequest();
if (cmdletContext.ClientRequestToken != null)
{
request.ClientRequestToken = cmdletContext.ClientRequestToken;
}
// populate DocumentLocation
var requestDocumentLocationIsNull = true;
request.DocumentLocation = new Amazon.Textract.Model.DocumentLocation();
Amazon.Textract.Model.S3Object requestDocumentLocation_documentLocation_S3Object = null;
// populate S3Object
var requestDocumentLocation_documentLocation_S3ObjectIsNull = true;
requestDocumentLocation_documentLocation_S3Object = new Amazon.Textract.Model.S3Object();
System.String requestDocumentLocation_documentLocation_S3Object_s3Object_Bucket = null;
if (cmdletContext.S3Object_Bucket != null)
{
requestDocumentLocation_documentLocation_S3Object_s3Object_Bucket = cmdletContext.S3Object_Bucket;
}
if (requestDocumentLocation_documentLocation_S3Object_s3Object_Bucket != null)
{
requestDocumentLocation_documentLocation_S3Object.Bucket = requestDocumentLocation_documentLocation_S3Object_s3Object_Bucket;
requestDocumentLocation_documentLocation_S3ObjectIsNull = false;
}
System.String requestDocumentLocation_documentLocation_S3Object_s3Object_Name = null;
if (cmdletContext.S3Object_Name != null)
{
requestDocumentLocation_documentLocation_S3Object_s3Object_Name = cmdletContext.S3Object_Name;
}
if (requestDocumentLocation_documentLocation_S3Object_s3Object_Name != null)
{
requestDocumentLocation_documentLocation_S3Object.Name = requestDocumentLocation_documentLocation_S3Object_s3Object_Name;
requestDocumentLocation_documentLocation_S3ObjectIsNull = false;
}
System.String requestDocumentLocation_documentLocation_S3Object_s3Object_Version = null;
if (cmdletContext.S3Object_Version != null)
{
requestDocumentLocation_documentLocation_S3Object_s3Object_Version = cmdletContext.S3Object_Version;
}
if (requestDocumentLocation_documentLocation_S3Object_s3Object_Version != null)
{
requestDocumentLocation_documentLocation_S3Object.Version = requestDocumentLocation_documentLocation_S3Object_s3Object_Version;
requestDocumentLocation_documentLocation_S3ObjectIsNull = false;
}
// determine if requestDocumentLocation_documentLocation_S3Object should be set to null
if (requestDocumentLocation_documentLocation_S3ObjectIsNull)
{
requestDocumentLocation_documentLocation_S3Object = null;
}
if (requestDocumentLocation_documentLocation_S3Object != null)
{
request.DocumentLocation.S3Object = requestDocumentLocation_documentLocation_S3Object;
requestDocumentLocationIsNull = false;
}
// determine if request.DocumentLocation should be set to null
if (requestDocumentLocationIsNull)
{
request.DocumentLocation = null;
}
if (cmdletContext.JobTag != null)
{
request.JobTag = cmdletContext.JobTag;
}
if (cmdletContext.KMSKeyId != null)
{
request.KMSKeyId = cmdletContext.KMSKeyId;
}
// populate NotificationChannel
var requestNotificationChannelIsNull = true;
request.NotificationChannel = new Amazon.Textract.Model.NotificationChannel();
System.String requestNotificationChannel_notificationChannel_RoleArn = null;
if (cmdletContext.NotificationChannel_RoleArn != null)
{
requestNotificationChannel_notificationChannel_RoleArn = cmdletContext.NotificationChannel_RoleArn;
}
if (requestNotificationChannel_notificationChannel_RoleArn != null)
{
request.NotificationChannel.RoleArn = requestNotificationChannel_notificationChannel_RoleArn;
requestNotificationChannelIsNull = false;
}
System.String requestNotificationChannel_notificationChannel_SNSTopicArn = null;
if (cmdletContext.NotificationChannel_SNSTopicArn != null)
{
requestNotificationChannel_notificationChannel_SNSTopicArn = cmdletContext.NotificationChannel_SNSTopicArn;
}
if (requestNotificationChannel_notificationChannel_SNSTopicArn != null)
{
request.NotificationChannel.SNSTopicArn = requestNotificationChannel_notificationChannel_SNSTopicArn;
requestNotificationChannelIsNull = false;
}
// determine if request.NotificationChannel should be set to null
if (requestNotificationChannelIsNull)
{
request.NotificationChannel = null;
}
// populate OutputConfig
var requestOutputConfigIsNull = true;
request.OutputConfig = new Amazon.Textract.Model.OutputConfig();
System.String requestOutputConfig_outputConfig_S3Bucket = null;
if (cmdletContext.OutputConfig_S3Bucket != null)
{
requestOutputConfig_outputConfig_S3Bucket = cmdletContext.OutputConfig_S3Bucket;
}
if (requestOutputConfig_outputConfig_S3Bucket != null)
{
request.OutputConfig.S3Bucket = requestOutputConfig_outputConfig_S3Bucket;
requestOutputConfigIsNull = false;
}
System.String requestOutputConfig_outputConfig_S3Prefix = null;
if (cmdletContext.OutputConfig_S3Prefix != null)
{
requestOutputConfig_outputConfig_S3Prefix = cmdletContext.OutputConfig_S3Prefix;
}
if (requestOutputConfig_outputConfig_S3Prefix != null)
{
request.OutputConfig.S3Prefix = requestOutputConfig_outputConfig_S3Prefix;
requestOutputConfigIsNull = false;
}
// determine if request.OutputConfig should be set to null
if (requestOutputConfigIsNull)
{
request.OutputConfig = null;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.Textract.Model.StartExpenseAnalysisResponse CallAWSServiceOperation(IAmazonTextract client, Amazon.Textract.Model.StartExpenseAnalysisRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Textract", "StartExpenseAnalysis");
try
{
#if DESKTOP
return client.StartExpenseAnalysis(request);
#elif CORECLR
return client.StartExpenseAnalysisAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String ClientRequestToken { get; set; }
public System.String S3Object_Bucket { get; set; }
public System.String S3Object_Name { get; set; }
public System.String S3Object_Version { get; set; }
public System.String JobTag { get; set; }
public System.String KMSKeyId { get; set; }
public System.String NotificationChannel_RoleArn { get; set; }
public System.String NotificationChannel_SNSTopicArn { get; set; }
public System.String OutputConfig_S3Bucket { get; set; }
public System.String OutputConfig_S3Prefix { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.JobId;
}
}
}