Esempio n. 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);
                }
            }
        }
        public async Task <Chapter> GetUpdatedChapter(int id, SimulateParams simulateParams)
        {
            Chapter chapter = await GetChapter(id);

            Simulate simulation = await Simulator.Run(simulateParams);

            chapter.Graphs = GetChapterGraphsData(chapter.Graphs, simulation);
            return(chapter);
        }
        public async Task <Chapter> GetInitChapter(int id)
        {
            Chapter chapter = await GetChapter(id);

            SimulateParams simParams  = GetSimulateParams(chapter.Inputs);
            Simulate       simulation = await Simulator.Run(simParams);

            chapter.Graphs = GetChapterGraphsData(chapter.Graphs, simulation);

            return(chapter);
        }
        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);
        }
Esempio n. 5
0
        public async Task <IActionResult> GetUpdatedChapter(int id, [FromQuery] SimulateParams simulateParams)
        {
            Chapter chapter = await ChapterRepository.GetUpdatedChapter(id, simulateParams);

            return(Ok(chapter));
        }