private static Dictionary <NodeID, StructureDescription> ParseStructureDescriptions(Stream inputStream) { if (inputStream == null || !inputStream.CanRead) { return(null); } int?length = BaseType.ReadInt32(inputStream); if (!length.HasValue) { return(null); } // check whether StructureDescriptions exist if (length.Value < 0) { // no StructureDescriptions return(null); } Dictionary <NodeID, StructureDescription> dictionary = new Dictionary <NodeID, StructureDescription>(length.Value); for (int i = 0; i < length.Value; i++) { StructureDescription desc = StructureDescription.Decode(inputStream); dictionary[desc.DataTypeId] = desc; } return(dictionary); }
private void EncodeDataTypeSchemaHeaderStructure(Stream outputStream) { // Namespaces int nameSpaceLength = -1; if (Namespaces != null) { nameSpaceLength = Namespaces.Count; } BaseType.WriteToStream(outputStream, BitConverter.GetBytes(nameSpaceLength)); for (int i = 0; i < nameSpaceLength; i++) { String nameSpace = Namespaces[i] ?? new String(); nameSpace.Encode(outputStream); } // Structures int structureLength = -1; if (StructureDataTypes != null) { structureLength = StructureDataTypes.Count; } BaseType.WriteToStream(outputStream, BitConverter.GetBytes(structureLength)); if (StructureDataTypes != null) { List <StructureDescription> structureDescriptions = StructureDataTypes.Values.ToList(); for (int i = 0; i < structureLength; i++) { StructureDescription desc = structureDescriptions[i] ?? new StructureDescription(); desc.Encode(outputStream); } } // Enums int enumLength = -1; if (EnumDataTypes != null) { enumLength = EnumDataTypes.Count; } BaseType.WriteToStream(outputStream, BitConverter.GetBytes(enumLength)); if (EnumDataTypes != null) { List <EnumDescription> enumDescriptions = EnumDataTypes.Values.ToList(); for (int i = 0; i < enumLength; i++) { EnumDescription desc = enumDescriptions[i] ?? new EnumDescription(); desc.Encode(outputStream); } } // Simple Data Types int simpleTypesArraySize = -1; BaseType.WriteToStream(outputStream, BitConverter.GetBytes(simpleTypesArraySize)); }
private string GetValueFromDataPointValue(DataPointValue dpv) { string text = string.Empty; if (dpv is File file) { return($"NAME [{file.Path}] [{file.Content.Length}]"); } if (dpv is ProcessDataPointValue pdpv) { if (dpv.EnumDescription != null) { StructureDescription desc = null; //DataPointsManager.GetEnumStructureDescription(dpv.EnumDescription.Name.Name.Value); if (desc != null) { string enumName = desc.Name.Name.Value.Substring(10); foreach (EnumField enumField in dpv.EnumDescription.Fields) { if (enumField.Value == (int)pdpv.Value) { text = string.Concat(enumField.Name.Value, " [ ", enumField.Value, " ]"); break; } } } } else { text = string.Concat(text, "[ ", pdpv.Value, " ]"); if (pdpv is CounterValue) { text = string.Concat(text, "-[ ", pdpv.GetAttributeValue(CounterValue.QuantityAttributeName) .ToString(), " ]" ); } if (dpv is StepPosValue || dpv is StepPosEvent) { text = string.Concat(text, "-[ ", pdpv.GetAttributeValue(StepPosValue.TransientAttributeName) .ToString(), " ]" ); } if (pdpv is ComplexMeasuredValue) { text = string.Concat(text, "-[ ", pdpv.GetAttributeValue(ComplexMeasuredValue.AngleAttributeName) .ToString(), " ]" ); } } } if (string.IsNullOrEmpty(text)) { text = "Could not parse value"; } return(text); }