public static string SmartFormat(ClientMessage.ReadEventCompleted completed, ICodec targetCodec)
        {
            var dto = new HttpClientMessageDto.ReadEventCompletedText(completed);
            if (completed.Record.Event.Flags.HasFlag(PrepareFlags.IsJson))
            {
                var deserializedData = Codec.Json.From<object>((string) dto.Data);
                var deserializedMetadata = Codec.Json.From<object>((string) dto.Metadata);

                if (deserializedData != null)
                    dto.Data = deserializedData;
                if (deserializedMetadata != null)
                    dto.Metadata = deserializedMetadata;
            }

            switch (targetCodec.ContentType)
            {
                case ContentType.Xml:
                case ContentType.ApplicationXml:
                case ContentType.Atom:
                {
                    var serializeObject = JsonConvert.SerializeObject(dto);
                    var deserializeXmlNode = JsonConvert.DeserializeXmlNode(serializeObject, "read-event-result");
                    return deserializeXmlNode.InnerXml;
                }

                default:
                    return targetCodec.To(dto);
            }
        }
        public static HttpClientMessageDto.ReadEventCompletedText CreateDataDto(ResolvedEvent evnt)
        {
            var dto = new HttpClientMessageDto.ReadEventCompletedText(evnt);
            if (evnt.Event.Flags.HasFlag(PrepareFlags.IsJson))
            {
                var deserializedData = Codec.Json.From<object>((string) dto.data);
                var deserializedMetadata = Codec.Json.From<object>((string) dto.metadata);

                if (deserializedData != null)
                    dto.data = deserializedData;
                if (deserializedMetadata != null)
                    dto.metadata = deserializedMetadata;
            }
            return dto;
        }