-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.g.cs
73 lines (65 loc) · 2.71 KB
/
Function.g.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This code was generated by Hypar.
// Edits to this code will be overwritten the next time you run 'hypar init'.
// DO NOT EDIT THIS FILE.
using Amazon;
using Amazon.Lambda.Core;
using Hypar.Functions.Execution;
using Hypar.Functions.Execution.AWS;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace JSONInspector
{
public class Function
{
// Cache the model store for use by subsequent
// executions of this lambda.
private IModelStore<JSONInspectorInputs> store;
public async Task<JSONInspectorOutputs> Handler(JSONInspectorInputs 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
{
Console.WriteLine($"Assembly Name: {asm.FullName}");
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<JSONInspectorInputs>(RegionEndpoint.GetBySystemName("us-west-1"));
}
var l = new InvocationWrapper<JSONInspectorInputs,JSONInspectorOutputs>(store, JSONInspector.Execute);
var output = await l.InvokeAsync(args);
return output;
}
}
}