Beispiel #1
0
        public void ByteArrayConverter_WriteJson_Can_Serialize_Null_Byte_Array()
        {
            var dataObject = new v11.Datatypes.Object.DataObject();
            var json       = EtpExtensions.Serialize(dataObject, true);

            Assert.IsTrue(json.Contains("\"data\": null"));
        }
        public void StreamingStartIndexConverter_ReadJson_deserializes_null_value()
        {
            const string json  = "{\"item\":null,\"value\":null}";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsNull(index.Item);
        }
Beispiel #3
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 StreamingStartIndexConverter_ReadJson_deserializes_null_object()
        {
            const string json  = "null";
            var          index = EtpExtensions.Deserialize <StreamingStartIndex>(json);

            Assert.IsNull(index);
        }
        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 #6
0
        private void OnBasicStreamerChannelMetadata(object sender, ResponseEventArgs <v11.Protocol.ChannelStreaming.ChannelDescribe, v11.Protocol.ChannelStreaming.ChannelMetadata> args)
        {
            if (args.Response == null)
            {
                return;
            }

            foreach (var metadata in args.Response.Body.Channels)
            {
                ChannelMetadata[metadata.ChannelId] = metadata;
            }

            var domainObjects = new List <string>();

            foreach (var channel in args.Response.Body.Channels)
            {
                domainObjects.Add(channel.DomainObject.GetString());
                channel.DomainObject.SetString(string.Empty);
            }
            for (int i = 0; i < args.Response.Body.Channels.Count; i++)
            {
                Console.WriteLine(EtpExtensions.Serialize(args.Response.Body.Channels[i]));
                Console.WriteLine(domainObjects[i]);
                args.Response.Body.Channels[i].DomainObject.SetString(domainObjects[i]);
            }
        }
Beispiel #7
0
        private Task <bool> GetServerCapabilities()
        {
            if (!Model.Connection.Uri.ToLowerInvariant().StartsWith("ws"))
            {
                return(Task.FromResult(false));
            }

            try
            {
                Runtime.ShowBusy();

                var capabilities = Model.Connection.GetEtpServerCapabilities();

                Parent.LogDetailMessage(
                    "Server Capabilites:",
                    EtpExtensions.Serialize(capabilities, true));

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                _log.Warn("Error getting server capabilities", ex);
                Parent.LogClientError("Error getting server capabilities:", ex);
                return(Task.FromResult(false));
            }
            finally
            {
                Runtime.ShowBusy(false);
            }
        }
Beispiel #8
0
        public void Save()
        {
            var dialog = new SaveFileDialog()
            {
                Title        = "Save Simulation Configuration Settings...",
                Filter       = "JSON Files|*.json;*.js|All Files|*.*",
                DefaultExt   = ".json",
                AddExtension = true,
                FileName     = DisplayName
            };

            if (dialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault())
            {
                try
                {
                    Model.Name = DisplayName;
                    var json = EtpExtensions.Serialize(Model, true);
                    File.WriteAllText(dialog.FileName, json);
                }
                catch (Exception ex)
                {
                    Runtime.ShowError("Error saving configuration settings.", ex);
                }
            }
        }
Beispiel #9
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");
        }
Beispiel #10
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));
        }
        public void StreamingStartIndexConverter_WriteJson_serializes_null_object()
        {
            const string expected = "null";
            var          json     = EtpExtensions.Serialize(null);

            Assert.AreEqual(expected, json);
        }
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 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);
        }
Beispiel #14
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);
        }
        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 #16
0
 /// <summary>
 /// Logs the object details.
 /// </summary>
 /// <typeparam name="T">The message type</typeparam>
 /// <param name="e">The <see cref="ProtocolEventArgs{T}"/> instance containing the event data.</param>
 private void LogObjectDetails <T>(ProtocolEventArgs <T> e) where T : ISpecificRecord
 {
     Details.SetText(string.Format(
                         "// Header:{2}{0}{2}{2}// Body:{2}{1}{2}",
                         EtpExtensions.Serialize(e.Header, true),
                         EtpExtensions.Serialize(e.Message, true),
                         Environment.NewLine));
 }
        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 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 #19
0
        private void OnNotificationSubscriptionEnded(object sender, NotificationEventArgs <v12.Datatypes.Object.SubscriptionInfo, v12.Protocol.StoreNotification.SubscriptionEnded> args)
        {
            if (args.Notification == null)
            {
                return;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Notification.Body));
        }
Beispiel #20
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 #21
0
        private void OnDeleteNotification(object sender, NotificationEventArgs <v11.Datatypes.Object.NotificationRequestRecord, v11.Protocol.StoreNotification.DeleteNotification> args)
        {
            if (args.Notification == null)
            {
                return;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Notification.Body));
        }
Beispiel #22
0
        private void OnResponseSubscriptionEnded(object sender, ResponseEventArgs <v12.Protocol.StoreNotification.UnsubscribeNotifications, v12.Protocol.StoreNotification.SubscriptionEnded> args)
        {
            if (args.Response == null)
            {
                return;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Response.Body));
        }
Beispiel #23
0
        private void OnGetDeletedResourcesResponse(object sender, ResponseEventArgs <v12.Protocol.Discovery.GetDeletedResources, v12.Protocol.Discovery.GetDeletedResourcesResponse> args)
        {
            if (args.Response == null)
            {
                return;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Response.Body));
        }
Beispiel #24
0
        private void OnGetSupportedTypesResponse(object sender, ResponseEventArgs <v12.Protocol.SupportedTypes.GetSupportedTypes, v12.Protocol.SupportedTypes.GetSupportedTypesResponse> args)
        {
            if (args.Response == null)
            {
                return;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Response.Body));
        }
Beispiel #25
0
        public void ByteArrayConverter_WriteJson_Can_Serialize_Compressed_Byte_Array_In_Avro_Format()
        {
            var dataObject = new v11.Datatypes.Object.DataObject();

            dataObject.SetString(Xml);

            var json       = EtpExtensions.Serialize(dataObject, true);
            var hexEscaped = Escape(HexGzip);

            Assert.IsTrue(json.Contains(hexEscaped));
        }
Beispiel #26
0
 private void OnGetResourcesResponse(object sender, DualResponseEventArgs <v12.Protocol.Discovery.GetResources, v12.Protocol.Discovery.GetResourcesResponse, v12.Protocol.Discovery.GetResourcesEdgesResponse> args)
 {
     if (args.Response1 != null)
     {
         Console.WriteLine(EtpExtensions.Serialize(args.Response1.Body));
     }
     if (args.Response2 != null)
     {
         Console.WriteLine(EtpExtensions.Serialize(args.Response2.Body));
     }
 }
        public void NullableStringConverter_WriteJson_serializes_Resource_uuid_with_empty_string()
        {
            var resource = new v11.Datatypes.Object.Resource
            {
                Uuid = string.Empty
            };

            const string expected = "\"uuid\":{\"string\":\"\"}";
            var          json     = EtpExtensions.Serialize(resource);

            Assert.IsTrue(json.Contains(expected));
        }
        public void StreamingStartIndexConverter_WriteJson_serializes_long_value()
        {
            var index = new StreamingStartIndex
            {
                Item = 10L
            };

            var expected = "{\"item\":{\"long\":10}}";
            var json     = EtpExtensions.Serialize(index);

            Assert.AreEqual(expected, json);
        }
        public void NullableStringConverter_WriteJson_serializes_Resource_uuid_with_null_value()
        {
            var resource = new v11.Datatypes.Object.Resource
            {
                Uuid = null
            };

            const string expected = "\"uuid\":null";
            var          json     = EtpExtensions.Serialize(resource);

            Assert.IsTrue(json.Contains(expected));
        }
        public void StreamingStartIndexConverter_WriteJson_serializes_null_value()
        {
            var index = new StreamingStartIndex
            {
                Item = null
            };

            const string expected = "{\"item\":null}";
            var          json     = EtpExtensions.Serialize(index);

            Assert.AreEqual(expected, json);
        }