- Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathEventContainer.cs
123 lines (97 loc) · 2.9 KB
/
EventContainer.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
usingAmazon.Lambda.TestTool.Services;
namespaceAmazon.Lambda.TestTool.Models;
publicclassEventContainer:IDisposable
{
publicenumStatus{Queued,Executing,Success,Failure}
privateconststringDefaultFunctionArn="arn:aws:lambda:us-west-2:123412341234:function:Function";
publicstringAwsRequestId{get;}
publicstringEventJson{get;}
publicstring?ErrorResponse{get;privateset;}
publicstring?ErrorType{get;privateset;}
publicstring?Response{get;privateset;}
publicDateTimeLastUpdated{get;privateset;}
privateStatus_status=Status.Queued;
privateManualResetEventSlim?_resetEvent;
publicStatusEventStatus
{
get=>_status;
set
{
_status=value;
LastUpdated=DateTime.Now;
}
}
privatereadonlyRuntimeApiDataStore_dataStore;
publicEventContainer(RuntimeApiDataStoredataStore,inteventCount,stringeventJson,boolisRequestResponseMode)
{
LastUpdated=DateTime.Now;
_dataStore=dataStore;
AwsRequestId=eventCount.ToString("D12");
EventJson=eventJson;
if(isRequestResponseMode)
{
_resetEvent=newManualResetEventSlim(false);
}
}
publicstringFunctionArn
{
get=>DefaultFunctionArn;
}
publicvoidReportSuccessResponse(stringresponse)
{
LastUpdated=DateTime.Now;
Response=response;
EventStatus=Status.Success;
if(_resetEvent!=null)
{
_resetEvent.Set();
}
_dataStore.RaiseStateChanged();
}
publicvoidReportErrorResponse(stringerrorType,stringerrorBody)
{
LastUpdated=DateTime.Now;
ErrorType=errorType;
ErrorResponse=errorBody;
EventStatus=Status.Failure;
if(_resetEvent!=null)
{
_resetEvent.Set();
}
_dataStore.RaiseStateChanged();
}
publicboolWaitForCompletion()
{
if(_resetEvent==null)
{
returnfalse;
}
// The 15 minutes is a fail safe so we at some point we unblock the thread. It is intentionally
// long to give the user time to debug the Lambda function.
return_resetEvent.Wait(TimeSpan.FromMinutes(15));
}
publicvoidDispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
privatebool_disposed=false;
protectedvirtualvoidDispose(booldisposing)
{
if(_disposed)
{
return;
}
if(disposing)
{
if(_resetEvent!=null)
{
_resetEvent.Dispose();
_resetEvent=null;
}
}
_disposed=true;
}
}