public void NullableStringConverter_ReadJson_deserializes_Resource_uuid_with_null_value()
        {
            const string json     = "{\"uuid\":null}";
            var          resource = EtpExtensions.Deserialize <v11.Datatypes.Object.Resource>(json);

            Assert.IsNull(resource.Uuid);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the server capabilities object using the specified URL and authorization header.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="headers">The authorization header.</param>
        /// <returns>The server capabilities object.</returns>
        private object GetServerCapabilities(string url, IDictionary <string, string> headers)
        {
            var json          = DownloadJson(url, headers);
            var capServerType = GetServerCapabilitiesType(url);

            return(EtpExtensions.Deserialize(capServerType, json));
        }
Beispiel #3
0
        /// <summary>
        /// Logs the data object.
        /// </summary>
        /// <typeparam name="T">The message type.</typeparam>
        /// <param name="e">The <see cref="ProtocolEventArgs{T}"/> instance containing the event data.</param>
        /// <param name="dataObject">The data object.</param>
        /// <param name="append">if set to <c>true</c> append the data object; otherwise, replace.</param>
        private void LogDataObject <T>(ProtocolEventArgs <T> e, DataObject dataObject, bool append = false) where T : ISpecificRecord
        {
            LogObjectDetails(e);

            var data   = dataObject.GetString();
            var uri    = new EtpUri(dataObject.Resource.Uri);
            var isJson = EtpContentType.Json.EqualsIgnoreCase(uri.Format);

            if (isJson)
            {
                var objectType = OptionsIn.DataVersion.Version200.Equals(uri.Version)
                    ? ObjectTypes.GetObjectType(uri.ObjectType, uri.Version)
                    : ObjectTypes.GetObjectGroupType(uri.ObjectType, uri.Version);

                var instance = EtpExtensions.Deserialize(objectType, data);
                data = EtpExtensions.Serialize(instance, true);
            }

            if (append)
            {
                DataObject.Append(data);
                DataObject.Append(Environment.NewLine + Environment.NewLine);
            }
            else
            {
                DataObject.SetText(data);
            }

            Runtime.Invoke(() => DataObject.Language = isJson ? "JavaScript" : "XML");
        }
        public void StreamingStartIndexConverter_ReadJson_deserializes_null_value()
        {
            const string json  = "{\"item\":null,\"value\":null}";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsNull(index.Item);
        }
        public void StreamingStartIndexConverter_ReadJson_deserializes_null_object()
        {
            const string json  = "null";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsNull(index);
        }
Beispiel #6
0
        /// <summary>
        /// Called when the GetObject response is received.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ProtocolEventArgs{Object}"/> instance containing the event data.</param>
        private void OnObject(object sender, ProtocolEventArgs <Energistics.Protocol.Store.Object> e)
        {
            Details.SetText(string.Format(
                                "// Header:{2}{0}{2}{2}// Body:{2}{1}",
                                Client.Serialize(e.Header, true),
                                Client.Serialize(e.Message, true),
                                Environment.NewLine));

            var data   = e.Message.DataObject.GetString();
            var uri    = new EtpUri(e.Message.DataObject.Resource.Uri);
            var isJson = EtpContentType.Json.EqualsIgnoreCase(uri.Format);

            if (isJson)
            {
                var objectType = OptionsIn.DataVersion.Version200.Equals(uri.Version)
                    ? ObjectTypes.GetObjectType(uri.ObjectType, uri.Version)
                    : ObjectTypes.GetObjectGroupType(uri.ObjectType, uri.Version);

                var dataObject = EtpExtensions.Deserialize(objectType, data);
                data = EtpExtensions.Serialize(dataObject, true);
            }

            DataObject.SetText(data);
            Runtime.Invoke(() => DataObject.Language = isJson ? "JavaScript" : "XML");
        }
        public void NullableStringConverter_ReadJson_deserializes_Resource_uuid_with_empty_string()
        {
            const string json     = "{\"uuid\":{\"string\":\"\"}}";
            var          resource = EtpExtensions.Deserialize <v11.Datatypes.Object.Resource>(json);

            Assert.IsNotNull(resource.Uuid);
            Assert.AreEqual(string.Empty, resource.Uuid);
        }
Beispiel #8
0
        public void ByteArrayConverter_ReadJson_Can_Deserialize_Null_Byte_Array()
        {
            const string json = "{ \"data\": null }";

            var instance = EtpExtensions.Deserialize <v11.Datatypes.Object.DataObject>(json);

            Assert.IsNull(instance.Data);
        }
Beispiel #9
0
        public void GrowingObjectIndexConverter_ReadJson_deserializes_string_value()
        {
            const string json  = "{\"item\":\"5\"}";
            var          index = EtpExtensions.Deserialize <GrowingObjectIndex>(json);

            Assert.IsTrue(index.Item is long);
            Assert.AreEqual(5L, (long)index.Item);
        }
        public void StreamingStartIndexConverter_ReadJson_deserializes_int_value()
        {
            const string json  = "{\"item\":{\"int\":2}}";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsTrue(index.Item is int);
            Assert.AreEqual(2, (int)index.Item);
        }
        public void StreamingStartIndexConverter_ReadJson_deserializes_long_value()
        {
            const string json  = "{\"item\":{\"long\":10}}";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsTrue(index.Item is long);
            Assert.AreEqual(10L, (long)index.Item);
        }
Beispiel #12
0
        public void GrowingObjectIndexConverter_ReadJson_deserializes_double_value()
        {
            const string json  = "{\"item\":{\"double\":2.5}}";
            var          index = EtpExtensions.Deserialize <GrowingObjectIndex>(json);

            Assert.IsTrue(index.Item is double);
            Assert.AreEqual(2.5, (double)index.Item, 0.001);
        }
Beispiel #13
0
        public void ByteArrayConverter_ReadJson_Can_Deserialize_Byte_Array_In_Avro_Format()
        {
            var json = "{ \"data\": \"" + Escape(Hex) + "\" }";

            var instance = EtpExtensions.Deserialize <v11.Datatypes.Object.DataObject>(json);
            var expected = Encoding.UTF8.GetBytes(Xml);

            CollectionAssert.AreEqual(expected, instance.Data);
        }
Beispiel #14
0
        /// <summary>
        /// Get the list of supported ETP versions using the specified URL.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public IList <string> GetEtpVersions(string url)
        {
            // Append GetVersions=true, if not already in the url
            if (url.IndexOf(EtpSettings.GetVersionsHeader, StringComparison.InvariantCultureIgnoreCase) < 0)
            {
                var delim = url.IndexOf("?", StringComparison.InvariantCultureIgnoreCase) < 0 ? "?" : "&";
                url = $"{url}{delim}{EtpSettings.GetVersionsHeader}=true";
            }

            var headers = BearerHeader.Any() ? BearerHeader : BasicHeader;
            var json    = DownloadJson(url, headers);

            return(EtpExtensions.Deserialize <List <string> >(json));
        }
Beispiel #15
0
        public void ByteArrayConverter_ReadJson_Can_Deserialize_Compressed_Byte_Array_In_Avro_Format()
        {
            var json = "{ \"data\": \"" + Escape(HexGzip) + "\", \"contentEncoding\": \"gzip\" }";

            var instance = EtpExtensions.Deserialize <v11.Datatypes.Object.DataObject>(json);

            var dataObject = new v11.Datatypes.Object.DataObject();

            dataObject.SetString(Xml);

            var expected = dataObject.Data;

            CollectionAssert.AreEqual(expected, instance.Data);
        }
Beispiel #16
0
        public void GrowingObjectIndexConverter_ReadJson_raises_error_for_unsupported_union_type()
        {
            const string json = "{\"item\":{\"string\":\"abc\"}}";
            var          pass = false;

            try
            {
                EtpExtensions.Deserialize <GrowingObjectIndex>(json);
            }
            catch (JsonSerializationException)
            {
                pass = true;
            }

            Assert.IsTrue(pass);
        }
        public void StreamingStartIndexConverter_ReadJson_raises_error_for_unsupported_data_type()
        {
            const string json = "{\"item\":\"abc\"}";
            var          pass = false;

            try
            {
                EtpExtensions.Deserialize <StreamingStartIndex>(json);
            }
            catch (JsonSerializationException)
            {
                pass = true;
            }

            Assert.IsTrue(pass);
        }
Beispiel #18
0
        /// <summary>
        /// Logs the data object.
        /// </summary>
        /// <typeparam name="T">The message type.</typeparam>
        /// <param name="e">The <see cref="ProtocolEventArgs{T}"/> instance containing the event data.</param>
        /// <param name="dataObject">The data object.</param>
        /// <param name="append">if set to <c>true</c> append the data object; otherwise, replace.</param>
        private void LogDataObject <T>(ProtocolEventArgs <T> e, IDataObject dataObject, bool append = false) where T : ISpecificRecord
        {
            dataObject.Resource?.FormatLastChanged();

            LogObjectDetails(e);

            // Check if user wants to see decoded byte arrays
            if (!Model.DecodeByteArrays)
            {
                return;
            }

            var data = dataObject
                       .GetString()
                       .Trim(_whiteSpace);

            var uri    = new EtpUri(dataObject.Resource.Uri);
            var isJson = EtpContentType.Json.EqualsIgnoreCase(uri.Format);

            if (isJson)
            {
                var objectType = OptionsIn.DataVersion.Version200.Equals(uri.Version)
                    ? ObjectTypes.GetObjectType(uri.ObjectType, uri.Version)
                    : ObjectTypes.GetObjectGroupType(uri.ObjectType, uri.Version);

                var instance = EtpExtensions.Deserialize(objectType, data);
                data = EtpExtensions.Serialize(instance, true);
            }

            if (append)
            {
                DataObject.Append(data);
                DataObject.Append(Environment.NewLine + Environment.NewLine);
            }
            else
            {
                DataObject.SetText(data);
            }

            Runtime.Invoke(() => DataObject.Language = isJson ? "JavaScript" : "XML");
        }
Beispiel #19
0
 public IAcknowledge DeserializeAcknowledge(string content)
 {
     return(EtpExtensions.Deserialize <Acknowledge>(content));
 }
Beispiel #20
0
 public IProtocolException DeserializeProtocolException(string content)
 {
     return(EtpExtensions.Deserialize <ProtocolException>(content));
 }
Beispiel #21
0
 public IMessageHeader DeserializeMessageHeader(string content)
 {
     return(EtpExtensions.Deserialize <MessageHeader>(content));
 }