コード例 #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"));
        }
コード例 #2
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");
        }
コード例 #3
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]);
            }
        }
コード例 #4
0
        public void StreamingStartIndexConverter_WriteJson_serializes_null_object()
        {
            const string expected = "null";
            var          json     = EtpExtensions.Serialize(null);

            Assert.AreEqual(expected, json);
        }
コード例 #5
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);
                }
            }
        }
コード例 #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");
        }
コード例 #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);
            }
        }
コード例 #8
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));
 }
コード例 #9
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));
        }
コード例 #10
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));
        }
コード例 #11
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));
        }
コード例 #12
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));
        }
コード例 #13
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));
        }
コード例 #14
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));
     }
 }
コード例 #15
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));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        public void GrowingObjectIndexConverter_WriteJson_serializes_double_value()
        {
            var index = new GrowingObjectIndex
            {
                Item = 2.5
            };

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

            Assert.AreEqual(expected, json);
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        private void OnMessageTypeChanged()
        {
            if (_selectedMessageType.Key == MessageTypes[0].Key)
            {
                return;
            }

            var type    = SelectedMessageType.Value;
            var message = Activator.CreateInstance(type) as ISpecificRecord;

            Message.SetText(EtpExtensions.Serialize(message, true));
            UpdateCurrentHeader(message?.Schema);
        }
コード例 #22
0
        private void OnGetChannelMetadataResponse(object sender, ResponseEventArgs <v12.Protocol.ChannelSubscribe.GetChannelMetadata, v12.Protocol.ChannelSubscribe.GetChannelMetadataResponse> args)
        {
            if (args.Response == null)
            {
                return;
            }

            foreach (var metadata in args.Response.Body.Metadata.Values)
            {
                ChannelMetadata[metadata.Id] = metadata;
            }
            Console.WriteLine(EtpExtensions.Serialize(args.Response.Body));
        }
コード例 #23
0
        private void OnObjectChanged(object sender, NotificationEventArgs <v12.Datatypes.Object.SubscriptionInfo, v12.Protocol.StoreNotification.ObjectChanged> args)
        {
            if (args.Notification == null)
            {
                return;
            }

            var @string = args.Notification.Body.Change.DataObject?.GetString();

            if (args.Notification.Body.Change.DataObject != null)
            {
                args.Notification.Body.Change.DataObject.Data = null;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Notification.Body));
            if (!string.IsNullOrEmpty(@string))
            {
                Console.WriteLine(@string);
            }
        }
コード例 #24
0
 private void OnGetDataObjectsResponse(object sender, DualResponseEventArgs <v12.Protocol.Store.GetDataObjects, v12.Protocol.Store.GetDataObjectsResponse, v12.Protocol.Store.Chunk> args)
 {
     if (args.Response1 != null)
     {
         foreach (var dataObject in args.Response1.Body.DataObjects.Values)
         {
             var @string = dataObject.GetString();
             dataObject.Data = null;
             Console.WriteLine(EtpExtensions.Serialize(dataObject));
             if (!string.IsNullOrEmpty(@string))
             {
                 Console.WriteLine(@string);
             }
         }
     }
     if (args.Response2 != null)
     {
         Console.WriteLine($"Chunk received for {args.Response2.Body.BlobId} with {args.Response2.Body.Data?.Length ?? 0} bytes.");
     }
 }
コード例 #25
0
        private void OnChangeNotification(object sender, NotificationEventArgs <v11.Datatypes.Object.NotificationRequestRecord, v11.Protocol.StoreNotification.ChangeNotification> args)
        {
            if (args.Notification == null)
            {
                return;
            }

            var @string = args.Notification.Body.Change.DataObject?.GetString();

            if (args.Notification.Body.Change.DataObject != null)
            {
                args.Notification.Body.Change.DataObject.Data = null;
            }

            Console.WriteLine(EtpExtensions.Serialize(args.Notification.Body));
            if (!string.IsNullOrEmpty(@string))
            {
                Console.WriteLine(@string);
            }
        }
コード例 #26
0
        public void StreamingStartIndexConverter_WriteJson_raises_error_for_unsupported_data_type()
        {
            var index = new StreamingStartIndex
            {
                Item = "abc"
            };

            var pass = false;

            try
            {
                EtpExtensions.Serialize(index);
            }
            catch (JsonSerializationException)
            {
                pass = true;
            }

            Assert.IsTrue(pass);
        }
コード例 #27
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");
        }
コード例 #28
0
 private void OnGetRangesResponse(object sender, ResponseEventArgs <v12.Protocol.ChannelSubscribe.GetRanges, v12.Protocol.ChannelSubscribe.GetRangesResponse> args)
 {
     Console.WriteLine(EtpExtensions.Serialize(args.Response.Body));
 }
コード例 #29
0
 private void OnUnsolicitedStoreNotifications(object sender, FireAndForgetEventArgs <v12.Protocol.StoreNotification.UnsolicitedStoreNotifications> args)
 {
     Console.WriteLine(EtpExtensions.Serialize(args.Message.Body));
 }
コード例 #30
0
 /// <summary>
 /// Handles the ChannelData message from a producer.
 /// </summary>
 /// <param name="header">The message header.</param>
 /// <param name="channelData">The ChannelData message.</param>
 protected override void HandleChannelData(IMessageHeader header, ChannelData channelData)
 {
     Console.WriteLine(string.Join(Environment.NewLine, channelData.Data.Select(d => EtpExtensions.Serialize(d))));
 }