private async Task <ActivityPayload> ConfigureQueryFr8Activity(List <ActivityTemplateDTO> activityTemplates)
        {
            var template = activityTemplates.Single(x => x.Terminal.Name == "terminalFr8Core" && x.Name == "Get_Data_From_Fr8_Warehouse" && x.Version == "1");
            var activity = await HubCommunicator.AddAndConfigureChildActivity(ActivityPayload, template, order : 3);

            var crateStorage    = activity.CrateStorage;
            var configControlCM = ActivityConfigurator.GetConfigurationControls(activity);
            var objectList      = (DropDownList)configControlCM.Controls.First(x => x.Name == "AvailableObjects");
            var selectedObject  = objectList.ListItems.Where(a => a.Key == (ActivityUI.BasedOnTemplateOption.Selected ? MT.DocuSignEnvelope_v2.GetEnumDisplayName() : MT.DocuSignRecipient.GetEnumDisplayName())).FirstOrDefault();

            if (selectedObject == null)
            {
                return(activity);
            }
            objectList.SelectByKey(selectedObject.Key);
            var queryBuilder = (QueryBuilder)configControlCM.Controls.First(c => c.Name == "QueryBuilder");
            var conditions   = new List <FilterConditionDTO>();

            if (ActivityUI.SentToSpecificRecipientOption.Selected)
            {
                conditions.Add(new FilterConditionDTO {
                    Field = "RecipientEmail", Operator = "eq", Value = ActivityUI.SpecificRecipientEmailText.Value
                });
            }

            conditions.Add(new FilterConditionDTO {
                Field = "EnvelopeId", Operator = "eq", Value = "FromPayload"
            });

            queryBuilder.Value = JsonConvert.SerializeObject(conditions);

            return(await HubCommunicator.ConfigureActivity(activity));
        }
        private async Task <ActivityPayload> CreateProcessingActivity(ReconfigurationContext context)
        {
            var loopActivity = await HubCommunicator.AddAndConfigureChildActivity(context.SolutionActivity, await HubCommunicator.GetActivityTemplate("terminalFr8Core", "Loop"), "Loop", "Loop", 2);

            var loopConfigControls  = ActivityConfigurator.GetConfigurationControls(loopActivity);
            var crateChooser        = loopConfigControls.Controls.OfType <CrateChooser>().Single();
            var firstActivity       = context.SolutionActivity.ChildrenActivities.OrderBy(x => x.Ordering).First();
            var firstActivityCrates = firstActivity.CrateStorage.CrateContentsOfType <CrateDescriptionCM>().FirstOrDefault();

            crateChooser.CrateDescriptions = firstActivityCrates?.CrateDescriptions;

            var tableDescription = crateChooser.CrateDescriptions?.FirstOrDefault(x => x.ManifestId == (int)MT.StandardTableData);

            if (tableDescription != null)
            {
                tableDescription.Selected = true;
            }

            var solutionActivityUi         = new ActivityUi().ClonePropertiesFrom(context.SolutionActivity.CrateStorage.FirstCrate <StandardConfigurationControlsCM>().Content) as ActivityUi;
            var mailSenderActivityTemplate = await HubCommunicator.GetActivityTemplate(Guid.Parse(solutionActivityUi.MailSenderActivitySelector.Value));

            var sendEmailActivity = await HubCommunicator.AddAndConfigureChildActivity(loopActivity, mailSenderActivityTemplate, order : 1);

            return(loopActivity);
        }
        private async Task SetQueryFr8WarehouseActivityFields(ActivityPayload queryFr8Warehouse, string recipientEmail)
        {
            //update action's duration value
            var crateStorage     = queryFr8Warehouse.CrateStorage;
            var configControlCM  = ActivityConfigurator.GetConfigurationControls(queryFr8Warehouse);
            var radioButtonGroup = (configControlCM.Controls.First() as RadioButtonGroup);

            radioButtonGroup.Radios[0].Selected = false;
            radioButtonGroup.Radios[1].Selected = true;
            var             objectList = (DropDownList)(radioButtonGroup.Radios[1].Controls.FirstOrDefault(c => c.Name == "AvailableObjects"));
            MtTypeReference selectedObject;

            if (string.IsNullOrEmpty(recipientEmail))
            {
                selectedObject = GetMtType(typeof(DocuSignEnvelopeCM_v2));
            }
            else
            {
                selectedObject = GetMtType(typeof(DocuSignRecipientStatus));
            }

            if (selectedObject == null)
            {
                return;
            }

            objectList.Value       = selectedObject.Id.ToString("N");
            objectList.selectedKey = selectedObject.Alias;

            var filterPane = (FilterPane)radioButtonGroup.Radios[1].Controls.First(c => c.Name == "Filter");

            var conditions = new List <FilterConditionDTO>
            {
                new FilterConditionDTO {
                    Field = "EnvelopeId", Operator = "eq", Value = "FromPayload"
                }
            };

            if (recipientEmail != null)
            {
                conditions.Add(new FilterConditionDTO {
                    Field = "Email", Operator = "eq", Value = recipientEmail
                });
            }

            filterPane.Value = JsonConvert.SerializeObject(new FilterDataDTO
            {
                ExecutionType = FilterExecutionType.WithFilter,
                Conditions    = conditions
            });

            using (var uow = _container.GetInstance <IUnitOfWork>())
            {
                var queryCriteria = Crate.FromContent("Queryable Criteria", new FieldDescriptionsCM(MTTypesHelper.GetFieldsByTypeId(uow, selectedObject.Id)));
                crateStorage.Add(queryCriteria);
            }
        }