public static Response GetIoNames(NancyContext ctx) { // load grasshopper file var archive = new GH_Archive(); // TODO: stream to string var body = ctx.Request.Body.ToString(); // //var body = input.Algo; string json = string.Empty; using (var reader = new StreamReader(ctx.Request.Body)) { json = reader.ReadToEnd(); } IoQuerySchema input = JsonConvert.DeserializeObject <IoQuerySchema>(json); string pointer = input.RequestedFile; string grasshopperXml = GetGhxFromPointer(pointer); if (!archive.Deserialize_Xml(grasshopperXml)) { throw new Exception(); } var definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { throw new Exception(); } // Parse input and output names List <string> InputNames = new List <string>(); List <string> OutputNames = new List <string>(); foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_IN")) { InputNames.Add(group.NickName); } else if (group.NickName.Contains("RH_OUT")) { OutputNames.Add(group.NickName); } } IoResponseSchema response = new IoResponseSchema(); response.InputNames = InputNames; response.OutputNames = OutputNames; string jsonResponse = JsonConvert.SerializeObject(response); return(jsonResponse); }
static Response GetIoNames(NancyContext ctx) { string json = ctx.Request.Body.AsString(); IoQuerySchema input = JsonConvert.DeserializeObject <IoQuerySchema>(json); string pointer = input.RequestedFile; GH_Archive archive = DataCache.GetCachedArchive(pointer); var definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { throw new Exception("Unable to extract definition"); } // Parse input and output names List <string> InputNames = new List <string>(); List <string> OutputNames = new List <string>(); var Inputs = new List <IoParamSchema>(); var Outputs = new List <IoParamSchema>(); foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_IN")) { InputNames.Add(group.NickName); var i = new IoParamSchema { Name = group.NickName, ParamType = (group.Objects()[0] as IGH_Param).TypeName }; Inputs.Add(i); } else if (group.NickName.Contains("RH_OUT")) { OutputNames.Add(group.NickName); var o = new IoParamSchema { Name = group.NickName, ParamType = (group.Objects()[0] as IGH_Param).TypeName }; Outputs.Add(o); } } var response = new IoResponseSchema { InputNames = InputNames, OutputNames = OutputNames, Inputs = Inputs, Outputs = Outputs }; string jsonResponse = JsonConvert.SerializeObject(response); return(jsonResponse); }