本文整理汇总了C#中IQueryContext.LastOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryContext.LastOrDefault方法的具体用法?C# IQueryContext.LastOrDefault怎么用?C# IQueryContext.LastOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryContext
的用法示例。
在下文中一共展示了IQueryContext.LastOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetData
/// <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;
}