//****************************************************************************************************** // ConfigurationLoaderBase.cs - Gbtc // // Copyright © 2016, 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://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: // ---------------------------------------------------------------------------------------------------- // 11/30/2016 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** using System; using System.Data; using GSF.Diagnostics; using GSF.TimeSeries.Adapters; namespace GSF.TimeSeries.Configuration { /// /// Represents a base class for implementations. /// public abstract class ConfigurationLoaderBase : IConfigurationLoader { #region [ Members ] // Events /// /// Occurs when the configuration loader has a message to provide about its current status. /// public event EventHandler> StatusMessage; /// /// Occurs when the configuration loader encounters a non-catastrophic exception. /// public event EventHandler> ProcessException; #endregion #region [ Constructors ] /// /// Creates a new instance. /// protected ConfigurationLoaderBase() { Log = Logger.CreatePublisher(GetType(), MessageClass.Framework); Log.InitialStackMessages = Log.InitialStackMessages.Union("ComponentName", GetType().Name); } #endregion #region [ Properties ] /// /// Log messages generated by an adapter. /// protected LogPublisher Log { get; } /// /// Gets the flag that indicates whether augmentation is supported by this configuration loader. /// public abstract bool CanAugment { get; } #endregion #region [ Methods ] /// /// Loads the entire configuration data set from scratch. /// /// The configuration data set. public abstract DataSet Load(); /// /// Augments the given configuration data set with the changes /// tracked since the version of the given configuration data set. /// /// The configuration data set to be augmented. public abstract void Augment(DataSet configuration); /// /// Raises the event and sends this data to the . /// /// The to assign to this message /// New status message. /// A fixed string to classify this event; defaults to null. /// to use, if any; defaults to . /// /// should be a constant string value associated with what type of message is being /// generated. In general, there should only be a few dozen distinct event names per class. Exceeding this /// threshold will cause the EventName to be replaced with a general warning that a usage issue has occurred. /// protected virtual void OnStatusMessage(MessageLevel level, string status, string eventName = null, MessageFlags flags = MessageFlags.None) { try { Log.Publish(level, flags, eventName ?? "ConfigurationLoader", status); using (Logger.SuppressLogMessages()) StatusMessage?.Invoke(this, new EventArgs(AdapterBase.GetStatusWithMessageLevelPrefix(status, level))); } catch (Exception ex) { // We protect our code from consumer thrown exceptions OnProcessException(MessageLevel.Info, new InvalidOperationException($"Exception in consumer handler for StatusMessage event: {ex.Message}", ex), "ConsumerEventException"); } } /// /// Raises the event. /// /// The to assign to this message /// Processing . /// A fixed string to classify this event; defaults to null. /// to use, if any; defaults to . /// /// should be a constant string value associated with what type of message is being /// generated. In general, there should only be a few dozen distinct event names per class. Exceeding this /// threshold will cause the EventName to be replaced with a general warning that a usage issue has occurred. /// protected virtual void OnProcessException(MessageLevel level, Exception exception, string eventName = null, MessageFlags flags = MessageFlags.None) { try { Log.Publish(level, flags, eventName ?? "ConfigurationLoader", exception?.Message, null, exception); using (Logger.SuppressLogMessages()) ProcessException?.Invoke(this, new EventArgs(exception)); } catch (Exception ex) { // We protect our code from consumer thrown exceptions Log.Publish(MessageLevel.Info, "ConsumerEventException", $"Exception in consumer handler for ProcessException event: {ex.Message}", null, ex); } } #endregion } }