/* ========================================================================
* 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.IO;
namespace Opc.Ua.Gds.Client
{
///
/// 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
}
}