public ActionResult <ExecutionModel> GetData() { JObject requestBodyJson = null; using (var reader = new StreamReader(Request.Body)) { string requestBody = reader.ReadToEnd(); requestBodyJson = JObject.Parse(requestBody); } List <object> parameters = new List <object>(); ExecutionModel model = new ExecutionModel(); model.Name = (string)(requestBodyJson["Name"]); //model.Description = "Add two numbers"; //model.Uri = "http://127.0.0.1:5000/ExecuteModel"; // Inputs List <Data> inputs = new List <Data>(); var inputsJson = requestBodyJson["Inputs"]; for (int i = 0; i < inputsJson.Count(); i++) { Data data = new Data(); data.Name = (string)(inputsJson[i]["Name"]); data.Value = (string)(inputsJson[i]["Value"]); parameters.Add(Convert.ToDouble(data.Value)); inputs.Add(data); } model.Inputs = inputs; // Outputs List <Data> outputs = new List <Data>(); var outputsJson = requestBodyJson["Outputs"]; for (int i = 0; i < outputsJson.Count(); i++) { Data data = new Data(); data.Name = (string)(outputsJson[i]["Name"]); data.Value = (string)(outputsJson[i]["Value"]); parameters.Add(Convert.ToDouble(data.Value)); outputs.Add(data); } model.Outputs = outputs; // Execute model AircraftDesign em = new AircraftDesign(); Type type = em.GetType(); var methodInfo = type.GetMethod(model.Name); object[] ppp = parameters.ToArray(); methodInfo.Invoke(em, ppp); // Set outputs for json int inputs_Count = inputsJson.Count(); for (int i = 0; i < outputs.Count(); i++) { outputs[i].Value = ppp[inputs_Count + i].ToString(); } return(model); }
public ActionResult <ExecutionModel> GetData() { JObject requestBodyJson = null; using (var reader = new StreamReader(Request.Body)) { string requestBody = reader.ReadToEnd(); requestBodyJson = JObject.Parse(requestBody); } string FileName = @"C:\home\site\repository\WindTurbine.explorer"; //string FileName = @"C:\Users\s130030\OneDrive - Cranfield University\Desktop\WebApplication1\WindTurbine.explorer"; AircadiaProject.Initialize("WindTurbine", @"C:\home\site\repository"); //AircadiaProject.Initialize("WindTurbine", @"C:\Users\s130030\OneDrive - Cranfield University\Desktop\WebApplication1"); AircadiaXmlSerializer.OpenProjectXML(FileName); AircadiaProject Project = AircadiaProject.Instance; ExecutionModel model = new ExecutionModel(); model.Name = (string)(requestBodyJson["Name"]); //model.Description = "Add two numbers"; //model.Uri = "http://127.0.0.1:5000/ExecuteModel"; Workflow workflow = null; foreach (Workflow wf in Project.WorkflowStore) { if (wf.Name == model.Name) { //wf.PrepareForExecution(); workflow = wf; break; } } List <object> parameters = new List <object>(); // Inputs List <Data> inputs = new List <Data>(); var inputsJson = requestBodyJson["Inputs"]; for (int i = 0; i < inputsJson.Count(); i++) { Data data = new Data(); data.Name = (string)(inputsJson[i]["Name"]); data.Value = (string)(inputsJson[i]["Value"]); parameters.Add(Convert.ToDouble(data.Value)); inputs.Add(data); } model.Inputs = inputs; for (int i = 0; i < workflow.ModelDataInputs.Count(); i++) { workflow.ModelDataInputs[i].Value = Convert.ToDouble(inputs[i].Value); } // Outputs List <Data> outputs = new List <Data>(); var outputsJson = requestBodyJson["Outputs"]; for (int i = 0; i < outputsJson.Count(); i++) { Data data = new Data(); data.Name = (string)(outputsJson[i]["Name"]); data.Value = (string)(outputsJson[i]["Value"]); parameters.Add(Convert.ToDouble(data.Value)); outputs.Add(data); } model.Outputs = outputs; if (workflow != null) { workflow.Execute(); // Set outputs for json int inputs_Count = inputsJson.Count(); for (int i = 0; i < outputs.Count(); i++) { outputs[i].Value = workflow.ModelDataOutputs[i].Value.ToString(); } } return(model); }