//------------------------------------------------------------------------------ // // Method: MetricLoggerBuffer (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MetricLoggerBuffer class. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> protected MetricLoggerBuffer(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { countMetricEventQueue = new Queue <CountMetricEventInstance>(); amountMetricEventQueue = new Queue <AmountMetricEventInstance>(); statusMetricEventQueue = new Queue <StatusMetricEventInstance>(); intervalMetricEventQueue = new Queue <IntervalMetricEventInstance>(); countMetricEventQueueLock = new object(); amountMetricEventQueueLock = new object(); statusMetricEventQueueLock = new object(); intervalMetricEventQueueLock = new object(); this.bufferProcessingStrategy = bufferProcessingStrategy; this.bufferProcessingStrategy.BufferProcessed += delegate(object sender, EventArgs e) { DequeueAndProcessMetricEvents(); }; dateTime = new OperatingSystemAbstraction.DateTime(); exceptionHandler = new ExceptionThrower(); startIntervalMetricEventStore = new Dictionary <Type, IntervalMetricEventInstance>(); this.intervalMetricChecking = intervalMetricChecking; }
//------------------------------------------------------------------------------ // // Method: PerformanceCounterMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param> /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="counterCreationDataCollection">A test (mock) counter creation data collection object.</param> /// <param name="counterCreationDataFactory">A test (mock) counter creation data factory object.</param> /// <param name="performanceCounterCategory">A test (mock) performance counter category object.</param> /// <param name="performanceCounterFactory">A test (mock) performance counter factory object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public PerformanceCounterMetricLogger(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, ICounterCreationDataCollection counterCreationDataCollection, ICounterCreationDataFactory counterCreationDataFactory, IPerformanceCounterCategory performanceCounterCategory, IPerformanceCounterFactory performanceCounterFactory, IDateTime dateTime, IExceptionHandler exceptionHandler) { loggerImplementation = new PerformanceCounterMetricLoggerImplementation(metricCategoryName, metricCategoryDescription, bufferProcessingStrategy, intervalMetricChecking, counterCreationDataCollection, counterCreationDataFactory, performanceCounterCategory, performanceCounterFactory, dateTime, exceptionHandler); }
//------------------------------------------------------------------------------ // // Method: PerformanceCounterMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLogger class. /// </summary> /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param> /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public PerformanceCounterMetricLogger(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { loggerImplementation = new PerformanceCounterMetricLoggerImplementation(metricCategoryName, metricCategoryDescription, bufferProcessingStrategy, intervalMetricChecking); }
//------------------------------------------------------------------------------ // // Method: FileMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLogger class. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="filePath">The full path of the file to write the metric events to.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public FileMetricLogger(char separatorCharacter, string filePath, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { loggerImplementation = new FileMetricLoggerImplementation(separatorCharacter, filePath, bufferProcessingStrategy, intervalMetricChecking); }
//------------------------------------------------------------------------------ // // Method: FileMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="streamWriter">A test (mock) stream writer.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public FileMetricLogger(char separatorCharacter, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IStreamWriter streamWriter, IDateTime dateTime, IExceptionHandler exceptionHandler) { loggerImplementation = new FileMetricLoggerImplementation(separatorCharacter, bufferProcessingStrategy, intervalMetricChecking, streamWriter, dateTime, exceptionHandler); }
//------------------------------------------------------------------------------ // // Method: PerformanceCounterMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLoggerImplementation class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param> /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="counterCreationDataCollection">A test (mock) counter creation data collection object.</param> /// <param name="counterCreationDataFactory">A test (mock) counter creation data factory object.</param> /// <param name="performanceCounterCategory">A test (mock) performance counter category object.</param> /// <param name="performanceCounterFactory">A test (mock) performance counter factory object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public PerformanceCounterMetricLoggerImplementation(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, ICounterCreationDataCollection counterCreationDataCollection, ICounterCreationDataFactory counterCreationDataFactory, IPerformanceCounterCategory performanceCounterCategory, IPerformanceCounterFactory performanceCounterFactory, IDateTime dateTime, IExceptionHandler exceptionHandler) : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler) { InitialisePrivateMembers(metricCategoryName, metricCategoryDescription); this.counterCreationDataCollection = counterCreationDataCollection; this.counterCreationDataFactory = counterCreationDataFactory; this.performanceCounterCategory = performanceCounterCategory; this.performanceCounterFactory = performanceCounterFactory; }
//------------------------------------------------------------------------------ // // Method: ConsoleMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.ConsoleMetricLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="console">A test (mock) console object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public ConsoleMetricLogger(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IConsole console, IDateTime dateTime, IExceptionHandler exceptionHandler) { loggerImplementation = new ConsoleMetricLoggerImplementation(bufferProcessingStrategy, intervalMetricChecking, console, dateTime, exceptionHandler); }
//------------------------------------------------------------------------------ // // Method: ConsoleMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.ConsoleMetricLoggerImplementation class. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public ConsoleMetricLoggerImplementation(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) : base(bufferProcessingStrategy, intervalMetricChecking) { console = new OperatingSystemAbstraction.Console(); }
//------------------------------------------------------------------------------ // // Method: MetricAggregateLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MetricAggregateLogger class. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> protected MetricAggregateLogger(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) : base(bufferProcessingStrategy, intervalMetricChecking) { InitialisePrivateMembers(); }
//------------------------------------------------------------------------------ // // Method: FileMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLoggerImplementation class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="streamWriter">A test (mock) stream writer.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public FileMetricLoggerImplementation(char separatorCharacter, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IStreamWriter streamWriter, IDateTime dateTime, IExceptionHandler exceptionHandler) : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler) { this.separatorCharacter = separatorCharacter; this.streamWriter = streamWriter; }
//------------------------------------------------------------------------------ // // Method: MetricLoggerBuffer (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MetricLoggerBuffer class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> protected MetricLoggerBuffer(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IDateTime dateTime, IExceptionHandler exceptionHandler) : this(bufferProcessingStrategy, intervalMetricChecking) { this.dateTime = dateTime; this.exceptionHandler = exceptionHandler; }
//------------------------------------------------------------------------------ // // Method: FileMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLoggerImplementation class. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="filePath">The full path of the file to write the metric events to.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="appendToFile">Whether to append to an existing file (if it exists) or overwrite. A value of true causes appending.</param> /// <param name="fileEncoding">The character encoding to use in the file.</param> public FileMetricLoggerImplementation(char separatorCharacter, string filePath, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, bool appendToFile, Encoding fileEncoding) : base(bufferProcessingStrategy, intervalMetricChecking) { this.separatorCharacter = separatorCharacter; streamWriter = new StreamWriter(filePath, intervalMetricChecking, fileEncoding); }
//------------------------------------------------------------------------------ // // Method: MicrosoftAccessMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MicrosoftAccessMetricLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="databaseFilePath">The full path to the Microsoft Access data file.</param> /// <param name="metricCategoryName">The name of the category which the metric events should be logged under in the database.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="dbConnection">A test (mock) database connection object.</param> /// <param name="dbCommand">A test (mock) database command object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public MicrosoftAccessMetricLogger(string databaseFilePath, string metricCategoryName, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IOleDbConnection dbConnection, IOleDbCommand dbCommand, IDateTime dateTime, IExceptionHandler exceptionHandler) { loggerImplementation = new MicrosoftAccessMetricLoggerImplementation(databaseFilePath, metricCategoryName, bufferProcessingStrategy, intervalMetricChecking, dbConnection, dbCommand, dateTime, exceptionHandler); }
//------------------------------------------------------------------------------ // // Method: MicrosoftAccessMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MicrosoftAccessMetricLogger class. /// </summary> /// <param name="databaseFilePath">The full path to the Microsoft Access data file.</param> /// <param name="metricCategoryName">The name of the category which the metric events should be logged under in the database.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public MicrosoftAccessMetricLogger(string databaseFilePath, string metricCategoryName, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { loggerImplementation = new MicrosoftAccessMetricLoggerImplementation(databaseFilePath, metricCategoryName, bufferProcessingStrategy, intervalMetricChecking); }
//------------------------------------------------------------------------------ // // Method: MicrosoftAccessMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MicrosoftAccessMetricLoggerImplementation class. /// </summary> /// <param name="databaseFilePath">The full path to the Microsoft Access data file.</param> /// <param name="metricCategoryName">The name of the category which the metric events should be logged under in the database.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public MicrosoftAccessMetricLoggerImplementation(string databaseFilePath, string metricCategoryName, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) : base(bufferProcessingStrategy, intervalMetricChecking) { InitialisePrivateMembers(databaseFilePath, metricCategoryName); dbConnection = new OleDbConnection(); // Need to cast the connection to an OleDbConnection in order to get the underlying connection // Usually would avoid casting, but in this case it should be safe, as the member was just set to this object type on the previous line dbCommand = new OleDbCommand("", ((OleDbConnection)dbConnection).Connection); }
//------------------------------------------------------------------------------ // // Method: MetricAggregateLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MetricAggregateLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> protected MetricAggregateLogger(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IDateTime dateTime, IExceptionHandler exceptionHandler) : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler) { InitialisePrivateMembers(); }
//------------------------------------------------------------------------------ // // Method: MicrosoftAccessMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.MicrosoftAccessMetricLoggerImplementation class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="databaseFilePath">The full path to the Microsoft Access data file.</param> /// <param name="metricCategoryName">The name of the category which the metric events should be logged under in the database.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="dbConnection">A test (mock) database connection object.</param> /// <param name="dbCommand">A test (mock) database command object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public MicrosoftAccessMetricLoggerImplementation(string databaseFilePath, string metricCategoryName, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IOleDbConnection dbConnection, IOleDbCommand dbCommand, IDateTime dateTime, IExceptionHandler exceptionHandler) : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler) { InitialisePrivateMembers(databaseFilePath, metricCategoryName); this.dbConnection = dbConnection; this.dbCommand = dbCommand; }
//------------------------------------------------------------------------------ // // Method: PerformanceCounterMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.PerformanceCounterMetricLoggerImplementation class. /// </summary> /// <param name="metricCategoryName">The name of the performance counter category which the metric events should be logged under.</param> /// <param name="metricCategoryDescription">The description of the performance counter category which the metric events should be logged under.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public PerformanceCounterMetricLoggerImplementation(string metricCategoryName, string metricCategoryDescription, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) : base(bufferProcessingStrategy, intervalMetricChecking) { InitialisePrivateMembers(metricCategoryName, metricCategoryDescription); counterCreationDataFactory = new CounterCreationDataFactory(); performanceCounterCategory = new PerformanceCounterCategory(); performanceCounterFactory = new PerformanceCounterFactory(); }
//------------------------------------------------------------------------------ // // Method: ConsoleMetricLoggerImplementation (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.ConsoleMetricLoggerImplementation class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="console">A test (mock) console object.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public ConsoleMetricLoggerImplementation(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IConsole console, IDateTime dateTime, IExceptionHandler exceptionHandler) : base(bufferProcessingStrategy, intervalMetricChecking, dateTime, exceptionHandler) { this.console = console; }
//------------------------------------------------------------------------------ // // Method: ConsoleMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.ConsoleMetricLogger class. /// </summary> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public ConsoleMetricLogger(IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { loggerImplementation = new ConsoleMetricLoggerImplementation(bufferProcessingStrategy, intervalMetricChecking); }