#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 Technosoftware.DaAeHdaClient.Da;
#endregion
namespace Technosoftware.DaAeHdaClient.Ae
{
///
/// A notification sent by the server when an event change occurs.
///
[Serializable]
public class TsCAeEventNotification : ICloneable
{
#region Fields
private DateTime time_ = DateTime.MinValue;
private TsCAeEventType eventType_ = TsCAeEventType.Condition;
private int severity_ = 1;
private AttributeCollection attributes_ = new AttributeCollection();
private TsCDaQuality daQuality_ = TsCDaQuality.Bad;
private DateTime activeTime_ = DateTime.MinValue;
#endregion
#region AttributeCollection Class
///
/// Contains a read-only collection of AttributeValues.
///
[Serializable]
public class AttributeCollection : OpcReadOnlyCollection
{
///
/// Creates an empty collection.
///
internal AttributeCollection() : base(new object[0]) { }
///
/// Creates a collection from an array of objects.
///
internal AttributeCollection(object[] attributes) : base(attributes) { }
}
#endregion
#region Properties
///
/// The handle of the subscription that requested the notification
///
public object ClientHandle { get; set; }
///
/// The identifier for the source that generated the event.
///
public string SourceID { get; set; }
///
/// The time of the event occurrence.
/// The ApplicationInstance.TimeAsUtc property defines
/// the time format (UTC or local time).
///
public DateTime Time
{
get => time_;
set => time_ = value;
}
///
/// Event notification message describing the event.
///
public string Message { get; set; }
///
/// The type of event that generated the notification.
///
public TsCAeEventType EventType
{
get => eventType_;
set => eventType_ = value;
}
///
/// The vendor defined category id for the event.
///
public int EventCategory { get; set; }
///
/// The severity of the event (1..1000).
///
public int Severity
{
get => severity_;
set => severity_ = value;
}
///
/// The name of the condition related to this event notification.
///
public string ConditionName { get; set; }
///
/// The name of the current sub-condition, for multi-state conditions.
/// For a single-state condition, this contains the condition name.
///
public string SubConditionName { get; set; }
///
/// The values of the attributes selected for the event subscription.
///
public AttributeCollection Attributes => attributes_;
///
/// Indicates which properties of the condition have changed, to have caused the server to send the event notification.
///
public int ChangeMask { get; set; }
///
/// Indicates which properties of the condition have changed, to have caused the server to send the event notification.
///
// ReSharper disable once UnusedMember.Global
public string ChangeMaskAsText
{
get
{
string str = null;
if ((ChangeMask & 0x0001) == 0x0001) str = "Active State, ";
if ((ChangeMask & 0x0002) == 0x0002) str += "Ack State, ";
if ((ChangeMask & 0x0004) == 0x0004) str += "Enable State, ";
if ((ChangeMask & 0x0008) == 0x0005) str += "Quality, ";
if ((ChangeMask & 0x0010) == 0x0010) str += "Severity, ";
if ((ChangeMask & 0x0020) == 0x0020) str += "SubCondition, ";
if ((ChangeMask & 0x0040) == 0x0040) str += "Message, ";
if ((ChangeMask & 0x0080) == 0x0080) str += "Attribute";
return str;
}
}
///
/// A bit mask specifying the new state of the condition.
///
public int NewState { get; set; }
///
/// A bit mask specifying the new state of the condition.
///
// ReSharper disable once UnusedMember.Global
public string NewStateAsText
{
get
{
string str;
if ((NewState & 0x0001) == 0x0001)
{
str = "Active, ";
}
else
{
str = "Inactive, ";
}
if ((NewState & 0x0002) == 0x0002)
{
str += "Acknowledged, ";
}
else
{
str += "UnAcknowledged, ";
}
if ((NewState & 0x0004) == 0x0004)
{
str += "Enabled";
}
else
{
str += "Disabled";
}
return str;
}
}
///
/// The quality associated with the condition state.
///
public TsCDaQuality Quality
{
get => daQuality_;
set => daQuality_ = value;
}
///
/// Whether the related condition requires acknowledgment of this event.
///
public bool AckRequired { get; set; }
///
/// The time that the condition became active (for single-state conditions), or the
/// time of the transition into the current sub-condition (for multi-state conditions).
/// The ApplicationInstance.TimeAsUtc property defines
/// the time format (UTC or local time).
///
public DateTime ActiveTime
{
get => activeTime_;
set => activeTime_ = value;
}
///
/// A server defined cookie associated with the event notification.
///
public int Cookie { get; set; }
///
/// For tracking events, this is the actor id for the event notification.
/// For condition-related events, this is the acknowledgment id passed by the client.
///
public string ActorID { get; set; }
#endregion
#region Public Methods
///
/// Sets the list of attribute values.
///
public void SetAttributes(object[] attributes)
{
if (attributes == null)
{
attributes_ = new AttributeCollection();
}
else
{
attributes_ = new AttributeCollection(attributes);
}
}
#endregion
#region ICloneable Members
///
/// Creates a deep copy of the object.
///
public virtual object Clone()
{
var clone = (TsCAeEventNotification)MemberwiseClone();
clone.attributes_ = (AttributeCollection)attributes_.Clone();
return clone;
}
#endregion
}
}