Exemple #1
0
 /// <summary>
 /// Fire event about updates
 /// </summary>
 /// <param name="updateargs">
 /// update arguments contains three fields UpdateType(Add/Remove), first new item pos, last new item pos</param>
 internal void RiseUpdate(UpdateArgs updateargs)
 {
     EventHandler<UpdateArgs> handler = Updated;
     if (updateargs.updateType == UpdateType.Nothing) return;
     if (handler != null)
     {
         Updated(this, updateargs);
     }
 }
Exemple #2
0
        /// <summary>
        /// Get latest news
        /// </summary>
        /// <returns></returns>
        public override async Task GetLatest()
        {
            Buisy = true;
            //get oldest news by offset parametr
            VKResponse<NewsFeedContainer> newitems = await this.provider.Call<VKResponse<NewsFeedContainer>>("newsfeed.get", new Dictionary<string, string> 
            {
            {
                "start_time", (this.newsfeed.items[0].date+1).ToString()
                }
            });
            if (newitems == null)
            {
                Buisy = false;
                return;
            }

            var last = newsfeed.items[0];
            var last1 = newsfeed.items[1];
            newitems.response.items.RemoveAll(it => (it.post_id == last.post_id) || (it.post_id == last1.post_id));
            //update offset
            if (newitems.response.new_from != "0")
                newsfeed.new_from = newitems.response.new_from;
            //update data            
            newitems.response.items.RemoveAll((i) => i.post_id == last.post_id);
            newsfeed.items.InsertRange(0, newitems.response.items);
            newsfeed.Groups.UnionWith(newitems.response.groups);
            newsfeed.Profiles.UnionWith(newitems.response.profiles);            
            //configure update information
            if (newitems.response.items.Count != 0)
            {
                UpdateArgs args = new UpdateArgs
                {
                    updateType = UpdateType.GetLatest,
                    first = 0,
                    last = newitems.response.items.Count - 1
                };
                //if nothing new set update type to nothing
                if (newitems.response.items.Count == 0) args.updateType = UpdateType.Nothing;
                RiseUpdate(args);
            }
            Buisy = false;
        }
Exemple #3
0
 /// <summary>
 /// Get oldest news
 /// </summary>
 /// <returns></returns>
 public override async Task GetOldest()
 {
     Buisy = true;
     //get lattest news by offset parametr
     int oldcount = this.newsfeed.items.Count;
     VKResponse<NewsFeedContainer> newitems = await this.provider.Call<VKResponse<NewsFeedContainer>>("newsfeed.get", new Dictionary<string, string> 
     {             
     { "offset", oldcount.ToString()}
     });
     if (newitems == null) return;
     NewsFeedContainer olddata = newitems.response;
     //update offset
     newsfeed.new_from = olddata.new_from;
     newsfeed.new_offset = olddata.new_offset;
     //update data
     newsfeed.items.AddRange(olddata.items);
     newsfeed.Groups.UnionWith(olddata.groups);
     newsfeed.Profiles.UnionWith(olddata.profiles);
     //configure update args
     UpdateArgs args = new UpdateArgs
     {
         updateType = UpdateType.GetOldest,
         last = newsfeed.items.Count-1,
         first = newsfeed.items.Count-olddata.items.Count
     };
     RiseUpdate(args);
     Buisy = false;
 }
Exemple #4
0
 /// <summary>
 /// Get NewsFeed
 /// </summary>
 /// <returns></returns>
 public override async Task FirstTimeDownload()
 {
     Buisy = true;
     System.Diagnostics.Debug.WriteLine("Newsfeed download started");
     //resieve all latest news items
     VKResponse<NewsFeedContainer> newitems = await this.provider.Call<VKResponse<NewsFeedContainer>>("newsfeed.get", new Dictionary<string, string>());
     if (newitems == null) return;
     //add it to ste responce
     this.newsfeed = newitems.response;
     this.newsfeed.Profiles.UnionWith(this.newsfeed.profiles);
     this.newsfeed.Groups.UnionWith(this.newsfeed.groups);
     //configure update arguments
     UpdateArgs args = new UpdateArgs()
     {
         updateType = UpdateType.FirstTime,
         first = 0,
         last = newsfeed.items.Count()-1,
     };
     //rise update event
     RiseUpdate(args);
     Buisy = false;
 }