/// <summary> /// Create Simple Crate Manifest used for polling process /// </summary> /// <param name="stat"></param> /// <returns></returns> public static StatXItemCM MapToStatItemCrateManifest(BaseStatDTO stat) { var result = new StatXItemCM() { Id = stat.Id, Title = stat.Title, VisualType = stat.VisualType, LastUpdatedDateTime = stat.LastUpdatedDateTime.ToString(), }; var statDTO = stat as GeneralStatDTO; if (statDTO != null) { result.Value = statDTO.Value; result.CurrentIndex = statDTO.CurrentIndex; } else { result.CurrentIndex = ((GeneralStatWithItemsDTO)stat).CurrentIndex; result.StatValueItems = ((GeneralStatWithItemsDTO)stat).Items.Select(x => new StatValueItemDTO() { Name = x.Name, Value = x.Value, Checked = x.Checked, }).ToList(); } return(result); }
/// <summary> /// Helper method used into StatX polling, Compare latest poll item with previous for value changes /// </summary> /// <param name="oldStat"></param> /// <param name="newStat"></param> /// <returns></returns> public static bool CompareStatsForValueChanges(StatXItemCM oldStat, StatXItemCM newStat) { if (DateTime.Parse(oldStat.LastUpdatedDateTime) >= DateTime.Parse(newStat.LastUpdatedDateTime)) { return(false); } if (newStat.StatValueItems.Any()) { foreach (var item in newStat.StatValueItems) { var oldStatItem = oldStat.StatValueItems.FirstOrDefault(x => x.Name == item.Name); //case for checklist if (oldStatItem == null) { continue; } if (newStat.VisualType == StatTypes.CheckList) { if (item.Checked != oldStatItem.Checked) { return(true); } } else if (newStat.VisualType == StatTypes.PickList) { if (newStat.CurrentIndex != oldStat.CurrentIndex) { return(true); } } else { if (item.Value != oldStatItem.Value) { return(true); } } } return(false); } return(oldStat.Value != newStat.Value); }
public override Task Run() { StatXItemCM stat = null; var eventCrate = Payload.CratesOfType <EventReportCM>().FirstOrDefault()?.Get <EventReportCM>()?.EventPayload; if (eventCrate != null) { stat = eventCrate.CrateContentsOfType <StatXItemCM>().SingleOrDefault(); } if (stat == null) { RequestPlanExecutionTermination("Stat was not found in the payload."); } Payload.Add(Crate.FromContent <StandardPayloadDataCM>(RunTimeCrateLabel, new StandardPayloadDataCM(CreateStatKeyValueItems(stat)))); return(Task.FromResult(0)); }
private List <FieldDTO> CreateStatValueFields(StatXItemCM stat) { var fields = new List <FieldDTO>(); if (stat.StatValueItems.Any()) { if (stat.VisualType == StatTypes.PickList) { fields.Add(new FieldDTO("Current Index", AvailabilityType.RunTime)); } else { fields.AddRange(stat.StatValueItems.Select(item => new FieldDTO(item.Name, AvailabilityType.RunTime))); } } else { fields.Add(new FieldDTO(string.IsNullOrEmpty(stat.Title) ? stat.Id : stat.Title, AvailabilityType.RunTime)); } return(fields); }
private List <KeyValueDTO> CreateStatKeyValueItems(StatXItemCM stat) { var fields = new List <KeyValueDTO>(); if (stat.StatValueItems.Any()) { if (stat.VisualType == StatTypes.PickList) { fields.Add(new KeyValueDTO("Current Index", stat.CurrentIndex.ToString())); } else { fields.AddRange(stat.VisualType == StatTypes.CheckList ? stat.StatValueItems.Select(item => new KeyValueDTO(item.Name, item.Checked.ToString())) : stat.StatValueItems.Select(item => new KeyValueDTO(item.Name, item.Value))); } } else { fields.Add(new KeyValueDTO(string.IsNullOrEmpty(stat.Title) ? stat.Id : stat.Title, stat.Value)); } return(fields); }