public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var push = value as PushNotification;
            if (push == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            // Write push type
            if (string.IsNullOrWhiteSpace(push.Query) == false)
                writer.WriteProperty("query", push.Query);
            else if( push.Channels.Count() > 0 )
                writer.WriteArray("channels", push.Channels);
            else if( push.DeviceIds.Count() > 0 )
                writer.WriteArray("deviceids", push.DeviceIds);
            else
                writer.WriteProperty("broadcast", true);
            // Write data
            WriteData(writer, push);
            // Write platform options
            WritePlatformOptions(writer, push.PlatformOptions);
            writer.EndObject();

        }
 private void WriteTileOptions(JsonWriter writer, TileNotification option)
 {
     writer.StartObject();
     writer.WriteProperty("notificationtype", "tile");
     WriteTile(writer, "wp8", option.WP8Tile);
     WriteTile(writer, "wp75", option.WP75Tile);
     WriteTile(writer, "wp7", option.WP7Tile);
     writer.EndObject();
 }
 private void WritePlatformOptions(JsonWriter writer, PlatformOptions options)
 {
     if (options == null || options.IsEmpty == true ) return;
     writer.WriteProperty("platformoptions");
     writer.StartObject();
     if (options.iOS != null)
         WriteIosOptions(writer, options.iOS);
     if (options.Android != null)
         WriteAndroidOptions(writer, options.Android);
     if (options.WindowsPhone != null)
         WriteWpOptions(writer, options.WindowsPhone);
     writer.EndObject();
 }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Entity entity = value as Entity;
            if (entity == null)
            {
                writer.WriteNull();
                return;
            }

            writer.StartObject();
            writer
                // Write id
                .WithWriter(w =>
                {
                    if (string.IsNullOrWhiteSpace(entity.Id) == false)
                        w.WriteProperty("__id", entity.Id);
                })
                // Write created by
                .WriteProperty("__createdby", entity.CreatedBy)
                // Write properties
                .WithWriter(w =>
                {
                    
                    foreach (var property in entity.Properties)
                        w.WriteProperty(property.Key, property.Value);
                })
                .WithWriter( w => WriteJson(entity, w, serializer) )
                .WithWriter(w =>
                {
                    var attr = entity.Attributes.ToArray();
                    if (attr.Length > 0)
                    {
                        w.WriteProperty("__attributes")
                         .StartObject();
                        // Write attributes
                        for (int i = 0; i < attr.Length; i++)
                            w.WriteProperty(attr[i].Key, attr[i].Value);
                        w.EndObject();
                    }

                })
                .WithWriter(w =>
                {
                    if (entity.Tags.Count() > 0)
                        w.WriteArray("__tags", entity.Tags);
                });
            writer.EndObject();
        }
 private void WriteData(JsonWriter writer, PushNotification push)
 {
     writer.WritePropertyName("data");
     writer.StartObject();
     writer
         .WriteProperty("alert", push.Alert)
         .WriteProperty("badge", push.Badge, true);
     foreach (var key in push.Data.Keys)
     {
         if (key.Equals("alert", StringComparison.OrdinalIgnoreCase) == true ||
             key.Equals("badge", StringComparison.OrdinalIgnoreCase) == true)
             continue;
         writer.WriteProperty(key, push.Data[key]);
     }
     writer.EndObject();
 }
 private static void WriteAttributes(JsonWriter writer, Entity entity, JsonSerializer serializer)
 {
     var attr = entity.Attributes.ToArray();
     if (attr.Length > 0)
     {
         writer.WriteProperty("__attributes");
         writer.StartObject();
         // Write attributes
         for (int i = 0; i < attr.Length; i++)
             writer.WriteProperty(attr[i].Key, attr[i].Value);
         writer.EndObject();
     }
 }
        private void WriteEndpoint(string property, JsonWriter writer, Endpoint endpoint)
        {
            writer
                .WriteProperty(property)
                .StartObject()
                .WriteProperty("label", endpoint.Label);

            if (endpoint.HasBatchReference == true)
                writer.WriteProperty("name", endpoint.ObjectReference.ObjectHandle);
            else if (endpoint.CreateEndpoint == false)
                writer.WriteProperty("objectid", endpoint.ObjectId);
            else
                writer
                    .WriteProperty("object")
                    .WithWriter(w => WriteObject(w, endpoint.Content));

            writer.EndObject();
        }