Example #1
0
        public async Task <CppWrapperExampleOutputs> Handler(CppWrapperExampleInputs 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 <CppWrapperExampleInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <CppWrapperExampleInputs, CppWrapperExampleOutputs>(store, CppWrapperExample.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Example #2
0
        /// <summary>
        /// The CppWrapperExample function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A CppWrapperExampleOutputs instance containing computed results and the model with any new elements.</returns>
        public static CppWrapperExampleOutputs Execute(Dictionary <string, Model> inputModels, CppWrapperExampleInputs input)
        {
            /// Your code here.
            var output    = new CppWrapperExampleOutputs(TheSecretOfTheUniverse());
            var rectangle = Polygon.Rectangle(input.Length, input.Width);
            var mass      = new Mass(rectangle, 1.0);

            output.Model.AddElement(mass);

            // Call our wrapped method
            PrintHelloWorld();

            return(output);
        }