public string GetApiStatsAsXml()
        {
            XElement xelement = new XElement("ApiStats");
            IOrderedEnumerable <KeyValuePair <OperationCategory, PerformanceEntry.ApiMeasure> > orderedEnumerable = from kvp in this.ApiMap
                                                                                                                    orderby kvp.Value.Latency.Max descending
                                                                                                                    select kvp;

            foreach (KeyValuePair <OperationCategory, PerformanceEntry.ApiMeasure> keyValuePair in orderedEnumerable)
            {
                OperationCategory           key   = keyValuePair.Key;
                PerformanceEntry.ApiMeasure value = keyValuePair.Value;
                XElement content = new XElement("Api", new object[]
                {
                    new XAttribute("Name", key),
                    new XAttribute("Succeeded", value.Succeeded),
                    new XAttribute("Failed", value.Failed),
                    new XAttribute("Average", value.Latency.Average.ToString(".00")),
                    new XAttribute("Max", value.Latency.Max),
                    new XAttribute("MaxMinusOne", value.Latency.MaxMinusOne),
                    new XAttribute("Min", value.Latency.Min),
                    new XAttribute("MinPlusOne", value.Latency.MinPlusOne)
                });
                xelement.Add(content);
            }
            return(xelement.ToString());
        }
 private void RecordApiResult(OperationCategory category, bool isSuccess, long latencyInMs)
 {
     PerformanceEntry.ApiMeasure apiMeasure;
     if (!this.ApiMap.TryGetValue(category, out apiMeasure) || apiMeasure == null)
     {
         apiMeasure            = new PerformanceEntry.ApiMeasure();
         this.ApiMap[category] = apiMeasure;
     }
     if (isSuccess)
     {
         apiMeasure.Succeeded++;
     }
     else
     {
         apiMeasure.Failed++;
     }
     apiMeasure.Latency.Update(latencyInMs);
 }