//****************************************************************************************************** // IAdapter.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 System.Data; using System.Linq; using System.Threading; namespace GSF.TimeSeries.Adapters { /// /// Represents the abstract interface for any adapter. /// public interface IAdapter : ISupportLifecycle, IProvideStatus { /// /// Provides status messages to consumer. /// /// /// is new status message. /// event EventHandler> StatusMessage; /// /// Event is raised when there is an exception encountered while processing. /// /// /// /// Implementations of this interface are expected to capture any exceptions that might be thrown by /// user code in any processing to prevent third-party code from causing an unhandled exception /// in the host. Errors are reported via this event so host administrators will be aware of the exception. /// Any needed connection cycle to data adapter should be restarted when an exception is encountered. /// /// /// is the exception that was thrown. /// /// event EventHandler> ProcessException; /// /// Event is raised when are updated. /// event EventHandler InputMeasurementKeysUpdated; /// /// Event is raised when are updated. /// event EventHandler OutputMeasurementsUpdated; /// /// Event is raised when adapter is aware of a configuration change. /// event EventHandler ConfigurationChanged; /// /// Gets or sets based data source available to . /// DataSet DataSource { get; set; } /// /// Gets or sets key/value pair connection information specific to . /// string ConnectionString { get; set; } /// /// Gets connection info for adapter, if any. /// /// /// For example, this could return IP or host name of source connection. /// string ConnectionInfo { get; } /// /// Gets settings parsed when was assigned. /// Dictionary Settings { get; } /// /// Gets or sets name of this . /// new string Name { get; set; } /// /// Gets or sets the numeric ID associated with this . /// uint ID { get; set; } /// /// Gets or sets flag indicating if the adapter has been initialized successfully. /// /// /// Implementers only need to track this value. /// bool Initialized { get; set; } /// /// Gets or sets maximum time system will wait during for initialization. /// /// /// Implementers should use value to wait indefinitely. /// int InitializationTimeout { get; set; } /// /// Gets or sets flag indicating if adapter should automatically start or connect on demand. /// bool AutoStart { get; set; } /// /// Gets or sets primary keys of input measurements the adapter expects. /// MeasurementKey[] InputMeasurementKeys { get; set; } /// /// Gets or sets output measurements that the adapter will produce, if any. /// IMeasurement[] OutputMeasurements { get; set; } /// /// Gets the total number of measurements processed thus far by the . /// long ProcessedMeasurements { get; } /// /// Gets the flag indicating if this adapter supports temporal processing. /// bool SupportsTemporalProcessing { get; } /// /// Gets the start time temporal processing constraint defined by call to . /// /// /// This value will be when start time constraint is not set - meaning the adapter /// is processing data in real-time. /// DateTime StartTimeConstraint { get; } /// /// Gets the stop time temporal processing constraint defined by call to . /// /// /// This value will be when stop time constraint is not set - meaning the adapter /// is processing data in real-time. /// DateTime StopTimeConstraint { get; } /// /// Gets or sets the desired processing interval, in milliseconds, for the adapter. /// /// /// With the exception of the values of -1 and 0, this value specifies the desired processing interval for data, i.e., /// basically a delay, or timer interval, over which to process data. A value of -1 means to use the default processing /// interval while a value of 0 means to process data as fast as possible. /// int ProcessingInterval { get; set; } /// /// Starts the adapter, if it is not already running. /// void Start(); /// /// Stops the adapter. /// void Stop(); /// /// Gets a short one-line adapter status. /// /// Maximum number of available characters for display. /// A short one-line summary of the current adapter status. string GetShortStatus(int maxLength); /// /// Defines a temporal processing constraint for the adapter. /// /// Defines a relative or exact start time for the temporal constraint. /// Defines a relative or exact stop time for the temporal constraint. /// Defines any temporal parameters related to the constraint. /// /// /// This method defines a temporal processing constraint for an adapter, i.e., the start and stop time over which an /// adapter will process data. Actual implementation of the constraint will be adapter specific. Implementations /// should be able to dynamically handle multiple calls to this function with new constraints. Passing in null /// for the and should cancel the temporal constraint and /// return the adapter to standard / real-time operation. /// /// /// The and parameters can be specified in one of the /// following formats: /// /// /// Time Format /// Format Description /// /// /// 12-30-2000 23:59:59.033 /// Absolute date and time. /// /// /// * /// Evaluates to . /// /// /// *-20s /// Evaluates to 20 seconds before . /// /// /// *-10m /// Evaluates to 10 minutes before . /// /// /// *-1h /// Evaluates to 1 hour before . /// /// /// *-1d /// Evaluates to 1 day before . /// /// /// /// void SetTemporalConstraint(string startTime, string stopTime, string constraintParameters); } /// /// Defines static extension functions for implementations. /// public static class IAdapterExtensions { /// /// Returns true if has a temporal constraint defined, i.e., either /// or is not /// set to its default value. /// /// instance to test. /// true if has a temporal constraint defined. public static bool TemporalConstraintIsDefined(this IAdapter adapter) { return adapter.StartTimeConstraint != DateTime.MinValue || adapter.StopTimeConstraint != DateTime.MaxValue; } /// /// Returns the values of the input measurements. /// /// instance input measurements to convert. /// values of the input measurements. public static MeasurementKey[] InputMeasurementKeys(this IAdapter adapter) { return adapter.InputMeasurementKeys ?? new MeasurementKey[0]; } /// /// Returns the values of the output measurements. /// /// instance output measurements to convert. /// values of the output measurements. public static MeasurementKey[] OutputMeasurementKeys(this IAdapter adapter) { return adapter.OutputMeasurements.MeasurementKeys().ToArray(); } /// /// Gets a distinct list of input measurement keys for all of the provided adapters. /// /// Type of . /// Source enumeration. /// Distinct list of input measurement keys for all of the provided adapters. public static MeasurementKey[] InputMeasurementKeys(this IEnumerable adapters) where T : IAdapter { List inputMeasurementKeys = new List(); foreach (T adapter in adapters) { MeasurementKey[] adapterInputMeasurementKeys = adapter.InputMeasurementKeys; if (adapterInputMeasurementKeys != null && adapterInputMeasurementKeys.Length > 0) inputMeasurementKeys.AddRange(adapterInputMeasurementKeys); } return inputMeasurementKeys.Distinct().ToArray(); } /// /// Gets a distinct list of output measurement keys for all of the provided adapters. /// /// Type of . /// Source enumeration. /// Distinct list of output measurement keys for all of the provided adapters. public static MeasurementKey[] OutputMeasurementKeys(this IEnumerable adapters) where T : IAdapter { List outputMeasurementKeys = new List(); foreach (T adapter in adapters) { IEnumerable adapterOutputMeasurementKeys = adapter.OutputMeasurementKeys(); if ((object)adapterOutputMeasurementKeys != null && adapterOutputMeasurementKeys.Any()) outputMeasurementKeys.AddRange(adapterOutputMeasurementKeys); } return outputMeasurementKeys.Distinct().ToArray(); } } }