private static Album TestAlbum(MyUser user) { Console.WriteLine("Test the album functions: "); Album myAlbumTitleOnly = null; try { // Create an album only with title (if the category isn't specified, the default one is "Other") myAlbumTitleOnly = user.CreateAlbum("TestAlbumTitleOnly"); Console.WriteLine("Created album {0}", myAlbumTitleOnly.Title); } catch (Exception e) { Console.WriteLine(e); } // Get all the albums from the site try { List <Album> myAlbumList = user.GetAlbums(true); foreach (var x in myAlbumList) { Console.WriteLine("{0}-{1}-{2}", x.Title, x.Category, (x.SubCategory == null) ? "None" : x.SubCategory.Name); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Get info for an album from the site and return it in a new album (here I use the same object) try { var testAlbum = myAlbumTitleOnly.GetInfo(); Console.WriteLine(testAlbum.Protected); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Populate the current album with info from the site try { myAlbumTitleOnly.PopulateAlbumWithInfoFromSite(); Console.WriteLine(myAlbumTitleOnly.Protected); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Change the settings for an album try { Console.WriteLine(myAlbumTitleOnly.Protected); myAlbumTitleOnly.Protected = true; myAlbumTitleOnly.ChangeSettings(); myAlbumTitleOnly.PopulateAlbumWithInfoFromSite(); Console.WriteLine(myAlbumTitleOnly.Protected); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Comments try { myAlbumTitleOnly.AddComment("Comment for album"); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Comments try { myAlbumTitleOnly.GetComments(); if ((myAlbumTitleOnly.CommentsList != null) && (myAlbumTitleOnly.CommentsList.Count > 0)) { Console.WriteLine(myAlbumTitleOnly.CommentsList[0].Text); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Upload piture to the album from an URL try { myAlbumTitleOnly.UploadImageFromURL("http://www.socialseo.com/files/images/best-free.jpg"); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Upload pictures to the album try { var up = myAlbumTitleOnly.CreateUploader(); up.UploadCompleted += new EventHandler <UploadEventArgs>(img_UploadCompleted); up.UploadProgress += new EventHandler <UploadEventArgs>(img_UploadProgress); Console.Write("Give picture with whole path (eg: " + @"C:\Users\Username\Pictures\IMG_1234.jpg): "); String img1 = "images\\1.jpg"; // Console.ReadLine(); Console.Write("Give picture with whole path (eg: " + @"C:\Users\Username\Pictures\IMG_1234.jpg): "); String img2 = "images\\2.jpg"; //Console.ReadLine(); Console.Write("Give picture with whole path (eg: " + @"C:\Users\Username\Pictures\IMG_1234.jpg): "); String img3 = "images\\3.jpg"; //Console.ReadLine(); up.UploadImage(img1); up.UploadImage(img2); up.UploadImage(img3); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Resort the album try { Console.WriteLine("Images before the sort"); foreach (var x in myAlbumTitleOnly.GetImages(true)) { Console.WriteLine("{0} - {1}", x.FileName, x.Aperture); } myAlbumTitleOnly.ReSort(By.FileName, Direction.DESC); Console.WriteLine("Images after the sort"); foreach (var x in myAlbumTitleOnly.GetImages(true)) { Console.WriteLine("{0} - {1}", x.FileName, x.Aperture); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); TestImage(user, myAlbumTitleOnly); return(myAlbumTitleOnly); }
private static void TestImage(MyUser user) { string image = "images\\1.jpg"; Album album = null; try { album = user.CreateAlbum("TestImageAlbum"); var imageUploader = album.CreateUploader(); try { System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource(); cts.CancelAfter(1000); imageUploader.UploadProgress += img_UploadProgress; imageUploader.UploadImageAsync(image, cts.Token).Wait(); Debug.Fail("Upload should have been cancelled."); } catch (AggregateException) { Console.WriteLine("Upload canceled --- OK!"); } finally { imageUploader.UploadProgress -= img_UploadProgress; } Console.WriteLine("Re-uploading the image."); var img = imageUploader.UploadImage(image); Console.WriteLine("Image uploaded."); var c1 = img.AddComment("Test comment - no rating"); var c2 = img.AddComment("Test comment - rating 1", 1); img.GetComments(); Debug.Assert(img.Comments.Count == 2); // Watermark var watermark1 = img.CreateWatermark("Watermark 1"); var watermark1_site = user.GetWatermarks().Where((w) => w.Name == "Watermark 1").FirstOrDefault(); Debug.Assert(watermark1_site.id == watermark1.id); watermark1.Delete(); watermark1_site = user.GetWatermarks().Where((w) => w.Name == "Watermark 1").FirstOrDefault(); Debug.Assert(watermark1_site == null); // Printmark var printmark1 = img.CreatePrintmark("Printmark 1"); var printmark1_site = user.GetPrintmarks().Where((w) => w.Name == "Printmark 1").FirstOrDefault(); Debug.Assert(printmark1_site.id == printmark1.id); printmark1.Delete(); } finally { if (album != null) { album.Delete(); } } }