Skip to content

Commit 3272cbc

Browse files
committed
implement trigger, get and cancel workflow
1 parent e704573 commit 3272cbc

File tree

20 files changed

+686
-27
lines changed

20 files changed

+686
-27
lines changed

ExamplesApiTypeExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public enum ExamplesApiType
4343
/// </summary>
4444
[Description("con")]
4545
Connect = 5,
46+
47+
48+
/// <summary>
49+
/// Maestro API
50+
/// </summary>
51+
[Description("mae")]
52+
Maestro = 6,
4653
}
4754

4855
public static class ExamplesApiTypeExtensions

launcher-csharp/Common/IRequestItemsService.cs

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

3535
public string TemplateId { get; set; }
3636

37+
public string WorkflowId { get; set; }
38+
39+
public bool WorkflowPublished { get; set; }
40+
41+
public string InstanceId { get; set; }
42+
3743
public string PausedEnvelopeId { get; set; }
3844

3945
public string Status { get; set; }

launcher-csharp/Common/LocalsFilter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ 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+
MaestroManageApiBasePath = this.configuration["DocuSign:MaestroManageApiEndpoint"],
101+
MaestroAuthApiBasePath = this.configuration["DocuSign:MaestroAuthApiEndpoint"],
100102
}
101103
:
102104
new Session
@@ -106,6 +108,8 @@ public void OnActionExecuting(ActionExecutingContext context)
106108
BasePath = this.requestItemsService.Session.BasePath,
107109
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
108110
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
111+
MaestroManageApiBasePath = this.configuration["DocuSign:MaestroManageApiEndpoint"],
112+
MaestroAuthApiBasePath = this.configuration["DocuSign:MaestroAuthApiEndpoint"],
109113
};
110114

111115
this.requestItemsService.Session = locals.Session;

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 18 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 WorkflowPublished
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 ClickwrapId
152170
{
153171
get => this.cache.Get<string>(this.GetKey("ClickwrapId"));
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
CodeExampleText = GetExampleText(EgName, ExamplesApiType.Maestro);
33+
ViewBag.title = 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 (RequestItemsService.EgName == EgName)
46+
{
47+
return actionResult;
48+
}
49+
50+
var accessToken = RequestItemsService.User.AccessToken;
51+
var accountId = RequestItemsService.Session.AccountId;
52+
var docuSignClient = new DocuSignClient(RequestItemsService.Session.MaestroManageApiBasePath);
53+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
54+
bool isInProgressStatus = false;
55+
if(RequestItemsService.InstanceId != null)
56+
{
57+
var instance = GetWorkflowService.GetWorkFlowInstance(docuSignClient, accountId, RequestItemsService.WorkflowId, RequestItemsService.InstanceId);
58+
isInProgressStatus = instance.InstanceState == WorkflowInstance.WorkflowInstanceState.InProgress;
59+
}
60+
61+
ViewBag.WorkflowId = RequestItemsService.WorkflowId;
62+
ViewBag.InstanceId = RequestItemsService.InstanceId;
63+
ViewBag.IsInProgressStatus = isInProgressStatus;
64+
//ViewBag.IsInProgressStatus = true;
65+
66+
return View("mae002");
67+
}
68+
catch (ApiException apiException)
69+
{
70+
ViewBag.errorCode = apiException.ErrorCode;
71+
ViewBag.errorMessage = apiException.Message;
72+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
73+
74+
return View("Error");
75+
}
76+
}
77+
78+
[MustAuthenticate]
79+
[SetViewBag]
80+
[HttpPost]
81+
[ValidateAntiForgeryToken]
82+
public ActionResult CancelFlow()
83+
{
84+
try
85+
{
86+
var accessToken = RequestItemsService.User.AccessToken;
87+
var accountId = RequestItemsService.Session.AccountId;
88+
var docuSignClient = new DocuSignClient(RequestItemsService.Session.MaestroManageApiBasePath);
89+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
90+
var result = CancelWorkflowService.CancelWorkflow(docuSignClient, accountId, RequestItemsService.InstanceId);
91+
92+
ViewBag.h1 = CodeExampleText.ExampleName;
93+
ViewBag.message = string.Format(CodeExampleText.ResultsPageText, RequestItemsService.InstanceId);
94+
ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented);
95+
96+
return View("example_done");
97+
}
98+
catch (ApiException apiException)
99+
{
100+
ViewBag.errorCode = apiException.ErrorCode;
101+
ViewBag.errorMessage = apiException.Message;
102+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
103+
104+
return View("Error");
105+
}
106+
}
107+
}
108+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
CodeExampleText = GetExampleText(EgName, ExamplesApiType.Maestro);
34+
ViewBag.title = 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 (RequestItemsService.EgName == EgName)
47+
{
48+
return actionResult;
49+
}
50+
51+
ViewBag.WorkflowId = RequestItemsService.WorkflowId;
52+
ViewBag.InstanceId = RequestItemsService.InstanceId;
53+
54+
return View("mae003");
55+
}
56+
catch (ApiException apiException)
57+
{
58+
ViewBag.errorCode = apiException.ErrorCode;
59+
ViewBag.errorMessage = apiException.Message;
60+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
61+
62+
return View("Error");
63+
}
64+
}
65+
66+
[MustAuthenticate]
67+
[SetViewBag]
68+
[HttpPost]
69+
[ValidateAntiForgeryToken]
70+
public ActionResult GetFlow()
71+
{
72+
try
73+
{
74+
var accessToken = RequestItemsService.User.AccessToken;
75+
var accountId = RequestItemsService.Session.AccountId;
76+
var docuSignClient = new DocuSignClient(RequestItemsService.Session.MaestroManageApiBasePath);
77+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
78+
var result = GetWorkflowService.GetWorkFlowInstance(docuSignClient, accountId, RequestItemsService.WorkflowId, RequestItemsService.InstanceId);
79+
80+
ViewBag.h1 = CodeExampleText.ExampleName;
81+
ViewBag.message = string.Format(CodeExampleText.ResultsPageText, result.InstanceState);
82+
ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented);
83+
84+
return View("example_done");
85+
}
86+
catch (ApiException apiException)
87+
{
88+
ViewBag.errorCode = apiException.ErrorCode;
89+
ViewBag.errorMessage = apiException.Message;
90+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
91+
92+
return View("Error");
93+
}
94+
}
95+
}
96+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// <copyright file="TriggerWorkflow.cs" company="DocuSign">
2+
// Copyright (c) DocuSign. All rights reserved.
3+
// </copyright>
4+
5+
namespace DocuSign.Maestro.Controllers
6+
{
7+
using System;
8+
using DocuSign.CodeExamples;
9+
using DocuSign.CodeExamples.Common;
10+
using DocuSign.CodeExamples.Controllers;
11+
using DocuSign.CodeExamples.Maestro.Models;
12+
using DocuSign.CodeExamples.Models;
13+
using DocuSign.Maestro.Client;
14+
using DocuSign.WebForms.Examples;
15+
using Microsoft.AspNetCore.Mvc;
16+
using Microsoft.Extensions.Configuration;
17+
using Newtonsoft.Json;
18+
19+
[Area("Maestro")]
20+
[Route("mae001")]
21+
public class TriggerWorkflow : EgController
22+
{
23+
private IConfiguration configuration;
24+
25+
public TriggerWorkflow(
26+
DsConfiguration config,
27+
IConfiguration configuration,
28+
LauncherTexts launcherTexts,
29+
IRequestItemsService requestItemsService)
30+
: base(config, launcherTexts, requestItemsService)
31+
{
32+
this.configuration = configuration;
33+
CodeExampleText = GetExampleText(EgName, ExamplesApiType.Maestro);
34+
ViewBag.title = CodeExampleText.ExampleName;
35+
}
36+
37+
public override string EgName => "mae001";
38+
39+
[MustAuthenticate]
40+
[HttpGet]
41+
public override IActionResult Get()
42+
{
43+
try
44+
{
45+
var actionResult = base.Get();
46+
if (RequestItemsService.EgName == EgName)
47+
{
48+
return actionResult;
49+
}
50+
51+
RequestItemsService.WorkflowId = configuration["DocuSign:WorkflowId"];
52+
var accessToken = RequestItemsService.User.AccessToken;
53+
var accountId = RequestItemsService.Session.AccountId;
54+
55+
if (!RequestItemsService.WorkflowPublished)
56+
{
57+
var docuSignClient = new DocuSignClient(RequestItemsService.Session.MaestroManageApiBasePath);
58+
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
59+
TriggerWorkflowService.PublishWorkFlow(docuSignClient, accountId, RequestItemsService.WorkflowId);
60+
RequestItemsService.WorkflowPublished = true;
61+
}
62+
63+
ViewBag.Config = Config;
64+
var workflowTriggerModel = new WorkflowTriggerModel();
65+
66+
return View("mae001", workflowTriggerModel);
67+
}
68+
catch (ApiException apiException)
69+
{
70+
ViewBag.errorCode = apiException.ErrorCode;
71+
ViewBag.errorMessage = apiException.Message;
72+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
73+
74+
return View("Error");
75+
}
76+
}
77+
78+
[MustAuthenticate]
79+
[SetViewBag]
80+
[HttpPost]
81+
[ValidateAntiForgeryToken]
82+
public ActionResult SubmitForm(WorkflowTriggerModel model)
83+
{
84+
try
85+
{
86+
var accessToken = RequestItemsService.User.AccessToken;
87+
var accountId = RequestItemsService.Session.AccountId;
88+
var docuSignManageClient = new DocuSignClient(RequestItemsService.Session.MaestroManageApiBasePath);
89+
docuSignManageClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
90+
var workflow = TriggerWorkflowService.GetWorkFlowDefinition(docuSignManageClient, accountId, RequestItemsService.WorkflowId);
91+
92+
var docuSignAuthClient = new DocuSignClient(RequestItemsService.Session.MaestroAuthApiBasePath);
93+
docuSignAuthClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
94+
var result = TriggerWorkflowService.TriggerWorkflow(docuSignAuthClient, accountId, new Uri(workflow.TriggerUrl), model);
95+
96+
RequestItemsService.InstanceId = result.InstanceId;
97+
98+
ViewBag.h1 = CodeExampleText.ExampleName;
99+
ViewBag.message = CodeExampleText.ResultsPageText;
100+
ViewBag.Locals.Json = JsonConvert.SerializeObject(result, Formatting.Indented);
101+
102+
return View("example_done");
103+
}
104+
catch (ApiException apiException)
105+
{
106+
ViewBag.errorCode = apiException.ErrorCode;
107+
ViewBag.errorMessage = apiException.Message;
108+
ViewBag.SupportingTexts = LauncherTexts.ManifestStructure.SupportingTexts;
109+
110+
return View("Error");
111+
}
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)