/* ======================================================================== * Copyright (c) 2005-2020 The OPC Foundation, Inc. All rights reserved. * * OPC Foundation MIT License 1.00 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * The complete license agreement can be found here: * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Security.Principal; namespace Opc.Ua.Aggregates { public class IServerInternal { } /// /// An object that manages aggregate factories supported by the server. /// public class AggregateManager : IDisposable { #region Constructors /// /// Initilizes the manager. /// public AggregateManager(IServerInternal server) { m_server = server; m_factories = new Dictionary(); m_minimumProcessingInterval = 1000; } #endregion #region IDisposable Members /// /// The finializer implementation. /// ~AggregateManager() { Dispose(false); } /// /// Frees any unmanaged resources. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// An overrideable version of the Dispose. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "m_requestTimer")] protected virtual void Dispose(bool disposing) { if (disposing) { // TBD } } #endregion #region Public Members /// /// Checks if the aggregate is supported by the server. /// /// The id of the aggregate function. /// True if the aggregate is supported. public bool IsSupported(NodeId aggregateId) { if (NodeId.IsNull(aggregateId)) { return false; } lock (m_lock) { return m_factories.ContainsKey(aggregateId); } } /// /// The minimum processing interval for any aggregate calculation. /// public double MinimumProcessingInterval { get { lock (m_lock) { return m_minimumProcessingInterval; } } set { lock (m_lock) { m_minimumProcessingInterval = value; } } } /// /// Returns the default configuration for the specified variable id. /// /// The id of history data node. /// The configuration. public AggregateConfiguration GetDefaultConfiguration(NodeId variableId) { lock (m_lock) { if (m_defaultConfiguration == null) { m_defaultConfiguration = new AggregateConfiguration(); m_defaultConfiguration.PercentDataBad = 0; m_defaultConfiguration.PercentDataGood = 100; m_defaultConfiguration.TreatUncertainAsBad = false; m_defaultConfiguration.UseSlopedExtrapolation = false; } return m_defaultConfiguration; } } /// /// Sets the default aggregate configuration. /// /// The default aggregate configuration.. public void SetDefaultConfiguration(AggregateConfiguration configuration) { lock (m_lock) { m_defaultConfiguration = configuration; } } /// /// Creates a new aggregate calculator. /// /// The id of the aggregate function. /// When to start processing. /// When to stop processing. /// The processing interval. /// The configuaration to use. /// public IAggregateCalculator CreateCalculator( NodeId aggregateId, DateTime startTime, DateTime endTime, double processingInterval, AggregateConfiguration configuration) { if (NodeId.IsNull(aggregateId)) { return null; } AggregatorFactory factory = null; lock (m_lock) { if (!m_factories.TryGetValue(aggregateId, out factory)) { return null; } } AggregateCalculatorImpl calculator = factory(); if (calculator == null) { return null; } calculator.StartTime = startTime; calculator.EndTime = endTime; calculator.ProcessingInterval = processingInterval; calculator.Configuration = configuration; calculator.SteppedVariable = configuration.UseSlopedExtrapolation; return calculator; } /// /// Registers an aggregate factory. /// /// The id of the aggregate function. /// The id of the aggregate name. /// The factory used to create calculators. public void RegisterFactory(NodeId aggregateId, string aggregateName, AggregatorFactory factory) { lock (m_lock) { m_factories[aggregateId] = factory; } } /// /// Unregisters an aggregate factory. /// /// The id of the aggregate function. public void RegisterFactory(NodeId aggregateId) { lock (m_lock) { m_factories.Remove(aggregateId); } } #endregion #region Private Methods #endregion #region Private Fields private object m_lock = new object(); private IServerInternal m_server; private AggregateConfiguration m_defaultConfiguration; private Dictionary m_factories; private double m_minimumProcessingInterval; #endregion } }