public async Task <CheckoutOutputs> Handler(CheckoutInputs 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 <CheckoutInputs>(RegionEndpoint.USWest1); } var l = new InvocationWrapper <CheckoutInputs, CheckoutOutputs>(store, Checkout.Execute); var output = await l.InvokeAsync(args); return(output); }
/// <summary> /// The Checkout function. /// </summary> /// <param name="model">The input model.</param> /// <param name="input">The arguments to the execution.</param> /// <returns>A CheckoutOutputs instance containing computed results and the model with any new elements.</returns> public static CheckoutOutputs Execute(Dictionary <string, Model> inputModels, CheckoutInputs input) { var rooms = new List <Room>(); inputModels.TryGetValue("Departments", out var model); if (model == null) { throw new ArgumentException("No Departments found."); } rooms.AddRange(model.AllElementsOfType <Room>()); var checkout = rooms.Find(r => r.Department == "checkout"); var lines = checkout.Perimeter.Segments().OrderBy(l => l.Length()).ToList(); var ang = Math.Atan2(lines.First().End.Y - lines.First().Start.Y, lines.First().End.X - lines.First().Start.X) * (180 / Math.PI); var sequence = new Line(lines[0].Midpoint(), lines[1].Midpoint()); if (sequence.Start.X < sequence.End.X) { sequence = new Line(sequence.End, sequence.Start); } var insert = sequence.Start; var counter = MakeCounter(false); var output = new CheckoutOutputs(0.0); foreach (var register in counter) { output.model.AddElement(new Mass(register.polygon.Rotate(Vector3.Origin, ang).MoveFromTo(Vector3.Origin, insert), register.height, register.material)); } var checkouts = 1; while (insert.DistanceTo(sequence.End) >= 1.2 + input.AisleWidth && checkouts < input.CheckoutStations) { insert = sequence.PositionAt(1.2 + input.AisleWidth); sequence = new Line(insert, sequence.End); counter = MakeCounter(); foreach (var register in counter) { output.model.AddElement(new Mass(register.polygon.Rotate(Vector3.Origin, ang).MoveFromTo(Vector3.Origin, insert), register.height, register.material)); } checkouts++; } return(output); }