当前位置: 首页>>代码示例>>C#>>正文


C# IQueryContext.LastOrDefault方法代码示例

本文整理汇总了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;
        }
开发者ID:AlphaGit,项目名称:newrelic_microsoft_sqlserver_plugin,代码行数:47,代码来源:ComponentDataRetriever.cs


注:本文中的IQueryContext.LastOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。