/// <summary> /// Разобрать из json. /// </summary> /// <param name="response">Ответ сервера.</param> /// <returns></returns> public static WallGetObject FromJson(VkResponse response) { WallGetObject wallGetObject; if (response.ContainsKey("items")) { wallGetObject = new WallGetObject { WallPosts = response["items"].ToReadOnlyCollectionOf <Post>(r => r), Profiles = response["profiles"].ToReadOnlyCollectionOf <User>(r => r), Groups = response["groups"].ToReadOnlyCollectionOf <Group>(r => r), TotalCount = response["count"] ?? 1UL }; } else { wallGetObject = new WallGetObject { WallPosts = response.ToReadOnlyCollectionOf <Post>(r => r) }; wallGetObject.TotalCount = (ulong)wallGetObject.WallPosts.Count; } return(wallGetObject); }
/// <summary> /// Разобрать из json. /// </summary> /// <param name="response">Ответ сервера.</param> /// <returns></returns> internal static WallGetObject FromJson(VkResponse response) { WallGetObject wallGetObject; if (response.ContainsKey("items")) { wallGetObject = new WallGetObject { WallPosts = response["items"].ToReadOnlyCollectionOf <Post>(r => r), Profiles = response["profiles"].ToReadOnlyCollectionOf <User>(r => r), Groups = response["groups"].ToReadOnlyCollectionOf <Group>(r => r) }; if (response["count"] != null) { wallGetObject.TotalCount = response["count"]; } else { wallGetObject.TotalCount = 1; } } else { wallGetObject = new WallGetObject { WallPosts = response.ToReadOnlyCollectionOf <Post>(r => r) }; } return(wallGetObject); }
/// <summary> /// Разобрать из json. /// </summary> /// <param name="response">Ответ сервера.</param> /// <returns></returns> internal static WallGetObject FromJson(VkResponse response) { var wallGetObject = new WallGetObject { TotalCount = response["count"], WallPosts = response["items"].ToReadOnlyCollectionOf <Post>(r => r), Profiles = response["profiles"].ToReadOnlyCollectionOf <User>(r => r), Groups = response["groups"].ToReadOnlyCollectionOf <Group>(r => r) }; return(wallGetObject); }
/// <summary> /// Разобрать из json. /// </summary> /// <param name="response">Ответ сервера.</param> /// <returns></returns> internal static WallGetObject FromJson(VkResponse response) { WallGetObject wallGetObject; if (response.ContainsKey("items")) { wallGetObject = new WallGetObject { TotalCount = response["count"], WallPosts = response["items"].ToReadOnlyCollectionOf<Post>(r => r), Profiles = response["profiles"].ToReadOnlyCollectionOf<User>(r => r), Groups = response["groups"].ToReadOnlyCollectionOf<Group>(r => r) }; } else { wallGetObject = new WallGetObject { WallPosts = response.ToReadOnlyCollectionOf<Post>(r => r) }; } return wallGetObject; }
public static Task<List<Post>> FilterPostsAsync(WallGetObject wall, WallLoadParametrs p, long thresholdId = long.MaxValue) { return Task.Run(() => { return FilterPosts(wall, p, thresholdId); }); }
/// <summary> /// Выделить из полученных записей те, что удовлетворяют условиям /// </summary> /// <param name="wall">Стена с записями</param> /// <param name="thresholdId">Верхняя граница, до которой записи уже были загружены</param> /// <param name="lastDateToLoad">Дата и время, до которого нужно выбрать посты</param> /// <param name="lastPostToLoad">Последний пост, который нужно выбрать</param> /// <returns></returns> public static List<Post> FilterPosts(WallGetObject wall, WallLoadParametrs p, long thresholdId = long.MaxValue) { var posts = wall.WallPosts; if (posts.Count > 0) { int startIndex = 0; int endIndex = posts.Count - 1; if (posts[0].IsPinned.Value) startIndex++; while (startIndex <= endIndex && posts[startIndex].Id >= thresholdId) startIndex++; if (p.LastDateToLoad.HasValue) while (endIndex >= startIndex && posts[endIndex].Date < p.LastDateToLoad.Value) endIndex--; if (p.LastPostToLoad > 0) while (endIndex >= startIndex && posts[endIndex].Id < p.LastPostToLoad) endIndex--; if (startIndex <= endIndex) return posts.Skip(startIndex).Take(endIndex - startIndex + 1).ToList(); } return new List<Post>(); }