public async Task <OpenCollaborationLayoutOutputs> Handler(OpenCollaborationLayoutInputs args, ILambdaContext context) { // Preload dependencies (if they exist), // so that they are available during model deserialization. var sw = System.Diagnostics.Stopwatch.StartNew(); var asmLocation = this.GetType().Assembly.Location; var asmDir = Path.GetDirectoryName(asmLocation); // Explicitly load the dependencies project, it might have types // that aren't used in the function but are necessary for correct // deserialization. var asmName = Path.GetFileNameWithoutExtension(asmLocation); var depPath = Path.Combine(asmDir, $"{asmName}.Dependencies.dll"); if (File.Exists(depPath)) { Console.WriteLine($"Loading dependencies assembly from: {depPath}..."); Assembly.LoadFrom(depPath); Console.WriteLine("Dependencies assembly loaded."); } // Load all reference assemblies. Console.WriteLine($"Loading all referenced assemblies."); foreach (var asm in this.GetType().Assembly.GetReferencedAssemblies()) { try { Assembly.Load(asm); } catch (Exception e) { Console.WriteLine($"Failed to load {asm.FullName}"); Console.WriteLine(e.Message); } } sw.Stop(); Console.WriteLine($"Time to load assemblies: {sw.Elapsed.TotalSeconds})"); if (this.store == null) { this.store = new S3ModelStore <OpenCollaborationLayoutInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <OpenCollaborationLayoutInputs, OpenCollaborationLayoutOutputs>(store, OpenCollaborationLayout.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The OpenCollaborationLayout function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A OpenCollaborationLayoutOutputs instance containing computed results and the model with any new elements.</returns> public static OpenCollaborationLayoutOutputs Execute(Dictionary <string, Model> inputModels, OpenCollaborationLayoutInputs input) { varietyCounter = 0; var spacePlanningZones = inputModels["Space Planning Zones"]; var levelsModel = inputModels["Levels"]; var hasOpenOffice = inputModels.TryGetValue("Open Office Layout", out var openOfficeModel); var levels = spacePlanningZones.AllElementsOfType <LevelElements>(); var levelVolumes = levelsModel.AllElementsOfType <LevelVolume>(); var output = new OpenCollaborationLayoutOutputs(); var configJson = File.ReadAllText("./OpenCollaborationConfigurations.json"); var configs = JsonConvert.DeserializeObject <SpaceConfiguration>(configJson); if (hasOpenOffice) { foreach (var sb in openOfficeModel.AllElementsOfType <SpaceBoundary>()) { if (sb.AdditionalProperties.TryGetValue("Parent Level Id", out var lvlId)) { var matchingLevel = levels.FirstOrDefault(l => l.Id.ToString() == lvlId as string); matchingLevel?.Elements.Add(sb); } } } foreach (var lvl in levels) { var corridors = lvl.Elements.OfType <Floor>(); var corridorSegments = corridors.SelectMany(p => p.Profile.Segments()); var meetingRmBoundaries = lvl.Elements.OfType <SpaceBoundary>().Where(z => z.Name == "Open Collaboration"); var levelVolume = levelVolumes.First(l => l.Name == lvl.Name); foreach (var room in meetingRmBoundaries) { var spaceBoundary = room.Boundary; Line orientationGuideEdge = FindEdgeAdjacentToSegments(spaceBoundary.Perimeter.Segments(), corridorSegments, out var wallCandidates); var orientationTransform = new Transform(Vector3.Origin, orientationGuideEdge.Direction(), Vector3.ZAxis); var boundaryCurves = new List <Polygon>(); boundaryCurves.Add(spaceBoundary.Perimeter); boundaryCurves.AddRange(spaceBoundary.Voids ?? new List <Polygon>()); var grid = new Grid2d(boundaryCurves, orientationTransform); foreach (var cell in grid.GetCells()) { var rect = cell.GetCellGeometry() as Polygon; var segs = rect.Segments(); var width = segs[0].Length(); var depth = segs[1].Length(); var trimmedGeo = cell.GetTrimmedCellGeometry(); if (!cell.IsTrimmed() && trimmedGeo.Count() > 0) { output.Model.AddElement(InstantiateLayout(configs, width, depth, rect, room.Transform)); } else if (trimmedGeo.Count() > 0) { var largestTrimmedShape = trimmedGeo.OfType <Polygon>().OrderBy(s => s.Area()).Last(); var cinchedVertices = rect.Vertices.Select(v => largestTrimmedShape.Vertices.OrderBy(v2 => v2.DistanceTo(v)).First()).ToList(); var cinchedPoly = new Polygon(cinchedVertices); // output.Model.AddElement(new ModelCurve(cinchedPoly, BuiltInMaterials.ZAxis, levelVolume.Transform)); try { output.Model.AddElement(InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform)); } catch (Exception e) { Console.WriteLine("Failed to instantiate config"); } Console.WriteLine("ЪциРђЇРЎѓ№ИЈ funny shape!!!"); } } } } InstancePositionOverrides(input.Overrides, output.Model); return(output); }