Skip to content

Commit 297f94f

Browse files
authored
Merge pull request #164 from docusign/feature/maestro
Implement getting, cancelling, triggering the workflow
2 parents 53bb735 + 460d72e commit 297f94f

23 files changed

+1668
-8
lines changed

ExamplesApiTypeExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public enum ExamplesApiType
4949
/// </summary>
5050
[Description("web")]
5151
WebForms = 6,
52+
53+
/// <summary>
54+
/// Maestro API
55+
/// </summary>
56+
[Description("mae")]
57+
Maestro = 7,
5258
}
5359

5460
public static class ExamplesApiTypeExtensions

launcher-csharp/Common/IRequestItemsService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public interface IRequestItemsService
3636

3737
public string WebFormsTemplateId { get; set; }
3838

39+
public string WorkflowId { get; set; }
40+
41+
public bool IsWorkflowPublished { get; set; }
42+
43+
public string InstanceId { get; set; }
44+
3945
public string PausedEnvelopeId { get; set; }
4046

4147
public string Status { get; set; }

launcher-csharp/Common/LocalsFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void OnActionExecuting(ActionExecutingContext context)
9797
BasePath = identity.FindFirst(x => x.Type.Equals("base_uri")).Value,
9898
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
9999
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
100+
MaestroApiBasePath = this.configuration["DocuSign:MaestroApiEndpoint"],
100101
WebFormsBasePath = this.configuration["DocuSign:WebFormsBasePath"],
101102
}
102103
:
@@ -107,6 +108,7 @@ public void OnActionExecuting(ActionExecutingContext context)
107108
BasePath = this.requestItemsService.Session.BasePath,
108109
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
109110
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
111+
MaestroApiBasePath = this.configuration["DocuSign:MaestroApiEndpoint"],
110112
WebFormsBasePath = this.configuration["DocuSign:WebFormsBasePath"],
111113
};
112114

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ public string TemplateId
148148
set => this.cache.Set(this.GetKey("TemplateId"), value);
149149
}
150150

151+
public string WorkflowId
152+
{
153+
get => this.cache.Get<string>(this.GetKey("WorkflowId"));
154+
set => this.cache.Set(this.GetKey("WorkflowId"), value);
155+
}
156+
157+
public bool IsWorkflowPublished
158+
{
159+
get => this.cache.Get<bool>(this.GetKey("WorkflowPublished"));
160+
set => this.cache.Set(this.GetKey("WorkflowPublished"), value);
161+
}
162+
163+
public string InstanceId
164+
{
165+
get => this.cache.Get<string>(this.GetKey("InstanceId"));
166+
set => this.cache.Set(this.GetKey("InstanceId"), value);
167+
}
168+
151169
public string WebFormsTemplateId
152170
{
153171
get => this.cache.Get<string>(this.GetKey("WebFormsTemplateId"));
@@ -213,6 +231,7 @@ public void UpdateUserFromJwt()
213231
RoomsApiBasePath = this.Configuration["DocuSign:RoomsApiEndpoint"],
214232
AdminApiBasePath = this.Configuration["DocuSign:AdminApiEndpoint"],
215233
WebFormsBasePath = this.Configuration["DocuSign:WebFormsBasePath"],
234+
MaestroApiBasePath = this.Configuration["DocuSign:MaestroApiEndpoint"],
216235
};
217236
}
218237

@@ -262,6 +281,10 @@ public string IdentifyApiOfCodeExample(string eg)
262281
{
263282
currentApiType = ExamplesApiType.Connect.ToString();
264283
}
284+
else if (eg.Contains(ExamplesApiType.Maestro.ToKeywordString()))
285+
{
286+
currentApiType = ExamplesApiType.Maestro.ToString();
287+
}
265288
else if (eg.Contains(ExamplesApiType.WebForms.ToKeywordString()))
266289
{
267290
currentApiType = ExamplesApiType.WebForms.ToString();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// <copyright file="CancelWorkflow.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.Maestro.Controllers
6+
{
7+
using DocuSign.CodeExamples;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Controllers;
10+
using DocuSign.CodeExamples.Models;
11+
using DocuSign.Maestro.Client;
12+
using DocuSign.Maestro.Model;
13+
using DocuSign.WebForms.Examples;
14+
using Microsoft.AspNetCore.Mvc;
15+
using Microsoft.Extensions.Configuration;
16+
using Newtonsoft.Json;
17+
18+
[Area("Maestro")]
19+
[Route("mae002")]
20+
public class CancelWorkflow : EgController
21+
{
22+
private IConfiguration configuration;
23+
24+
public CancelWorkflow(
25+
DsConfiguration config,
26+
IConfiguration configuration,
27+
LauncherTexts launcherTexts,
28+
IRequestItemsService requestItemsService)
29+
: base(config, launcherTexts, requestItemsService)
30+
{
31+
this.configuration = configuration;
32+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
33+
this.ViewBag.title = this.CodeExampleText.ExampleName;
34+
}
35+
36+
public override string EgName => "mae002";
37+
38+
[MustAuthenticate]
39+
[HttpGet]
40+
public override IActionResult Get()
41+
{
42+
try
43+
{
44+
var actionResult = base.Get();
45+
if (this.RequestItemsService.EgName == this.EgName)
46+
{
47+
return actionResult;
48+
}
49+
50+
var accessToken = this.RequestItemsService.User.AccessToken;
51+
var accountId = this.RequestItemsService.Session.AccountId;
52+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
53+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
54+
bool isInProgressStatus = false;
55+
if (this.RequestItemsService.InstanceId != null)
56+
{
57+
var instance = GetWorkflowService.GetWorkFlowInstance(
58+
docuSignClient,
59+
accountId,
60+
this.RequestItemsService.WorkflowId,
61+
this.RequestItemsService.InstanceId);
62+
isInProgressStatus = instance.InstanceState == WorkflowInstanceState.InProgress;
63+
}
64+
65+
this.ViewBag.WorkflowId = this.RequestItemsService.WorkflowId;
66+
this.ViewBag.InstanceId = this.RequestItemsService.InstanceId;
67+
this.ViewBag.IsInProgressStatus = isInProgressStatus;
68+
69+
return this.View("mae002");
70+
}
71+
catch (ApiException apiException)
72+
{
73+
this.ViewBag.errorCode = apiException.ErrorCode;
74+
this.ViewBag.errorMessage = apiException.Message;
75+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
76+
77+
return this.View("Error");
78+
}
79+
}
80+
81+
[MustAuthenticate]
82+
[SetViewBag]
83+
[HttpPost]
84+
[ValidateAntiForgeryToken]
85+
public ActionResult CancelFlow()
86+
{
87+
try
88+
{
89+
var accessToken = this.RequestItemsService.User.AccessToken;
90+
var accountId = this.RequestItemsService.Session.AccountId;
91+
//ds-snippet-start:Maestro2Step2
92+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
93+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
94+
//ds-snippet-end:Maestro2Step2
95+
var result = CancelWorkflowService.CancelWorkflow(docuSignClient, accountId, this.RequestItemsService.InstanceId);
96+
97+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
98+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, this.RequestItemsService.InstanceId);
99+
this.ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented);
100+
101+
return this.View("example_done");
102+
}
103+
catch (ApiException apiException)
104+
{
105+
this.ViewBag.errorCode = apiException.ErrorCode;
106+
this.ViewBag.errorMessage = apiException.Message;
107+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
108+
109+
return this.View("Error");
110+
}
111+
}
112+
}
113+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// <copyright file="GetWorkflow.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.Maestro.Controllers
6+
{
7+
using DocuSign.CodeExamples;
8+
using DocuSign.CodeExamples.Common;
9+
using DocuSign.CodeExamples.Controllers;
10+
using DocuSign.CodeExamples.Models;
11+
using DocuSign.Maestro.Client;
12+
using DocuSign.WebForms.Examples;
13+
using Microsoft.AspNetCore.Mvc;
14+
using Microsoft.Extensions.Configuration;
15+
using Newtonsoft.Json;
16+
17+
[Area("Maestro")]
18+
[Route("mae003")]
19+
public class GetWorkflow : EgController
20+
{
21+
public const string TemplateName = "Web Form Example Template";
22+
23+
private IConfiguration configuration;
24+
25+
public GetWorkflow(
26+
DsConfiguration config,
27+
IConfiguration configuration,
28+
LauncherTexts launcherTexts,
29+
IRequestItemsService requestItemsService)
30+
: base(config, launcherTexts, requestItemsService)
31+
{
32+
this.configuration = configuration;
33+
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
34+
this.ViewBag.title = this.CodeExampleText.ExampleName;
35+
}
36+
37+
public override string EgName => "mae003";
38+
39+
[MustAuthenticate]
40+
[HttpGet]
41+
public override IActionResult Get()
42+
{
43+
try
44+
{
45+
var actionResult = base.Get();
46+
if (this.RequestItemsService.EgName == this.EgName)
47+
{
48+
return actionResult;
49+
}
50+
51+
this.ViewBag.WorkflowId = this.RequestItemsService.WorkflowId;
52+
this.ViewBag.InstanceId = this.RequestItemsService.InstanceId;
53+
54+
return this.View("mae003");
55+
}
56+
catch (ApiException apiException)
57+
{
58+
this.ViewBag.errorCode = apiException.ErrorCode;
59+
this.ViewBag.errorMessage = apiException.Message;
60+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
61+
62+
return this.View("Error");
63+
}
64+
}
65+
66+
[MustAuthenticate]
67+
[SetViewBag]
68+
[HttpPost]
69+
[ValidateAntiForgeryToken]
70+
public ActionResult GetFlow()
71+
{
72+
try
73+
{
74+
var accessToken = this.RequestItemsService.User.AccessToken;
75+
var accountId = this.RequestItemsService.Session.AccountId;
76+
//ds-snippet-start:Maestro3Step2
77+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
78+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
79+
//ds-snippet-end:Maestro3Step2
80+
var result = GetWorkflowService.GetWorkFlowInstance(
81+
docuSignClient,
82+
accountId,
83+
this.RequestItemsService.WorkflowId,
84+
this.RequestItemsService.InstanceId);
85+
86+
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
87+
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, result.InstanceState);
88+
this.ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented);
89+
90+
return this.View("example_done");
91+
}
92+
catch (ApiException apiException)
93+
{
94+
this.ViewBag.errorCode = apiException.ErrorCode;
95+
this.ViewBag.errorMessage = apiException.Message;
96+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
97+
98+
return this.View("Error");
99+
}
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)