Example #1
0
        internal String ToJson(StreamClient client)
        {
            JObject obj = new JObject(
                new JProperty(Field_Actor, this.Actor),
                new JProperty(Field_Verb, this.Verb),
                new JProperty(Field_Object, this.Object));

            if (Time.HasValue)
            {
                obj.Add(new JProperty(Field_Time, this.Time.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture)));
            }

            if (!String.IsNullOrWhiteSpace(ForeignId))
            {
                obj.Add(new JProperty(Field_ForeignId, this.ForeignId));
            }

            if (!String.IsNullOrWhiteSpace(Target))
            {
                obj.Add(new JProperty(Field_Target, this.Target));
            }

            if (To.SafeCount() > 0)
            {
                JArray toArray = new JArray();
                (from t in To select client.SignTo(t)).ForEach((st) =>
                {
                    toArray.Add(st);
                });
                obj.Add(new JProperty(Field_To, toArray));
            }

            if (_data.SafeCount() > 0)
            {
                _data.Keys.ForEach((k) =>
                {
                    obj.Add(new JProperty(k, _data[k]));
                });
            }

            return(obj.ToString());
        }