//****************************************************************************************************** // InputAdapterCollection.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 09/02/2010 - J. Ritchie Carroll // Generated original version of source code. // 12/20/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.Collections.Generic; using GSF.Diagnostics; namespace GSF.TimeSeries.Adapters { /// /// Represents a collection of implementations. /// public class InputAdapterCollection : AdapterCollectionBase, IInputAdapter { #region [ Members ] // Events /// /// This event will be raised when there are new measurements available from the input data source. /// /// /// is collection of new measurements for host to process. /// public event EventHandler>> NewMeasurements; /// /// Indicates to the host that processing for one of the input adapters has completed. /// /// /// This event is expected to only be raised when an input adapter has been designed to process /// a finite amount of data, e.g., reading a historical range of data during temporal processing. /// public event EventHandler ProcessingComplete; #endregion #region [ Constructors ] /// /// Creates a new . /// public InputAdapterCollection() { base.Name = "Input Adapter Collection"; base.DataMember = "InputAdapters"; base.MonitorTimerEnabled = true; } #endregion #region [ Methods ] /// /// Raises the event. /// /// New measurements. protected virtual void OnNewMeasurements(ICollection measurements) { try { NewMeasurements?.Invoke(this, new EventArgs>(measurements)); } catch (Exception ex) { // We protect our code from consumer thrown exceptions OnProcessException(MessageLevel.Info, new InvalidOperationException($"Exception in consumer handler for NewMeasurements event: {ex.Message}", ex), "ConsumerEventException"); } } /// /// Raises the event. /// protected virtual void OnProcessingComplete() { try { ProcessingComplete?.Invoke(this, EventArgs.Empty); } catch (Exception ex) { // We protect our code from consumer thrown exceptions OnProcessException(MessageLevel.Info, new InvalidOperationException($"Exception in consumer handler for ProcessingComplete event: {ex.Message}", ex), "ConsumerEventException"); } } /// /// Wires events and initializes new implementation. /// /// New implementation. protected override void InitializeItem(IInputAdapter item) { if ((object)item != null) { // Wire up new measurement event item.NewMeasurements += item_NewMeasurements; item.ProcessingComplete += item_ProcessingComplete; base.InitializeItem(item); } } /// /// Unwires events and disposes of implementation. /// /// to dispose. protected override void DisposeItem(IInputAdapter item) { if ((object)item != null) { // Un-wire new measurements event item.NewMeasurements -= item_NewMeasurements; item.ProcessingComplete -= item_ProcessingComplete; base.DisposeItem(item); } } // Raise new measurements event on behalf of each item in collection private void item_NewMeasurements(object sender, EventArgs> e) => NewMeasurements?.Invoke(sender, e); // Raise processing complete event on behalf of each item in collection private void item_ProcessingComplete(object sender, EventArgs e) => ProcessingComplete?.Invoke(sender, e); #endregion } }