private void tsmiPublicate_ClickAsync(object sender, EventArgs e) { VkPublicationDTO publication = (VkPublicationDTO)dgvPosts.SelectedRows[0].Tag; TelegramPublicationDTO telegramPost = PublicationCreator.CreateTelegramPublication(publication); if (telegramPost == null) { MessageBox.Show("Ошибка публикации."); return; } else if (telegramPost.Error.Length > 0) { MessageBox.Show(telegramPost.Error); return; } else if (telegramPost.CanPublicate == false) { MessageBox.Show("Публикация отклонена. Не соответствует фильтру."); return; } bool ExistsImage = false; if (telegramPost.PhotoUrl != null && telegramPost.PhotoUrl != string.Empty) { ExistsImage = true; } TelegramAPI.SendPublicationAsync(telegramPost, ExistsImage); }
private void AddRow(VkPublicationDTO publication, bool IsPublicated = false) { dgvPosts.Invoke(new MethodInvoker(() => { int NewRowIndex = dgvPosts.Rows.Add(); DataGridViewRow pRow = dgvPosts.Rows[NewRowIndex]; pRow.Tag = publication; pRow.Cells["colGroupName"].Value = publication.Group.Name; pRow.Cells["colCreated"].Value = publication.Created; pRow.Cells["colType"].Value = publication.PostType + (publication.IsRepost ? " (Repost)" : string.Empty); pRow.Cells["colGroupLink"].Value = publication.Group.URL; pRow.Cells["colPublicationLink"].Value = publication.PostLink; pRow.Cells["colLikes"].Value = publication.Likes; pRow.Cells["colReposts"].Value = publication.Reposts; pRow.Cells["colComments"].Value = publication.Comments; pRow.Cells["colViews"].Value = publication.Views; pRow.Cells["colLikesCTR"].Value = Math.Round(publication.Likes / publication.Views, 4, MidpointRounding.ToEven) + "%"; pRow.Cells["colPinned"].Value = Converters.BoolToText(publication.IsPinned); pRow.Cells["colMarkedAsAds"].Value = Converters.BoolToText(publication.MarkedAsAds); pRow.Cells["colExistsAttachments"].Value = Converters.BoolToText(publication.ExistsAttachments); pRow.Cells["colExistsSigner"].Value = Converters.BoolToText(publication.ExistsSigner); pRow.Cells["colSignerLink"].Value = publication.SignerLink; pRow.Cells["colLinks"].Value = string.Join(" ", publication.Links); pRow.Cells["colExistsLinks"].Value = Converters.BoolToText(publication.ExistsLinks); pRow.Cells["colIsPublicated"].Value = Converters.BoolToText(IsPublicated); })); }
private void tsmiShowImages_Click(object sender, EventArgs e) { VkPublicationDTO publication = (VkPublicationDTO)dgvPosts.SelectedRows[0].Tag; frmImages imagesPanel = new frmImages(); imagesPanel.AddImageRange(publication.ImageLinks.ToArray()); imagesPanel.Show(this); }
public static List <VkPublicationDTO> GetWallPosts(GroupDTO Group, int quantity, int offset, string AccessToken, WebProxy proxy = null) { List <VkPublicationDTO> posts = new List <VkPublicationDTO>(); WebData https = new WebData(proxy); string method = "wall.get"; int RequstedQuantity = quantity > 100 ? 100 : quantity; NameValueCollection vkParams = new NameValueCollection { { "access_token", AccessToken }, { "v", "5.103" }, { "domain", Group.ScreenName }, { "count", RequstedQuantity.ToString() }, { "filter", "owner" } }; if (offset > 0) { vkParams.Add("offset", offset.ToString()); } HttpResponse response = https.POST(ApiPage + method, vkParams); if (response == null) { return(null); } JObject JsonObject = JObject.Parse(response.Content); if (JsonObject.TryGetValue("response", out JToken JsonResponse) == false) { if (JsonObject.TryGetValue("error", out JToken JsonError)) { string errorCode = JsonError["error_code"].ToString(); string errorMessage = JsonError["error_msg"].ToString(); MessageBox.Show($"Ошибка {errorCode}\r\n{errorMessage}"); } else { MessageBox.Show("Неизвестная ошибка!"); } return(null); } JToken JOItems = JsonResponse["items"]; foreach (JObject item in JOItems) { VkPublicationDTO publication = new VkPublicationDTO(); //string postLink = "https://vk.com/" + domain + "?w=wall" + item["from_id"] + "_" + item["id"] + "/all"; string postLink = Group.URL + "?w=wall" + item["from_id"] + "_" + item["id"] + "/all"; publication.Group = Group; publication.Id = item["id"].ToString(); publication.Created = Converters.UnixTimeToDateTime(long.Parse(item["date"].ToString())); publication.PostType = item["post_type"].ToString(); publication.PostLink = postLink; publication.Text = item["text"].ToString(); if (item.TryGetValue("copy_history", out JToken JsonCopyHistory)) { publication.IsRepost = true; } if (item.TryGetValue("is_pinned", out JToken JsonIsPinned)) { publication.IsPinned = Converters.StringBitToBool(JsonIsPinned.Value <string>()); } if (item.TryGetValue("marked_as_ads", out JToken JsonMarkedAsAds)) { publication.MarkedAsAds = Converters.StringBitToBool(JsonMarkedAsAds.Value <string>()); } if (item.TryGetValue("signer_id", out JToken JsonSignerId)) { publication.ExistsSigner = true; publication.SignerLink = "https://vk.com/id" + JsonSignerId.Value <string>(); } publication.Comments = decimal.Parse(item["comments"]["count"].ToString()); publication.Likes = decimal.Parse(item["likes"]["count"].ToString()); publication.Reposts = decimal.Parse(item["reposts"]["count"].ToString()); publication.Views = decimal.Parse(item["views"]["count"].ToString()); string[] paragraphs = Regex.Split(publication.Text, "\n"); foreach (string paragraph in paragraphs) { if (paragraph.Contains("http")) { string[] words = Regex.Split(paragraph, " "); foreach (string word in words) { string link = Regex.Match(word, "http([^(]*)").Groups[0].Value; if (string.IsNullOrEmpty(link) == false) { publication.Links.Add(link); } } } } publication.ExistsLinks = publication.Links.Count > 0; publication.ExistsAttachments = item.TryGetValue("attachments", out JToken JsonAttachments); if (publication.ExistsAttachments) { // JsonAttachments foreach (JToken attachment in JsonAttachments) { if (attachment["type"].ToString().Equals("photo") == false) { continue; } if (publication.ExistsImages == false) { publication.ExistsImages = true; } JToken photo = attachment["photo"]["sizes"].Last; publication.ImageLinks.Add(photo["url"].ToString()); } } posts.Add(publication); } return(posts); }
private void tsmiShowPostText_Click(object sender, EventArgs e) { VkPublicationDTO publication = (VkPublicationDTO)dgvPosts.SelectedRows[0].Tag; MessageBox.Show(publication.Text, "Содержимое записи"); }