public static Poster[] FindPosters(string pathToFolderOfPosterJsons) { var posters = new List <Poster>(); string[] posterJsonPaths = Directory.GetFiles(pathToFolderOfPosterJsons, "*.json"); foreach (string posterJsonPath in posterJsonPaths) { string posterName = Path.GetFileNameWithoutExtension(posterJsonPath); Poster poster = null; if (posterName == "telegram") { string telegramPosterSettingsJson = File.ReadAllText(posterJsonPath); JObject telegramPosterSettings = JsonConvert.DeserializeObject <JObject>(telegramPosterSettingsJson); string accessToken = telegramPosterSettings.GetValue("accessToken").Value <string>(); long chatId = telegramPosterSettings.GetValue("chatId").Value <long>(); poster = new TelegramPoster(accessToken, chatId); posters.Add(poster); } else if (posterName == "vk") { string posterSettingsJson = File.ReadAllText(posterJsonPath); JObject posterSettings = JsonConvert.DeserializeObject <JObject>(posterSettingsJson); string accessToken = posterSettings.GetValue("accessToken").Value <string>(); string clientSecret = posterSettings.GetValue("clientSecret").Value <string>(); ulong appId = posterSettings.GetValue("appId").Value <ulong>(); string login = posterSettings.GetValue("login").Value <string>(); string password = posterSettings.GetValue("password").Value <string>(); poster = new VkPoster(accessToken, appId, clientSecret, login, password); posters.Add(poster); } } return(posters.Where(p => p != null).ToArray()); }
/// <summary> /// Share article via VK /// </summary> /// <param name="msg">comment</param> public void ShareArticle(string msg) { try { if (!string.IsNullOrEmpty(Article) && _currentFeedItem != null) { string response = VkPoster.PostMessage(msg, _currentFeedItem.Link.ToString()); } else { throw new Exception("Choose an article to share"); } } catch { throw new Exception("Error sending post"); } }
private void ShareWebBrowser_Navigated(object sender, NavigationEventArgs e) { VkPoster.GetVkAccess(e.Uri.Fragment.Replace("#", "").Trim()); if (VkAccess.IsAuthorized()) { try { feedViewModel.ShareArticle(_message); Message = "Success"; } catch (Exception ex) { Message = ex.Message; } HideGrid(InputBox); shareWebBrowser.Visibility = Visibility.Hidden; ShowGrid(ResultBox); VkAccess.LogOut(); WebBrowserHelper.SuppressCookiePersistence(); } }
private void SendButton_Click(object sender, RoutedEventArgs e) { _message = InputTextBox.Text; shareWebBrowser.Visibility = Visibility.Visible; shareWebBrowser.Navigate(VkPoster.Authorize()); }