/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            RunTaskResponse response = new RunTaskResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("failures", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Failure, FailureUnmarshaller>(FailureUnmarshaller.Instance);
                    response.Failures = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("tasks", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Task, TaskUnmarshaller>(TaskUnmarshaller.Instance);
                    response.Tasks = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #2
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            RunTaskResponse response = new RunTaskResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("RunTaskResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Example #3
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, RunTaskResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("failures/member", targetDepth))
                    {
                        var unmarshaller = FailureUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Failures.Add(item);
                        continue;
                    }
                    if (context.TestExpression("tasks/member", targetDepth))
                    {
                        var unmarshaller = TaskUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Tasks.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
        public async Task <IActionResult> RunTask([FromBody] RunTaskRequest request)
        {
            /* Handle an included challenge */
            if (request.Header != null)
            {
                var postChallengeContent = new
                {
                    header = request.Header,
                    target = request.Target
                };

                var postChallengeResponse = await HttpHelper.PostToChallengeAsync("/", postChallengeContent);

                ChallengeStatusResponse challengeResponse = JsonConvert.DeserializeObject <ChallengeStatusResponse>(postChallengeResponse);

                if (!challengeResponse.Access)
                {
                    return(BadRequest("Invalid solution proivded"));
                }

                var challengeExecutionResult   = executeTask("executable");
                var challengeExecutionResponse = new RunTaskResponse(challengeExecutionResult);
                return(Ok(challengeExecutionResponse));
            }

            var client = getCacheClient();

            RequestDetails requestDetails = client.Get <RequestDetails>(REQUEST_PREFIX + request.RequestId);

            if (requestDetails == null)
            {
                return(NotFound("Invalid request details"));
            }

            var postMerchantContent = new
            {
                transactionId = requestDetails.TransactionId
            };

            var postMerchantResponse = await HttpHelper.PostToMerchantAsync("/api/transaction/status", postMerchantContent);

            StatusResponse merchantResult = JsonConvert.DeserializeObject <StatusResponse>(postMerchantResponse);

            if (merchantResult.AmountPaid < merchantResult.Amount)
            {
                return(BadRequest("Payment not completed"));
            }

            var executionResult = executeTask(requestDetails.Method);
            var response        = new RunTaskResponse(executionResult);

            return(Ok(response));
        }
        static void Main(string[] args)
        {
            string accessKey = "";
            string secretKey = "";

            Amazon.RegionEndpoint region = Amazon.RegionEndpoint.EUWest1;
            string strIdCuenta           = "";

            //Ejecucion de tarea en Fargate
            AmazonECSClient ECSClient = new AmazonECSClient(accessKey, secretKey, region);

            RunTaskResponse runTaskResponse = ECSClient.RunTaskAsync(new RunTaskRequest()
            {
                Cluster              = "practica1",                                  //nombre del cluster
                Count                = 1,                                            //número de tareas
                LaunchType           = Amazon.ECS.LaunchType.FARGATE,                //tipo de ejecucion
                NetworkConfiguration = new Amazon.ECS.Model.NetworkConfiguration()   //configuracion de red
                {
                    AwsvpcConfiguration = new Amazon.ECS.Model.AwsVpcConfiguration() //tipo de red awsvpc, la usada por Fargate
                    {
                        Subnets = new List <string>()
                        {
                            "subnet-831004e5"
                        },                                                 //subredes
                        AssignPublicIp = Amazon.ECS.AssignPublicIp.ENABLED //asignar IP púlica
                    }
                },
                Overrides = new TaskOverride()                          //configuracion de contenedores
                {
                    ContainerOverrides = new List <ContainerOverride>() //lista de contenedores a configurar
                    {
                        new ContainerOverride()                         //opciones del contenedor
                        {
                            Name    = "FormacionFargateTask",           //nombre del contenedor
                            Command = new List <string>()
                            {
                                "formacion-batch-sieca", "mifichero"
                            }                                                                   //input del contenedor
                        }
                    }
                },
                TaskDefinition = "FormacionFargateTask" //tarea a ejecutar
            }).Result;


            //Ejecucion de trabajo en Batch
            AmazonBatchClient batchClient = new AmazonBatchClient(accessKey, secretKey, region);

            SubmitJobResponse submitJobResponse = batchClient.SubmitJobAsync(new SubmitJobRequest()
            {
                ContainerOverrides = new ContainerOverrides() //opciones de contenedor
                {
                    Command = new List <string>()
                    {
                        "formacion-batch-sieca", "mifichero"
                    }                             //input del contenedor
                },
                JobDefinition = "formacionBatch", //definicion de trabajo
                JobName       = "mi-trabajo",     //nombre del trabajo
                JobQueue      = "formacionBatch", //cola de trabajo
            }).Result;
        }