internal static Post FromJson(VkResponse response) { var post = new Post(); long? postId = Utilities.GetNullableLongId(response["id"]); if (postId == null) return null; post.Id = response["id"]; post.OwnerId = response["owner_id"]; post.FromId = response["from_id"]; post.Date = response["date"]; post.Text = response["text"]; post.ReplyOwnerId = response["reply_owner_id"]; post.ReplyPostId = response["reply_post_id"]; post.FriendsOnly = response["friends_only"]; post.Comments = response["comments"]; post.Likes = response["likes"]; post.Reposts = response["reposts"]; post.PostType = response["post_type"]; post.PostSource = response["post_source"]; post.Attachments = response["attachments"]; post.Geo = response["geo"]; post.SignerId = response["signer_id"]; post.CopyPostDate = response["copy_post_date"]; post.CopyPostType = response["copy_post_type"]; post.CopyOwnerId = response["copy_owner_id"]; post.CopyPostId = response["copy_post_id"]; post.CopyText = response["copy_text"]; post.CopyHistory = response["copy_history"]; // далее идут поля, установленные экcпериментальным путем post.CopyCommenterId = response["copy_commenter_id"]; post.CopyCommentId = response["copy_comment_id"]; post.CanDelete = response["can_delete"]; post.CanEdit = response["can_edit"]; return post; }
private void postThis(Post best) { IList<MediaAttachment> mediaAttachments = new List<MediaAttachment>(); foreach (Attachment att in best.Attachments) { if (att.Instance is MediaAttachment) { MediaAttachment medAtt = (MediaAttachment)att.Instance; if (att.Type == typeof(Photo)) { UploadServerInfo info = vk.Photo.GetWallUploadServer(_group.Id); NameValueCollection nvc = new NameValueCollection(); Dictionary<string, string> response = new Dictionary<string, string>(); using (WebClient client = new WebClient()) { byte[] downloaded = client.DownloadData(((Photo)medAtt).Photo604); var values = new NameValueCollection(); values["photo"] = Convert.ToBase64String(downloaded); string s = HttpUploadFile(info.UploadUrl.ToString(), downloaded, "photo", "image/jpeg", nvc); response = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(s); } Photo ph = null; ph = vk.Photo.SaveWallPhoto(response["photo"], null, _group.Id, int.Parse(response["server"]), response["hash"])[0]; mediaAttachments.Add(ph); } else { mediaAttachments.Add(medAtt); } } } long id = vk.Wall.Post(-_group.Id, false, true, best.Text, mediaAttachments, null, null, false, null, null, null, null, null); logger.Info("new post published with id == " + id); }
internal static Post FromJson(VkResponse response) { if (response["id"] == null) { return null; } var post = new Post { Id = response["id"], OwnerId = response["owner_id"], FromId = response["from_id"], Date = response["date"], Text = response["text"], ReplyOwnerId = response["reply_owner_id"], ReplyPostId = response["reply_post_id"], FriendsOnly = response["friends_only"], Comments = response["comments"], Likes = response["likes"], Reposts = response["reposts"], PostType = response["post_type"], PostSource = response["post_source"], Attachments = response["attachments"].ToReadOnlyCollectionOf<Attachment>(x => x), Geo = response["geo"], SignerId = response["signer_id"], CopyPostDate = response["copy_post_date"], CopyPostType = response["copy_post_type"], CopyOwnerId = response["copy_owner_id"], CopyPostId = response["copy_post_id"], CopyText = response["copy_text"], CopyHistory = response["copy_history"], IsPinned = response["is_pinned"], CreatedBy = response["created_by"], CopyCommenterId = response["copy_commenter_id"], CopyCommentId = response["copy_comment_id"], CanDelete = response["can_delete"], CanEdit = response["can_edit"], CanPin = response["can_pin"] }; return post; }
private double getKef(Post post) { int members = (int)_group.MembersCount; return (float)(post.Reposts.Count * 2 + post.Likes.Count) / ((float)members * (DateTime.Now - (DateTime)post.Date).Minutes); }