Exemplo n.º 1
0
        public async Task<bool> Save(Source source)
        {
            var url = this.BuildUrl("source");
            if (source.Id != 0)
            {
                url = this.BuildUrl("source/" + source.Id);
            }
            var parameters = new Dictionary<string, string>();
            parameters["title"] = source.Title;
            parameters["spout"] = source.Spout;
            parameters["tags"] = String.Join(",", source.Tags);
            foreach (var spoutParameter in source.Params)
            {
                parameters.Add(spoutParameter.Key, spoutParameter.Value);
            }
            var json = await this.Http.Post(url.Uri.AbsoluteUri, parameters);

            JToken token;
            json.ToObject<JObject>().TryGetValue("id", out token);

            var id = token.Value<int>();
            source.Id = id;

            return this.ReadSuccess(json);
        }
Exemplo n.º 2
0
 private IEnumerable<Source> ReadSources(JContainer json)
 {
     var sources =  new List<Source>();
     var items = json.ToObject<List<JObject>>();
     foreach (var item in items)
     {
         var source = new Source()
         {
             Id = item["id"].Value<int>(),
             Title = item["title"].ToString(),
             Spout = item["spout"].ToString(),
             Params = item["params"].ToObject<Dictionary<string, string>>(),
             Error = item["error"].ToString(),
             Favicon = item["icon"].ToString(),
             Tags = new List<string>(item["tags"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         };
         sources.Add(source);
     }
     return sources;
 }