Beispiel #1
0
        private void CallMethodButtonClick(object sender, EventArgs e)
        {
            if (_selectedObjectId == null || _selectedMethodId == null)
            {
                return;
            }
            List <object>  arguments       = GetInputArgumentFromUserControl();
            IList <object> outputArguments =
                _applicationInstanceManager.Session.Call(_selectedObjectId, _selectedMethodId, arguments.Count > 0?arguments.ToArray():null);
            ExtensionObject inputExtensionObjects = outputArguments[1] as ExtensionObject;
            BinaryDecoder   binaryDecoder         = new BinaryDecoder(inputExtensionObjects.Body as byte[], _applicationInstanceManager.Session.MessageContext);
            string          name     = binaryDecoder.ReadString("Name");
            double          maxSpeed = binaryDecoder.ReadDouble("MaxSpeed");
            double          minSpeed = binaryDecoder.ReadDouble("MinSpeed");

            SetOutputArgumentValueForUserControl(outputArguments.ToList());
        }
Beispiel #2
0
 public void TestDouble(double expected)
 {
     using (var stream = new MemoryStream())
         using (var encoder = new BinaryEncoder(stream))
             using (var decoder = new BinaryDecoder(stream))
             {
                 encoder.WriteDouble(expected);
                 stream.Seek(0, SeekOrigin.Begin);
                 var actual = decoder.ReadDouble();
                 Assert.AreEqual(expected, actual);
             }
 }
        public void DecodeDouble(double expectedValue, int expectedLength, byte[] value)
        {
            using (var stream = new MemoryStream(value))
                using (var decoder = new BinaryDecoder(stream))
                {
                    var decode = decoder.ReadDouble();
                    Assert.AreEqual(expectedLength, stream.Position, "Decode offset error");
                    Assert.AreEqual(expectedValue, decode);

                    stream.Seek(0, SeekOrigin.Begin);
                    decoder.SkipDouble();
                    Assert.AreEqual(expectedLength, stream.Position, "Skip offset error");
                }
        }
Beispiel #4
0
        /// <summary>
        /// Decode a scalar type
        /// </summary>
        /// <param name="binaryDecoder"></param>
        /// <param name="builtInType"></param>
        /// <returns>The decoded object</returns>
        private object DecodeRawScalar(BinaryDecoder binaryDecoder, byte builtInType)
        {
            switch ((BuiltInType)builtInType)
            {
            case BuiltInType.Boolean:
                return(binaryDecoder.ReadBoolean(null));

            case BuiltInType.SByte:
                return(binaryDecoder.ReadSByte(null));

            case BuiltInType.Byte:
                return(binaryDecoder.ReadByte(null));

            case BuiltInType.Int16:
                return(binaryDecoder.ReadInt16(null));

            case BuiltInType.UInt16:
                return(binaryDecoder.ReadUInt16(null));

            case BuiltInType.Int32:
                return(binaryDecoder.ReadInt32(null));

            case BuiltInType.UInt32:
                return(binaryDecoder.ReadUInt32(null));

            case BuiltInType.Int64:
                return(binaryDecoder.ReadInt64(null));

            case BuiltInType.UInt64:
                return(binaryDecoder.ReadUInt64(null));

            case BuiltInType.Float:
                return(binaryDecoder.ReadFloat(null));

            case BuiltInType.Double:
                return(binaryDecoder.ReadDouble(null));

            case BuiltInType.String:
                return(binaryDecoder.ReadString(null));

            case BuiltInType.DateTime:
                return(binaryDecoder.ReadDateTime(null));

            case BuiltInType.Guid:
                return(binaryDecoder.ReadGuid(null));

            case BuiltInType.ByteString:
                return(binaryDecoder.ReadByteString(null));

            case BuiltInType.XmlElement:
                return(binaryDecoder.ReadXmlElement(null));

            case BuiltInType.NodeId:
                return(binaryDecoder.ReadNodeId(null));

            case BuiltInType.ExpandedNodeId:
                return(binaryDecoder.ReadExpandedNodeId(null));

            case BuiltInType.StatusCode:
                return(binaryDecoder.ReadStatusCode(null));

            case BuiltInType.QualifiedName:
                return(binaryDecoder.ReadQualifiedName(null));

            case BuiltInType.LocalizedText:
                return(binaryDecoder.ReadLocalizedText(null));

            case BuiltInType.DataValue:
                return(binaryDecoder.ReadDataValue(null));

            case BuiltInType.Enumeration:
                return(binaryDecoder.ReadInt32(null));

            case BuiltInType.Variant:
                return(binaryDecoder.ReadVariant(null));

            case BuiltInType.ExtensionObject:
                return(binaryDecoder.ReadExtensionObject(null));

            default:
                return(null);
            }
        }