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);
                    }

                    CrateSignaller.ClearAvailableCrates();
                    CrateSignaller.MarkAvailableAtRuntime <StandardPayloadDataCM>(RunTimeCrateLabel)
                    .AddFields(CreateStatValueFields(StatXUtilities.MapToStatItemCrateManifest(firstStat)));
                }
                SelectedGroup = ActivityUI.ExistingGroupsList.Value;
                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.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)
                    {
                        CrateSignaller.ClearAvailableCrates();
                        CrateSignaller.MarkAvailableAtRuntime <StandardPayloadDataCM>(RunTimeCrateLabel).AddFields(CreateStatValueFields(StatXUtilities.MapToStatItemCrateManifest(currentStat)));
                    }
                }
                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;

                EventSubscriptions.Subscriptions?.Clear();
                EventSubscriptions.Manufacturer = "StatX";
                EventSubscriptions.Add("StatXValueChange_" + SelectedStat.Substring(0, 18));
            }
            else
            {
                CrateSignaller.ClearAvailableCrates();
                ActivityUI.ExistingGroupStats.ListItems.Clear();
                ActivityUI.ExistingGroupStats.selectedKey = string.Empty;
                ActivityUI.ExistingGroupStats.Value       = string.Empty;
                SelectedStat = string.Empty;
            }
        }
Example #2
0
        private async Task <StatXItemCM> GetLatestStatItem(string token, string groupId, string statId)
        {
            var latestStat = await _statXIntegration.GetStat(StatXUtilities.GetStatXAuthToken(token), groupId, statId);

            return(StatXUtilities.MapToStatItemCrateManifest(latestStat));
        }