public async Task <CoreBySketchOutputs> Handler(CoreBySketchInputs 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 <CoreBySketchInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <CoreBySketchInputs, CoreBySketchOutputs>(store, CoreBySketch.Execute); var output = await l.InvokeAsync(args); return(output); }
public async Task <CoreBySketchOutputs> Handler(CoreBySketchInputs 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 <CoreBySketchInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <CoreBySketchInputs, CoreBySketchOutputs>(store, CoreBySketch.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The CoreBySketch function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A CoreBySketchOutputs instance containing computed results and the model with any new elements.</returns> public static CoreBySketchOutputs Execute(Dictionary <string, Model> inputModels, CoreBySketchInputs input) { { //Extract the Levels from the model. var levels = new List <Level>(); inputModels.TryGetValue("Levels", out var model); if (model == null || model.AllElementsOfType <Level>().Count() == 0) { throw new ArgumentException("No Levels found."); } levels.AddRange(model.AllElementsOfType <Level>()); var top = levels.OrderByDescending(l => l.Elevation).First().Elevation + input.CoreHeightAboveRoof; var elevation = levels.OrderBy(l => l.Elevation).First().Elevation; var height = top - elevation; // Create the Core extrusion. var extrude = new Elements.Geometry.Solids.Extrude(input.Perimeter, height, Vector3.ZAxis, false); var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>() { extrude }); var corMatl = new Material("core", new Color(1.0, 1.0, 1.0, 0.6), 0.0f, 0.0f); var svcCore = new ServiceCore(input.Perimeter, Vector3.ZAxis, elevation, height, 0.0, new Transform(0.0, 0.0, elevation), corMatl, geomRep, false, Guid.NewGuid(), "serviceCore"); var output = new CoreBySketchOutputs(height); output.Model.AddElement(svcCore); return(output); } }