using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Opc.Ua.Gds { /// /// The set known capability identifiers. /// public class ServerCapabilities : IEnumerable { #region Constructors /// /// Initializes a new instance of the class. /// public ServerCapabilities() { Load(); } #endregion #region IEnumerable Members public IEnumerator GetEnumerator() { if (m_capabilities == null) { return new List().GetEnumerator(); } return m_capabilities.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this.GetEnumerator(); } #endregion #region Public Members /// /// Loads the default set of server capability identifiers. /// public void Load() { Load(null); } /// /// Loads the set of server capability identifiers from the stream. /// /// The input stream. public void Load(Stream istrm) { var capabilities = new List(); if (istrm == null) { foreach (var resourceName in typeof(Opc.Ua.ObjectIds).Assembly.GetManifestResourceNames()) { if (resourceName.EndsWith("ServerCapabilities.csv", StringComparison.OrdinalIgnoreCase)) { istrm = typeof(Opc.Ua.ObjectIds).Assembly.GetManifestResourceStream(resourceName); break; } } } if (istrm != null) { using (StreamReader reader = new StreamReader(istrm)) { string line = reader.ReadLine(); while (line != null) { int index = line.IndexOf(','); if (index >= 0) { string id = line.Substring(0, index).Trim(); string description = line.Substring(index + 1).Trim(); capabilities.Add(new ServerCapability() { Id = id, Description = description }); } line = reader.ReadLine(); } } } m_capabilities = capabilities; } /// /// Finds the sever capability with the specified identifier. /// /// The identifier. /// The sever capability, if found. NULL if it does not exist. public ServerCapability Find(string id) { if (id != null) { if (m_capabilities != null) { foreach (var capability in m_capabilities) { if (capability.Id == id) { return capability; } } } } return null; } #endregion #region Private Fields private List m_capabilities; #endregion } /// /// A server capability. /// public class ServerCapability : IFormattable { /// /// Gets or sets the identifier. /// /// /// The identifier. /// public string Id { get; set; } /// /// Gets or sets the description. /// /// /// The description. /// public string Description { get; set; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return ToString(null, null); } /// /// Returns a that represents this instance. /// /// The format. /// The format provider. /// /// A that represents this instance. /// public string ToString(string format, IFormatProvider formatProvider) { return "[" + Id + "] " + Description; } #region Well Known Identifiers /// /// No information is available. /// public const string NoInformation = "NA"; /// /// The server supports live data. /// public const string LiveData = "DA"; /// /// The server supports alarms and conditions /// public const string AlarmsAndConditions = "AC"; /// /// The server supports historical data. /// public const string HistoricalData = "HD"; /// /// The server supports historical events. /// public const string HistoricalEvents = "HE"; /// /// The server is a global discovery server. /// public const string GlobalDiscoveryServer = "GDS"; /// /// The server is a local discovery server. /// public const string LocalDiscoveryServer = "LDS"; /// /// The server supports the data integration (DI) information model. /// public const string DI = "DI"; #endregion } }