private async void Button_Click_1(object sender, RoutedEventArgs e) { // Remove from favorite await ExClient.RemoveFromFavorite(GalleryViewModel.Gallery.Gid); GalleryViewModel.IsFavorited = false; }
public static async Task <ExFavoriteList> DownloadFavoritesAsync(int pagenumber) { try { // Get page html if (pagenumber == 1) { var htmlStr = await ExClient.GetStringWithExCookie($"http://exhentai.org/favorites.php", "dm_l"); return(ExFavoriteList.FromHtml(htmlStr)); } else { var htmlStr = await ExClient.GetStringWithExCookie($"http://exhentai.org/favorites.php?page= {pagenumber - 1}"); return(ExFavoriteList.FromHtml(htmlStr)); } //return await client.GetStringAsync(uri); } catch (Exception ex) { throw new Exception("Cannot download favorite list"); } }
public static async Task <ExGallery> DownloadGalleryAsync(string link, int pagenumber, uint maxAttempt = 1) { uint attempt = 1; string htmlString = null; while (attempt <= maxAttempt && htmlString == null) { try { // Get page html htmlString = await ExClient.GetStringWithExCookie($"{link}?p={pagenumber - 1}&inline_set=ts_l", "dm_t"); } catch (HttpRequestException ex) { if (attempt == maxAttempt) { // Last attempt throw; } else { attempt++; } } catch (Exception ex) { } } return(GetExGalleryFromHtml(link, htmlString)); }
private async void Button_Click(object sender, RoutedEventArgs e) { // Add to favorite await ExClient.AddToFavorite(GalleryViewModel.Gallery.Gid, GalleryViewModel.Gallery.Token, FavoriteCatalogComboBox.SelectedIndex, FavoriteNoteTextBox.Text); GalleryViewModel.IsFavorited = true; FavoriteButton.Flyout.Hide(); }
private async Task Download(ExGalleryImageListItem image, StorageFile file, BackgroundDownloader downloader) { Debug.WriteLine(image.Link); var htmlSource = await ExClient.GetStringWithExCookie($"{image.Link}"); Uri uri = new Uri(ExImage.GetImageUriFromHtml(htmlSource)); DownloadOperation download = downloader.CreateDownload(uri, file); //Task<DownloadOperation> startTask = download.StartAsync().AsTask(); download.StartAsync(); }
public async Task LoadFromInternetAsync() { try { // Get page html var htmlSource = await ExClient.GetStringWithExCookie($"{this.Link}"); this.ImageSource = GetImageUriFromHtml(htmlSource); } catch (Exception ex) { } }
public static void ClientRetrivesFileListContentsCorrectly() { var credentials = CredentialsProvider.Instance.GetCredentials(); var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var apiClient = new ExClient(); var firstFileId = apiClient.FileList(credentials, 0, 100).Result.Items.First().Id; var fileList = httpClient.GetObjectFileInfosAsync(firstFileId, cookies).Result; fileList.Should().NotBeEmpty(); }
public static async Task <ExGalleryList> DownloadGalleryListAsync(int pagenumber, string uri) { try { // Get page html var htmlStr = await ExClient.GetStringWithExCookie($"{uri}&page={pagenumber}&inline_set=dm_t", $"xl_{ExSettings.Current.xl}"); var e = ExGalleryList.GetExGalleryListFromHtml(htmlStr); e.uri = uri; return(e); } catch (Exception ex) { return(null); } }
public static void Main() { var testFilePath = "..\\..\\..\\sample-content-for-upload.jpg"; var apiClient = new ExClient(); var uploder = new EXUAUploader.Uploader(apiClient); var configurationManager = ConfigurationManager.AppSettings; var login = configurationManager["login"]; var password = configurationManager["password"]; var objectId = long.Parse(configurationManager["test-object-id"]); var fileList = apiClient.FileList(new Credentials(login, password), 0, Int32.MaxValue).Result; uploder.UploadFileAsync(testFilePath, objectId, new Credentials(login, password)).Wait(); }
public async Task PostCommentAsync(string comment) { var requestBody = $"commenttext={WebUtility.UrlEncode(comment)}&postcomment=Post+Comment"; var httpClient = new Windows.Web.Http.HttpClient(new HttpBaseProtocolFilter()); var message = new Windows.Web.Http.HttpRequestMessage( new Windows.Web.Http.HttpMethod("POST"), new Uri(this.Link)) { Content = new HttpStringContent(requestBody) }; message.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"); message.Headers["Cookie"] = await ExClient.GetExCookieAsync(""); var response = await httpClient.SendRequestAsync(message); var responseString = await response.Content.ReadAsStringAsync(); // Handle error page returned from server if (true) // sccuess { // Refresh the commenet list HtmlDocument htmlDocument = new HtmlDocument() { OptionFixNestedTags = true }; htmlDocument.LoadHtml(responseString); this.Comments.Clear(); HtmlNodeCollection commentNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='c1']"); if (commentNodes != null) { foreach (var node in commentNodes) { this.Comments.Add(ExComment.FromNode(node)); } } } }
public static void ClientPerformsFileDownloadCorrectly() { var credentials = CredentialsProvider.Instance.GetCredentials(); var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var apiClient = new ExClient(); var firstFileId = apiClient.FileList(credentials, 0, 100).Result.Items.First().Id; var fileInfo = httpClient.GetObjectFileInfosAsync(72195263, cookies).Result.Last(); //for (int i = 0; i < 10; i++) { // var downloadFirstChunk = httpClient.DownloadFileAsync(fileInfo, cookies: cookies).Result; } }
public static void WhenMultipleFilesAreCreated_TheySHouldBeDeletedProperly() { var credentials = CredentialsProvider.Instance.GetCredentials(); var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var newIdsCollection = new Collection<long>(); for (int i = 0; i < 2; i++) { httpClient.GetNewObjectUriAsync(cookies).ContinueWith(t => { var newId = long.Parse(t.Result.Segments.Last()); newIdsCollection.Add(newId); httpClient.SaveObjectAsync(newId, "Test object #" + i, "Contents #" + i, cookies).Wait(); Debug.WriteLine("Created object #{0}", t.Result); }).Wait(); } var apiClient = new ExClient(); apiClient.FileList(credentials, 0, 100).ContinueWith(t => { t.Result.Items.Select(it => it.Id).Should().Contain(newIdsCollection); }).Wait(); foreach (long id in newIdsCollection) { httpClient.DeleteObjectAsync(id, cookies).Wait(); Debug.WriteLine("Deleted object #{0}", id); } apiClient.FileList(credentials, 0, 100).ContinueWith(t => { t.Result.Items.Select(it => it.Id).Should().NotContain(newIdsCollection); }).Wait(); }
public static async Task <ExFavoriteList> DownloadFavoritesAsync(int pagenumber, ExFavoriteSortingMode sortingMode) { try { // Get page html if (pagenumber == 1) { var htmlStr = await ExClient.GetStringWithExCookie($"https://exhentai.org/favorites.php?inline_set={SORTING_STRING[(int)sortingMode]}-https://exhentai.org/favorites.php?inline_set-dm_e", $""); return(ExFavoriteList.FromHtml(htmlStr, sortingMode)); } else { var htmlStr = await ExClient.GetStringWithExCookie($"https://exhentai.org/favorites.php?page={pagenumber - 1}&inline_set={SORTING_STRING[(int)sortingMode]}-dm_e", $""); return(ExFavoriteList.FromHtml(htmlStr, sortingMode)); } } catch (Exception ex) { throw new Exception("Cannot download favorite list"); } }
static void Main(string[] args) { var credentials = CredentialsProvider.Instance.GetCredentials(); var httpClient = new ExHttpClient(); var cookies = httpClient.GetCookiesAsync(credentials).Result; var apiClient = new ExClient(); var firstFileId = apiClient.FileList(credentials, 0, 100).Result.Items.First().Id; var fileInfo = httpClient.GetObjectFileInfosAsync(92489544, cookies).Result.Last(); // var downloadFirstChunk = httpClient.DownloadFileAsync(fileInfo, cookies: cookies).Result; // var downloadTracker = new DownloadTracker(exBaseAddress: "http://www.ex.ua/"); // var cts = new CancellationTokenSource(); //downloadTracker.StartOrResumeDownload(fileInfo, cts.Token).Wait(); System.Console.ReadKey(); }
private void Button_Click(object sender, RoutedEventArgs e) { ExClient.SignOut(); }