Esempio n. 1
0
        /// <summary>
        /// Return news carrier. It contains all information about single news
        /// </summary>
        /// <param name="index">index of news in newsfeed</param>
        /// <returns>NewsCarrier - carrier of the news item</returns>
        public override async Task<Lists.IListDataCarrier> GetCarrier(int index)
        {
            //if we out of range
            if (index>=this.newsfeed.items.Count()) return null;
            NewsСarrier carrier = new NewsСarrier();
            carrier.Data = newsfeed.items[index];
            //if sender is Friend

            try
            {
                if (carrier.Data.source_id > 0)
                    carrier.Sender = newsfeed.Profiles.First<Profiles.Profile>(
                        delegate(Profiles.Profile p)
                        {
                            return p.ID == carrier.Data.source_id;
                        });
                else
                    //if sender is group
                    carrier.Sender = newsfeed.Groups.First<Profiles.Group>(
                        delegate(Profiles.Group g)
                        {
                            return g.ID == carrier.Data.source_id;
                        });
            
            if (carrier.Data.copy_owner_id == null)
            {
                carrier.Owner = null;
            }
            else
            {
                if (carrier.Data.copy_owner_id > 0)
                    carrier.Owner = newsfeed.Profiles.First<Profiles.Profile>(
                        delegate(Profiles.Profile p) 
                        { 
                            return p.ID == carrier.Data.copy_owner_id; 
                        });
                else
                    carrier.Owner = newsfeed.Groups.First<Profiles.Group>(
                        delegate(Profiles.Group g) 
                        {
                            return g.ID == carrier.Data.copy_owner_id;
                        });
            }
            }
            catch (InvalidOperationException)
            {
                System.Diagnostics.Debugger.Break();
            }
            carrier.Id = carrier.Data.post_id;
            return carrier;
                
        }
Esempio n. 2
0
        public static async Task<List<Lists.IListDataCarrier>> FastDownloadCount(int count)
        {
            System.Diagnostics.Debug.WriteLine("Newsfeed download started");
            //resieve all latest news items
            VKResponse<NewsFeedContainer> newitems = await VKApi.Core.VKProvider.Instance.Call<VKResponse<NewsFeedContainer>>("newsfeed.get",
                new Dictionary<string, string>() { {"count",count.ToString()}});

            List<Lists.IListDataCarrier> resultdata = new List<Lists.IListDataCarrier>();
            if (newitems == null) return resultdata;


            foreach (var item in newitems.response.items)
            {
                NewsСarrier carrier = new NewsСarrier();
                carrier.Data = item;
                //if sender is Friend

                try
                {
                    if (carrier.Data.source_id > 0)
                        carrier.Sender = newitems.response.profiles.First<Profiles.Profile>(
                            delegate(Profiles.Profile p)
                            {
                                return p.ID == carrier.Data.source_id;
                            });
                    else
                        //if sender is group
                        carrier.Sender = newitems.response.groups.First<Profiles.Group>(
                            delegate(Profiles.Group g)
                            {
                                return g.ID == carrier.Data.source_id;
                            });
                
                }
                catch (InvalidOperationException)
                {
                    System.Diagnostics.Debugger.Break();
                }
                carrier.Id = carrier.Data.post_id;
                resultdata.Add(carrier);
            }
            return resultdata;         
            
        }