Esempio n. 1
0
        public async Task <FloorsByLevelsOutputs> Handler(FloorsByLevelsInputs args, ILambdaContext context)
        {
            if (this.store == null)
            {
                // Preload the dependencies (if they exist),
                // so that they are available during model deserialization.
                var asmLocation = this.GetType().Assembly.Location;
                var asmDir      = Path.GetDirectoryName(asmLocation);
                var asmName     = Path.GetFileNameWithoutExtension(asmLocation);
                var depPath     = Path.Combine(asmDir, $"{asmName}.Dependencies.dll");

                if (File.Exists(depPath))
                {
                    Console.WriteLine($"Loading dependencies from assembly: {depPath}...");
                    Assembly.LoadFrom(depPath);
                    Console.WriteLine("Dependencies assembly loaded.");
                }

                this.store = new S3ModelStore <FloorsByLevelsInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <FloorsByLevelsInputs, FloorsByLevelsOutputs>(store, FloorsByLevels.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Esempio n. 2
0
        public async Task <FloorsByLevelsOutputs> Handler(FloorsByLevelsInputs 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 <FloorsByLevelsInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <FloorsByLevelsInputs, FloorsByLevelsOutputs>(store, FloorsByLevels.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Esempio n. 3
0
        /// <summary>
        /// Generates Floors for each LevelPerimeter in the model configured ith slab thickness and setback..
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A FloorsByLevelsOutputs instance containing computed results and the model with any new elements.</returns>
        public static FloorsByLevelsOutputs Execute(Dictionary <string, Model> inputModels, FloorsByLevelsInputs input)
        {
            inputModels.Keys.ToList().ForEach(key => Console.WriteLine(key));

            // Extract LevelVolumes from Levels dependency
            var levels = new List <LevelPerimeter>();

            inputModels.TryGetValue("Levels", out var model);
            if (model == null ||
                (
                    model.AllElementsOfType <LevelPerimeter>().Count() == 0 &&
                    model.AllElementsOfType <LevelVolume>().Count() == 0
                )
                )
            {
                throw new ArgumentException("No LevelPerimeters found.");
            }
            var levelVolumes  = model.AllElementsOfType <LevelVolume>();
            var floorMaterial = new Material("Concrete", new Color(0.34, 0.34, 0.34, 1.0), 0.3, 0.3);

            levels.AddRange(model.AllElementsOfType <LevelPerimeter>());

            // Extract shafts from Core dependency, if it exists
            var shafts = new List <Polygon>();

            inputModels.TryGetValue("Core", out var core);
            if (core != null)
            {
                var shaftMasses     = core.AllElementsOfType <Mass>();
                var shaftPerimeters = shaftMasses.Where(mass => mass.Name == "void").Select(mass => mass.Profile.Perimeter.Project(new Plane(Vector3.Origin, Vector3.ZAxis)));

                shafts.AddRange(shaftPerimeters);
            }

            var floors    = new List <Floor>();
            var floorArea = 0.0;

            if (levelVolumes.Count() > 0)
            {
                foreach (var level in levelVolumes)
                {
                    var representation = level.Representation;
                    var profiles       = representation.SolidOperations.Count > 1 ?
                                         GetProfilesFromRepresentation(representation) :
                                         new List <Profile> {
                        level.Profile
                    };
                    foreach (var profile in profiles)
                    {
                        var flrOffsets = profile.Offset(input.FloorSetback * -1);
                        var elevation  = level.Transform.Origin.Z;
                        if (flrOffsets.Count() > 0)
                        {
                            if (shafts.Count() > 0)
                            {
                                flrOffsets = flrOffsets.Select(offset => CreateFloorProfile(offset.Perimeter, shafts)).ToList();
                            }

                            foreach (var fo in flrOffsets)
                            {
                                var floor = new Floor(fo, input.FloorThickness,
                                                      new Transform(0.0, 0.0, elevation - input.FloorThickness),
                                                      floorMaterial, null, false, Guid.NewGuid(), null);
                                floor.AdditionalProperties["Level"] = level.Id;
                                floors.Add(floor);
                                floorArea += floor.Area();
                            }
                        }
                        else
                        {
                            var floorProfile = shafts.Count() > 0 ? CreateFloorProfile(profile.Perimeter, shafts.Union(profile.Voids).ToList()) : profile;

                            var floor = new Floor(floorProfile, input.FloorThickness,
                                                  new Transform(0.0, 0.0, elevation - input.FloorThickness),
                                                  floorMaterial, null, false, Guid.NewGuid(), null);
                            floor.AdditionalProperties["Level"] = level.Id;
                            floors.Add(floor);
                            floorArea += floor.Area();
                        }
                    }
                }
            }
            else
            {
                // Old pathway, which did not support floors with holes
                foreach (var level in levels)
                {
                    Floor floor      = null;
                    var   flrOffsets = level.Perimeter.Offset(input.FloorSetback * -1);
                    if (flrOffsets.Count() > 0)
                    {
                        floor = new Floor(flrOffsets.First(), input.FloorThickness,
                                          new Transform(0.0, 0.0, level.Elevation - input.FloorThickness),
                                          floorMaterial, null, false, Guid.NewGuid(), null);
                    }
                    else
                    {
                        floor = new Floor(level.Perimeter, input.FloorThickness,
                                          new Transform(0.0, 0.0, level.Elevation - input.FloorThickness),
                                          floorMaterial, null, false, Guid.NewGuid(), null);
                    }
                    floors.Add(floor);
                    floorArea += floor.Area();
                }
            }
            floors = floors.OrderBy(f => f.Elevation).ToList();
            floors.First().Transform.Move(new Vector3(0.0, 0.0, input.FloorThickness));
            var output = new FloorsByLevelsOutputs(floorArea, floors.Count());

            output.Model.AddElements(floors);
            return(output);
        }
        /// <summary>
        /// The FloorsByLevels function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A FloorsByLevelsOutputs instance containing computed results and the model with any new elements.</returns>
        public static FloorsByLevelsOutputs Execute(Dictionary <string, Model> inputModels, FloorsByLevelsInputs input)
        {
            var levels = new List <LevelPerimeter>();

            inputModels.TryGetValue("Levels", out var model);
            if (model == null || model.AllElementsOfType <LevelPerimeter>().Count() == 0)
            {
                throw new ArgumentException("No LevelPerimeters found.");
            }
            levels.AddRange(model.AllElementsOfType <LevelPerimeter>());
            var floors    = new List <Floor>();
            var floorArea = 0.0;

            foreach (var level in levels)
            {
                Floor floor      = null;
                var   flrOffsets = level.Perimeter.Offset(input.FloorSetback * -1);
                if (flrOffsets.Count() > 0)
                {
                    floor = new Floor(flrOffsets.First(), input.FloorThickness,
                                      new Transform(0.0, 0.0, level.Elevation - input.FloorThickness),
                                      BuiltInMaterials.Concrete, null, false, Guid.NewGuid(), null);
                }
                else
                {
                    floor = new Floor(level.Perimeter, input.FloorThickness,
                                      new Transform(0.0, 0.0, level.Elevation - input.FloorThickness),
                                      BuiltInMaterials.Concrete, null, false, Guid.NewGuid(), null);
                }
                var opening = level.Perimeter.Offset(-1.0).First();
                floor.Openings.Add(new Opening(opening));
                floors.Add(floor);
                floorArea += floor.Area();
            }
            floors = floors.OrderBy(f => f.Elevation).ToList();
            var output = new FloorsByLevelsOutputs(floorArea, floors.Count());

            output.model.AddElements(floors);
            return(output);
        }