-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathWorkFlowExamples.cs
More file actions
207 lines (183 loc) · 8.85 KB
/
WorkFlowExamples.cs
File metadata and controls
207 lines (183 loc) · 8.85 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright 2024 Conductor Authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
using Conductor.Client;
using Conductor.Definition.TaskType;
using Conductor.Definition;
using Conductor.Executor;
using Conductor.Api;
using Conductor.Client.Authentication;
using Newtonsoft.Json;
using Conductor.Examples;
using Conductor.Examples.Copilot;
namespace csharp_examples
{
public class WorkFlowExamples
{
private const string WORKFLOW_ID = "<REPLACE_WITH_WORKFLOW_ID>";
private const string WORKFLOW_NAME = "<REPLACE_WITH_WORKFLOW_NAME>";
private const string WORKFLOW_DESCRIPTION = "<REPLACE_WITH_WORKFLOW_DESCRIPTION>";
private const string TASK_NAME = "<REPLACE_WITH_TASK_NAME >";
private const string TASK_REFERENCE = "<REPLACE_WITH_TASK_REFERENCE_NAME>";
private const string VARIABLE_OLD_VALUE = "SOME_OLD_VALUE";
private const string VARIABLE_NAME_1 = "<REPLACE_WITH_VARIABLE_NAME_1>";
private const string VARIABLE_NEW_VALUE_1 = "<REPLACE_WITH_OWNER_VALUE_1>";
private const string VARIABLE_NAME_2 = "<REPLACE_WITH_VARIABLE_NAME_2>";
private const string VARIABLE_NEW_VALUE_2 = "<REPLACE_WITH_OWNER_VALUE_2>";
//Method to tets dynamic workflow
public void TestDynamicWorkFlow()
{
DynamicWorkflow dynamicWorkflow = new DynamicWorkflow();
dynamicWorkflow.DynamicWorkFlowMain();
}
//Method to test greetings workflow
public void TestGreetingsWorkFlow()
{
GreetingsMain greetingsMain = new GreetingsMain();
greetingsMain.GreetingsMainMethod();
}
//Method to test OpenAICopilot example
public void TestOpenAICopilot()
{
OpenAICopilot openAICopilotTest = new OpenAICopilot();
openAICopilotTest.OpenAICopilotTest();
}
public void RegisterWorkFlow()
{
// Method-1 for using custom serialization settings - START
// Step 1:- Prepare JsonSerializer Settings with certain properties
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
// Step 2:- Use overloaded constructor of Configuration and pass the JsonSerializer Settings
// Restclient internally use the settings to serialize on request/response while making a call to serialize/deserialize
Configuration configuration = new Configuration(jsonSerializerSettings, Constants.REST_CLIENT_REQUEST_TIME_OUT)
{
AuthenticationSettings = new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET)
};
WorkflowExecutor executor = new WorkflowExecutor(configuration);
executor.RegisterWorkflow(GetConductorWorkflow(), true);
// Method-1 for using custom serialization settings - END
// Method-2 for using custom serialization settings - START
/*
Configuration configuration = new Configuration();
configuration.ApiClient.serializerSettings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
WorkflowExecutor executor = new WorkflowExecutor(configuration);
executor.RegisterWorkflow(GetConductorWorkflow(), true);
*/
// Method-2 for using custom serialization settings - END
}
private ConductorWorkflow GetConductorWorkflow()
{
var conductorWorkFlow = new ConductorWorkflow()
.WithName(WORKFLOW_NAME).WithDescription(WORKFLOW_DESCRIPTION)
.WithTask(new SimpleTask(TASK_NAME, TASK_REFERENCE))
.WithOwner(Constants.OWNER_EMAIL);
var workflowVariableTobeAdded = new Dictionary<string, object>
{
{ VARIABLE_NAME_1, VARIABLE_OLD_VALUE},
{ VARIABLE_NAME_2, VARIABLE_OLD_VALUE }
};
conductorWorkFlow.Variables = workflowVariableTobeAdded;
return conductorWorkFlow;
}
/// <summary>
/// To test Update variables with workflowId
/// </summary>
public void TestUpdateWorkflowVariablesWithWorkFlowId()
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
var workFlowVariables = new Dictionary<string, object>
{
{ VARIABLE_NAME_1, VARIABLE_NEW_VALUE_1 },
{ VARIABLE_NAME_2, VARIABLE_NEW_VALUE_2 }
};
workflowClient.UpdateWorkflowVariables(WORKFLOW_ID, workFlowVariables);
}
/// <summary>
/// To Terminate Workflow Execution using WorkflowId
/// </summary>
/// <param name="WorkflowId"></param>
public void TestTerminateWorkflowExecution(String WorkflowId)
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.Terminate(WORKFLOW_ID, null, null);
}
/// <summary>
/// To remove Workflow from the system using workflowId
/// </summary>
/// <param name="WorkflowId"></param>
public void TestRemoveWorkflow(String WorkflowId)
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.Delete(WorkflowId, null);
}
/// <summary>
/// To Retry the last failed Task using WorkflowId
/// </summary>
/// <param name="WorkflowId"></param>
public void TestRetryLastFailedTask(String WorkflowId)
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.Retry(WorkflowId, null);
}
/// <summary>
/// To Pause the Running Workflow using WorkflowId
/// </summary>
/// <param name="WorkflowId"></param>
public void TestPauseworkflow(String WorkflowId)
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.PauseWorkflow(WorkflowId);
}
/// <summary>
/// To Get Execution Status of the Workflow using WorkflowId
/// </summary>
/// <param name="WorkflowId"></param>
public void TestGetWorkflowByWorkflowId(String WorkflowId)
{
var orkesApiClient = new OrkesApiClient(new Configuration(),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.GetExecutionStatus(WorkflowId, null);
}
/// <summary>
/// To Resume the Paused Workflow with WorkflowId with our own custom values for timeout.
/// </summary>
/// <param name="WorkflowId"></param>
public void TestResumeWorkflow(String WorkflowId)
{
Configuration configuration = new Configuration(timeOut: 20000);
configuration.BasePath = "https://play.orkes.io/api";
var orkesApiClient = new OrkesApiClient(new Configuration(timeOut: 20000),
new OrkesAuthenticationSettings(Constants.KEY_ID, Constants.KEY_SECRET));
var workflowClient = orkesApiClient.GetClient<WorkflowResourceApi>();
workflowClient.ResumeWorkflow(WorkflowId);
}
}
}