/* ======================================================================== * Copyright (c) 2005-2025 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.Collections.Immutable; namespace Opc.Ua.Gds.Client { /// /// The set of known server capability identifiers, populated from the /// generated catalog. /// public class ServerCapabilities : IEnumerable { /// /// Initializes a new instance of the class. /// public ServerCapabilities() { ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); var lookup = new Dictionary(StringComparer.Ordinal); foreach (KeyValuePair entry in ServerCapability.All) { var capability = new ServerCapabilityInfo { Id = entry.Key, Description = entry.Value }; builder.Add(capability); lookup[entry.Key] = capability; } m_capabilities = builder.ToImmutable(); m_lookup = lookup; } /// public IEnumerator GetEnumerator() { ImmutableArray capabilities = m_capabilities; for (int i = 0; i < capabilities.Length; i++) { yield return capabilities[i]; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } /// /// Finds the server capability with the specified identifier. /// /// The identifier. /// The server capability, if found. NULL if it does not exist. public ServerCapabilityInfo? Find(string? id) { if (id == null || m_lookup == null) { return null; } return m_lookup.TryGetValue(id, out ServerCapabilityInfo? capability) ? capability : null; } private readonly ImmutableArray m_capabilities; private readonly Dictionary m_lookup; } /// /// A server capability entry (identifier and human-readable description). /// public class ServerCapabilityInfo : IFormattable { /// /// Gets or sets the identifier. /// public string? Id { get; set; } /// /// Gets or sets the description. /// public string? Description { get; set; } /// public override string ToString() { return ToString(null, null); } /// /// Returns a that represents this instance. /// /// The format. Must be null. /// The format provider. /// public string ToString(string? format, IFormatProvider? formatProvider) { if (format != null) { throw new FormatException(Utils.Format("Invalid format string: '{0}'.", format)); } return string.Format(formatProvider, "[{0}] {1}", Id, Description); } } }