This commit is contained in:
luosheng
2023-07-16 08:17:03 +08:00
parent 6d655b24d1
commit 2055c10c59
127 changed files with 7414 additions and 7470 deletions

View File

@@ -30,230 +30,230 @@ using System.Runtime.Serialization;
namespace Technosoftware.DaAeHdaClient.Ae
{
/// <summary>
/// An in-process object which provides access to AE subscription objects.
/// </summary>
[Serializable]
public class TsCAeSubscription : ITsCAeSubscription, ISerializable, ICloneable
{
#region CategoryCollection Class
/// <summary>
/// An in-process object which provides access to AE subscription objects.
/// </summary>
[Serializable]
public class TsCAeSubscription : ITsCAeSubscription, ISerializable, ICloneable
{
#region CategoryCollection Class
/// <summary>
/// Contains a read-only collection category ids.
/// </summary>
public class CategoryCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// Contains a read-only collection category ids.
/// </summary>
public class CategoryCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal CategoryCollection() : base(new int[0]) { }
/// Creates an empty collection.
/// </summary>
internal CategoryCollection() : base(new int[0]) { }
/// <summary>
/// Creates a collection containing the list of category ids.
/// </summary>
internal CategoryCollection(int[] categoryIDs) : base(categoryIDs) { }
/// <summary>
/// Creates a collection containing the list of category ids.
/// </summary>
internal CategoryCollection(int[] categoryIDs) : base(categoryIDs) { }
#endregion
#region Public Methods
#region Public Methods
/// <summary>
/// An indexer for the collection.
/// </summary>
public new int this[int index] => (int)Array.GetValue(index);
/// An indexer for the collection.
/// </summary>
public new int this[int index] => (int)Array.GetValue(index);
/// <summary>
/// Returns a copy of the collection as an array.
/// </summary>
public new int[] ToArray()
{
return (int[])OpcConvert.Clone(Array);
}
{
return (int[])OpcConvert.Clone(Array);
}
#endregion
}
}
#endregion
#region StringCollection Class
#region StringCollection Class
/// <summary>
/// Contains a read-only collection of strings.
/// </summary>
public class StringCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// Contains a read-only collection of strings.
/// </summary>
public class StringCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal StringCollection() : base(new string[0]) { }
/// Creates an empty collection.
/// </summary>
internal StringCollection() : base(new string[0]) { }
/// <summary>
/// Creates a collection containing the specified strings.
/// </summary>
internal StringCollection(string[] strings) : base(strings) { }
#endregion
#region Public Methods
/// <summary>
/// An indexer for the collection.
/// </summary>
public new string this[int index] => (string)Array.GetValue(index);
/// Creates a collection containing the specified strings.
/// </summary>
internal StringCollection(string[] strings) : base(strings) { }
#endregion
#region Public Methods
/// <summary>
/// An indexer for the collection.
/// </summary>
public new string this[int index] => (string)Array.GetValue(index);
/// <summary>
/// Returns a copy of the collection as an array.
/// </summary>
public new string[] ToArray()
{
return (string[])OpcConvert.Clone(Array);
}
{
return (string[])OpcConvert.Clone(Array);
}
#endregion
}
}
#endregion
#region AttributeDictionary Class
#region AttributeDictionary Class
/// <summary>
/// Contains a read-only dictionary of attribute lists indexed by category id.
/// </summary>
[Serializable]
public class AttributeDictionary : OpcReadOnlyDictionary
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal AttributeDictionary() : base(null) { }
/// Contains a read-only dictionary of attribute lists indexed by category id.
/// </summary>
[Serializable]
public class AttributeDictionary : OpcReadOnlyDictionary
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal AttributeDictionary() : base(null) { }
/// <summary>
/// Constructs an dictionary from a set of category ids.
/// </summary>
internal AttributeDictionary(Hashtable dictionary) : base(dictionary) { }
/// <summary>
/// Constructs an dictionary from a set of category ids.
/// </summary>
internal AttributeDictionary(Hashtable dictionary) : base(dictionary) { }
#endregion
#region Public Methods
#region Public Methods
/// <summary>
/// Gets or sets the attribute collection for the specified category.
/// </summary>
public AttributeCollection this[int categoryId] => (AttributeCollection)base[categoryId];
/// Gets or sets the attribute collection for the specified category.
/// </summary>
public AttributeCollection this[int categoryId] => (AttributeCollection)base[categoryId];
/// <summary>
/// Adds or replaces the set of attributes associated with the category.
/// </summary>
internal void Update(int categoryId, int[] attributeIDs)
{
Dictionary[categoryId] = new AttributeCollection(attributeIDs);
}
{
Dictionary[categoryId] = new AttributeCollection(attributeIDs);
}
#endregion
#region ISerializable Members
/// <summary>
/// Constructs an object by deserializing it from a stream.
/// </summary>
protected AttributeDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
}
#region ISerializable Members
/// <summary>
/// Constructs an object by deserializing it from a stream.
/// </summary>
protected AttributeDictionary(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
}
#endregion
#region AttributeCollection Class
#region AttributeCollection Class
/// <summary>
/// Contains a read-only collection attribute ids.
/// </summary>
[Serializable]
public class AttributeCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal AttributeCollection() : base(new int[0]) { }
/// Contains a read-only collection attribute ids.
/// </summary>
[Serializable]
public class AttributeCollection : OpcReadOnlyCollection
{
#region Constructors, Destructor, Initialization
/// <summary>
/// Creates an empty collection.
/// </summary>
internal AttributeCollection() : base(new int[0]) { }
/// <summary>
/// Creates a collection containing the specified attribute ids.
/// </summary>
internal AttributeCollection(int[] attributeIDs) : base(attributeIDs) { }
/// <summary>
/// Creates a collection containing the specified attribute ids.
/// </summary>
internal AttributeCollection(int[] attributeIDs) : base(attributeIDs) { }
#endregion
#region Public Methods
/// <summary>
/// An indexer for the collection.
/// </summary>
public new int this[int index] => (int)Array.GetValue(index);
#region Public Methods
/// <summary>
/// An indexer for the collection.
/// </summary>
public new int this[int index] => (int)Array.GetValue(index);
/// <summary>
/// Returns a copy of the collection as an array.
/// </summary>
public new int[] ToArray()
{
return (int[])OpcConvert.Clone(Array);
}
{
return (int[])OpcConvert.Clone(Array);
}
#endregion
#region ISerializable Members
#region ISerializable Members
/// <summary>
/// Constructs an object by deserializing it from a stream.
/// </summary>
protected AttributeCollection(SerializationInfo info, StreamingContext context) : base(info, context) { }
/// Constructs an object by deserializing it from a stream.
/// </summary>
protected AttributeCollection(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endregion
}
#endregion
#region Names Class
/// <summary>
/// A set of names for fields used in serialization.
/// </summary>
private class Names
{
internal const string State = "ST";
internal const string Filters = "FT";
internal const string Attributes = "AT";
}
}
#endregion
#region Fields
#region Names Class
/// <summary>
/// A set of names for fields used in serialization.
/// </summary>
private class Names
{
internal const string State = "ST";
internal const string Filters = "FT";
internal const string Attributes = "AT";
}
#endregion
#region Fields
private bool disposed_;
private TsCAeServer server_;
private ITsCAeSubscription subscription_;
private TsCAeServer server_;
private ITsCAeSubscription subscription_;
// state
private TsCAeSubscriptionState state_;
private string name_;
// state
private TsCAeSubscriptionState state_;
private string name_;
// filters
private TsCAeSubscriptionFilters subscriptionFilters_ = new TsCAeSubscriptionFilters();
private CategoryCollection categories_ = new CategoryCollection();
private StringCollection areas_ = new StringCollection();
private StringCollection sources_ = new StringCollection();
// filters
private TsCAeSubscriptionFilters subscriptionFilters_ = new TsCAeSubscriptionFilters();
private CategoryCollection categories_ = new CategoryCollection();
private StringCollection areas_ = new StringCollection();
private StringCollection sources_ = new StringCollection();
// returned attributes
private AttributeDictionary attributes_ = new AttributeDictionary();
// returned attributes
private AttributeDictionary attributes_ = new AttributeDictionary();
#endregion
#region Constructors, Destructor, Initialization
#region Constructors, Destructor, Initialization
/// <summary>
/// Initializes object with default values.
/// </summary>
public TsCAeSubscription(TsCAeServer server, ITsCAeSubscription subscription, TsCAeSubscriptionState state)
{
/// Initializes object with default values.
/// </summary>
public TsCAeSubscription(TsCAeServer server, ITsCAeSubscription subscription, TsCAeSubscriptionState state)
{
server_ = server ?? throw new ArgumentNullException(nameof(server));
subscription_ = subscription ?? throw new ArgumentNullException(nameof(subscription));
state_ = (TsCAeSubscriptionState)state.Clone();
name_ = state.Name;
}
subscription_ = subscription ?? throw new ArgumentNullException(nameof(subscription));
state_ = (TsCAeSubscriptionState)state.Clone();
name_ = state.Name;
}
/// <summary>
/// The finalizer implementation.
/// </summary>
~TsCAeSubscription()
{
Dispose(false);
}
{
Dispose(false);
}
/// <summary>
///
/// </summary>
public virtual void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
/// <summary>
///
/// </summary>
public virtual void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
/// <summary>
/// Dispose(bool disposing) executes in two distinct scenarios.
@@ -266,34 +266,34 @@ namespace Technosoftware.DaAeHdaClient.Ae
/// </summary>
/// <param name="disposing">If true managed and unmanaged resources can be disposed. If false only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if(!disposed_)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if(disposing)
{
if (subscription_ != null)
{
server_.SubscriptionDisposed(this);
subscription_.Dispose();
}
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
disposed_ = true;
}
{
// Check to see if Dispose has already been called.
if (!disposed_)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
if (subscription_ != null)
{
server_.SubscriptionDisposed(this);
subscription_.Dispose();
}
}
// Release unmanaged resources. If disposing is false,
// only the following code is executed.
}
disposed_ = true;
}
#endregion
#endregion
#region Properties
#region Properties
/// <summary>
/// The server that the subscription object belongs to.
/// </summary>
public TsCAeServer Server => server_;
/// <summary>
/// The server that the subscription object belongs to.
/// </summary>
public TsCAeServer Server => server_;
/// <summary>
/// A descriptive name for the subscription.
@@ -365,19 +365,19 @@ namespace Technosoftware.DaAeHdaClient.Ae
public AttributeDictionary Attributes => attributes_;
#endregion
#region Public Methods
#region Public Methods
/// <summary>
/// Returns a writable copy of the current attributes.
/// </summary>
public TsCAeAttributeDictionary GetAttributes()
{
/// Returns a writable copy of the current attributes.
/// </summary>
public TsCAeAttributeDictionary GetAttributes()
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
var attributes = new TsCAeAttributeDictionary();
var attributes = new TsCAeAttributeDictionary();
var enumerator = attributes_.GetEnumerator();
var enumerator = attributes_.GetEnumerator();
while (enumerator.MoveNext())
{
while (enumerator.MoveNext())
{
if (enumerator.Key != null)
{
var categoryId = (int)enumerator.Key;
@@ -387,48 +387,48 @@ namespace Technosoftware.DaAeHdaClient.Ae
}
}
return attributes;
}
return attributes;
}
#endregion
#region ISerializable Members
#region ISerializable Members
/// <summary>
/// Constructs a server by de-serializing its OpcUrl from the stream.
/// </summary>
protected TsCAeSubscription(SerializationInfo info, StreamingContext context)
{
state_ = (TsCAeSubscriptionState)info.GetValue(Names.State, typeof(TsCAeSubscriptionState));
subscriptionFilters_ = (TsCAeSubscriptionFilters)info.GetValue(Names.Filters, typeof(TsCAeSubscriptionFilters));
attributes_ = (AttributeDictionary)info.GetValue(Names.Attributes, typeof(AttributeDictionary));
/// Constructs a server by de-serializing its OpcUrl from the stream.
/// </summary>
protected TsCAeSubscription(SerializationInfo info, StreamingContext context)
{
state_ = (TsCAeSubscriptionState)info.GetValue(Names.State, typeof(TsCAeSubscriptionState));
subscriptionFilters_ = (TsCAeSubscriptionFilters)info.GetValue(Names.Filters, typeof(TsCAeSubscriptionFilters));
attributes_ = (AttributeDictionary)info.GetValue(Names.Attributes, typeof(AttributeDictionary));
name_ = state_.Name;
name_ = state_.Name;
categories_ = new CategoryCollection(subscriptionFilters_.Categories.ToArray());
areas_ = new StringCollection(subscriptionFilters_.Areas.ToArray());
sources_ = new StringCollection(subscriptionFilters_.Sources.ToArray());
}
categories_ = new CategoryCollection(subscriptionFilters_.Categories.ToArray());
areas_ = new StringCollection(subscriptionFilters_.Areas.ToArray());
sources_ = new StringCollection(subscriptionFilters_.Sources.ToArray());
}
/// <summary>
/// Serializes a server into a stream.
/// </summary>
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(Names.State, state_);
info.AddValue(Names.Filters, subscriptionFilters_);
info.AddValue(Names.Attributes, attributes_);
}
/// <summary>
/// Serializes a server into a stream.
/// </summary>
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(Names.State, state_);
info.AddValue(Names.Filters, subscriptionFilters_);
info.AddValue(Names.Attributes, attributes_);
}
#endregion
#region ICloneable Members
#region ICloneable Members
/// <summary>
/// Returns an unconnected copy of the subscription with the same items.
/// </summary>
public virtual object Clone()
{
// do a memberwise clone.
var clone = (TsCAeSubscription)MemberwiseClone();
/// Returns an unconnected copy of the subscription with the same items.
/// </summary>
public virtual object Clone()
{
// do a memberwise clone.
var clone = (TsCAeSubscription)MemberwiseClone();
/*
/*
// place clone in disconnected state.
clone.server = null;
clone.subscription = null;
@@ -454,12 +454,12 @@ namespace Technosoftware.DaAeHdaClient.Ae
}
*/
// return clone.
return clone;
}
// return clone.
return clone;
}
#endregion
#region ISubscription Members
#region ISubscription Members
/// <summary>
/// An event to receive data change updates.
/// </summary>
@@ -469,136 +469,136 @@ namespace Technosoftware.DaAeHdaClient.Ae
remove => subscription_.DataChangedEvent -= value;
}
/// <summary>
/// Returns the current state of the subscription.
/// </summary>
/// <returns>The current state of the subscription.</returns>
public TsCAeSubscriptionState GetState()
{
/// <summary>
/// Returns the current state of the subscription.
/// </summary>
/// <returns>The current state of the subscription.</returns>
public TsCAeSubscriptionState GetState()
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
state_ = subscription_.GetState();
state_.Name = name_;
state_ = subscription_.GetState();
state_.Name = name_;
return (TsCAeSubscriptionState)state_.Clone();
}
return (TsCAeSubscriptionState)state_.Clone();
}
/// <summary>
/// Changes the state of a subscription.
/// </summary>
/// <param name="masks">A bit mask that indicates which elements of the subscription state are changing.</param>
/// <param name="state">The new subscription state.</param>
/// <returns>The actual subscription state after applying the changes.</returns>
public TsCAeSubscriptionState ModifyState(int masks, TsCAeSubscriptionState state)
{
/// <summary>
/// Changes the state of a subscription.
/// </summary>
/// <param name="masks">A bit mask that indicates which elements of the subscription state are changing.</param>
/// <param name="state">The new subscription state.</param>
/// <returns>The actual subscription state after applying the changes.</returns>
public TsCAeSubscriptionState ModifyState(int masks, TsCAeSubscriptionState state)
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
state_ = subscription_.ModifyState(masks, state);
if ((masks & (int)TsCAeStateMask.Name) != 0)
{
state_.Name = name_ = state.Name;
}
else
{
state_.Name = name_;
}
if ((masks & (int)TsCAeStateMask.Name) != 0)
{
state_.Name = name_ = state.Name;
}
else
{
state_.Name = name_;
}
return (TsCAeSubscriptionState)state_.Clone();
}
return (TsCAeSubscriptionState)state_.Clone();
}
/// <summary>
/// Returns the current filters for the subscription.
/// </summary>
/// <returns>The current filters for the subscription.</returns>
public TsCAeSubscriptionFilters GetFilters()
{
/// <summary>
/// Returns the current filters for the subscription.
/// </summary>
/// <returns>The current filters for the subscription.</returns>
public TsCAeSubscriptionFilters GetFilters()
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
subscriptionFilters_ = subscription_.GetFilters();
categories_ = new CategoryCollection(subscriptionFilters_.Categories.ToArray());
areas_ = new StringCollection(subscriptionFilters_.Areas.ToArray());
sources_ = new StringCollection(subscriptionFilters_.Sources.ToArray());
categories_ = new CategoryCollection(subscriptionFilters_.Categories.ToArray());
areas_ = new StringCollection(subscriptionFilters_.Areas.ToArray());
sources_ = new StringCollection(subscriptionFilters_.Sources.ToArray());
return (TsCAeSubscriptionFilters)subscriptionFilters_.Clone();
}
return (TsCAeSubscriptionFilters)subscriptionFilters_.Clone();
}
/// <summary>
/// Sets the current filters for the subscription.
/// </summary>
/// <param name="filters">The new filters to use for the subscription.</param>
public void SetFilters(TsCAeSubscriptionFilters filters)
{
/// <summary>
/// Sets the current filters for the subscription.
/// </summary>
/// <param name="filters">The new filters to use for the subscription.</param>
public void SetFilters(TsCAeSubscriptionFilters filters)
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
subscription_.SetFilters(filters);
GetFilters();
}
GetFilters();
}
/// <summary>
/// Returns the set of attributes to return with event notifications.
/// </summary>
/// <returns>The set of attributes to returned with event notifications.</returns>
public int[] GetReturnedAttributes(int eventCategory)
{
/// <summary>
/// Returns the set of attributes to return with event notifications.
/// </summary>
/// <returns>The set of attributes to returned with event notifications.</returns>
public int[] GetReturnedAttributes(int eventCategory)
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
var attributeIDs = subscription_.GetReturnedAttributes(eventCategory);
attributes_.Update(eventCategory, (int[])OpcConvert.Clone(attributeIDs));
attributes_.Update(eventCategory, (int[])OpcConvert.Clone(attributeIDs));
return attributeIDs;
}
return attributeIDs;
}
/// <summary>
/// Selects the set of attributes to return with event notifications.
/// </summary>
/// <param name="eventCategory">The specific event category for which the attributes apply.</param>
/// <param name="attributeIDs">The list of attribute ids to return.</param>
public void SelectReturnedAttributes(int eventCategory, int[] attributeIDs)
{
/// <summary>
/// Selects the set of attributes to return with event notifications.
/// </summary>
/// <param name="eventCategory">The specific event category for which the attributes apply.</param>
/// <param name="attributeIDs">The list of attribute ids to return.</param>
public void SelectReturnedAttributes(int eventCategory, int[] attributeIDs)
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
subscription_.SelectReturnedAttributes(eventCategory, attributeIDs);
attributes_.Update(eventCategory, (int[])OpcConvert.Clone(attributeIDs));
}
attributes_.Update(eventCategory, (int[])OpcConvert.Clone(attributeIDs));
}
/// <summary>
/// Force a refresh for all active conditions and inactive, unacknowledged conditions whose event notifications match the filter of the event subscription.
/// </summary>
public void Refresh()
{
/// <summary>
/// Force a refresh for all active conditions and inactive, unacknowledged conditions whose event notifications match the filter of the event subscription.
/// </summary>
public void Refresh()
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
subscription_.Refresh();
}
}
/// <summary>
/// Cancels an outstanding refresh request.
/// </summary>
public void CancelRefresh()
{
/// <summary>
/// Cancels an outstanding refresh request.
/// </summary>
public void CancelRefresh()
{
LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.AlarmsConditions);
if (subscription_ == null) throw new NotConnectedException();
subscription_.CancelRefresh();
}
#endregion
}
#endregion
#region Internal Properties
#region Internal Properties
/// <summary>
/// The current state.
/// </summary>
internal TsCAeSubscriptionState State => state_;
/// The current state.
/// </summary>
internal TsCAeSubscriptionState State => state_;
/// <summary>
/// The current filters.
@@ -606,5 +606,5 @@ namespace Technosoftware.DaAeHdaClient.Ae
internal TsCAeSubscriptionFilters Filters => subscriptionFilters_;
#endregion
}
}
}