using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;
using Telerik.Web.UI;

/// <summary>
/// Summary description for SchedulerConverter
/// </summary>
public class SchedulerConverter : JsonConverter
{

    public override bool CanConvert(Type objectType)
    {
        return true;
    }

    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        var o = JObject.Load(reader);
        var info = o["schedulerInfo"].ToObject<SchedulerInfo>() as ISchedulerInfo;

        return new SchedulerViewModel(info);
    }

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        serializer.Serialize(writer, JObject.Parse(value as string));
    }
}