#region Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved //----------------------------------------------------------------------------- // Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved // Web: https://www.technosoftware.com // // The source code in this file is covered under a dual-license scenario: // - Owner of a purchased license: SCLA 1.0 // - GPL V3: everybody else // // SCLA license terms accompanied with this source code. // See SCLA 1.0: https://technosoftware.com/license/Source_Code_License_Agreement.pdf // // GNU General Public License as published by the Free Software Foundation; // version 3 of the License are accompanied with this source code. // See https://technosoftware.com/license/GPLv3License.txt // // This source code is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. //----------------------------------------------------------------------------- #endregion Copyright (c) 2011-2023 Technosoftware GmbH. All rights reserved #region Using Directives using System; using System.Collections; using System.Runtime.Serialization; #endregion namespace Technosoftware.DaAeHdaClient.Hda { /// /// An in-process object used to access OPC Data Access servers. /// [Serializable] public class TsCHdaServer : OpcServer { #region Class Names /// /// A set of names for fields used in serialization. /// private class Names { internal const string Trends = "Trends"; } #endregion #region Fields private Hashtable items_ = new Hashtable(); private TsCHdaAttributeCollection attributes_ = new TsCHdaAttributeCollection(); private TsCHdaAggregateCollection aggregates_ = new TsCHdaAggregateCollection(); private TsCHdaTrendCollection trends_ = new TsCHdaTrendCollection(); #endregion #region Constructors, Destructor, Initialization /// /// Initializes the object with a factory and a default OpcUrl. /// /// The TsOpcFactory used to connect to remote servers. /// The network address of a remote server. public TsCHdaServer(OpcFactory factory, OpcUrl url) : base(factory, url) { } /// /// Construct a server by de-serializing its OpcUrl from the stream. /// protected TsCHdaServer(SerializationInfo info, StreamingContext context) : base(info, context) { var trends = (TsCHdaTrend[])info.GetValue(Names.Trends, typeof(TsCHdaTrend[])); if (trends != null) { Array.ForEach(trends, trend => { trend.SetServer(this); trends_.Add(trend); }); } } #endregion #region Properties /// /// Returns a collection of item attributes supported by the server. /// public TsCHdaAttributeCollection Attributes => attributes_; /// /// Returns a collection of aggregates supported by the server. /// public TsCHdaAggregateCollection Aggregates => aggregates_; /// /// Returns a collection of items with server handles assigned to them. /// public OpcItemCollection Items => new OpcItemCollection(items_.Values); /// /// Returns a collection of trends created for the server. /// public TsCHdaTrendCollection Trends => trends_; #endregion #region Public Methods /// /// Connects to the server with the specified OpcUrl and credentials. /// public override void Connect(OpcUrl url, OpcConnectData connectData) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); // connect to server. base.Connect(url, connectData); // fetch supported attributes. GetAttributes(); // fetch supported aggregates. GetAggregates(); // create items for trends. foreach (TsCHdaTrend trend in trends_) { var itemIDs = new ArrayList(); foreach (TsCHdaItem item in trend.Items) { itemIDs.Add(new OpcItem(item)); } // save server handles for each item. var results = CreateItems((OpcItem[])itemIDs.ToArray(typeof(OpcItem))); if (results != null) { for (var ii = 0; ii < results.Length; ii++) { trend.Items[ii].ServerHandle = null; if (results[ii].Result.Succeeded()) { trend.Items[ii].ServerHandle = results[ii].ServerHandle; } } } } } /// /// Disconnects from the server and releases all network resources. /// public override void Disconnect() { if (Server == null) throw new NotConnectedException(); // dispose of all items first. if (items_.Count > 0) { try { var items = new ArrayList(items_.Count); items.AddRange(items_); ((ITsCHdaServer)Server).ReleaseItems((OpcItem[])items.ToArray(typeof(OpcItem))); } catch { // ignore errors. } items_.Clear(); } // invalidate server handles for trends. foreach (TsCHdaTrend trend in trends_) { foreach (TsCHdaItem item in trend.Items) { item.ServerHandle = null; } } // disconnect from server. base.Disconnect(); } #endregion #region GetStatus /// /// Returns the current server status. /// /// The current server status. public OpcServerStatus GetServerStatus() { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var status = ((ITsCHdaServer)Server).GetServerStatus(); if (status != null) { if (status.StatusInfo == null) { status.StatusInfo = GetString($"serverState.{status.ServerState}"); } } else { throw new NotConnectedException(); } return status; } #endregion #region GetAttributes /// /// Returns the item attributes supported by the server. /// /// The a set of item attributes and their descriptions. public TsCHdaAttribute[] GetAttributes() { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); // clear existing cached list. attributes_.Clear(); var attributes = ((ITsCHdaServer)Server).GetAttributes(); // save a locale copy. if (attributes != null) { attributes_.Init(attributes); } return attributes; } #endregion #region GetAggregates /// /// Returns the aggregates supported by the server. /// /// The a set of aggregates and their descriptions. public TsCHdaAggregate[] GetAggregates() { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); // discard existing cached list. aggregates_.Clear(); var aggregates = ((ITsCHdaServer)Server).GetAggregates(); // save a locale copy. if (aggregates != null) { aggregates_.Init(aggregates); } return aggregates; } #endregion #region CreateBrowser /// /// Creates a object used to browse the server address space. /// /// The set of attribute filters to use when browsing. /// A result code for each individual filter. /// A browser object that must be released by calling Dispose(). public ITsCHdaBrowser CreateBrowser(TsCHdaBrowseFilter[] filters, out OpcResult[] results) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).CreateBrowser(filters, out results); } #endregion #region CreateItems /// /// Creates a set of items. /// /// The identifiers for the items to create. /// The results for each item containing the server handle and result code. public OpcItemResult[] CreateItems(OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).CreateItems(items); // save items for future reference. if (results != null) { foreach (var result in results) { if (result.Result.Succeeded()) { items_.Add(result.ServerHandle, new OpcItem(result)); } } } return results; } #endregion #region ReleaseItems /// /// Releases a set of previously created items. /// /// The server handles for the items to release. /// The results for each item containing the result code. public OpcItemResult[] ReleaseItems(OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReleaseItems(items); // remove items from local cache. if (results != null) { foreach (var result in results) { if (result.Result.Succeeded()) { items_.Remove(result.ServerHandle); } } } return results; } #endregion #region ValidateItems /// /// Validates a set of items. /// /// The identifiers for the items to validate. /// The results for each item containing the result code. public OpcItemResult[] ValidateItems(OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ValidateItems(items); } #endregion #region ReadRaw /// /// Reads raw (unprocessed) data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The number of values to be read for each item. /// Whether the bounding item values should be returned. /// The set of items to read (must include the item name). /// A set of values, qualities and timestamps within the requested time range for each item. internal TsCHdaItemValueCollection[] ReadRaw( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, bool includeBounds, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadRaw(startTime, endTime, maxValues, includeBounds, items); } /// /// Sends an asynchronous request to read raw data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The number of values to be read for each item. /// Whether the bounding item values should be returned. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] ReadRaw( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, bool includeBounds, OpcItem[] items, object requestHandle, TsCHdaReadValuesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadRaw(startTime, endTime, maxValues, includeBounds, items, requestHandle, callback, out request); } /// /// Requests that the server periodically send notifications when new data becomes available for a set of items. /// /// The beginning of the history period to read. /// The frequency, in seconds, that the server should check for new data. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] AdviseRaw( TsCHdaTime startTime, decimal updateInterval, OpcItem[] items, object requestHandle, TsCHdaDataUpdateEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).AdviseRaw(startTime, updateInterval, items, requestHandle, callback, out request); } /// /// Begins the playback raw data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The number of values to be read for each item. /// The frequency, in seconds, that the server send data. /// The duration, in seconds, of the timespan returned with each update. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] PlaybackRaw( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, decimal updateInterval, decimal playbackDuration, OpcItem[] items, object requestHandle, TsCHdaDataUpdateEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).PlaybackRaw(startTime, endTime, maxValues, updateInterval, playbackDuration, items, requestHandle, callback, out request); } #endregion #region ReadProcessed /// /// Reads processed data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The interval between returned values. /// The set of items to read (must include the item name). /// A set of values, qualities and timestamps within the requested time range for each item. internal TsCHdaItemValueCollection[] ReadProcessed( TsCHdaTime startTime, TsCHdaTime endTime, decimal resampleInterval, TsCHdaItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadProcessed(startTime, endTime, resampleInterval, items); } /// /// Sends an asynchronous request to read processed data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The interval between returned values. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] ReadProcessed( TsCHdaTime startTime, TsCHdaTime endTime, decimal resampleInterval, TsCHdaItem[] items, object requestHandle, TsCHdaReadValuesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReadProcessed( startTime, endTime, resampleInterval, items, requestHandle, callback, out request); return results; } /// /// Requests that the server periodically send notifications when new data becomes available for a set of items. /// /// The beginning of the history period to read. /// The interval between returned values. /// The number of resample intervals that the server should return in each callback. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] AdviseProcessed( TsCHdaTime startTime, decimal resampleInterval, int numberOfIntervals, TsCHdaItem[] items, object requestHandle, TsCHdaDataUpdateEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).AdviseProcessed( startTime, resampleInterval, numberOfIntervals, items, requestHandle, callback, out request); return results; } /// /// Begins the playback of processed data from the historian database for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The interval between returned values. /// The number of resample intervals that the server should return in each callback. /// The frequency, in seconds, that the server send data. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] PlaybackProcessed( TsCHdaTime startTime, TsCHdaTime endTime, decimal resampleInterval, int numberOfIntervals, decimal updateInterval, TsCHdaItem[] items, object requestHandle, TsCHdaDataUpdateEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).PlaybackProcessed( startTime, endTime, resampleInterval, numberOfIntervals, updateInterval, items, requestHandle, callback, out request); return results; } #endregion #region ReadAtTime /// /// Reads data from the historian database for a set of items at specific times. /// /// The set of timestamps to use when reading items values. /// The set of items to read (must include the item name). /// A set of values, qualities and timestamps within the requested time range for each item. internal TsCHdaItemValueCollection[] ReadAtTime(DateTime[] timestamps, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadAtTime(timestamps, items); } /// /// Sends an asynchronous request to read item values at specific times. /// /// The set of timestamps to use when reading items values. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] ReadAtTime( DateTime[] timestamps, OpcItem[] items, object requestHandle, TsCHdaReadValuesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReadAtTime( timestamps, items, requestHandle, callback, out request); return results; } #endregion #region ReadModified /// /// Reads item values that have been deleted or replaced. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The number of values to be read for each item. /// The set of items to read (must include the item name). /// A set of values, qualities and timestamps within the requested time range for each item. internal TsCHdaModifiedValueCollection[] ReadModified( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadModified(startTime, endTime, maxValues, items); } /// /// Sends an asynchronous request to read item values that have been deleted or replaced. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The number of values to be read for each item. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] ReadModified( TsCHdaTime startTime, TsCHdaTime endTime, int maxValues, OpcItem[] items, object requestHandle, TsCHdaReadValuesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReadModified( startTime, endTime, maxValues, items, requestHandle, callback, out request); return results; } #endregion #region ReadAttributes /// /// Reads the current or historical values for the attributes of an item. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The item to read (must include the item name). /// The attributes to read. /// A set of attribute values for each requested attribute. internal TsCHdaItemAttributeCollection ReadAttributes( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem item, int[] attributeIDs) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadAttributes(startTime, endTime, item, attributeIDs); } /// /// Sends an asynchronous request to read the attributes of an item. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The item to read (must include the item name). /// The attributes to read. /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the attribute ids. internal TsCHdaResultCollection ReadAttributes( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem item, int[] attributeIDs, object requestHandle, TsCHdaReadAttributesCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReadAttributes( startTime, endTime, item, attributeIDs, requestHandle, callback, out request); return results; } #endregion #region ReadAnnotations /// /// Reads any annotations for an item within the a time interval. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The set of items to read (must include the item name). /// A set of annotations within the requested time range for each item. internal TsCHdaAnnotationValueCollection[] ReadAnnotations( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).ReadAnnotations(startTime, endTime, items); } /// /// Sends an asynchronous request to read the annotations for a set of items. /// /// The beginning of the history period to read. /// The end of the history period to be read. /// The set of items to read (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] ReadAnnotations( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem[] items, object requestHandle, TsCHdaReadAnnotationsCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).ReadAnnotations( startTime, endTime, items, requestHandle, callback, out request); return results; } #endregion #region InsertAnnotations /// /// Inserts annotations for one or more items. /// /// A list of annotations to add for each item (must include the item name). /// The results of the insert operation for each annotation set. public TsCHdaResultCollection[] InsertAnnotations(TsCHdaAnnotationValueCollection[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).InsertAnnotations(items); } /// /// Sends an asynchronous request to inserts annotations for one or more items. /// /// A list of annotations to add for each item (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. public OpcItemResult[] InsertAnnotations( TsCHdaAnnotationValueCollection[] items, object requestHandle, TsCHdaUpdateCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).InsertAnnotations( items, requestHandle, callback, out request); return results; } #endregion #region Insert /// /// Inserts the values into the history database for one or more items. /// /// The set of values to insert. /// Whether existing values should be replaced. /// public TsCHdaResultCollection[] Insert(TsCHdaItemValueCollection[] items, bool replace) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).Insert(items, replace); } /// /// Sends an asynchronous request to inserts values for one or more items. /// /// The set of values to insert. /// Whether existing values should be replaced. /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. public OpcItemResult[] Insert( TsCHdaItemValueCollection[] items, bool replace, object requestHandle, TsCHdaUpdateCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).Insert( items, replace, requestHandle, callback, out request); return results; } #endregion #region Replace /// /// Replace the values into the history database for one or more items. /// /// The set of values to replace. /// public TsCHdaResultCollection[] Replace(TsCHdaItemValueCollection[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).Replace(items); } /// /// Sends an asynchronous request to replace values for one or more items. /// /// The set of values to replace. /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. public OpcItemResult[] Replace( TsCHdaItemValueCollection[] items, object requestHandle, TsCHdaUpdateCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).Replace( items, requestHandle, callback, out request); return results; } #endregion #region Delete /// /// Deletes the values with the specified time domain for one or more items. /// /// The beginning of the history period to delete. /// The end of the history period to be delete. /// The set of items to delete (must include the item name). /// The results of the delete operation for each item. internal OpcItemResult[] Delete( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).Delete(startTime, endTime, items); } /// /// Sends an asynchronous request to delete values for one or more items. /// /// The beginning of the history period to delete. /// The end of the history period to be delete. /// The set of items to delete (must include the item name). /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] Delete( TsCHdaTime startTime, TsCHdaTime endTime, OpcItem[] items, object requestHandle, TsCHdaUpdateCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).Delete( startTime, endTime, items, requestHandle, callback, out request); return results; } #endregion #region DeleteAtTime /// /// Deletes the values at the specified times for one or more items. /// /// The set of timestamps to delete for one or more items. /// The results of the operation for each timestamp. internal TsCHdaResultCollection[] DeleteAtTime(TsCHdaItemTimeCollection[] items) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); return ((ITsCHdaServer)Server).DeleteAtTime(items); } /// /// Sends an asynchronous request to delete values for one or more items at a specified times. /// /// The set of timestamps to delete for one or more items. /// An identifier for the request assigned by the caller. /// A delegate used to receive notifications when the request completes. /// An object that contains the state of the request (used to cancel the request). /// A set of results containing any errors encountered when the server validated the items. internal OpcItemResult[] DeleteAtTime( TsCHdaItemTimeCollection[] items, object requestHandle, TsCHdaUpdateCompleteEventHandler callback, out IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); var results = ((ITsCHdaServer)Server).DeleteAtTime( items, requestHandle, callback, out request); return results; } #endregion #region CancelRequest /// /// Cancels an asynchronous request. /// /// The state object for the request to cancel. public void CancelRequest(IOpcRequest request) { LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess); if (Server == null) throw new NotConnectedException(); ((ITsCHdaServer)Server).CancelRequest(request); } /// /// Cancels an asynchronous request. /// /// The state object for the request to cancel. /// A delegate used to receive notifications when the request completes. public void CancelRequest(IOpcRequest request, TsCHdaCancelCompleteEventHandler callback) { if (Server == null) throw new NotConnectedException(); ((ITsCHdaServer)Server).CancelRequest(request, callback); } #endregion #region ISerializable Members /// /// Serializes a server into a stream. /// public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); TsCHdaTrend[] trends = null; if (trends_.Count > 0) { trends = new TsCHdaTrend[trends_.Count]; for (var ii = 0; ii < trends.Length; ii++) { trends[ii] = trends_[ii]; } } info.AddValue(Names.Trends, trends); } #endregion #region ICloneable Members /// /// Returns an unconnected copy of the server with the same OpcUrl. /// public override object Clone() { // clone the base object. var clone = (TsCHdaServer)base.Clone(); // return clone. return clone; } #endregion } }