Beispiel #1
0
 private Amazon.MTurk.Model.CreateHITResponse CallAWSServiceOperation(IAmazonMTurk client, Amazon.MTurk.Model.CreateHITRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon MTurk Service", "CreateHIT");
     try
     {
         #if DESKTOP
         return(client.CreateHIT(request));
         #elif CORECLR
         return(client.CreateHITAsync(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;
     }
 }
Beispiel #2
0
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.MTurk.Model.CreateHITRequest();

            if (cmdletContext.AssignmentDurationInSecond != null)
            {
                request.AssignmentDurationInSeconds = cmdletContext.AssignmentDurationInSecond.Value;
            }

            // populate AssignmentReviewPolicy
            var requestAssignmentReviewPolicyIsNull = true;

            request.AssignmentReviewPolicy = new Amazon.MTurk.Model.ReviewPolicy();
            List <Amazon.MTurk.Model.PolicyParameter> requestAssignmentReviewPolicy_assignmentReviewPolicy_Parameter = null;

            if (cmdletContext.AssignmentReviewPolicy_Parameter != null)
            {
                requestAssignmentReviewPolicy_assignmentReviewPolicy_Parameter = cmdletContext.AssignmentReviewPolicy_Parameter;
            }
            if (requestAssignmentReviewPolicy_assignmentReviewPolicy_Parameter != null)
            {
                request.AssignmentReviewPolicy.Parameters = requestAssignmentReviewPolicy_assignmentReviewPolicy_Parameter;
                requestAssignmentReviewPolicyIsNull       = false;
            }
            System.String requestAssignmentReviewPolicy_assignmentReviewPolicy_PolicyName = null;
            if (cmdletContext.AssignmentReviewPolicy_PolicyName != null)
            {
                requestAssignmentReviewPolicy_assignmentReviewPolicy_PolicyName = cmdletContext.AssignmentReviewPolicy_PolicyName;
            }
            if (requestAssignmentReviewPolicy_assignmentReviewPolicy_PolicyName != null)
            {
                request.AssignmentReviewPolicy.PolicyName = requestAssignmentReviewPolicy_assignmentReviewPolicy_PolicyName;
                requestAssignmentReviewPolicyIsNull       = false;
            }
            // determine if request.AssignmentReviewPolicy should be set to null
            if (requestAssignmentReviewPolicyIsNull)
            {
                request.AssignmentReviewPolicy = null;
            }
            if (cmdletContext.AutoApprovalDelayInSecond != null)
            {
                request.AutoApprovalDelayInSeconds = cmdletContext.AutoApprovalDelayInSecond.Value;
            }
            if (cmdletContext.Description != null)
            {
                request.Description = cmdletContext.Description;
            }
            if (cmdletContext.HITLayoutId != null)
            {
                request.HITLayoutId = cmdletContext.HITLayoutId;
            }
            if (cmdletContext.HITLayoutParameter != null)
            {
                request.HITLayoutParameters = cmdletContext.HITLayoutParameter;
            }

            // populate HITReviewPolicy
            var requestHITReviewPolicyIsNull = true;

            request.HITReviewPolicy = new Amazon.MTurk.Model.ReviewPolicy();
            List <Amazon.MTurk.Model.PolicyParameter> requestHITReviewPolicy_hITReviewPolicy_Parameter = null;

            if (cmdletContext.HITReviewPolicy_Parameter != null)
            {
                requestHITReviewPolicy_hITReviewPolicy_Parameter = cmdletContext.HITReviewPolicy_Parameter;
            }
            if (requestHITReviewPolicy_hITReviewPolicy_Parameter != null)
            {
                request.HITReviewPolicy.Parameters = requestHITReviewPolicy_hITReviewPolicy_Parameter;
                requestHITReviewPolicyIsNull       = false;
            }
            System.String requestHITReviewPolicy_hITReviewPolicy_PolicyName = null;
            if (cmdletContext.HITReviewPolicy_PolicyName != null)
            {
                requestHITReviewPolicy_hITReviewPolicy_PolicyName = cmdletContext.HITReviewPolicy_PolicyName;
            }
            if (requestHITReviewPolicy_hITReviewPolicy_PolicyName != null)
            {
                request.HITReviewPolicy.PolicyName = requestHITReviewPolicy_hITReviewPolicy_PolicyName;
                requestHITReviewPolicyIsNull       = false;
            }
            // determine if request.HITReviewPolicy should be set to null
            if (requestHITReviewPolicyIsNull)
            {
                request.HITReviewPolicy = null;
            }
            if (cmdletContext.Keyword != null)
            {
                request.Keywords = cmdletContext.Keyword;
            }
            if (cmdletContext.LifetimeInSecond != null)
            {
                request.LifetimeInSeconds = cmdletContext.LifetimeInSecond.Value;
            }
            if (cmdletContext.MaxAssignment != null)
            {
                request.MaxAssignments = cmdletContext.MaxAssignment.Value;
            }
            if (cmdletContext.QualificationRequirement != null)
            {
                request.QualificationRequirements = cmdletContext.QualificationRequirement;
            }
            if (cmdletContext.Question != null)
            {
                request.Question = cmdletContext.Question;
            }
            if (cmdletContext.RequesterAnnotation != null)
            {
                request.RequesterAnnotation = cmdletContext.RequesterAnnotation;
            }
            if (cmdletContext.Reward != null)
            {
                request.Reward = cmdletContext.Reward;
            }
            if (cmdletContext.Title != null)
            {
                request.Title = cmdletContext.Title;
            }
            if (cmdletContext.UniqueRequestToken != null)
            {
                request.UniqueRequestToken = cmdletContext.UniqueRequestToken;
            }

            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);
        }