Skip to content

Commit 0faeaea

Browse files
authored
Merge pull request #27 from docusign/transfer-monitor-example-to-use-sdk
Changed monitor example to use sdk
2 parents a7e32c8 + c4d680f commit 0faeaea

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

launcher-csharp/Monitor/Examples/GetMonitoringData.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Net;
5-
using Microsoft.AspNetCore.Mvc;
6-
using Newtonsoft.Json.Linq;
3+
using DocuSign.Monitor.Api;
4+
using DocuSign.Monitor.Client;
5+
using static DocuSign.Monitor.Api.DataSetApi;
76

87
namespace DocuSign.CodeExamples.Monitor.Examples
98
{
@@ -17,40 +16,36 @@ public class GetMonitoringDataFunc
1716
/// <returns>The list of JObjects, containing data from monitor</returns>
1817
public virtual IEnumerable<Object> Invoke(string accessToken, string requestPath)
1918
{
19+
ApiClient apiClient = new ApiClient(ApiClient.Demo_REST_BasePath);
20+
2021
// Construct API headers
2122
// step 2 start
22-
WebHeaderCollection headers = new WebHeaderCollection();
23-
headers.Add("Authorization", String.Format("Bearer {0}", accessToken));
24-
headers.Add("Content-Type", "application/json");
23+
apiClient.SetBasePath(ApiClient.Demo_REST_BasePath);
24+
apiClient.Configuration.DefaultHeader.Add("Authorization", String.Format("Bearer {0}", accessToken));
25+
apiClient.Configuration.DefaultHeader.Add("Content-Type", "application/json");
2526
// step 2 end
2627

2728
// Declare variables
2829
// step 3 start
2930
bool complete = false;
3031
string cursorValue = "";
3132
int limit = 2; // Amount of records you want to read in one request
32-
List<JObject> functionResult = new List<JObject>();
33+
List<object> functionResult = new List<object>();
34+
35+
DataSetApi dataSetApi = new DataSetApi(apiClient);
36+
GetStreamOptions options = new GetStreamOptions();
37+
38+
options.limit = limit;
3339

3440
// Get monitoring data
3541
do
3642
{
37-
var cursorValueFormatted = (!string.IsNullOrEmpty(cursorValue)) ? $"={cursorValue}" : cursorValue;
38-
39-
// Add cursor value and amount of records to read to the request
40-
var requestParameters = String.Format("stream?cursor{0}&limit={1}",
41-
cursorValueFormatted, limit);
42-
43-
WebRequest request = WebRequest.Create(requestPath + requestParameters);
44-
request.Headers = headers;
45-
46-
Stream requestStream = request.GetResponse().GetResponseStream();
47-
StreamReader requestStreamReader = new StreamReader(requestStream);
43+
if (!string.IsNullOrEmpty(cursorValue))
44+
options.cursor = cursorValue;
4845

49-
string result = requestStreamReader.ReadToEnd();
46+
var cursoredResult = dataSetApi.GetStreamWithHttpInfo("2.0", "monitor", options);
5047

51-
// Parse result to JSON format
52-
JObject resultJson = JObject.Parse(result);
53-
string endCursor = resultJson.GetValue("endCursor").ToString();
48+
string endCursor = cursoredResult.Data.EndCursor;
5449

5550
// If the endCursor from the response is the same as the one that you already have,
5651
// it means that you have reached the end of the records
@@ -61,7 +56,7 @@ public virtual IEnumerable<Object> Invoke(string accessToken, string requestPath
6156
else
6257
{
6358
cursorValue = endCursor;
64-
functionResult.Add(resultJson);
59+
functionResult.AddRange(cursoredResult.Data.Data);
6560
}
6661
}
6762
while (!complete);

launcher-csharp/launcher-csharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ItemGroup>
2121
<PackageReference Include="DocuSign.Click" Version="1.0.0" />
2222
<PackageReference Include="DocuSign.eSign.dll" Version="5.3.1-rc" />
23+
<PackageReference Include="DocuSign.Monitor" Version="1.0.0-beta" />
2324
<PackageReference Include="DocuSign.Rooms" Version="1.1.0" />
2425
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
2526
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0-preview1.19506.2" />

0 commit comments

Comments
 (0)