public override async Task Run()
        {
            var userDefinedFields = Storage.FirstCrateOrDefault <KeyValueListCM>(x => x.Label == UserFieldsAndRolesCrateLabel);

            if (userDefinedFields == null)
            {
                throw new ActivityExecutionException("Activity storage doesn't contain info about DocuSign envelope properties. This may indicate that activity was not properly configured. Try to reconfigure this activity");
            }
            var allFields   = userDefinedFields.Content.Values;
            var roleValues  = ActivityUI.RolesFields.Select(x => new { x.Name, Value = x.TextValue }).ToDictionary(x => x.Name, x => x.Value);
            var fieldValues = ActivityUI.CheckBoxFields.Select(x => new { x.Name, Value = x.Selected.ToString().ToLower() })
                              .Concat(ActivityUI.DropDownListFields.Select(x => new { x.Name, Value = x.selectedKey }))
                              .Concat(ActivityUI.RadioButtonGroupFields.Select(x => new { x.Name, x.Radios.FirstOrDefault(y => y.Selected)?.Value }))
                              .Concat(ActivityUI.TextFields.Select(x => new { x.Name, Value = x.TextValue }))
                              .ToDictionary(x => x.Name, x => x.Value);
            var docuSignConfiguration = DocuSignManager.SetUp(AuthorizationToken);
            var roleFields            = allFields.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignSignerTag, StringComparison.InvariantCultureIgnoreCase)).ToList();

            foreach (var roleField in roleFields)
            {
                roleField.Value = roleValues[roleField.Key];
            }
            var userFields = allFields.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignTabTag)).ToList();

            foreach (var userField in userFields)
            {
                userField.Value = fieldValues[userField.Key];
            }
            DocuSignManager.SendAnEnvelopeFromTemplate(docuSignConfiguration, roleFields, userFields, SelectedTemplateId);
        }
        private async Task FillDropdowns()
        {
            var docusignToken = JsonConvert.DeserializeObject <DocuSignAuthTokenDTO>(AuthorizationToken.Token);

            if (this["AccountId"] != docusignToken.AccountId)
            {
                var configuration = DocuSignManager.SetUp(AuthorizationToken);

                ActivityUI.TemplateSelector.selectedKey  = null;
                ActivityUI.TemplateSelector.SelectedItem = null;
                ActivityUI.TemplateSelector.ListItems.Clear();
                ActivityUI.TemplateSelector.ListItems.AddRange(DocuSignManager.GetTemplatesList(configuration)
                                                               .Select(x => new ListItem {
                    Key = x.Key, Value = x.Value
                }));

                ActivityUI.NotifierSelector.selectedKey  = null;
                ActivityUI.NotifierSelector.SelectedItem = null;
                ActivityUI.NotifierSelector.ListItems.Clear();
                ActivityUI.NotifierSelector.ListItems.AddRange((await HubCommunicator.GetActivityTemplates(Tags.Notifier, true))
                                                               .Select(x => new ListItem {
                    Key = x.Label, Value = x.Id.ToString()
                }));

                this["AccountId"] = docusignToken.AccountId;
            }
        }
        private Crate PackAvailableTemplates()
        {
            var conf   = DocuSignManager.SetUp(AuthorizationToken);
            var fields = DocuSignManager.GetTemplatesList(conf);

            var crate = Crate.FromContent("AvailableTemplates", new KeyValueListCM(fields));

            return(crate);
        }
        public override async Task Run()
        {
            var loginInfo     = DocuSignManager.SetUp(AuthorizationToken);
            var curTemplateId = ExtractTemplateId();
            var fieldList     = MapControlsToFields();
            var rolesList     = MapRoleControlsToFields();

            SendAnEnvelope(loginInfo, rolesList, fieldList, curTemplateId);
        }
Example #5
0
        public override async Task Run()
        {
            var configuration = DocuSignManager.SetUp(AuthorizationToken);
            var settings      = GetDocusignQuery();
            var folderItems   = DocuSignFolders.GetFolderItems(configuration, settings);

            Payload.Add(Crate.FromContent(RunTimeCrateLabel, new DocuSignEnvelopeCM_v3
            {
                Envelopes = folderItems.Select(ConvertFolderItemToDocuSignEnvelope).ToList()
            }));
        }
        public override async Task Run()
        {
            var configuration = DocuSignManager.SetUp(AuthorizationToken);
            var settings      = GetDocusignQuery();
            var folderItems   = DocuSignFolders.GetFolderItems(configuration, settings);

            foreach (var item in folderItems)
            {
                Payload.Add(Crate.FromContent(RunTimeCrateLabel, MapFolderItemToDocuSignEnvelopeCM(item)));
            }
            Success();
        }
        private void FillFolderSource(string controlName)
        {
            var control = ConfigurationControls.FindByNameNested <DropDownList>(controlName);

            if (control != null)
            {
                var conf = DocuSignManager.SetUp(AuthorizationToken);
                control.ListItems = DocuSignFolders.GetFolders(conf)
                                    .Select(x => new ListItem()
                {
                    Key = x.Key, Value = x.Value
                })
                                    .ToList();
            }
        }
        private void LoadDocuSignTemplates()
        {
            var selectedTemplateId = SelectedTemplateId;
            var configuratin       = DocuSignManager.SetUp(AuthorizationToken);

            ActivityUI.TemplateSelector.ListItems = DocuSignManager.GetTemplatesList(configuratin)
                                                    .Select(x => new ListItem {
                Key = x.Key, Value = x.Value
            })
                                                    .ToList();
            if (string.IsNullOrEmpty(selectedTemplateId))
            {
                return;
            }
            ActivityUI.TemplateSelector.SelectByValue(selectedTemplateId);
        }
Example #9
0
        public override async Task Run()
        {
            //Get template Id
            var    control = GetControl <DropDownList>("Available_Templates");
            string selectedDocusignTemplateId = control.Value;

            if (selectedDocusignTemplateId == null)
            {
                RaiseError("No Template was selected at design time", ActivityErrorCode.DESIGN_TIME_DATA_MISSING);
                return;
            }
            var config = DocuSignManager.SetUp(AuthorizationToken);
            //lets download specified template from user's docusign account
            var downloadedTemplate = DocuSignManager.DownloadDocuSignTemplate(config, selectedDocusignTemplateId);
            //and add it to payload
            var templateCrate = CreateDocuSignTemplateCrateFromDto(downloadedTemplate);

            Payload.Add(templateCrate);
            Success();
        }
Example #10
0
        public override async Task Initialize()
        {
            var configuration = DocuSignManager.SetUp(AuthorizationToken);

            ActivityUI.FolderFilter.ListItems = DocuSignFolders.GetFolders(configuration)
                                                .Select(x => new ListItem {
                Key = x.Key, Value = x.Value
            })
                                                .ToList();
            ActivityUI.FolderFilter.ListItems.Insert(0, new ListItem {
                Key = "Any Folder", Value = string.Empty
            });
            ActivityUI.StatusFilter.ListItems = DocuSignQuery.Statuses
                                                .Select(x => new ListItem {
                Key = x.Key, Value = x.Value
            })
                                                .ToList();
            CrateSignaller.MarkAvailableAtRuntime <DocuSignEnvelopeCM_v3>(RunTimeCrateLabel, true)
            .AddFields(GetEnvelopeProperties());
        }
        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();
        }
        public override async Task FollowUp()
        {
            //Load DocuSign template again in case there are new templates available
            LoadDocuSignTemplates();
            var selectedTemplateId = SelectedTemplateId;

            //If template selection is cleared we should remove existing template fields
            if (string.IsNullOrEmpty(selectedTemplateId))
            {
                PreviousSelectedTemplateId = null;
                ActivityUI.ClearDynamicFields();
                Storage.RemoveByLabel(UserFieldsAndRolesCrateLabel);
                return;
            }
            if (selectedTemplateId == PreviousSelectedTemplateId)
            {
                return;
            }
            ActivityUI.ClearDynamicFields();
            PreviousSelectedTemplateId = selectedTemplateId;
            var docuSignConfiguration = DocuSignManager.SetUp(AuthorizationToken);
            var tabsAndFields         = DocuSignManager.GetTemplateRecipientsTabsAndDocuSignTabs(docuSignConfiguration, selectedTemplateId);
            var roles             = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignSignerTag, StringComparison.InvariantCultureIgnoreCase)).ToArray();
            var userDefinedFields = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignTabTag));
            var envelopeData      = tabsAndFields.Item2.ToLookup(x => x.Fr8DisplayType);

            //check for DocuSign default template names and add advisory json
            var hasDefaultNames = DocuSignManager.DocuSignTemplateDefaultNames(tabsAndFields.Item2);

            if (hasDefaultNames)
            {
                var advisoryCrate          = Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault();
                var currentAdvisoryResults = advisoryCrate == null ? new AdvisoryMessagesCM() : advisoryCrate.Content;

                var advisory = currentAdvisoryResults.Advisories.FirstOrDefault(x => x.Name == AdvisoryName);

                if (advisory == null)
                {
                    currentAdvisoryResults.Advisories.Add(new AdvisoryMessageDTO {
                        Name = AdvisoryName, Content = AdvisoryContent
                    });
                }
                else
                {
                    advisory.Content = AdvisoryContent;
                }

                Storage.Add(Crate.FromContent("Advisories", currentAdvisoryResults));
            }
            //Add TextSource control for every DocuSign role to activity UI
            ActivityUI.RolesFields.AddRange(roles.Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Key, x.Key, requestUpstream: true, specificValue: x.Value)));
            //Add TextSrouce control for every DocuSign template text field to activity UI
            ActivityUI.TextFields.AddRange(envelopeData[ControlTypes.TextBox].Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Name, x.Name, requestUpstream: true, specificValue: x.Value)));
            //Add RadioButtonGroup with respective options for every DocuSign template radio selection field to activity UI
            ActivityUI.RadioButtonGroupFields.AddRange(
                envelopeData[ControlTypes.RadioButtonGroup]
                .OfType <DocuSignMultipleOptionsTabDTO>()
                .Select(x => new RadioButtonGroup
            {
                GroupName = x.Name,
                Name      = x.Name,
                Label     = $"For the <strong>{x.Name}</strong>, use:",
                Radios    = x.Items.Select(y => new RadioButtonOption
                {
                    Name     = y.Value,
                    Value    = y.Value,
                    Selected = y.Selected
                })
                            .ToList()
            }));
            //Add CheckBox for every DocuSign template yes/no field to activity UI
            ActivityUI.CheckBoxFields.AddRange(envelopeData[ControlTypes.CheckBox].Select(x => new CheckBox {
                Name = x.Name, Label = x.Name, Selected = Convert.ToBoolean(x.Value)
            }));
            //Add DropDownList for every DocuSign template list selection field to activity UI
            ActivityUI.DropDownListFields.AddRange(
                envelopeData[ControlTypes.DropDownList]
                .OfType <DocuSignMultipleOptionsTabDTO>()
                .Select(x => new DropDownList
            {
                Name      = x.Name,
                Label     = $"For the <strong>{x.Name}</strong>, use:",
                ListItems = x.Items.Select(y => new ListItem
                {
                    Key      = string.IsNullOrEmpty(y.Value) ? y.Text : y.Value,
                    Value    = string.IsNullOrEmpty(y.Text) ? y.Value : y.Text,
                    Selected = y.Selected
                })
                            .ToList()
            }));

            Storage.ReplaceByLabel(Crate.FromContent(UserFieldsAndRolesCrateLabel, new KeyValueListCM(userDefinedFields.Concat(roles))));
        }
        public async void Test_MonitorAllDocuSignEvents_Plan()
        {
            using (var unitOfWork = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var testAccount = unitOfWork.UserRepository
                                  .GetQuery()
                                  .SingleOrDefault(x => x.UserName == UserAccountName);

                var docuSignTerminal = unitOfWork.TerminalRepository
                                       .GetQuery()
                                       .SingleOrDefault(x => x.Name == TerminalName);

                if (testAccount == null)
                {
                    throw new ApplicationException(
                              string.Format("No test account found with UserName = {0}", UserAccountName)
                              );
                }

                if (docuSignTerminal == null)
                {
                    throw new ApplicationException(
                              string.Format("No terminal found with Name = {0}", TerminalName)
                              );
                }

                await RecreateDefaultAuthToken(unitOfWork, testAccount, docuSignTerminal);

                var mtDataCountBefore = unitOfWork.MultiTenantObjectRepository
                                        .AsQueryable <DocuSignEnvelopeCM_v2>(testAccount.Id).MtCount();
                int mtDataCountAfter = mtDataCountBefore;

                //Set up DS
                var token = await Authenticate();

                var authToken = new AuthorizationToken()
                {
                    Token = token.Token
                };
                var authTokenDO = new AuthorizationTokenDO()
                {
                    Token = token.Token
                };
                var docuSignManager = new DocuSignManager();
                var loginInfo       = docuSignManager.SetUp(authToken);

                //let's wait 10 seconds to ensure that MADSE plan was created/activated by re-authentication
                await Task.Delay(MadseCreationPeriod);

                //send envelope
                SendDocuSignTestEnvelope(docuSignManager, loginInfo, authTokenDO);

                var stopwatch = new Stopwatch();
                stopwatch.Start();


                while (stopwatch.ElapsedMilliseconds <= MaxAwaitPeriod)
                {
                    await Task.Delay(SingleAwaitPeriod);

                    mtDataCountAfter = unitOfWork.MultiTenantObjectRepository
                                       .AsQueryable <DocuSignEnvelopeCM_v2>(testAccount.Id).MtCount();

                    if (mtDataCountBefore < mtDataCountAfter)
                    {
                        break;
                    }
                }

                Assert.IsTrue(mtDataCountBefore < mtDataCountAfter,
                              $"The number of MtData: ({mtDataCountAfter}) records for user {UserAccountName} remained unchanged within {MaxAwaitPeriod} miliseconds.");
            }
        }
        protected async Task HandleFollowUpConfiguration()
        {
            if (Storage.Count == 0)
            {
                return;
            }


            //update docusign templates list to get if new templates were provided by DS
            FillDocuSignTemplateSource("target_docusign_template");
            // Try to find DocuSignTemplate drop-down.

            var dropdownControlDTO = ConfigurationControls.FindByName("target_docusign_template");

            if (dropdownControlDTO == null)
            {
                return;
            }
            // Get DocuSign Template Id
            var docusignTemplateId = dropdownControlDTO.Value;

            //Abort configuration if templateId is the same that before
            if (!IsNewTemplateIdChoosen(Storage, docusignTemplateId))
            {
                return;
            }

            var conf          = DocuSignManager.SetUp(AuthorizationToken);
            var tabsandfields = DocuSignManager.GetTemplateRecipientsTabsAndDocuSignTabs(conf, docusignTemplateId);

            var roles = tabsandfields.Item1.Where(a => a.Tags.Contains(DocuSignConstants.DocuSignSignerTag));

            Storage.RemoveByLabel("DocuSignTemplateRolesFields");
            Storage.Add("DocuSignTemplateRolesFields", new KeyValueListCM(roles));


            var envelopeDataDTO = tabsandfields.Item2;

            var userDefinedFields = tabsandfields.Item1.Where(a => a.Tags.Contains(DocuSignConstants.DocuSignTabTag));

            //check for DocuSign default template names and add advisory json
            var hasDefaultNames = DocuSignManager.DocuSignTemplateDefaultNames(tabsandfields.Item2);

            if (hasDefaultNames)
            {
                var advisoryCrate          = Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault();
                var currentAdvisoryResults = advisoryCrate == null ? new AdvisoryMessagesCM() : advisoryCrate.Content;

                var advisory = currentAdvisoryResults.Advisories.FirstOrDefault(x => x.Name == advisoryName);

                if (advisory == null)
                {
                    currentAdvisoryResults.Advisories.Add(new AdvisoryMessageDTO {
                        Name = advisoryName, Content = advisoryContent
                    });
                }
                else
                {
                    advisory.Content = advisoryContent;
                }

                Storage.Add(Crate.FromContent("Advisories", currentAdvisoryResults));
            }

            Storage.RemoveByLabel("DocuSignTemplateUserDefinedFields");
            Storage.Add("DocuSignTemplateUserDefinedFields", new KeyValueListCM(userDefinedFields.Concat(roles)));

            //Create TextSource controls for ROLES
            var rolesMappingBehavior = new TextSourceMappingBehavior(Storage, "RolesMapping", true);

            rolesMappingBehavior.Clear();
            rolesMappingBehavior.Append(roles.Select(x => x.Key).ToList(), "Upstream Terminal-Provided Fields", AvailabilityType.RunTime);

            //Create Text Source controls for TABS
            var textSourceFields = new List <string>();

            textSourceFields = envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.TextBox).Select(x => x.Name).ToList();
            var mappingBehavior = new TextSourceMappingBehavior(
                Storage,
                "Mapping",
                true
                );

            mappingBehavior.Clear();
            mappingBehavior.Append(textSourceFields, "Upstream Terminal-Provided Fields", AvailabilityType.RunTime);
            //Create TextSource controls for ROLES

            //Create radio Button Groups
            var radioButtonGroupBehavior = new RadioButtonGroupMappingBehavior(Storage, "RadioGroupMapping");

            radioButtonGroupBehavior.Clear();
            foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.RadioButtonGroup).ToList())
            {
                var radioButtonGroupDTO = item as DocuSignMultipleOptionsTabDTO;
                if (radioButtonGroupDTO == null)
                {
                    continue;
                }
                //todo: migrate the string format for label into template
                radioButtonGroupBehavior.Append(radioButtonGroupDTO.Name,
                                                $"For the <strong>{radioButtonGroupDTO.Name}</strong>, use:", radioButtonGroupDTO.Items.Select(x => new RadioButtonOption()
                {
                    Name     = x.Value,
                    Value    = x.Value,
                    Selected = x.Selected
                }).ToList());
            }

            //create checkbox controls
            var checkBoxMappingBehavior = new CheckBoxMappingBehavior(Storage, "CheckBoxMapping");

            checkBoxMappingBehavior.Clear();
            foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.CheckBox).ToList())
            {
                checkBoxMappingBehavior.Append(item.Name, item.Name);
            }

            //create dropdown controls
            var dropdownListMappingBehavior = new DropDownListMappingBehavior(Storage, "DropDownMapping");

            dropdownListMappingBehavior.Clear();
            foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.DropDownList).ToList())
            {
                var dropDownListDTO = item as DocuSignMultipleOptionsTabDTO;
                if (dropDownListDTO == null)
                {
                    continue;
                }

                dropdownListMappingBehavior.Append(dropDownListDTO.Name, $"For the <strong>{item.Name}</strong>, use:", dropDownListDTO.Items.Where(x => x.Text != string.Empty || x.Value != string.Empty).Select(x => new ListItem()
                {
                    Key      = string.IsNullOrEmpty(x.Value) ? x.Text : x.Value,
                    Value    = string.IsNullOrEmpty(x.Text) ? x.Value : x.Text,
                    Selected = x.Selected,
                }).ToList());
            }
        }