public async Task <PrivateOfficeLayoutOutputs> Handler(PrivateOfficeLayoutInputs 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 <PrivateOfficeLayoutInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <PrivateOfficeLayoutInputs, PrivateOfficeLayoutOutputs>(store, PrivateOfficeLayout.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The PrivateOfficeLayout function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A PrivateOfficeLayoutOutputs instance containing computed results and the model with any new elements.</returns> public static PrivateOfficeLayoutOutputs Execute(Dictionary <string, Model> inputModels, PrivateOfficeLayoutInputs input) { var spacePlanningZones = inputModels["Space Planning Zones"]; var levelsModel = inputModels["Levels"]; var levels = spacePlanningZones.AllElementsOfType <LevelElements>(); var levelVolumes = levelsModel.AllElementsOfType <LevelVolume>(); var output = new PrivateOfficeLayoutOutputs(); var configJson = File.ReadAllText("./PrivateOfficeConfigurations.json"); var configs = JsonConvert.DeserializeObject <SpaceConfiguration>(configJson); var wallMat = new Material("Drywall", new Color(0.9, 0.9, 0.9, 1.0), 0.01, 0.01); var glassMat = new Material("Glass", new Color(0.7, 0.7, 0.7, 0.3), 0.3, 0.6); var mullionMat = new Material("Storefront Mullions", new Color(0.5, 0.5, 0.5, 1.0)); foreach (var lvl in levels) { var corridors = lvl.Elements.OfType <Floor>(); var corridorSegments = corridors.SelectMany(p => p.Profile.Segments()).ToList(); var meetingRmBoundaries = lvl.Elements.OfType <SpaceBoundary>().Where(z => z.Name == "Private Office"); if (input.OfficeSizing.AutomateOfficeSubdivisions) { meetingRmBoundaries = meetingRmBoundaries.SelectMany((room) => { Line orientationGuideEdge = FindEdgeAdjacentToSegments(room.Boundary.Perimeter.Segments(), corridorSegments, out var wallCandidates); var orientationTransform = new Transform(Vector3.Origin, orientationGuideEdge.Direction(), Vector3.ZAxis); var boundaryCurves = new List <Polygon>(); boundaryCurves.Add(room.Boundary.Perimeter); boundaryCurves.AddRange(room.Boundary.Voids ?? new List <Polygon>()); var tempGrid = new Grid2d(boundaryCurves, orientationTransform); try { var vLength = tempGrid.V.Domain.Length; if (vLength > 3 * input.OfficeSizing.OfficeSize) { var officeCount = Math.Floor(vLength / input.OfficeSizing.OfficeSize); var corridorCount = Math.Floor(officeCount / 2 - 0.1); // 1 corridor for 3, 4 offices, 2 corridors for 5, 6 offices, etc var idealOfficeSize = ((vLength - (corridorCount * 1.5)) / officeCount) * .99; Console.WriteLine($"ЁЯдк officeCount: {officeCount}, corridorCount: {corridorCount}, idealOfficeSize: {idealOfficeSize}"); tempGrid.V.DivideByPattern(new[] { ("Office", idealOfficeSize), ("Office", idealOfficeSize), ("Corridor", 1.5) });