protected List <KeyValueDTO> CreateDocuSignEventValues(DocuSignEnvelopeCM_v2 envelope) { string curRecipientEmail = ""; string curRecipientUserName = ""; if (envelope != null) { var current_recipient = envelope.GetCurrentRecipient(); curRecipientEmail = current_recipient.Email; curRecipientUserName = current_recipient.Name; } return(new List <KeyValueDTO> { new KeyValueDTO("CurrentRecipientEmail", curRecipientEmail) { Tags = "EmailAddress" }, new KeyValueDTO("CurrentRecipientUserName", curRecipientUserName) { Tags = "UserName" }, new KeyValueDTO("EnvelopeStatus", envelope?.Status), new KeyValueDTO("CreateDate", envelope?.CreateDate?.ToString()) { Tags = "Date" }, new KeyValueDTO("SentDate", envelope?.SentDate?.ToString()) { Tags = "Date" }, new KeyValueDTO("Subject", envelope?.Subject), new KeyValueDTO("EnvelopeId", envelope?.EnvelopeId), }); }
public static string GetEventNames(DocuSignEnvelopeCM_v2 eventManifest) { List <string> result = new List <string>(); //Envelope events if (eventManifest.Status != null) { result.Add("Envelope" + eventManifest.Status); } //Recipinent events if (eventManifest.Recipients.Count != 0) { var recipientEvents = eventManifest.Recipients.Select(s => "Recipient" + s.Status).Distinct(); result.AddRange(recipientEvents); } return(string.Join(",", result)); }
public async Task <PollingDataDTO> Poll(PollingDataDTO pollingData) { var config = _docuSignManager.SetUp(pollingData.AuthToken); EnvelopesApi api = new EnvelopesApi((Configuration)config.Configuration); List <DocuSignEnvelopeCM_v2> changed_envelopes = new List <DocuSignEnvelopeCM_v2>(); // 1. Poll changes var changed_envelopes_info = api.ListStatusChanges(config.AccountId, new EnvelopesApi.ListStatusChangesOptions() { fromDate = DateTime.UtcNow.AddMinutes(-Convert.ToInt32(pollingData.PollingIntervalInMinutes)).ToString("o") }); foreach (var envelope in changed_envelopes_info.Envelopes) { var envelopeCM = new DocuSignEnvelopeCM_v2() { EnvelopeId = envelope.EnvelopeId, Status = envelope.Status, StatusChangedDateTime = DateTime.Parse(envelope.StatusChangedDateTime), ExternalAccountId = JToken.Parse(pollingData.AuthToken)["Email"].ToString(), }; changed_envelopes.Add(envelopeCM); } // 2. Check if we processed these envelopes before and if so - retrieve them //TODO: add overlapping minute handling var recorded_crates = new List <DocuSignEnvelopeCM_v2>(); // var recorded_crates = await _hubCommunicator.GetStoredManifests(curFr8UserId, changed_envelopes); // 3. Fill polled envelopes with data changed_envelopes = FillChangedEnvelopesWithData(config, changed_envelopes); // 4. Exclude envelopes that came from a 1 minute overlap var envelopesToNotify = ExcludeCollisions(changed_envelopes, recorded_crates); // 5. Push envelopes to event controller await PushEnvelopesToTerminalEndpoint(envelopesToNotify); pollingData.Result = true; return(pollingData); }
public static DocuSignEnvelopeCM_v2 ParseXMLintoCM(DocuSignEnvelopeInformation curDocuSignEnvelopeInfo) { var result = new DocuSignEnvelopeCM_v2(); result.EnvelopeId = curDocuSignEnvelopeInfo.EnvelopeStatus.EnvelopeID; result.Status = Enum.GetName(typeof(EnvelopeStatusCode), curDocuSignEnvelopeInfo.EnvelopeStatus.Status); result.StatusChangedDateTime = DateTime.UtcNow; result.Subject = curDocuSignEnvelopeInfo.EnvelopeStatus.Subject; result.ExternalAccountId = curDocuSignEnvelopeInfo.EnvelopeStatus.Email; result.SentDate = curDocuSignEnvelopeInfo.EnvelopeStatus.Sent; result.CreateDate = curDocuSignEnvelopeInfo.EnvelopeStatus.Created; //Recipients foreach (var recipient in curDocuSignEnvelopeInfo.EnvelopeStatus.RecipientStatuses) { var docusignRecipient = new DocuSignRecipientStatus() { Type = Enum.GetName(typeof(RecipientTypeCode), recipient.Type), Email = recipient.Email, Name = recipient.UserName, RecipientId = recipient.RecipientId, RoutingOrderId = recipient.RoutingOrder.ToString(), Status = Enum.GetName(typeof(RecipientStatusCode), recipient.Status) }; //Tabs if (recipient.TabStatuses != null) { foreach (var dstab in recipient.TabStatuses.Where(a => a.CustomTabType != CustomTabType.Radio && a.CustomTabType != CustomTabType.List)) { DocuSignTabStatus tab = ParseTab(dstab); docusignRecipient.Tabs.Add(tab); } ParseTabsWithItems(recipient, docusignRecipient); } result.Recipients.Add(docusignRecipient); } foreach (var dstemplate in curDocuSignEnvelopeInfo.EnvelopeStatus.DocumentStatuses) { var template = new DocuSignTemplate(); template.DocumentId = dstemplate.ID; //sadly Connect gives us only a template name template.TemplateId = ""; template.Name = dstemplate.TemplateName; result.Templates.Add(template); } // Connect doesn't provide CourentRoutingOrder. let's assume that it's a highest routingOrderId from recipients who completed/signed var completedRecipients = curDocuSignEnvelopeInfo.EnvelopeStatus.RecipientStatuses.Where(a => a.Status == RecipientStatusCode.Completed || a.Status == RecipientStatusCode.Signed); if (completedRecipients.Count() > 0) { result.CurrentRoutingOrderId = completedRecipients.OrderByDescending(a => a.RoutingOrder).First().RoutingOrder.ToString(); } else { result.CurrentRoutingOrderId = curDocuSignEnvelopeInfo.EnvelopeStatus.RecipientStatuses.First().RoutingOrder.ToString(); } return(result); }
public static DocuSignEnvelopeCM_v2 ParseAPIresponsesIntoCM(out DocuSignEnvelopeCM_v2 envelope, TemplateInformation templates, Recipients recipients) { envelope = new DocuSignEnvelopeCM_v2(); envelope.CurrentRoutingOrderId = recipients.CurrentRoutingOrder; if (templates.Templates != null) { foreach (var ds_template in templates.Templates) { DocuSignTemplate template = new DocuSignTemplate(); template.DocumentId = ds_template.DocumentId; template.Name = ds_template.Name; template.TemplateId = ds_template.TemplateId; envelope.Templates.Add(template); } } //Recipients if (recipients.Signers != null) { foreach (var dsrecipient in recipients.Signers) { DocuSignRecipientStatus recipient = new DocuSignRecipientStatus(); recipient.Email = dsrecipient.Email; recipient.Name = dsrecipient.Name; recipient.RecipientId = dsrecipient.RecipientId; recipient.RoutingOrderId = dsrecipient.RoutingOrder; recipient.Status = dsrecipient.Status; recipient.Type = "Signer"; envelope.Recipients.Add(recipient); //Tabs if (dsrecipient.Tabs != null) { var tabsDTO = DocuSignTab.ExtractTabs(JObject.Parse(dsrecipient.Tabs.ToJson()), ""); foreach (var tabDTO in tabsDTO) { DocuSignTabStatus tab = new DocuSignTabStatus(); tab.DocumentId = tabDTO.DocumentId.ToString(); tab.Name = tabDTO.Name; tab.TabType = tabDTO.Type; tab.Value = tabDTO.Value; tab.TabLabel = tabDTO.TabLabel; if (tabDTO is DocuSignMultipleOptionsTabDTO) { var multiTabDTO = (DocuSignMultipleOptionsTabDTO)tabDTO; foreach (var childDTO in multiTabDTO.Items) { var childTab = new DocuSignTabStatus(); childTab.Selected = childDTO.Selected.ToString(); childTab.Value = childDTO.Value; childTab.TabLabel = childDTO.Text; tab.Items.Add(childTab); } } recipient.Tabs.Add(tab); } } } } return(envelope); }
public override async Task Run() { DocuSignEnvelopeCM_v2 envelopeStatus = null; var eventCrate = Payload.CratesOfType <EventReportCM>().FirstOrDefault()?.Get <EventReportCM>()?.EventPayload; if (eventCrate != null) { envelopeStatus = eventCrate.CrateContentsOfType <DocuSignEnvelopeCM_v2>().SingleOrDefault(); } if (envelopeStatus == null) { RequestPlanExecutionTermination("Evelope was not found in the payload."); return; } //Create run-time fields var eventFields = CreateDocuSignEventValues(envelopeStatus); //get currently selected option and its value string curSelectedOption, curSelectedValue, curSelectedTemplate; GetTemplateRecipientPickerValue(out curSelectedOption, out curSelectedValue, out curSelectedTemplate); var envelopeId = string.Empty; //retrieve envelope ID based on the selected option and its value if (!string.IsNullOrEmpty(curSelectedOption)) { switch (curSelectedOption) { case "template": //filter the incoming envelope by template value selected by the user var incomingTemplate = string.Join(",", envelopeStatus.Templates.Select(t => t.Name).ToArray()); //Dirty quick fix for FR-2858 if (string.IsNullOrEmpty(incomingTemplate)) { var manager = new DocuSignManager(); var config = manager.SetUp(AuthorizationToken); TemplatesApi api = new TemplatesApi(config.Configuration); var templateslist = api.ListTemplates(config.AccountId); if (templateslist.TotalSetSize == "0") { break; } incomingTemplate = string.Join(",", templateslist.EnvelopeTemplates.Select(a => a.Name).ToArray()); } if (incomingTemplate.Contains(curSelectedTemplate, StringComparison.InvariantCultureIgnoreCase)) { envelopeId = envelopeStatus.EnvelopeId; } else { //this event isn't about us let's stop execution RequestPlanExecutionTermination(); return; } break; case "recipient": string envelopeCurentRecipientEmail = eventFields.FirstOrDefault(a => a.Key == "CurrentRecipientEmail")?.Value; //filter incoming envelope by recipient email address specified by the user if (envelopeCurentRecipientEmail != null) { //if the incoming envelope's recipient is user specified one, get the envelope ID if (envelopeCurentRecipientEmail.Contains(curSelectedValue, StringComparison.InvariantCultureIgnoreCase)) { envelopeId = envelopeStatus.EnvelopeId; } else { //this event isn't about us let's stop execution RequestPlanExecutionTermination(); return; } } break; } } var allFields = new List <KeyValueDTO>(eventFields); if (curSelectedOption == "template") { allFields.AddRange(GetEnvelopeData(envelopeId)); allFields.Add(new KeyValueDTO("TemplateName", curSelectedTemplate)); } Payload.Add(AllFieldsCrateName, new StandardPayloadDataCM(allFields)); Success(); }