Пример #1
0
        public async Task <Simulate> Run(SimulateParams simulateParams)
        {
            using (var client = new AmazonLambdaClient(RegionEndpoint.USEast2))
            {
                var apirequest = new APIGatewayProxyRequest()
                {
                    QueryStringParameters = new Dictionary <string, string>()
                };

                foreach (PropertyInfo param in simulateParams.GetType().GetProperties())
                {
                    apirequest.QueryStringParameters.Add(param.Name, param.GetValue(simulateParams).ToString());
                }

                var request = new InvokeRequest
                {
                    FunctionName = "simulate",
                    Payload      = JsonConvert.SerializeObject(apirequest)
                };

                var response = await client.InvokeAsync(request);

                string result;

                using (var sr = new StreamReader(response.Payload))
                {
                    result = sr.ReadToEnd();
                    SimulateHttpResponse httpResponse = JsonConvert.DeserializeObject <SimulateHttpResponse>(result);
                    Simulate             simulation   = JsonConvert.DeserializeObject <Simulate>(httpResponse.Body);
                    return(simulation);
                }
            }
        }
        private SimulateParams GetSimulateParams(List <ChapterInput> chapterInputs)
        {
            SimulateParams parentParams = new SimulateParams();
            SimulateParams childParams  = new SimulateParams();

            chapterInputs.ForEach(chapterInput =>
            {
                if (chapterInput.Inputs == null)
                {
                    PropertyInfo prop = parentParams.GetType().GetProperty(chapterInput.Name);
                    prop.SetValue(parentParams, chapterInput.Init.ToString());
                }
                else
                {
                    childParams = GetSimulateParams(chapterInput.Inputs);
                }
            });

            SimulateParams combineParams = Utils.Combine <SimulateParams>(parentParams, childParams);

            return(combineParams);
        }