Skip to content

Commit 75d7048

Browse files
committed
Added new maestro code examples
1 parent 87b85e2 commit 75d7048

File tree

14 files changed

+589
-27
lines changed

14 files changed

+589
-27
lines changed

launcher-csharp/Maestro/Controllers/Mae001TriggerWorkflowController.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public async Task<IActionResult> Create(
6161
accessToken,
6262
accountId);
6363

64-
if (workflowsList.Data != null || workflowsList.Data.Workflows.Count > 0)
64+
if (workflowsList.Data != null || workflowsList.Data.Count > 0)
6565
{
66-
var maestroWorkflow = workflowsList.Data.Workflows.FirstOrDefault(workflow =>
66+
var maestroWorkflow = workflowsList.Data.FirstOrDefault(workflow =>
6767
workflow.Status == "active" && workflow.Name == "Example workflow - send invite to signer");
6868

6969
if (maestroWorkflow != null)
7070
{
71-
string instanceUrl = await TriggerMaestroWorkflow.TriggerWorkflowInstance(
71+
var instance = await TriggerMaestroWorkflow.TriggerWorkflowInstance(
7272
basePath,
7373
accessToken,
7474
accountId,
@@ -79,8 +79,11 @@ public async Task<IActionResult> Create(
7979
ccName,
8080
instanceName);
8181

82+
this.RequestItemsService.WorkflowId = maestroWorkflow.Id;
83+
this.RequestItemsService.InstanceId = instance.InstanceId;
84+
8285
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
83-
this.ViewBag.Url = instanceUrl;
86+
this.ViewBag.Url = instance.InstanceUrl;
8487
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText);
8588

8689
return this.View("embed");
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// <copyright file="Mae002PauseWorkflowController.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using System;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Examples;
10+
using DocuSign.CodeExamples.Models;
11+
using Microsoft.AspNetCore.Mvc;
12+
using Newtonsoft.Json;
13+
14+
[Area("Maestro")]
15+
[Route("mae002")]
16+
public class Mae002PauseWorkflowController : EgController
17+
{
18+
private const int StatusCode = 500;
19+
20+
public Mae002PauseWorkflowController(DsConfiguration dsConfig,
21+
LauncherTexts launcherTexts,
22+
IRequestItemsService requestItemsService)
23+
: base(dsConfig, launcherTexts, requestItemsService)
24+
{
25+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
26+
this.ViewBag.title = this.CodeExampleText.ExampleName;
27+
}
28+
29+
public override string EgName => "mae002";
30+
31+
[MustAuthenticate]
32+
[HttpGet]
33+
public override IActionResult Get()
34+
{
35+
IActionResult actionResult = base.Get();
36+
if (this.RequestItemsService.EgName == this.EgName)
37+
{
38+
return actionResult;
39+
}
40+
41+
this.ViewBag.IsWorkflowIdPresent = this.RequestItemsService.WorkflowId != null;
42+
43+
return this.View("mae002", this);
44+
}
45+
46+
[HttpPost]
47+
[SetViewBag]
48+
public IActionResult Create()
49+
{
50+
// Check the token with minimal buffer time.
51+
bool tokenOk = this.CheckToken(3);
52+
if (!tokenOk)
53+
{
54+
// We could store the parameters of the requested operation
55+
// so it could be restarted automatically.
56+
// But since it should be rare to have a token issue here,
57+
// we'll make the user re-enter the form data after
58+
// authentication.
59+
this.RequestItemsService.EgName = this.EgName;
60+
return this.Redirect("/ds/mustAuthenticate");
61+
}
62+
63+
string accessToken = this.RequestItemsService.User.AccessToken;
64+
string basePath = this.RequestItemsService.Session.IamBasePath;
65+
string accountId = this.RequestItemsService.Session.AccountId;
66+
string workflowId = this.RequestItemsService.WorkflowId;
67+
68+
try
69+
{
70+
var pauseWorkflowResponse = PauseWorkflow.PauseMaestroWorkflow(
71+
basePath,
72+
accessToken,
73+
accountId,
74+
workflowId).Result;
75+
76+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
77+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText);
78+
this.ViewBag.Locals.Json = JsonConvert.SerializeObject(pauseWorkflowResponse, Formatting.Indented);
79+
80+
return this.View("example_done");
81+
}
82+
catch (Exception exception)
83+
{
84+
this.ViewBag.fixingInstructions = string.Format(
85+
this.CodeExampleText.CustomErrorTexts[1].ErrorMessage,
86+
this.RequestItemsService.WorkflowId);
87+
this.ViewBag.errorCode = StatusCode;
88+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
89+
this.ViewBag.errorMessage = exception.Message;
90+
91+
return this.View("Error");
92+
}
93+
}
94+
}
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// <copyright file="Mae003ResumeWorkflowController.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using System;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Examples;
10+
using DocuSign.CodeExamples.Models;
11+
using Microsoft.AspNetCore.Mvc;
12+
using Newtonsoft.Json;
13+
14+
[Area("Maestro")]
15+
[Route("mae003")]
16+
public class Mae003ResumeWorkflowController : EgController
17+
{
18+
private const int StatusCode = 500;
19+
20+
public Mae003ResumeWorkflowController(DsConfiguration dsConfig,
21+
LauncherTexts launcherTexts,
22+
IRequestItemsService requestItemsService)
23+
: base(dsConfig, launcherTexts, requestItemsService)
24+
{
25+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
26+
this.ViewBag.title = this.CodeExampleText.ExampleName;
27+
}
28+
29+
public override string EgName => "mae003";
30+
31+
[MustAuthenticate]
32+
[HttpGet]
33+
public override IActionResult Get()
34+
{
35+
IActionResult actionResult = base.Get();
36+
if (this.RequestItemsService.EgName == this.EgName)
37+
{
38+
return actionResult;
39+
}
40+
41+
this.ViewBag.IsWorkflowIdPresent = this.RequestItemsService.WorkflowId != null;
42+
43+
return this.View("mae003", this);
44+
}
45+
46+
[HttpPost]
47+
[SetViewBag]
48+
public IActionResult Create()
49+
{
50+
// Check the token with minimal buffer time.
51+
bool tokenOk = this.CheckToken(3);
52+
if (!tokenOk)
53+
{
54+
// We could store the parameters of the requested operation
55+
// so it could be restarted automatically.
56+
// But since it should be rare to have a token issue here,
57+
// we'll make the user re-enter the form data after
58+
// authentication.
59+
this.RequestItemsService.EgName = this.EgName;
60+
return this.Redirect("/ds/mustAuthenticate");
61+
}
62+
63+
string accessToken = this.RequestItemsService.User.AccessToken;
64+
string basePath = this.RequestItemsService.Session.IamBasePath;
65+
string accountId = this.RequestItemsService.Session.AccountId;
66+
string workflowId = this.RequestItemsService.WorkflowId;
67+
68+
try
69+
{
70+
var resumeWorkflowResponse = ResumeWorkflow.ResumeMaestroWorkflow(
71+
basePath,
72+
accessToken,
73+
accountId,
74+
workflowId).Result;
75+
76+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
77+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText);
78+
this.ViewBag.Locals.Json = JsonConvert.SerializeObject(resumeWorkflowResponse, Formatting.Indented);
79+
80+
return this.View("example_done");
81+
}
82+
catch (Exception exception)
83+
{
84+
this.ViewBag.fixingInstructions = string.Format(
85+
this.CodeExampleText.CustomErrorTexts[1].ErrorMessage,
86+
this.RequestItemsService.WorkflowId);
87+
this.ViewBag.errorCode = StatusCode;
88+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
89+
this.ViewBag.errorMessage = exception.Message;
90+
91+
return this.View("Error");
92+
}
93+
}
94+
}
95+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// <copyright file="Mae004CancelWorkflowInstanceController.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Controllers
6+
{
7+
using System;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Examples;
10+
using DocuSign.CodeExamples.Models;
11+
using Microsoft.AspNetCore.Mvc;
12+
using Newtonsoft.Json;
13+
14+
[Area("Maestro")]
15+
[Route("mae004")]
16+
public class Mae004CancelWorkflowInstanceController : EgController
17+
{
18+
private const int StatusCode = 500;
19+
20+
public Mae004CancelWorkflowInstanceController(DsConfiguration dsConfig,
21+
LauncherTexts launcherTexts,
22+
IRequestItemsService requestItemsService)
23+
: base(dsConfig, launcherTexts, requestItemsService)
24+
{
25+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
26+
this.ViewBag.title = this.CodeExampleText.ExampleName;
27+
}
28+
29+
public override string EgName => "mae004";
30+
31+
[MustAuthenticate]
32+
[HttpGet]
33+
public override IActionResult Get()
34+
{
35+
IActionResult actionResult = base.Get();
36+
if (this.RequestItemsService.EgName == this.EgName)
37+
{
38+
return actionResult;
39+
}
40+
41+
this.ViewBag.IsWorkflowIdPresent = this.RequestItemsService.WorkflowId != null &&
42+
this.RequestItemsService.InstanceId != null;
43+
44+
return this.View("mae004", this);
45+
}
46+
47+
[HttpPost]
48+
[SetViewBag]
49+
public IActionResult Create()
50+
{
51+
// Check the token with minimal buffer time.
52+
bool tokenOk = this.CheckToken(3);
53+
if (!tokenOk)
54+
{
55+
// We could store the parameters of the requested operation
56+
// so it could be restarted automatically.
57+
// But since it should be rare to have a token issue here,
58+
// we'll make the user re-enter the form data after
59+
// authentication.
60+
this.RequestItemsService.EgName = this.EgName;
61+
return this.Redirect("/ds/mustAuthenticate");
62+
}
63+
64+
string accessToken = this.RequestItemsService.User.AccessToken;
65+
string basePath = this.RequestItemsService.Session.IamBasePath;
66+
string accountId = this.RequestItemsService.Session.AccountId;
67+
string workflowId = this.RequestItemsService.WorkflowId;
68+
string workflowInstanceId = this.RequestItemsService.InstanceId;
69+
70+
try
71+
{
72+
var cancelWorkflowInstanceResponse = CancelWorkflowInstance.CancelInstanceMaestroWorkflow(
73+
basePath,
74+
accessToken,
75+
accountId,
76+
workflowId,
77+
workflowInstanceId).Result;
78+
79+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
80+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText);
81+
this.ViewBag.Locals.Json = JsonConvert.SerializeObject(cancelWorkflowInstanceResponse, Formatting.Indented);
82+
83+
return this.View("example_done");
84+
}
85+
catch (Exception exception)
86+
{
87+
this.ViewBag.errorCode = StatusCode;
88+
this.ViewBag.fixingInstructions = string.Format(
89+
this.CodeExampleText.CustomErrorTexts[1].ErrorMessage,
90+
this.RequestItemsService.InstanceId);
91+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
92+
this.ViewBag.errorMessage = exception.Message;
93+
94+
return this.View("Error");
95+
}
96+
}
97+
}
98+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <copyright file="CancelWorkflowInstance.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Examples
6+
{
7+
using System.Threading.Tasks;
8+
using Docusign.IAM.SDK;
9+
using Docusign.IAM.SDK.Models.Components;
10+
11+
public static class CancelWorkflowInstance
12+
{
13+
public static async Task<CancelWorkflowInstanceResponse> CancelInstanceMaestroWorkflow(
14+
string basePath,
15+
string accessToken,
16+
string accountId,
17+
string workflowId,
18+
string workflowInstanceId)
19+
{
20+
var client = CreateAuthenticatedClient(basePath, accessToken);
21+
return await client.Maestro.WorkflowInstanceManagement.CancelWorkflowInstanceAsync(accountId, workflowId, workflowInstanceId);
22+
}
23+
24+
/// <summary>
25+
/// Creates an authenticated IAM client.
26+
/// </summary>
27+
private static IamClient CreateAuthenticatedClient(string basePath, string accessToken)
28+
{
29+
return IamClient.Builder()
30+
.WithServerUrl(basePath)
31+
.WithAccessToken(accessToken)
32+
.Build();
33+
}
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// <copyright file="PauseWorkflow.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.CodeExamples.Examples
6+
{
7+
using System.Threading.Tasks;
8+
using Docusign.IAM.SDK;
9+
using Docusign.IAM.SDK.Models.Components;
10+
11+
public static class PauseWorkflow
12+
{
13+
public static async Task<PauseNewWorkflowInstancesSuccess> PauseMaestroWorkflow(
14+
string basePath,
15+
string accessToken,
16+
string accountId,
17+
string workflowId)
18+
{
19+
var client = CreateAuthenticatedClient(basePath, accessToken);
20+
return await client.Maestro.Workflows.PauseNewWorkflowInstancesAsync(accountId, workflowId);
21+
}
22+
23+
/// <summary>
24+
/// Creates an authenticated IAM client.
25+
/// </summary>
26+
private static IamClient CreateAuthenticatedClient(string basePath, string accessToken)
27+
{
28+
return IamClient.Builder()
29+
.WithServerUrl(basePath)
30+
.WithAccessToken(accessToken)
31+
.Build();
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)