public async Task <LevelBySketchOutputs> Handler(LevelBySketchInputs 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 <LevelBySketchInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <LevelBySketchInputs, LevelBySketchOutputs>(store, LevelBySketch.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The LevelBySketch function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A LevelBySketchOutputs instance containing computed results and the model with any new elements.</returns> public static LevelBySketchOutputs Execute(Dictionary <string, Model> inputModels, LevelBySketchInputs input) { var lamina = new Elements.Geometry.Solids.Lamina(input.Perimeter, false); var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>() { lamina }); var lvlMatl = new Material("level", Palette.White, 0.0f, 0.0f); var output = new LevelBySketchOutputs(input.Perimeter.Area()); output.model.AddElement(new Level(0.0, Guid.NewGuid(), "")); output.model.AddElement(new LevelPerimeter(0.0, input.Perimeter, Guid.NewGuid(), "")); output.model.AddElement(new Panel(input.Perimeter, lvlMatl, null, geomRep, false, Guid.NewGuid(), "")); return(output); }