本文整理汇总了C#中Opc.Ua.NamespaceTable.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceTable.GetIndex方法的具体用法?C# NamespaceTable.GetIndex怎么用?C# NamespaceTable.GetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opc.Ua.NamespaceTable
的用法示例。
在下文中一共展示了NamespaceTable.GetIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNamespaceTable
/// <summary>
/// Returns a namespace table with all of the URIs defined.
/// </summary>
/// <remarks>
/// This table is was used to create any relative paths in the model design.
/// </remarks>
public static NamespaceTable GetNamespaceTable()
{
FieldInfo[] fields = typeof(Namespaces).GetFields(BindingFlags.Public | BindingFlags.Static);
NamespaceTable namespaceTable = new NamespaceTable();
foreach (FieldInfo field in fields)
{
string namespaceUri = (string)field.GetValue(typeof(Namespaces));
if (namespaceTable.GetIndex(namespaceUri) == -1)
{
namespaceTable.Append(namespaceUri);
}
}
return namespaceTable;
}
示例2: UpdateNamespaceTable
/// <summary>
/// Updates the namespace table with URI used in the relative path.
/// </summary>
/// <param name="currentTable">The current table.</param>
/// <param name="targetTable">The target table.</param>
public void UpdateNamespaceTable(NamespaceTable currentTable, NamespaceTable targetTable)
{
// build mapping table.
int[] mappings = new int[currentTable.Count];
mappings[0] = 0;
if (mappings.Length > 0)
{
mappings[1] = 1;
}
// ensure a placeholder for the local namespace.
if (targetTable.Count <= 1)
{
targetTable.Append("---");
}
string[] uris = new string[mappings.Length];
for (int ii = 2; ii < mappings.Length; ii++)
{
uris[ii] = currentTable.GetString((uint)ii);
if (uris[ii] != null)
{
mappings[ii] = targetTable.GetIndex(uris[ii]);
}
}
// update each element.
foreach (Element element in m_elements)
{
// check reference type name.
QualifiedName qname = element.ReferenceTypeName;
if (qname != null && qname.NamespaceIndex > 1)
{
if (qname.NamespaceIndex < mappings.Length)
{
if (mappings[qname.NamespaceIndex] == -1)
{
mappings[qname.NamespaceIndex] = targetTable.GetIndexOrAppend(uris[qname.NamespaceIndex]);
}
}
}
// check target name.
qname = element.TargetName;
if (qname != null && qname.NamespaceIndex > 1)
{
if (qname.NamespaceIndex < mappings.Length)
{
if (mappings[qname.NamespaceIndex] == -1)
{
mappings[qname.NamespaceIndex] = targetTable.GetIndexOrAppend(uris[qname.NamespaceIndex]);
}
}
}
}
}
示例3: TranslateNamespaceIndexes
/// <summary>
/// Updates the path to use the indexes from the target table.
/// </summary>
/// <param name="currentTable">The NamespaceTable which the RelativePathString currently references</param>
/// <param name="targetTable">The NamespaceTable which the RelativePathString should reference</param>
public void TranslateNamespaceIndexes(NamespaceTable currentTable, NamespaceTable targetTable)
{
// build mapping table.
int[] mappings = new int[currentTable.Count];
mappings[0] = 0;
// copy mappings.
string[] uris = new string[mappings.Length];
for (int ii = 1; ii < mappings.Length; ii++)
{
uris[ii] = currentTable.GetString((uint)ii);
if (uris[ii] != null)
{
mappings[ii] = targetTable.GetIndex(uris[ii]);
}
}
// update each element.
foreach (Element element in m_elements)
{
QualifiedName qname = element.ReferenceTypeName;
if (qname != null && qname.NamespaceIndex > 0)
{
if (qname.NamespaceIndex < mappings.Length && mappings[qname.NamespaceIndex] > 0)
{
element.ReferenceTypeName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
}
qname = element.TargetName;
if (qname != null && qname.NamespaceIndex > 0)
{
if (qname.NamespaceIndex < mappings.Length && mappings[qname.NamespaceIndex] > 0)
{
element.TargetName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
}
}
}
示例4: Create
/// <summary>
/// Converts an expanded node id to a node id using a namespace table.
/// </summary>
public static QualifiedName Create(string name, string namespaceUri, NamespaceTable namespaceTable)
{
// check for null.
if (String.IsNullOrEmpty(name))
{
return QualifiedName.Null;
}
// return a name using the default namespace.
if (String.IsNullOrEmpty(namespaceUri))
{
return new QualifiedName(name);
}
// find the namespace index.
int namespaceIndex = -1;
if (namespaceTable != null)
{
namespaceIndex = namespaceTable.GetIndex(namespaceUri);
}
// oops - not found.
if (namespaceIndex < 0)
{
throw new ApplicationException(String.Format("NamespaceUri ({0}) is not in the NamespaceTable.", namespaceUri));
}
// return the name.
return new QualifiedName(name, (ushort)namespaceIndex);
}