mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 07:07:24 +08:00
Merge pull request #1279 from OPCFoundation/modelcompiler-fixes
Merge model compiler fixes with latest code.
This commit is contained in:
@@ -295,6 +295,7 @@ namespace Opc.Ua.Export
|
||||
exportedNode.Description = new LocalizedText[0];
|
||||
}
|
||||
|
||||
exportedNode.Documentation = node.NodeSetDocumentation;
|
||||
exportedNode.Category = (node.Categories != null && node.Categories.Count > 0) ? new List<string>(node.Categories).ToArray() : null;
|
||||
exportedNode.ReleaseStatus = node.ReleaseStatus;
|
||||
exportedNode.WriteMask = (uint)node.WriteMask;
|
||||
@@ -624,6 +625,7 @@ namespace Opc.Ua.Export
|
||||
}
|
||||
|
||||
importedNode.Description = Import(node.Description);
|
||||
importedNode.NodeSetDocumentation = node.Documentation;
|
||||
importedNode.Categories = (node.Category != null && node.Category.Length > 0) ? node.Category : null;
|
||||
importedNode.ReleaseStatus = node.ReleaseStatus;
|
||||
importedNode.WriteMask = (AttributeWriteMask)node.WriteMask;
|
||||
@@ -909,8 +911,10 @@ namespace Opc.Ua.Export
|
||||
{
|
||||
List<Opc.Ua.Export.DataTypeField> fields = new List<DataTypeField>();
|
||||
|
||||
foreach (StructureField field in structureDefinition.Fields)
|
||||
for (int ii = structureDefinition.FirstExplicitFieldIndex; ii < structureDefinition.Fields.Count; ii++)
|
||||
{
|
||||
StructureField field = structureDefinition.Fields[ii];
|
||||
|
||||
Opc.Ua.Export.DataTypeField output = new Opc.Ua.Export.DataTypeField();
|
||||
|
||||
output.Name = field.Name;
|
||||
@@ -948,7 +952,16 @@ namespace Opc.Ua.Export
|
||||
Opc.Ua.Export.DataTypeField output = new Opc.Ua.Export.DataTypeField();
|
||||
|
||||
output.Name = field.Name;
|
||||
output.DisplayName = Export(new Opc.Ua.LocalizedText[] { field.Name });
|
||||
|
||||
if (field.DisplayName != null && output.Name != field.DisplayName.Text)
|
||||
{
|
||||
output.DisplayName = Export(new Opc.Ua.LocalizedText[] { field.DisplayName });
|
||||
}
|
||||
else
|
||||
{
|
||||
output.DisplayName = new LocalizedText[0];
|
||||
}
|
||||
|
||||
output.Description = Export(new Opc.Ua.LocalizedText[] { field.Description });
|
||||
output.ValueRank = ValueRanks.Scalar;
|
||||
output.Value = (int)field.Value;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Opc.Ua
|
||||
{
|
||||
public partial class NodeState
|
||||
{
|
||||
/// <summary>
|
||||
/// The specification that defines the node.
|
||||
/// </summary>
|
||||
public string Specification { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The documentation for the node that is saved in the NodeSet.
|
||||
/// </summary>
|
||||
public string NodeSetDocumentation { get; set; }
|
||||
}
|
||||
|
||||
public partial class StructureDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// The first non-inherited field in the structure definition.
|
||||
/// </summary>
|
||||
public int FirstExplicitFieldIndex { get; set; }
|
||||
}
|
||||
|
||||
public partial class NodeStateCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes the collection to a stream using the Opc.Ua.Schema.UANodeSet schema.
|
||||
/// </summary>
|
||||
public void SaveAsNodeSet2(
|
||||
ISystemContext context,
|
||||
Stream ostrm,
|
||||
Export.ModelTableEntry model,
|
||||
DateTime lastModified,
|
||||
bool outputRedundantNames)
|
||||
{
|
||||
Opc.Ua.Export.UANodeSet nodeSet = new Opc.Ua.Export.UANodeSet();
|
||||
|
||||
if (lastModified != DateTime.MinValue)
|
||||
{
|
||||
nodeSet.LastModified = lastModified;
|
||||
nodeSet.LastModifiedSpecified = true;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
nodeSet.Models = new Export.ModelTableEntry[] { model };
|
||||
}
|
||||
|
||||
for (int ii = 0; ii < s_AliasesToUse.Length; ii++)
|
||||
{
|
||||
nodeSet.AddAlias(context, s_AliasesToUse[ii].Alias, s_AliasesToUse[ii].NodeId);
|
||||
}
|
||||
|
||||
for (int ii = 0; ii < this.Count; ii++)
|
||||
{
|
||||
nodeSet.Export(context, this[ii], outputRedundantNames);
|
||||
}
|
||||
|
||||
nodeSet.Write(ostrm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace Opc.Ua
|
||||
/// <summary>
|
||||
/// The base class for custom nodes.
|
||||
/// </summary>
|
||||
public abstract class NodeState : IDisposable, IFormattable
|
||||
public abstract partial class NodeState : IDisposable, IFormattable
|
||||
{
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Opc.Ua
|
||||
/// <summary>
|
||||
/// Stores a collection of nodes.
|
||||
/// </summary>
|
||||
public class NodeStateCollection : List<NodeState>
|
||||
public partial class NodeStateCollection : List<NodeState>
|
||||
{
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Opc.Ua
|
||||
private StreamWriter m_writer;
|
||||
private Stack<string> m_namespaces;
|
||||
private bool m_commaRequired;
|
||||
private bool m_inVariantWithEncoding;
|
||||
private ServiceMessageContext m_context;
|
||||
private ushort[] m_namespaceMappings;
|
||||
private ushort[] m_serverMappings;
|
||||
@@ -228,14 +229,14 @@ namespace Opc.Ua
|
||||
{
|
||||
if (!m_dontWriteClosing)
|
||||
{
|
||||
if (m_topLevelIsArray)
|
||||
{
|
||||
m_writer.Write("]");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_writer.Write("}");
|
||||
}
|
||||
if (m_topLevelIsArray)
|
||||
{
|
||||
m_writer.Write("]");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_writer.Write("}");
|
||||
}
|
||||
}
|
||||
|
||||
m_writer.Flush();
|
||||
@@ -1296,6 +1297,7 @@ namespace Opc.Ua
|
||||
m_context.MaxEncodingNestingLevels);
|
||||
}
|
||||
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
@@ -1376,7 +1378,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteBooleanArray(string fieldName, IList<bool> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1403,7 +1405,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteSByteArray(string fieldName, IList<sbyte> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1430,7 +1432,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteByteArray(string fieldName, IList<byte> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1457,7 +1459,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt16Array(string fieldName, IList<short> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1484,7 +1486,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt16Array(string fieldName, IList<ushort> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1511,7 +1513,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt32Array(string fieldName, IList<int> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1538,7 +1540,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt32Array(string fieldName, IList<uint> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1565,7 +1567,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt64Array(string fieldName, IList<long> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1592,7 +1594,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt64Array(string fieldName, IList<ulong> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1619,7 +1621,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteFloatArray(string fieldName, IList<float> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1646,7 +1648,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDoubleArray(string fieldName, IList<double> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1673,7 +1675,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteStringArray(string fieldName, IList<string> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1700,7 +1702,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDateTimeArray(string fieldName, IList<DateTime> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1734,7 +1736,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteGuidArray(string fieldName, IList<Uuid> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1761,7 +1763,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteGuidArray(string fieldName, IList<Guid> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1788,7 +1790,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteByteStringArray(string fieldName, IList<byte[]> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1815,7 +1817,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteXmlElementArray(string fieldName, IList<XmlElement> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1842,7 +1844,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteNodeIdArray(string fieldName, IList<NodeId> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1869,7 +1871,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteExpandedNodeIdArray(string fieldName, IList<ExpandedNodeId> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1896,7 +1898,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteStatusCodeArray(string fieldName, IList<StatusCode> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1931,7 +1933,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDiagnosticInfoArray(string fieldName, IList<DiagnosticInfo> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1958,7 +1960,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteQualifiedNameArray(string fieldName, IList<QualifiedName> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -1985,7 +1987,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteLocalizedTextArray(string fieldName, IList<LocalizedText> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2012,7 +2014,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteVariantArray(string fieldName, IList<Variant> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2045,7 +2047,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDataValueArray(string fieldName, IList<DataValue> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2072,7 +2074,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteExtensionObjectArray(string fieldName, IList<ExtensionObject> values)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2099,7 +2101,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteEncodeableArray(string fieldName, IList<IEncodeable> values, System.Type systemType)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2136,18 +2138,18 @@ namespace Opc.Ua
|
||||
{
|
||||
PushArray(fieldName);
|
||||
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
{
|
||||
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
|
||||
}
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
{
|
||||
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
|
||||
}
|
||||
|
||||
for (int ii = 0; ii < values.Count; ii++)
|
||||
{
|
||||
WriteEncodeable(null, values[ii], systemType);
|
||||
}
|
||||
for (int ii = 0; ii < values.Count; ii++)
|
||||
{
|
||||
WriteEncodeable(null, values[ii], systemType);
|
||||
}
|
||||
|
||||
PopArray();
|
||||
PopArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2156,7 +2158,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteEnumeratedArray(string fieldName, Array values, System.Type systemType)
|
||||
{
|
||||
if (values == null)
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
@@ -2203,130 +2205,139 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteVariantContents(object value, TypeInfo typeInfo)
|
||||
{
|
||||
// check for null.
|
||||
if (value == null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_inVariantWithEncoding = UseReversibleEncoding;
|
||||
|
||||
m_commaRequired = false;
|
||||
|
||||
// write scalar.
|
||||
if (typeInfo.ValueRank < 0)
|
||||
{
|
||||
switch (typeInfo.BuiltInType)
|
||||
// check for null.
|
||||
if (value == null)
|
||||
{
|
||||
case BuiltInType.Boolean: { WriteBoolean(null, (bool)value); return; }
|
||||
case BuiltInType.SByte: { WriteSByte(null, (sbyte)value); return; }
|
||||
case BuiltInType.Byte: { WriteByte(null, (byte)value); return; }
|
||||
case BuiltInType.Int16: { WriteInt16(null, (short)value); return; }
|
||||
case BuiltInType.UInt16: { WriteUInt16(null, (ushort)value); return; }
|
||||
case BuiltInType.Int32: { WriteInt32(null, (int)value); return; }
|
||||
case BuiltInType.UInt32: { WriteUInt32(null, (uint)value); return; }
|
||||
case BuiltInType.Int64: { WriteInt64(null, (long)value); return; }
|
||||
case BuiltInType.UInt64: { WriteUInt64(null, (ulong)value); return; }
|
||||
case BuiltInType.Float: { WriteFloat(null, (float)value); return; }
|
||||
case BuiltInType.Double: { WriteDouble(null, (double)value); return; }
|
||||
case BuiltInType.String: { WriteString(null, (string)value); return; }
|
||||
case BuiltInType.DateTime: { WriteDateTime(null, (DateTime)value); return; }
|
||||
case BuiltInType.Guid: { WriteGuid(null, (Uuid)value); return; }
|
||||
case BuiltInType.ByteString: { WriteByteString(null, (byte[])value); return; }
|
||||
case BuiltInType.XmlElement: { WriteXmlElement(null, (XmlElement)value); return; }
|
||||
case BuiltInType.NodeId: { WriteNodeId(null, (NodeId)value); return; }
|
||||
case BuiltInType.ExpandedNodeId: { WriteExpandedNodeId(null, (ExpandedNodeId)value); return; }
|
||||
case BuiltInType.StatusCode: { WriteStatusCode(null, (StatusCode)value); return; }
|
||||
case BuiltInType.QualifiedName: { WriteQualifiedName(null, (QualifiedName)value); return; }
|
||||
case BuiltInType.LocalizedText: { WriteLocalizedText(null, (LocalizedText)value); return; }
|
||||
case BuiltInType.ExtensionObject: { WriteExtensionObject(null, (ExtensionObject)value); return; }
|
||||
case BuiltInType.DataValue: { WriteDataValue(null, (DataValue)value); return; }
|
||||
case BuiltInType.Enumeration: { WriteEnumerated(null, (Enum)value); return; }
|
||||
}
|
||||
}
|
||||
|
||||
// write array.
|
||||
else if (typeInfo.ValueRank <= 1)
|
||||
{
|
||||
switch (typeInfo.BuiltInType)
|
||||
{
|
||||
case BuiltInType.Boolean: { WriteBooleanArray(null, (bool[])value); return; }
|
||||
case BuiltInType.SByte: { WriteSByteArray(null, (sbyte[])value); return; }
|
||||
case BuiltInType.Byte: { WriteByteArray(null, (byte[])value); return; }
|
||||
case BuiltInType.Int16: { WriteInt16Array(null, (short[])value); return; }
|
||||
case BuiltInType.UInt16: { WriteUInt16Array(null, (ushort[])value); return; }
|
||||
case BuiltInType.Int32: { WriteInt32Array(null, (int[])value); return; }
|
||||
case BuiltInType.UInt32: { WriteUInt32Array(null, (uint[])value); return; }
|
||||
case BuiltInType.Int64: { WriteInt64Array(null, (long[])value); return; }
|
||||
case BuiltInType.UInt64: { WriteUInt64Array(null, (ulong[])value); return; }
|
||||
case BuiltInType.Float: { WriteFloatArray(null, (float[])value); return; }
|
||||
case BuiltInType.Double: { WriteDoubleArray(null, (double[])value); return; }
|
||||
case BuiltInType.String: { WriteStringArray(null, (string[])value); return; }
|
||||
case BuiltInType.DateTime: { WriteDateTimeArray(null, (DateTime[])value); return; }
|
||||
case BuiltInType.Guid: { WriteGuidArray(null, (Uuid[])value); return; }
|
||||
case BuiltInType.ByteString: { WriteByteStringArray(null, (byte[][])value); return; }
|
||||
case BuiltInType.XmlElement: { WriteXmlElementArray(null, (XmlElement[])value); return; }
|
||||
case BuiltInType.NodeId: { WriteNodeIdArray(null, (NodeId[])value); return; }
|
||||
case BuiltInType.ExpandedNodeId: { WriteExpandedNodeIdArray(null, (ExpandedNodeId[])value); return; }
|
||||
case BuiltInType.StatusCode: { WriteStatusCodeArray(null, (StatusCode[])value); return; }
|
||||
case BuiltInType.QualifiedName: { WriteQualifiedNameArray(null, (QualifiedName[])value); return; }
|
||||
case BuiltInType.LocalizedText: { WriteLocalizedTextArray(null, (LocalizedText[])value); return; }
|
||||
case BuiltInType.ExtensionObject: { WriteExtensionObjectArray(null, (ExtensionObject[])value); return; }
|
||||
case BuiltInType.DataValue: { WriteDataValueArray(null, (DataValue[])value); return; }
|
||||
case BuiltInType.Enumeration:
|
||||
{
|
||||
Array array = value as Array;
|
||||
WriteEnumeratedArray(null, array, array.GetType().GetElementType());
|
||||
return;
|
||||
}
|
||||
|
||||
case BuiltInType.Variant:
|
||||
{
|
||||
Variant[] variants = value as Variant[];
|
||||
|
||||
if (variants != null)
|
||||
{
|
||||
WriteVariantArray(null, variants);
|
||||
return;
|
||||
}
|
||||
|
||||
object[] objects = value as object[];
|
||||
|
||||
if (objects != null)
|
||||
{
|
||||
WriteObjectArray(null, objects);
|
||||
return;
|
||||
}
|
||||
|
||||
throw ServiceResultException.Create(
|
||||
StatusCodes.BadEncodingError,
|
||||
"Unexpected type encountered while encoding an array of Variants: {0}",
|
||||
value.GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write matrix.
|
||||
else if (typeInfo.ValueRank > 1)
|
||||
{
|
||||
Matrix matrix = value as Matrix;
|
||||
if (matrix != null)
|
||||
{
|
||||
if (UseReversibleEncoding)
|
||||
{
|
||||
WriteVariantContents(matrix.Elements, new TypeInfo(typeInfo.BuiltInType, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = 0;
|
||||
WriteStructureMatrix(matrix, 0, ref index, typeInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// oops - should never happen.
|
||||
throw new ServiceResultException(
|
||||
StatusCodes.BadEncodingError,
|
||||
Utils.Format("Type '{0}' is not allowed in an Variant.", value.GetType().FullName));
|
||||
m_commaRequired = false;
|
||||
|
||||
// write scalar.
|
||||
if (typeInfo.ValueRank < 0)
|
||||
{
|
||||
switch (typeInfo.BuiltInType)
|
||||
{
|
||||
case BuiltInType.Boolean: { WriteBoolean(null, (bool)value); return; }
|
||||
case BuiltInType.SByte: { WriteSByte(null, (sbyte)value); return; }
|
||||
case BuiltInType.Byte: { WriteByte(null, (byte)value); return; }
|
||||
case BuiltInType.Int16: { WriteInt16(null, (short)value); return; }
|
||||
case BuiltInType.UInt16: { WriteUInt16(null, (ushort)value); return; }
|
||||
case BuiltInType.Int32: { WriteInt32(null, (int)value); return; }
|
||||
case BuiltInType.UInt32: { WriteUInt32(null, (uint)value); return; }
|
||||
case BuiltInType.Int64: { WriteInt64(null, (long)value); return; }
|
||||
case BuiltInType.UInt64: { WriteUInt64(null, (ulong)value); return; }
|
||||
case BuiltInType.Float: { WriteFloat(null, (float)value); return; }
|
||||
case BuiltInType.Double: { WriteDouble(null, (double)value); return; }
|
||||
case BuiltInType.String: { WriteString(null, (string)value); return; }
|
||||
case BuiltInType.DateTime: { WriteDateTime(null, (DateTime)value); return; }
|
||||
case BuiltInType.Guid: { WriteGuid(null, (Uuid)value); return; }
|
||||
case BuiltInType.ByteString: { WriteByteString(null, (byte[])value); return; }
|
||||
case BuiltInType.XmlElement: { WriteXmlElement(null, (XmlElement)value); return; }
|
||||
case BuiltInType.NodeId: { WriteNodeId(null, (NodeId)value); return; }
|
||||
case BuiltInType.ExpandedNodeId: { WriteExpandedNodeId(null, (ExpandedNodeId)value); return; }
|
||||
case BuiltInType.StatusCode: { WriteStatusCode(null, (StatusCode)value); return; }
|
||||
case BuiltInType.QualifiedName: { WriteQualifiedName(null, (QualifiedName)value); return; }
|
||||
case BuiltInType.LocalizedText: { WriteLocalizedText(null, (LocalizedText)value); return; }
|
||||
case BuiltInType.ExtensionObject: { WriteExtensionObject(null, (ExtensionObject)value); return; }
|
||||
case BuiltInType.DataValue: { WriteDataValue(null, (DataValue)value); return; }
|
||||
case BuiltInType.Enumeration: { WriteEnumerated(null, (Enum)value); return; }
|
||||
}
|
||||
}
|
||||
|
||||
// write array.
|
||||
else if (typeInfo.ValueRank <= 1)
|
||||
{
|
||||
switch (typeInfo.BuiltInType)
|
||||
{
|
||||
case BuiltInType.Boolean: { WriteBooleanArray(null, (bool[])value); return; }
|
||||
case BuiltInType.SByte: { WriteSByteArray(null, (sbyte[])value); return; }
|
||||
case BuiltInType.Byte: { WriteByteArray(null, (byte[])value); return; }
|
||||
case BuiltInType.Int16: { WriteInt16Array(null, (short[])value); return; }
|
||||
case BuiltInType.UInt16: { WriteUInt16Array(null, (ushort[])value); return; }
|
||||
case BuiltInType.Int32: { WriteInt32Array(null, (int[])value); return; }
|
||||
case BuiltInType.UInt32: { WriteUInt32Array(null, (uint[])value); return; }
|
||||
case BuiltInType.Int64: { WriteInt64Array(null, (long[])value); return; }
|
||||
case BuiltInType.UInt64: { WriteUInt64Array(null, (ulong[])value); return; }
|
||||
case BuiltInType.Float: { WriteFloatArray(null, (float[])value); return; }
|
||||
case BuiltInType.Double: { WriteDoubleArray(null, (double[])value); return; }
|
||||
case BuiltInType.String: { WriteStringArray(null, (string[])value); return; }
|
||||
case BuiltInType.DateTime: { WriteDateTimeArray(null, (DateTime[])value); return; }
|
||||
case BuiltInType.Guid: { WriteGuidArray(null, (Uuid[])value); return; }
|
||||
case BuiltInType.ByteString: { WriteByteStringArray(null, (byte[][])value); return; }
|
||||
case BuiltInType.XmlElement: { WriteXmlElementArray(null, (XmlElement[])value); return; }
|
||||
case BuiltInType.NodeId: { WriteNodeIdArray(null, (NodeId[])value); return; }
|
||||
case BuiltInType.ExpandedNodeId: { WriteExpandedNodeIdArray(null, (ExpandedNodeId[])value); return; }
|
||||
case BuiltInType.StatusCode: { WriteStatusCodeArray(null, (StatusCode[])value); return; }
|
||||
case BuiltInType.QualifiedName: { WriteQualifiedNameArray(null, (QualifiedName[])value); return; }
|
||||
case BuiltInType.LocalizedText: { WriteLocalizedTextArray(null, (LocalizedText[])value); return; }
|
||||
case BuiltInType.ExtensionObject: { WriteExtensionObjectArray(null, (ExtensionObject[])value); return; }
|
||||
case BuiltInType.DataValue: { WriteDataValueArray(null, (DataValue[])value); return; }
|
||||
case BuiltInType.Enumeration:
|
||||
{
|
||||
Array array = value as Array;
|
||||
WriteEnumeratedArray(null, array, array.GetType().GetElementType());
|
||||
return;
|
||||
}
|
||||
|
||||
case BuiltInType.Variant:
|
||||
{
|
||||
Variant[] variants = value as Variant[];
|
||||
|
||||
if (variants != null)
|
||||
{
|
||||
WriteVariantArray(null, variants);
|
||||
return;
|
||||
}
|
||||
|
||||
object[] objects = value as object[];
|
||||
|
||||
if (objects != null)
|
||||
{
|
||||
WriteObjectArray(null, objects);
|
||||
return;
|
||||
}
|
||||
|
||||
throw ServiceResultException.Create(
|
||||
StatusCodes.BadEncodingError,
|
||||
"Unexpected type encountered while encoding an array of Variants: {0}",
|
||||
value.GetType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write matrix.
|
||||
else if (typeInfo.ValueRank > 1)
|
||||
{
|
||||
Matrix matrix = value as Matrix;
|
||||
if (matrix != null)
|
||||
{
|
||||
if (UseReversibleEncoding)
|
||||
{
|
||||
WriteVariantContents(matrix.Elements, new TypeInfo(typeInfo.BuiltInType, 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = 0;
|
||||
WriteStructureMatrix(matrix, 0, ref index, typeInfo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// oops - should never happen.
|
||||
throw new ServiceResultException(
|
||||
StatusCodes.BadEncodingError,
|
||||
Utils.Format("Type '{0}' is not allowed in an Variant.", value.GetType().FullName));
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_inVariantWithEncoding = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -2382,6 +2393,12 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteObjectArray(string fieldName, IList<object> values)
|
||||
{
|
||||
if (values == null || (values.Count == 0 && !m_inVariantWithEncoding))
|
||||
{
|
||||
WriteSimpleField(fieldName, null, false);
|
||||
return;
|
||||
}
|
||||
|
||||
PushArray(fieldName);
|
||||
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
|
||||
@@ -1403,9 +1403,16 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public ExtensionObject ReadExtensionObject(string fieldName)
|
||||
{
|
||||
if (!BeginField(fieldName, true))
|
||||
bool isNil;
|
||||
|
||||
if (!BeginField(fieldName, true, out isNil))
|
||||
{
|
||||
return null;
|
||||
if (isNil)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ExtensionObject.Null;
|
||||
}
|
||||
|
||||
PushNamespace(Namespaces.OpcUaXsd);
|
||||
|
||||
@@ -39,6 +39,8 @@ namespace Opc.Ua
|
||||
XmlWriterSettings settings = new XmlWriterSettings();
|
||||
settings.CheckCharacters = false;
|
||||
settings.ConformanceLevel = ConformanceLevel.Auto;
|
||||
settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
|
||||
settings.NewLineHandling = NewLineHandling.Replace;
|
||||
|
||||
m_writer = XmlWriter.Create(m_destination, settings);
|
||||
}
|
||||
@@ -435,7 +437,12 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteString(string fieldName, string value)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true))
|
||||
WriteString(fieldName, value, false);
|
||||
}
|
||||
|
||||
private void WriteString(string fieldName, string value, bool isArrayElement)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true, isArrayElement))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxStringLength > 0 && m_context.MaxStringLength < value.Length)
|
||||
@@ -443,7 +450,11 @@ namespace Opc.Ua
|
||||
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
|
||||
}
|
||||
|
||||
m_writer.WriteString(value);
|
||||
if (!String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
m_writer.WriteString(value);
|
||||
}
|
||||
|
||||
EndField(fieldName);
|
||||
}
|
||||
}
|
||||
@@ -496,7 +507,12 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteByteString(string fieldName, byte[] value)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true))
|
||||
WriteByteString(fieldName, value, false);
|
||||
}
|
||||
|
||||
private void WriteByteString(string fieldName, byte[] value, bool isArrayElement = false)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true, isArrayElement))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxByteStringLength > 0 && m_context.MaxByteStringLength < value.Length)
|
||||
@@ -504,7 +520,7 @@ namespace Opc.Ua
|
||||
throw new ServiceResultException(StatusCodes.BadEncodingLimitsExceeded);
|
||||
}
|
||||
|
||||
m_writer.WriteValue(Convert.ToBase64String(value));
|
||||
m_writer.WriteValue(Convert.ToBase64String(value, Base64FormattingOptions.InsertLineBreaks));
|
||||
EndField(fieldName);
|
||||
}
|
||||
}
|
||||
@@ -514,7 +530,12 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteXmlElement(string fieldName, XmlElement value)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true))
|
||||
WriteXmlElement(fieldName, value, false);
|
||||
}
|
||||
|
||||
private void WriteXmlElement(string fieldName, XmlElement value, bool isArrayElement)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true, isArrayElement))
|
||||
{
|
||||
m_writer.WriteRaw(value.OuterXml);
|
||||
EndField(fieldName);
|
||||
@@ -684,8 +705,15 @@ namespace Opc.Ua
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
WriteString("Locale", value.Locale);
|
||||
WriteString("Text", value.Text);
|
||||
if (!String.IsNullOrEmpty(value.Locale))
|
||||
{
|
||||
WriteString("Locale", value.Locale);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(value.Text))
|
||||
{
|
||||
WriteString("Text", value.Text);
|
||||
}
|
||||
}
|
||||
|
||||
PopNamespace();
|
||||
@@ -884,7 +912,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteBooleanArray(string fieldName, IList<bool> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -913,7 +941,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteSByteArray(string fieldName, IList<sbyte> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -942,7 +970,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteByteArray(string fieldName, IList<byte> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -971,7 +999,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt16Array(string fieldName, IList<short> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1000,7 +1028,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt16Array(string fieldName, IList<ushort> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1029,7 +1057,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt32Array(string fieldName, IList<int> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1058,7 +1086,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt32Array(string fieldName, IList<uint> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1087,7 +1115,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteInt64Array(string fieldName, IList<long> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1116,7 +1144,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteUInt64Array(string fieldName, IList<ulong> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1145,7 +1173,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteFloatArray(string fieldName, IList<float> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1174,7 +1202,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDoubleArray(string fieldName, IList<double> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1203,7 +1231,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteStringArray(string fieldName, IList<string> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1217,7 +1245,7 @@ namespace Opc.Ua
|
||||
{
|
||||
for (int ii = 0; ii < values.Count; ii++)
|
||||
{
|
||||
WriteString("String", values[ii]);
|
||||
WriteString("String", values[ii], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1232,7 +1260,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDateTimeArray(string fieldName, IList<DateTime> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1261,7 +1289,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteGuidArray(string fieldName, IList<Uuid> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1290,7 +1318,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteGuidArray(string fieldName, IList<Guid> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1319,7 +1347,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteByteStringArray(string fieldName, IList<byte[]> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1333,7 +1361,7 @@ namespace Opc.Ua
|
||||
{
|
||||
for (int ii = 0; ii < values.Count; ii++)
|
||||
{
|
||||
WriteByteString("ByteString", values[ii]);
|
||||
WriteByteString("ByteString", values[ii], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1348,7 +1376,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteXmlElementArray(string fieldName, IList<XmlElement> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1362,7 +1390,7 @@ namespace Opc.Ua
|
||||
{
|
||||
for (int ii = 0; ii < values.Count; ii++)
|
||||
{
|
||||
WriteXmlElement("XmlElement", values[ii]);
|
||||
WriteXmlElement("XmlElement", values[ii], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1377,7 +1405,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteNodeIdArray(string fieldName, IList<NodeId> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1406,7 +1434,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteExpandedNodeIdArray(string fieldName, IList<ExpandedNodeId> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1435,7 +1463,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteStatusCodeArray(string fieldName, IList<StatusCode> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1464,7 +1492,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDiagnosticInfoArray(string fieldName, IList<DiagnosticInfo> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1493,7 +1521,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteQualifiedNameArray(string fieldName, IList<QualifiedName> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1522,7 +1550,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteLocalizedTextArray(string fieldName, IList<LocalizedText> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1551,7 +1579,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteVariantArray(string fieldName, IList<Variant> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1580,7 +1608,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteDataValueArray(string fieldName, IList<DataValue> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1609,7 +1637,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteExtensionObjectArray(string fieldName, IList<ExtensionObject> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1638,7 +1666,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteEncodeableArray(string fieldName, IList<IEncodeable> values, System.Type systemType)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1685,7 +1713,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteEnumeratedArray(string fieldName, Array values, System.Type systemType)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Length)
|
||||
@@ -1817,6 +1845,7 @@ namespace Opc.Ua
|
||||
ints[ii] = (int)(object)enums[ii];
|
||||
}
|
||||
}
|
||||
|
||||
WriteInt32Array("ListOfInt32", ints);
|
||||
return;
|
||||
}
|
||||
@@ -1882,7 +1911,7 @@ namespace Opc.Ua
|
||||
if (bytes != null)
|
||||
{
|
||||
m_writer.WriteStartElement("ByteString", Namespaces.OpcUaXsd);
|
||||
m_writer.WriteString(Convert.ToBase64String(bytes));
|
||||
m_writer.WriteString(Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks));
|
||||
m_writer.WriteEndElement();
|
||||
return;
|
||||
}
|
||||
@@ -1921,7 +1950,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
private void WriteMatrix(string fieldName, Matrix value)
|
||||
{
|
||||
if (BeginField(fieldName, value == null, true))
|
||||
if (BeginField(fieldName, value == null, true, true))
|
||||
{
|
||||
PushNamespace(Namespaces.OpcUaXsd);
|
||||
|
||||
@@ -1945,7 +1974,7 @@ namespace Opc.Ua
|
||||
/// </summary>
|
||||
public void WriteObjectArray(string fieldName, IList<object> values)
|
||||
{
|
||||
if (BeginField(fieldName, values == null, true))
|
||||
if (BeginField(fieldName, values == null, true, true))
|
||||
{
|
||||
// check the length.
|
||||
if (m_context.MaxArrayLength > 0 && m_context.MaxArrayLength < values.Count)
|
||||
@@ -1972,11 +2001,16 @@ namespace Opc.Ua
|
||||
/// <summary>
|
||||
/// Writes the start element for a field.
|
||||
/// </summary>
|
||||
private bool BeginField(string fieldName, bool isDefault, bool isNillable)
|
||||
private bool BeginField(string fieldName, bool isDefault, bool isNillable, bool isArrayElement = false)
|
||||
{
|
||||
// specifying a null field name means the start/end tags should not be written.
|
||||
if (!String.IsNullOrEmpty(fieldName))
|
||||
{
|
||||
if (isNillable && isDefault && !isArrayElement)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_writer.WriteStartElement(fieldName, m_namespaces.Peek());
|
||||
|
||||
if (isDefault)
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Opc.Ua.Schema
|
||||
/// <summary>
|
||||
/// Loads the dictionary from a file.
|
||||
/// </summary>
|
||||
protected object Load(System.Type type, string namespaceUri, string path)
|
||||
protected object Load(System.Type type, string namespaceUri, string path, Assembly assembly = null)
|
||||
{
|
||||
// check if already loaded.
|
||||
if (m_loadedFiles.ContainsKey(namespaceUri))
|
||||
@@ -178,7 +178,7 @@ namespace Opc.Ua.Schema
|
||||
}
|
||||
|
||||
// load embedded resource.
|
||||
return LoadResource(type, location, null);
|
||||
return LoadResource(type, location, assembly);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(path))
|
||||
@@ -186,7 +186,7 @@ namespace Opc.Ua.Schema
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
// load embedded resource.
|
||||
return LoadResource(type, path, null);
|
||||
return LoadResource(type, path, assembly);
|
||||
}
|
||||
|
||||
// check for file in the same directory as the input file.
|
||||
|
||||
@@ -209,11 +209,14 @@ namespace Opc.Ua.Core.Tests.Types.Encoders
|
||||
Encode(encoder, builtInType, builtInType.ToString(), expected);
|
||||
Dispose(encoder);
|
||||
var buffer = encoderStream.ToArray();
|
||||
string jsonFormatted;
|
||||
string formatted;
|
||||
switch (encoderType)
|
||||
{
|
||||
case EncodingType.Json:
|
||||
jsonFormatted = PrettifyAndValidateJson(Encoding.UTF8.GetString(buffer));
|
||||
formatted = PrettifyAndValidateJson(Encoding.UTF8.GetString(buffer));
|
||||
break;
|
||||
default:
|
||||
formatted = Encoding.UTF8.GetString(buffer);
|
||||
break;
|
||||
}
|
||||
var decoderStream = new MemoryStream(buffer);
|
||||
|
||||
Reference in New Issue
Block a user