/// <summary>
        /// ExportEvemtSamples is the shared logic for all event metric exports
        /// </summary>
        private void ExportEventSamples(StreamWriter writer, IEventMetricDefinition metricDefinition, IEventMetric metric)
        {
            writer.Write("\"Sequence\",\"Timestamp\"");
            foreach (var valueDefinition in metricDefinition.Values)
            {
                writer.Write(",\"{0}\"", valueDefinition.Caption);
            }
            writer.WriteLine();

            foreach (var sample in metric.Samples)
            {
                var eventSample = sample as IEventMetricSample;
                if (eventSample == null)
                {
                    continue;
                }

                writer.Write("{0},\"{1}\"", eventSample.Sequence, eventSample.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
                for (var i = 0; i < eventSample.Values.Count(); i++)
                {
                    writer.Write(",\"{0}\"", eventSample.Values[i]);
                }
                writer.WriteLine();
            }
        }
 /// <summary>
 /// Export a CSV file for each instance of am EventMetric
 /// </summary>
 private void ExportEventMetric(ISession session, IEventMetricDefinition metricDefinition, ref int metricFileCount)
 {
     if (metricDefinition.Metrics.Count == 1)
     {
         try
         {
             using (
                 var writer = StreamCreator.CreateMetricStream(_context, Config, session, metricDefinition,
                                                               ref metricFileCount))
             {
                 ExportEventSamples(writer, metricDefinition, metricDefinition.Metrics[0] as IEventMetric);
             }
         }
         catch (Exception ex)
         {
             _context.Log.RecordException(ex, LogCategory, true);
         }
     }
     else
     {
         foreach (var metric in metricDefinition.Metrics)
         {
             try
             {
                 using (
                     var writer = StreamCreator.CreateMetricInstanceStream(_context, Config, session, metric,
                                                                           ref metricFileCount))
                 {
                     ExportEventSamples(writer, metricDefinition, metric as IEventMetric);
                 }
             }
             catch (Exception ex)
             {
                 _context.Log.RecordException(ex, LogCategory, true);
             }
         }
     }
 }
 /// <summary>
 /// Determines if the provided object is identical to this object.
 /// </summary>
 /// <param name="other">The object to compare this object to</param>
 /// <returns>True if the objects represent the same data.</returns>
 public bool Equals(IEventMetricDefinition other)
 {
     //We're really just a type cast, refer to our base object
     return(base.Equals(other));
 }
 /// <summary>
 /// Indicates the relative sort order of this object to another of the same type.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public int CompareTo(IEventMetricDefinition other)
 {
     //we let our base object do the compare, we're really just casting things
     return(base.CompareTo(other));
 }
        /// <summary>
        /// ExportEvemtSamples is the shared logic for all event metric exports
        /// </summary>
        private void ExportEventSamples(StreamWriter writer, IEventMetricDefinition metricDefinition, IEventMetric metric)
        {
            writer.Write("\"Sequence\",\"Timestamp\"");
            foreach (var valueDefinition in metricDefinition.Values)
            {
                writer.Write(",\"{0}\"", valueDefinition.Caption);
            }
            writer.WriteLine();

            foreach (var sample in metric.Samples)
            {
                var eventSample = sample as IEventMetricSample;
                if (eventSample == null)
                    continue;

                writer.Write("{0},\"{1}\"", eventSample.Sequence, eventSample.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
                for (var i = 0; i < eventSample.Values.Count(); i++)
                {
                    writer.Write(",\"{0}\"", eventSample.Values[i]);
                }
                writer.WriteLine();
            }
        }
 /// <summary>
 /// Export a CSV file for each instance of am EventMetric
 /// </summary>
 private void ExportEventMetric(ISession session, IEventMetricDefinition metricDefinition, ref int metricFileCount)
 {
     if (metricDefinition.Metrics.Count == 1)
     {
         try
         {
             using (
                 var writer = StreamCreator.CreateMetricStream(_context, Config, session, metricDefinition,
                     ref metricFileCount))
             {
                 ExportEventSamples(writer, metricDefinition, metricDefinition.Metrics[0] as IEventMetric);
             }
         }
         catch (Exception ex)
         {
             _context.Log.RecordException(ex, LogCategory, true);
         }
     }
     else
     {
         foreach (var metric in metricDefinition.Metrics)
         {
             try
             {
                 using (
                     var writer = StreamCreator.CreateMetricInstanceStream(_context, Config, session, metric,
                         ref metricFileCount))
                 {
                     ExportEventSamples(writer, metricDefinition, metric as IEventMetric);
                 }
             }
             catch (Exception ex)
             {
                 _context.Log.RecordException(ex, LogCategory, true);
             }
         }
     }
 }