public override async Task Run()
        {
            ActivityUI.RestoreCustomFields(Storage);

            var issueInfo = ExtractIssueInfo();
            await _atlassianService.CreateIssue(issueInfo, AuthorizationToken);

            var credentialsDTO = JsonConvert.DeserializeObject <CredentialsDTO>(AuthorizationToken.Token);
            var jiraUrl        = $"{credentialsDTO.Domain}/browse/{issueInfo.Key}";


            Payload.Add(Crate.FromContent("jira issue", new StandardPayloadDataCM(new KeyValueDTO()
            {
                Key = "jira issue key", Value = issueInfo.Key
            })));
            Payload.Add(Crate.FromContent("jira issue", new StandardPayloadDataCM(new KeyValueDTO()
            {
                Key = "jira domain", Value = credentialsDTO.Domain
            })));
            await _pushNotificationService.PushUserNotification(MyTemplate, "Jira Issue Created", $"Created new jira issue: {jiraUrl}");

            Payload.Add(Crate <KeyValueListCM> .FromContent(RuntimeCrateLabel, new KeyValueListCM(
                                                                new KeyValueDTO(JiraIdField, issueInfo.Key),
                                                                new KeyValueDTO(JiraUrlField, jiraUrl))));
        }
        /**********************************************************************************/
        // Activity logic can update state of configuration controls. But as long we have copied  configuration controls crate from the storage into
        // new instance of ActivityUi changes made to ActivityUi won't be reflected in storage.
        // we have to persist in storage changes we've made to ActivityUi.
        // we do this in the most simple way by replacing old StandardConfigurationControlsCM with ActivityUi.
        private void SyncConfControlsBack()
        {
            Storage.Remove <StandardConfigurationControlsCM>();
            // we create new StandardConfigurationControlsCM with controls from ActivityUi.
            // We do this because ActivityUi can has properties to access specific controls. We don't want those propeties exist in serialized crate.

            var configurationControlsToAdd = new StandardConfigurationControlsCM(ActivityUI.Controls);

            Storage.Add(Crate.FromContent(ConfigurationControlsLabel, configurationControlsToAdd, AvailabilityType.Configuration));
            ActivityUI.SaveDynamicControlsTo(configurationControlsToAdd);
        }
        private async Task FillFieldDdls()
        {
            ActivityUI.AvailablePriorities.ListItems = _atlassianService
                                                       .GetPriorities(AuthorizationToken)
                                                       .ToListItems()
                                                       .ToList();

            ActivityUI.Sprint.ListItems = await _atlassianService.GetSprints(AuthorizationToken, ActivityUI.AvailableProjects.Value);

            var customFields = _atlassianService.GetCustomFields(AuthorizationToken);

            ActivityUI.AppendCustomFields(customFields);
        }
Esempio n. 4
0
    public PlaceGroup FindPlace(MovesJson.SegmentsInfo.PlaceInfo place, ActivityUI timelineObject)
    {
        PlaceGroup thisPlace = new PlaceGroup();

        if (places.TryGetValue(place.id, out thisPlace))
        {
            thisPlace.AddTimelineObject(timelineObject);
            return(thisPlace);
        }
        else
        {
            return(null);
        }
    }
Esempio n. 5
0
        public override async Task FollowUp()
        {
            Storage.RemoveByLabel(ColumnHeadersCrateLabel);
            //If file is not uploaded we hide file description
            if (string.IsNullOrEmpty(ActivityUI.FilePicker.Value))
            {
                Storage.RemoveByLabel(ColumnHeadersCrateLabel);
                Storage.RemoveByLabel(TabularUtilities.ExtractedFieldsCrateLabel);
                ActivityUI.ClearFileDescription();
                SelectedFileDescription = null;
            }
            else
            {
                var previousValues = SelectedFileDescription;
                //Update column header only if new file was uploaded
                if (previousValues == null || previousValues.Key != ActivityUI.FilePicker.Value)
                {
                    Storage.RemoveByLabel(ColumnHeadersCrateLabel);
                    Storage.RemoveByLabel(TabularUtilities.ExtractedFieldsCrateLabel);
                    var selectedFileDescription = new KeyValueDTO(ActivityUI.FilePicker.Value, ExtractFileName(ActivityUI.FilePicker.Value));

                    CrateSignaller.MarkAvailableAtRuntime <StandardTableDataCM>(RunTimeCrateLabel, true)
                    .AddFields((await _excelUtils.GetColumnHeaders(selectedFileDescription.Key)).Select(x => new FieldDTO(x)));

                    ActivityUI.MarkFileAsUploaded(selectedFileDescription.Value, selectedFileDescription.Key);
                    SelectedFileDescription = selectedFileDescription;

                    // Process table and get the Table and optionally (if one row) fields crate
                    var fileAsByteArray = await _excelUtils.GetExcelFileAsByteArray(ActivityUI.FilePicker.Value);

                    var tableCrates = GetExcelFileDescriptionCrates(fileAsByteArray, ActivityUI.FilePicker.Value, null, false);

                    foreach (var crate in tableCrates)
                    {
                        Storage.ReplaceByLabel(crate);
                    }

                    Storage.ReplaceByLabel(CreateExternalObjectHandlesCrate());
                }
            }

            Storage.Add(Crate.FromContent(FileCrateLabel, new StandardFileDescriptionCM()
            {
                Filename = FileCrateLabel
            }));
        }
        public override async Task FollowUp()
        {
            ActivityUI.RestoreCustomFields(Storage);
            var configProps = GetConfigurationProperties();

            var projectKey = ActivityUI.AvailableProjects.Value;

            if (!string.IsNullOrEmpty(projectKey))
            {
                ToggleProjectSelectedVisibility(true);

                if (projectKey != configProps.SelectedProjectKey)
                {
                    FillIssueTypeDdl(projectKey);
                    await FillAssigneeSelector(projectKey);
                }

                var issueTypeKey = ActivityUI.AvailableIssueTypes.Value;
                if (!string.IsNullOrEmpty(issueTypeKey))
                {
                    ToggleFieldsVisibility(true);

                    if (configProps.SelectedIssueType != issueTypeKey)
                    {
                        await FillFieldDdls();
                    }
                }
                else
                {
                    ToggleFieldsVisibility(false);
                }
            }
            else
            {
                ToggleProjectSelectedVisibility(false);
            }

            configProps.SelectedProjectKey = ActivityUI.AvailableProjects.Value;
            configProps.SelectedIssueType  = ActivityUI.AvailableIssueTypes.Value;

            SetConfigurationProperties(configProps);

            await Task.Yield();
        }
        public override async Task FollowUp()
        {
            if (!string.IsNullOrEmpty(ActivityUI.StatTypesList.Value))
            {
                var previousGroup = SelectedStatType;
                if (string.IsNullOrEmpty(previousGroup) || !string.Equals(previousGroup, ActivityUI.StatTypesList.Value))
                {
                    var propertyInfos = StatXUtilities.GetStatTypeProperties(ActivityUI.StatTypesList.Value);
                    ActivityUI.ClearDynamicFields();
                    foreach (var property in propertyInfos)
                    {
                        var t = property.PropertyType;
                        if (t.IsGenericType && typeof(IList <>).IsAssignableFrom(t.GetGenericTypeDefinition()) ||
                            t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList <>)))
                        {
                            //render corresponding FieldList control for properties that are collections
                            ActivityUI.AvailableStatItemsList.Add(CreateFieldListBasedOnStatType());
                        }
                        else
                        {
                            ActivityUI.AvailableStatProperties.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(property.Name, property.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }
                SelectedStatType = ActivityUI.StatTypesList.Value;
            }
            else
            {
                ActivityUI.ClearDynamicFields();
                SelectedStatType = string.Empty;
            }

            SelectedStatGroup = ActivityUI.ExistingStatGroupList.Value;
            ActivityUI.ExistingStatGroupList.ListItems = (await _statXIntegration.GetGroups(StatXUtilities.GetStatXAuthToken(AuthorizationToken)))
                                                         .Select(x => new ListItem {
                Key = x.Name, Value = x.Id
            }).ToList();
            ActivityUI.ExistingStatGroupList.Value = SelectedStatGroup;
        }
        private IssueInfo ExtractIssueInfo()
        {
            var projectKey = ActivityUI.AvailableProjects.Value;

            if (string.IsNullOrEmpty(projectKey))
            {
                throw new ApplicationException("Jira Project is not selected.");
            }

            var issueTypeKey = ActivityUI.AvailableIssueTypes.Value;

            if (string.IsNullOrEmpty(issueTypeKey))
            {
                throw new ApplicationException("Jira Issue Type is not selected.");
            }

            var result = new IssueInfo()
            {
                ProjectKey   = projectKey,
                IssueTypeKey = issueTypeKey,
                PriorityKey  = ActivityUI.AvailablePriorities.Value,
                Description  = ActivityUI.Description.TextValue,
                Summary      = ActivityUI.Summary.TextValue,
                CustomFields = ActivityUI.GetValues(Payload).ToList(),
                Assignee     = ActivityUI.AssigneeSelector.Value
            };


            if (ActivityUI.Sprint.Value != null)
            {
                result.CustomFields.Add(new KeyValueDTO()
                {
                    Key = ActivityUI.SprintFieldName.Label, Value = ActivityUI.Sprint.Value
                });
            }

            return(result);
        }
        /**********************************************************************************/
        // SyncConfControls and SyncConfControlsBack are pair of methods that serves the following reason:
        // We want to work with StandardConfigurationControlsCM in form of ActivityUi that has handy properties to directly access certain controls
        // But when we deserialize activity's crate storage we get StandardConfigurationControlsCM. So we need a way to 'convert' StandardConfigurationControlsCM
        // from crate storage to ActivityUI.
        // SyncConfControls takes properties of controls in StandardConfigurationControlsCM from activity's storage and copies them into ActivityUi.
        private void SyncConfControls(bool throwException)
        {
            var configurationControls = Storage.CrateContentsOfType <StandardConfigurationControlsCM>().FirstOrDefault();

            ActivityUI = CrateActivityUI();

            if (configurationControls == null)
            {
                if (throwException)
                {
                    throw new InvalidOperationException("Configuration controls crate is missing");
                }

                return;
            }

            ActivityUI.SyncWith(configurationControls);

            if (ActivityUI.Controls != null)
            {
                ActivityUI.RestoreDynamicControlsFrom(configurationControls);
            }
        }
Esempio n. 10
0
        public override async Task FollowUp()
        {
            if (!string.IsNullOrEmpty(ActivityUI.ExistingGroupsList.Value))
            {
                var previousGroup = SelectedGroup;
                if (string.IsNullOrEmpty(previousGroup) || !string.Equals(previousGroup, ActivityUI.ExistingGroupsList.Value))
                {
                    var stats = await _statXIntegration.GetStatsForGroup(StatXUtilities.GetStatXAuthToken(AuthorizationToken), ActivityUI.ExistingGroupsList.Value);

                    if (stats.Any(x => string.IsNullOrEmpty(x.Title)))
                    {
                        StatXUtilities.AddAdvisoryMessage(Storage);
                    }
                    else
                    {
                        if (Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault() != null)
                        {
                            ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                                Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                            }).ToList();
                        }
                        Storage.RemoveByLabel("Advisories");
                    }

                    ActivityUI.ExistingGroupStats.ListItems = stats
                                                              .Select(x => new ListItem {
                        Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                    }).ToList();

                    var firstStat = stats.FirstOrDefault();
                    if (firstStat != null)
                    {
                        ActivityUI.ExistingGroupStats.SelectByValue(firstStat.Id);
                        ActivityUI.StatTitle.TextValue = firstStat.Title;
                        ActivityUI.StatNotes.TextValue = firstStat.Notes;
                        var statDTO = firstStat as GeneralStatWithItemsDTO;
                        if (statDTO != null)
                        {
                            if (statDTO.VisualType == StatTypes.PickList)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser("Current Index", "CurrentIndex", requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                            else
                            {
                                foreach (var item in statDTO.Items)
                                {
                                    ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item.Name, item.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                                }
                            }
                        }
                        else
                        {
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(firstStat.Title) ? firstStat.Id : firstStat.Title, string.IsNullOrEmpty(firstStat.Title) ? firstStat.Id : firstStat.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }
                SelectedGroup = ActivityUI.ExistingGroupsList.Value;
                //refresh statx groups
                ActivityUI.ExistingGroupsList.ListItems = (await _statXIntegration.GetGroups(StatXUtilities.GetStatXAuthToken(AuthorizationToken)))
                                                          .Select(x => new ListItem {
                    Key = x.Name, Value = x.Id
                }).ToList();
                ActivityUI.ExistingGroupsList.Value = SelectedGroup;
            }
            else
            {
                ActivityUI.StatTitle.Value = string.Empty;
                ActivityUI.StatNotes.Value = string.Empty;
                ActivityUI.ExistingGroupStats.ListItems.Clear();
                ActivityUI.ExistingGroupStats.selectedKey = string.Empty;
                ActivityUI.ExistingGroupStats.Value       = string.Empty;
                SelectedGroup = string.Empty;
            }

            if (!string.IsNullOrEmpty(ActivityUI.ExistingGroupStats.Value))
            {
                var previousStat = SelectedStat;
                var stats        = await _statXIntegration.GetStatsForGroup(StatXUtilities.GetStatXAuthToken(AuthorizationToken), ActivityUI.ExistingGroupsList.Value);

                if (stats.Any(x => string.IsNullOrEmpty(x.Title)))
                {
                    StatXUtilities.AddAdvisoryMessage(Storage);
                }
                else
                {
                    if (Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault() != null)
                    {
                        ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                            Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                        }).ToList();
                    }
                    Storage.RemoveByLabel("Advisories");
                }

                if (string.IsNullOrEmpty(previousStat) || !string.Equals(previousStat, ActivityUI.ExistingGroupStats.Value))
                {
                    var currentStat = stats.FirstOrDefault(x => x.Id == ActivityUI.ExistingGroupStats.Value);
                    if (currentStat != null)
                    {
                        ActivityUI.ClearDynamicFields();
                        var statDTO = currentStat as GeneralStatWithItemsDTO;
                        if (statDTO != null && statDTO.Items.Any())
                        {
                            if (statDTO.VisualType == StatTypes.PickList)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser("Current Index", "CurrentIndex", requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                            else
                            {
                                foreach (var item in statDTO.Items)
                                {
                                    ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item.Name, item.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                                }
                            }
                        }
                        else
                        {
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(currentStat.Title) ? currentStat.Id : currentStat.Title, string.IsNullOrEmpty(currentStat.Title) ? currentStat.Id : currentStat.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }

                #region Refresh Stat Items to Track for Changes in app
                SelectedStat = ActivityUI.ExistingGroupStats.Value;
                ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                    Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                }).ToList();
                ActivityUI.ExistingGroupStats.Value = SelectedStat;
                var statToCheck = stats.FirstOrDefault(x => x.Id == SelectedStat);


                //check for changes in statValue Array
                if (statToCheck != null)
                {
                    ActivityUI.ExistingGroupStats.selectedKey = string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title;
                    var statDTO = statToCheck as GeneralStatWithItemsDTO;
                    if (statDTO != null && statDTO.Items.Any())
                    {
                        var oldStatNames = ActivityUI.StatValues.Select(x => x.Name).ToList();
                        var newStatNames = new List <string>();

                        if (statDTO.VisualType != StatTypes.PickList)
                        {
                            newStatNames = statDTO.Items.Select(x => x.Name).ToList();

                            //recreate new items
                            var newItems         = newStatNames.Where(x => !oldStatNames.Contains(x)).ToList();
                            var oldItemsToDelete = oldStatNames.Where(x => !newStatNames.Contains(x)).ToList();

                            foreach (var item in oldItemsToDelete.ToList())
                            {
                                var itemToDelete = ActivityUI.StatValues.FirstOrDefault(x => x.Name == item);
                                if (itemToDelete != null)
                                {
                                    ActivityUI.StatValues.Remove(itemToDelete);
                                }
                            }

                            foreach (var item in newItems)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item, item, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                        }
                    }
                    else
                    {
                        var currentTextSource = ActivityUI.StatValues.FirstOrDefault()?.Name;
                        if (currentTextSource != (string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title))
                        {
                            ActivityUI.StatValues?.Clear();
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title, string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }

                #endregion
            }
            else
            {
                ActivityUI.StatTitle.Value = string.Empty;
                ActivityUI.StatNotes.Value = string.Empty;
                ActivityUI.ClearDynamicFields();
                ActivityUI.ExistingGroupStats.ListItems.Clear();
                ActivityUI.ExistingGroupStats.selectedKey = string.Empty;
                ActivityUI.ExistingGroupStats.Value       = string.Empty;
                SelectedStat = string.Empty;
            }
        }
Esempio n. 11
0
        public override async Task FollowUp()
        {
            CrateSignaller.ClearAvailableCrates();

            List <Crate> crates       = new List <Crate>();
            var          googleAuth   = GetGoogleAuthToken();
            var          spreadsheets = await _googleApi.GetSpreadsheets(googleAuth);

            ActivityUI.SpreadsheetList.ListItems = spreadsheets
                                                   .Select(x => new ListItem {
                Key = x.Value, Value = x.Key
            })
                                                   .ToList();

            var selectedSpreadsheet = ActivityUI.SpreadsheetList.selectedKey;

            if (!string.IsNullOrEmpty(selectedSpreadsheet))
            {
                //This chunk here is about removing a selection if a spreadsheet was deleted but at the same time it was chosen in UI
                if (ActivityUI.SpreadsheetList.ListItems.All(x => x.Key != selectedSpreadsheet))
                {
                    ActivityUI.SpreadsheetList.selectedKey = null;
                    ActivityUI.SpreadsheetList.Value       = null;
                }
            }

            //If spreadsheet selection is cleared we hide worksheet DDLB
            if (string.IsNullOrEmpty(ActivityUI.SpreadsheetList.selectedKey))
            {
                ActivityUI.HideWorksheetList();
                StoredSelectedSheet = null;
            }
            else
            {
                var previousValues = StoredSelectedSheet;
                //Spreadsheet was changed - populate the list of worksheets and select first one
                if (previousValues == null || previousValues.Key != ActivityUI.SpreadsheetList.Value)
                {
                    var worksheets = await _googleApi.GetWorksheets(ActivityUI.SpreadsheetList.Value, googleAuth);

                    //We show worksheet list only if there is more than one worksheet
                    if (worksheets.Count > 1)
                    {
                        ActivityUI.ShowWorksheetList();
                        ActivityUI.WorksheetList.ListItems = worksheets.Select(x => new ListItem {
                            Key = x.Value, Value = x.Key
                        }).ToList();
                        var firstWorksheet = ActivityUI.WorksheetList.ListItems.First();
                        ActivityUI.WorksheetList.SelectByKey(firstWorksheet.Key);
                    }
                    else
                    {
                        ActivityUI.HideWorksheetList();
                    }
                }
                //Retrieving worksheet headers to make them avaialble for downstream activities
                var selectedSpreasheetWorksheet = new KeyValueDTO(ActivityUI.SpreadsheetList.Value,
                                                                  ActivityUI.WorksheetList.IsHidden
                                                                   ? string.Empty
                                                                   : ActivityUI.WorksheetList.Value);
                var columnHeaders = await _googleApi.GetWorksheetHeaders(selectedSpreasheetWorksheet.Key, selectedSpreasheetWorksheet.Value, googleAuth);

                StoredSelectedSheet = selectedSpreasheetWorksheet;
                var table = await GetSelectedSpreadSheet();

                var hasHeaderRow = TryAddHeaderRow(table);
                Storage.ReplaceByLabel(Crate.FromContent(GetRuntimeCrateLabel(), new StandardTableDataCM {
                    Table = table, FirstRowHeaders = hasHeaderRow
                }));

                CrateSignaller.MarkAvailableAtRuntime <StandardTableDataCM>(GetRuntimeCrateLabel(), true)
                .AddFields(columnHeaders.Select(x => new FieldDTO(x.Key)));

                //here was logic responsible for handling one-row tables but it was faulty. It's main purpose was to spawn fields like "value immediatly below of" in a StandardPayload.
                //You might view TabularUtilities.PrepareFieldsForOneRowTable for reference
            }
        }
        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))));
        }
Esempio n. 13
0
 public void AddTimelineObject(ActivityUI timelineObject)
 {
     this.timelineObject = timelineObject;
     RefreshIcons();
 }
    /// <summary>
    /// Colour codes connections according to activity
    /// Time: if within 0 or 1 turns ago -> red, 2 turns ago -> yellow, 3+ turns ago -> green, None -> grey
    /// Count: it's 3+ red, 2 yellow, 1 green, 0 grey. Saves original connection state and sets resetNeeded to true
    /// </summary>
    public void ShowConnectionActivity(ActivityUI activityUI)
    {
        int activityData = -1;
        int currentTurn  = GameManager.i.turnScript.Turn;
        List <Connection> listOfConnections = GameManager.i.dataScript.GetListOfConnections();

        if (listOfConnections != null)
        {
            //reset back to normal prior to any changes
            if (resetConnections == true)
            {
                RestoreConnections();
            }
            //set flag as changes will be made
            resetConnections = true;
            //loop all connections regardless
            foreach (Connection conn in listOfConnections)
            {
                //save existing security level
                conn.SaveSecurityLevel();
                //action depends on type of activity display required
                switch (activityUI)
                {
                //Time (# of turns ago)
                case ActivityUI.Time:
                    int limit = GameManager.i.aiScript.activityTimeLimit;
                    activityData = conn.activityTime;
                    if (activityData > -1)
                    {
                        int timeElapsed = currentTurn - activityData;
                        if (timeElapsed > -1)
                        {
                            switch (timeElapsed)
                            {
                            case 0:
                            case 1:
                                conn.ChangeSecurityLevel(ConnectionType.HIGH);
                                break;

                            case 2:
                                conn.ChangeSecurityLevel(ConnectionType.MEDIUM);
                                break;

                            case 3:
                            default:
                                if (timeElapsed > limit)
                                {
                                    conn.ChangeSecurityLevel(ConnectionType.None);
                                }
                                else
                                {
                                    //within time elapsed allowance
                                    conn.ChangeSecurityLevel(ConnectionType.LOW);
                                }
                                break;
                            }
                        }
                        else
                        {
                            conn.ChangeSecurityLevel(ConnectionType.None);
                        }
                    }
                    else
                    {
                        conn.ChangeSecurityLevel(ConnectionType.None);
                    }
                    break;

                //Count
                case ActivityUI.Count:
                    activityData = conn.activityCount;
                    if (activityData > -1)
                    {
                        switch (activityData)
                        {
                        case 3:
                            conn.ChangeSecurityLevel(ConnectionType.HIGH);
                            break;

                        case 2:
                            conn.ChangeSecurityLevel(ConnectionType.MEDIUM);
                            break;

                        case 1:
                            conn.ChangeSecurityLevel(ConnectionType.LOW);
                            break;

                        case 0:
                            conn.ChangeSecurityLevel(ConnectionType.None);
                            break;

                        default:
                            //more than 3
                            conn.ChangeSecurityLevel(ConnectionType.HIGH);
                            break;
                        }
                    }
                    else
                    {
                        conn.ChangeSecurityLevel(ConnectionType.None);
                    }
                    break;
                }
            }
        }
        else
        {
            Debug.LogError("Invalid listOfConnections (Null)");
        }
    }