/// <summary> /// Retrieves or generates the appropriate ComponentData object from the historical and current QueryContexts in <paramref name="queryHistory"/> /// </summary> /// <param name="queryHistory">A FIFO array of QueryContexts representing the current and historical query data, most recent query is last position</param> /// <returns></returns> public static ComponentData GetData(IQueryContext[] queryHistory) { if (!queryHistory.Any()) { return null; } var queryName = queryHistory.First().QueryName; if (queryHistory.Any(qh => qh.QueryName != queryName)) { throw new ArgumentException("GetData can only process history for one query at a time!"); } var mostRecentUnsentQuery = queryHistory.LastOrDefault(q => !q.DataSent); //If nothing to send, return null if (mostRecentUnsentQuery == null) { return null; } //If the query metric should be a Delta (differential, generate ComponentData based on passed in history if (mostRecentUnsentQuery.MetricTransformEnum == MetricTransformEnum.Delta) { //For first encounter, send empty metric if (queryHistory.Length == 1) { _VerboseMetricsLogger.InfoFormat("Not enough historical data to perform delta on data from {0}, generating zeroed out ComponentData", mostRecentUnsentQuery.QueryName); return GetZeroedComponentData(mostRecentUnsentQuery.ComponentData); } //Get Previous Query var previousQueryContext = queryHistory.Reverse().Skip(1).First(); _VerboseMetricsLogger.InfoFormat("Generating delta for data from {0}", mostRecentUnsentQuery.QueryName); //Return Delta of current and previous data return GetDelta(mostRecentUnsentQuery.ComponentData, previousQueryContext.ComponentData); } //Otherwise, just return latest unsent return mostRecentUnsentQuery.ComponentData; }