public async Task <LevelsFromEnvelopesOutputs> Handler(LevelsFromEnvelopesInputs 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 <LevelsFromEnvelopesInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <LevelsFromEnvelopesInputs, LevelsFromEnvelopesOutputs>(store, LevelsFromEnvelopes.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// Create levels in every envelopes in the project. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A LevelsFromEnvelopesOutputs instance containing computed results and the model with any new elements.</returns> public static LevelsFromEnvelopesOutputs Execute(Dictionary <string, Model> inputModels, LevelsFromEnvelopesInputs 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.BaseLevels, "Level"); var levelArea = 0.0; foreach (var lp in levelMaker.LevelPerimeters) { levelArea += lp.Area; } var output = new LevelsFromEnvelopesOutputs(levelMaker.Levels.Count(), levelArea); output.Model.AddElements(levelMaker.Levels); output.Model.AddElements(levelMaker.LevelPerimeters); var matl = BuiltInMaterials.Glass; matl.SpecularFactor = 0.0; 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); }