示例#1
0
        public async Task <LevelsByEnvelopeOutputs> Handler(LevelsByEnvelopeInputs 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 <LevelsByEnvelopeInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <LevelsByEnvelopeInputs, LevelsByEnvelopeOutputs>(store, LevelsByEnvelope.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
示例#2
0
        public async Task <LevelsByEnvelopeOutputs> Handler(LevelsByEnvelopeInputs 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 <LevelsByEnvelopeInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <LevelsByEnvelopeInputs, LevelsByEnvelopeOutputs>(store, LevelsByEnvelope.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
示例#3
0
        /// <summary>
        /// Creates Levels and LevelPerimeters from an incoming Envelope and height arguments.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A LevelsByEnvelopeOutputs instance containing computed results and the model with any new elements.</returns>
        public static LevelsByEnvelopeOutputs Execute(Dictionary <string, Model> inputModels, LevelsByEnvelopeInputs input)
        {
            var envelopes = new List <Envelope>();

            inputModels.TryGetValue("Envelope", out var model);
            if (model == null || model.AllElementsOfType <Envelope>().Count() == 0)
            {
                throw new ArgumentException("No Envelope found.");
            }
            envelopes.AddRange(model.AllElementsOfType <Envelope>());
            var levelMaker = new LevelMaker(envelopes,
                                            input.StandardLevelHeight,
                                            input.GroundLevelHeight,
                                            input.PenthouseLevelHeight);
            var levelArea = 0.0;

            foreach (var lp in levelMaker.LevelPerimeters)
            {
                levelArea += lp.Area;
            }
            var output = new LevelsByEnvelopeOutputs(levelMaker.Levels.Count(),
                                                     levelArea,
                                                     input.GroundLevelHeight,
                                                     input.StandardLevelHeight,
                                                     input.PenthouseLevelHeight);

            output.Model.AddElements(levelMaker.Levels);
            output.Model.AddElements(levelMaker.LevelPerimeters);
            var matl = BuiltInMaterials.Glass;

            matl.SpecularFactor   = 0.5;
            matl.GlossinessFactor = 0.0;
            foreach (var item in levelMaker.LevelPerimeters)
            {
                output.Model.AddElement(new Panel(item.Perimeter, matl, new Transform(0.0, 0.0, item.Elevation),
                                                  null, false, Guid.NewGuid(), ""));
            }
            return(output);
        }