Exemplo n.º 1
0
        private static void TestImage(MyUser user, Album myAlbumTitleOnly)
        {
            // Get all the images from the current album
            List <Image> myImageList  = new List <Image>();
            Watermark    myWatermark1 = null;
            Watermark    myWatermark2 = null;
            Image        myImage2     = null;
            Image        myImage3     = null;

            try
            {
                myImageList = myAlbumTitleOnly.GetImages(true);
                foreach (var x in myImageList)
                {
                    Console.WriteLine("{0} - {1}", x.FileName, x.Date);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Comments
            try
            {
                myImageList[0].AddComment("Comment on image");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();



            Console.WriteLine("Test the image functions:");

            try
            {
                Image myImage = myImageList[0];
                myImage2 = myImageList[1];
                myImage3 = myImageList[2];
                // Change position
                myImage.ChangePosition(2);
                myImageList = myAlbumTitleOnly.GetImages(true);
                foreach (var x in myImageList)
                {
                    Console.WriteLine(x.FileName);
                }
                // Crop the picture
                myImage2.Crop(300, 300, 0, 10);
                // Change settings
                myImage.Caption = "Test image";
                myImage.ChangeSettings();
                Console.WriteLine("The new image caption is: " + myImage.Caption);
                // Get EXIF info from site
                myImage = myImage.GetEXIF();

                var imageWithStats = myImage.GetStats(12, 2011);

                myImage2.PopulateImageWithEXIFFromSite();
                Console.WriteLine("EXIF info: " + myImage.Model);
                Console.WriteLine("EXIF info: " + myImage2.Model);
                // Get info from site
                myImage = myImage.GetInfo();
                myImage2.PopulateImageWithInfoFromSite();
                Console.WriteLine("Info: " + myImage.FileName);
                Console.WriteLine("Info: " + myImage2.FileName);
                // Get the URLs
                myImage = myImage.GetURLs();
                myImage2.PopulateImageWithURLsFromSite();
                Console.WriteLine(myImage2.OriginalURL);
                // Rotate an image
                myImage.Rotate(DegreesEnum.Left, false);
                // Zoom the thumbnail
                myImage3.ZoomThumbnail(100, 100, 1, 1);
                myImage.Delete();
                Console.WriteLine("The remaining pictures after delete: ");
                myImageList = myAlbumTitleOnly.GetImages(true);
                foreach (var x in myImageList)
                {
                    Console.WriteLine(x.FileName);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();


            // Comments
            try
            {
                myImageList[0].GetComments();
                if (myImage2.Comments != null)
                {
                    Console.WriteLine(myImage2.Comments[0].Text);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();


            Console.WriteLine("Test the watermarking functions:");
            // Create a watermark
            try
            {
                myWatermark1 = myImage2.CreateWatermark("TestWatermark1");
                myImage3.ApplyWatermark(myWatermark1);
                myWatermark2 = myImage3.CreateWatermark("TestWatermark2");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Display the existing watermarks
            try
            {
                var myWatermarksList = user.GetWatermarks(true);
                foreach (var x in myWatermarksList)
                {
                    Console.WriteLine(x.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Change settings
            try
            {
                myWatermark1.Name     = "TestWatermarkNameChanged";
                myWatermark1.Dissolve = 50;
                // Get info
                myWatermark1 = myWatermark1.GetInfo();
                Console.WriteLine(myWatermark1.Name);
                myWatermark2.PopulateWatermarkWithInfoFromSite();
                Console.WriteLine(myWatermark2.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                myImage3.RemoveWatermark();
                myWatermark1.Delete();
                myWatermark2.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
        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();
                }
            }
        }