public static GH_Structure <IGH_Goo> DeserializeGrasshopperData(byte[] array) { GH_LooseChunk val = new GH_LooseChunk("Noah Data"); val.Deserialize_Binary(array); if (val.ItemCount == 0) { return(null); } GH_Structure <IGH_Goo> gH_Structure = new GH_Structure <IGH_Goo>(); GH_IReader val2 = val.FindChunk("Block", 0); bool boolean = val2.GetBoolean("Empty"); if (boolean) { return(null); } GH_IReader val3 = val2.FindChunk("Data"); if (val3 == null) { return(null); } else if (!gH_Structure.Read(val3)) { return(null); } return(gH_Structure); }
protected override void SolveInstance(IGH_DataAccess DA) { DA.DisableGapLogic(); string SourceFile = ""; DA.GetData(0, ref SourceFile); if (string.IsNullOrWhiteSpace(SourceFile)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No source file has been specified."); return; } if (!File.Exists(SourceFile)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Source file location doesn't exist: " + SourceFile); return; } byte[] array; try { array = File.ReadAllBytes(SourceFile); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); return; } GH_LooseChunk val = new GH_LooseChunk("Grasshopper Data"); val.Deserialize_Binary(array); if (val.ItemCount == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Source data file is corrupt."); return; } GH_Structure <IGH_Goo> gH_Structure = new GH_Structure <IGH_Goo>(); GH_IReader val2 = val.FindChunk("Block", 0); if (val2 == null) { base.Params.Output[0].NickName = "?"; DA.SetDataTree(0, gH_Structure); } bool boolean = val2.GetBoolean("Empty"); if (!boolean) { GH_IReader val3 = val2.FindChunk("Data"); if (val3 == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Source file is corrupt."); } else if (!gH_Structure.Read(val3)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data could not be deserialized."); } } DA.SetDataTree(0, gH_Structure); }