public string SerializeRoom2D( List <Room2D> rooms, ProgramType bProgramType, ConstructionSet bConstructionSet, bool dragonfly, List <Shade> shades) { try { var modelFilePath = string.Empty; var hbProgramTypes = GetProgramTypeSet(rooms, bProgramType); var hbConstructionSets = GetConstructionSets(rooms, bConstructionSet); var properties = new ModelProperties { Energy = new ModelEnergyProperties() }; hbProgramTypes.ForEach(x => properties.Energy.ProgramTypes.Add(x)); hbConstructionSets.ForEach(x => properties.Energy.ConstructionSets.Add(x)); var contextShades = shades ?? GetContextShades(); if (dragonfly) { var stories = rooms .GroupBy(x => x.LevelName) .Select(x => new Story(x.Key, x.ToList(), new StoryPropertiesAbridged { Energy = new StoryEnergyPropertiesAbridged { ConstructionSet = bConstructionSet?.Identifier } })) .ToList(); var building = new Building("Building 1", stories, new BuildingPropertiesAbridged { Energy = new BuildingEnergyPropertiesAbridged { ConstructionSet = bConstructionSet?.Identifier } }); var model = new Model("Model 1", new List <Building> { building }, new ModelProperties(), contextShades) { Units = HB.Units.Feet, Tolerance = 0.0001d }; var dfModel = model.ToDragonfly(); dfModel.Properties = properties.ToDragonfly(); var json = JsonConvert.SerializeObject(dfModel, Formatting.Indented, new HB.AnyOfJsonConverter()); if (string.IsNullOrWhiteSpace(json)) { return(modelFilePath); } var simulationDir = AppSettings.Instance.StoredSettings.SimulationSettings.SimulationFolder; var filePath = Path.Combine(simulationDir, "Dragonfly.json"); if (string.IsNullOrWhiteSpace(simulationDir)) { return(modelFilePath); } if (!Directory.Exists(simulationDir)) { Directory.CreateDirectory(simulationDir); } if (File.Exists(filePath)) { FileUtils.TryDeleteFile(filePath); } File.WriteAllText(filePath, json); modelFilePath = filePath; return(modelFilePath); } else { var model = new Model("Model 1", new List <HB.Room>(), new ModelProperties(), contextShades) { Units = HB.Units.Feet, Tolerance = 0.0001d }; var hbRooms = rooms.Select(x => { var hb = x.ToHoneybee(); hb.Properties.Energy.ConstructionSet = x.Properties.Energy.ConstructionSet.Identifier; hb.Properties.Energy.ProgramType = x.Properties.Energy.ProgramType.Identifier; return(hb); }).ToList(); model.Rooms = hbRooms; var hbModel = model.ToHoneybee(); hbModel.Properties = properties.ToHoneybee(); var json = JsonConvert.SerializeObject(hbModel, Formatting.Indented, new HB.AnyOfJsonConverter()); if (string.IsNullOrWhiteSpace(json)) { return(modelFilePath); } var simulationDir = AppSettings.Instance.StoredSettings.SimulationSettings.SimulationFolder; var filePath = Path.Combine(simulationDir, "Honeybee.json"); if (string.IsNullOrWhiteSpace(simulationDir)) { return(modelFilePath); } if (!Directory.Exists(simulationDir)) { Directory.CreateDirectory(simulationDir); } if (File.Exists(filePath)) { FileUtils.TryDeleteFile(filePath); } File.WriteAllText(filePath, json); modelFilePath = filePath; return(modelFilePath); } } catch (Exception e) { _logger.Fatal(e); return(string.Empty); } }