Exemplo n.º 1
0
        public void Serialize <TEntity>(TEntity entity, Stream stream)
        {
            var s = JsonSerializer.SerializeToString(entity);

            s = JsvFormatter.Format(s);

            using (var writer = new StreamWriter(stream))
            {
                writer.Write(s);
            }
        }
Exemplo n.º 2
0
        protected override Formatter PrepareFormatter(Type type)
        {
            var name = ContractEvil.GetContractReference(type);

            return(new Formatter(name, type, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) =>
            {
                using (var writer = new StreamWriter(s))
                {
                    writer.WriteLine();
                    writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type)));
                }
            }));
        }
Exemplo n.º 3
0
 public override string ToString()
 {
     return(Item.PrintToString(o =>
     {
         string details = JsvFormatter.Format(JsonSerializer.SerializeToString(o));
         string description;
         if (Describe.TryDescribe(o, out description))
         {
             return "\r\n" + Indent(description) + "\r\n\r\n" + details;
         }
         return details;
     }));
 }
Exemplo n.º 4
0
            protected override Formatter PrepareFormatter(Type type)
            {
                var name = ContractEvil.GetContractReference(type);

                return(new Formatter(name, s => JsonSerializer.DeserializeFromStream(type, s), (o, s) =>
                {
                    using (var writer = new StreamWriter(s))
                    {
                        writer.WriteLine();
                        writer.WriteLine(JsvFormatter.Format(JsonSerializer.SerializeToString(o, type)));
                    }
                }));
                //var formatter = RuntimeTypeModel.Default.CreateFormatter(type);
                //return new Formatter(name, formatter.Deserialize, (o, stream) => formatter.Serialize(stream, o));
            }
Exemplo n.º 5
0
        public static string SerializeAndFormat <T>(this T instance)
        {
            var fn = instance as Delegate;

            if (fn != null)
            {
                return(Dump(fn));
            }

            var dtoStr = !HasCircularReferences(instance)
                ? SerializeToString(instance)
                : SerializeToString(instance.ToSafePartialObjectDictionary());
            var formatStr = JsvFormatter.Format(dtoStr);

            return(formatStr);
        }
        public void Should_be_able_to_serialize_responses_to_json(
            object response,
            string serializedContent)
        {
            "Given a response of type {0}"
            .Given(() => { });

            "When serializing to json"
            .When(() => serializedContent = Serialize(response, (o, stream) =>
                                                      new ServiceStackJsonFormatter().WriteToStream(o.GetType(), o, stream, new StringContent(""))));

            "Then should have serialized successfully".Then(() =>
            {
                Debug.Write(JsvFormatter.Format(serializedContent).Replace("\t", "  "));
                serializedContent.Should().NotBeNullOrEmpty();
            });
        }
        public override string ToString()
        {
            return(Item.PrintToString(o =>
            {
                var details = JsvFormatter.Format(JsonSerializer.SerializeToString(o));

                var ie = o as IEvent <IIdentity>;

                //if (ie != null)
                //{
                //    details = details + "\r\n From:" + IdentityConvert.ToPartitionedName(ie.Id);
                //}

                string description;
                if (Describe.TryDescribe(o, out description))
                {
                    return "\r\n" + Indent(description) + "\r\n\r\n" + details;
                }
                return details;
            }));
        }
Exemplo n.º 8
0
        public string GetView()
        {
            Maybe <TView> possibleView;

            if (this.Key != null)
            {
                possibleView = this.Client.GetView <TView>(this.Key);
            }
            else
            {
                possibleView = this.Client.GetSingleton <TView>();
            }

            if (possibleView.HasValue)
            {
                return(JsvFormatter.Format(TypeSerializer.SerializeToString(possibleView.Value)));
            }
            else
            {
                return("View does not exist");
            }
        }
Exemplo n.º 9
0
 static void DescribeMessage(StringBuilder builder, ImmutableEnvelope context)
 {
     builder.AppendLine(context.PrintToString(o => JsvFormatter.Format(JsonSerializer.SerializeToString(o))));
 }
Exemplo n.º 10
0
 public void BindMessage(Type messageType, object instance)
 {
     MessageType       = messageType;
     richTextBox1.Text = JsvFormatter.Format(JsonSerializer.SerializeToString(instance));
 }