예제 #1
0
        public async Task <SiteBySketchOutputs> Handler(SiteBySketchInputs 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 <SiteBySketchInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <SiteBySketchInputs, SiteBySketchOutputs>(store, SiteBySketch.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
예제 #2
0
        public async Task <SiteBySketchOutputs> Handler(SiteBySketchInputs 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 <SiteBySketchInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <SiteBySketchInputs, SiteBySketchOutputs>(store, SiteBySketch.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
예제 #3
0
        /// <summary>
        /// Generates a planar Site from a supplied sketch.
        /// </summary>
        /// <param name="inputModels">The input models.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A SiteBySketchOutputs instance containing computed results and the model with any new elements.</returns>
        public static SiteBySketchOutputs Execute(Dictionary <string, Model> inputModels, SiteBySketchInputs input)
        {
            var geomRep      = new Elements.Geometry.Solids.Lamina(input.Perimeter, false);
            var siteMaterial = new Material("site", Palette.Emerald, 0.0f, 0.0f);
            var area         = input.Perimeter.Area();
            var output       = new SiteBySketchOutputs(area);
            var site         = new Site()
            {
                Perimeter      = input.Perimeter,
                Area           = area,
                Material       = siteMaterial,
                Representation = geomRep,
            };

            output.Model.AddElement(site);
            return(output);
        }
예제 #4
0
        /// <summary>
        /// The SiteBySketch function.
        /// </summary>
        /// <param name="inputModels">The input models.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A SiteBySketchOutputs instance containing computed results and the model with any new elements.</returns>
        public static SiteBySketchOutputs Execute(Dictionary <string, Model> inputModels, SiteBySketchInputs input)
        {
            var lamina  = new Elements.Geometry.Solids.Lamina(input.Perimeter, false);
            var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
            {
                lamina
            });
            var sitMatl = new Material("site", Palette.Emerald, 0.0f, 0.0f);
            var output  = new SiteBySketchOutputs(Math.Abs(input.Perimeter.Area()));
            var site    = new Site(input.Perimeter, Math.Abs(input.Perimeter.Area()), null, sitMatl, geomRep, false, Guid.NewGuid(), "");

            output.Model.AddElement(site);
            return(output);
        }