Exemplo n.º 1
0
        private static void TestCategories(MyUser user)
        {
            Console.WriteLine("Test the category and subcategory methods");
            Album myAlbumInCategory = null;

            Category    myCategory           = null;
            SubCategory mySubCategory        = null;
            SubCategory mySubCategoryNew     = null;
            Album       myAlbumInSubCategory = null;
            Album       myAlbumInCategory2   = null;

            try
            {
                // Create a category
                myCategory = user.CreateCategory("TestCategory");
                Console.WriteLine("Created category {0}", myCategory.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            try
            {
                // Create a subcategory in a category
                mySubCategory = myCategory.CreateSubCategory("TestSubCategory");
                Console.WriteLine("Created subcategoy {0} in category {1}", mySubCategory.Name, myCategory.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            try
            {
                // Creating an album in a category
                myAlbumInCategory = myCategory.CreateAlbum("TestAlbumInCategory");
                Console.WriteLine("Created album {0} in category {1}", myAlbumInCategory.Title, myCategory.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            try
            {
                // Creating an album in a subcategory
                myAlbumInSubCategory = mySubCategory.CreateAlbum("TestAlbumInSubCategory");
                Console.WriteLine("Created album {0} in the subcategory {1}", myAlbumInSubCategory.Title, mySubCategory.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            try
            {
                List <Category> myCategoriesList = null;
                // Retrieves a list of categories for the user
                myCategoriesList = user.GetCategories();
                foreach (var x in myCategoriesList)
                {
                    Console.WriteLine(x.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                // Renaming a category
                myCategory.Rename("TestCategoryRenamed");
                Console.WriteLine("TestCategory is renamed to " + myCategory.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            // Create a subcategory within a category
            try
            {
                mySubCategoryNew = myCategory.CreateSubCategory("TestSubCategoryNew");
                Console.WriteLine(mySubCategoryNew.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Get the subcategories for a category
            try
            {
                var mySubCategoriesList = myCategory.GetSubCategories();
                Console.WriteLine(myCategory.Name + " - " + myCategory.SubCategories.Count);
                foreach (var x in mySubCategoriesList)
                {
                    Console.WriteLine(x.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Get all the subcategories that the user has
            try
            {
                var mySubCategoriesListAll = user.GetAllSubCategories();
                foreach (var x in mySubCategoriesListAll)
                {
                    Console.WriteLine(x.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Rename a subcategory
            try
            {
                mySubCategoryNew.Rename("TestSubCategoryNewChangedName");
                Console.WriteLine("TestSubCategoryNew is renamed to " + mySubCategoryNew.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            // Deleting a subcategory
            try
            {
                mySubCategoryNew.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            // Creating an album in a category
            try
            {
                Console.WriteLine(myCategory.Albums.Count);
                myAlbumInCategory2 = myCategory.CreateAlbum("TestAlbumInCategory2");
                Console.WriteLine();
                Console.WriteLine(myCategory.Albums.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                // Deleting that album
                myAlbumInCategory2.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();
            try
            {
                myAlbumInCategory.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                myAlbumInSubCategory.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                myCategory.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();

            try
            {
                mySubCategory.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
        } // RemoveControlCharacters

        static bool CreateAlbum(int idx, string article_uid, string category, DataSet dsImage)
        {
            string message = "";
            bool   sent    = true;
            Album  myAlbum = null;

            try
            {
                Category myCategory = null;
                myCategory = user.FindCategory(category);
                if (myCategory == null)
                {
                    myCategory = user.CreateCategory(category);
                }
                myAlbum = myCategory.CreateAlbum(article_uid);
                var uploader = myAlbum.CreateUploader();

                foreach (DataRow dr in dsImage.Tables[0].Rows)
                {
                    string sourceurl = dr[0].ToString();
                    string caption   = dr[1].ToString();
                    int    bytecount = Convert.ToInt32(dr[2]);
                    caption = RemoveControlCharactersAndExtended(caption);
                    Uri    uri       = new Uri(sourceurl);
                    byte[] byteArray = rc.getFile(uri, ref message);
                    if (byteArray != null)
                    {
                        //if (byteArray.Length > 1024 * 50)
                        //{

                        //    Stream stream = new MemoryStream(byteArray);
                        //    System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
                        //    int thumbSize = 300;
                        //    float percent = DeterminePercentageForResize(thumbSize, image.Width, image.Height);
                        //    int iw = Convert.ToInt32((float)(image.Width * percent));
                        //    int ih = Convert.ToInt32((float)(image.Height * percent));

                        //    System.Drawing.Image thumbnailImage = image.GetThumbnailImage(iw, ih, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
                        //    MemoryStream imageStream = new MemoryStream();
                        //    thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        //    byte[] imageContent = new Byte[imageStream.Length];
                        //    imageStream.Position = 0;
                        //    imageStream.Read(imageContent, 0, (int)imageStream.Length);
                        //    stream.Close();
                        //    stream.Dispose();
                        //    Console.WriteLine("Start Smug {0} {1} {2} ", DateTime.Now, Path.GetFileName(uri.LocalPath), imageStream.Length);
                        //    imageStream.Close();
                        //    imageStream.Dispose();
                        //    uploader.UploadImage(Path.GetFileName(uri.LocalPath), caption, imageContent);
                        //    Console.WriteLine("Complete Smug {0} {1}  ", DateTime.Now, Path.GetFileName(uri.LocalPath));
                        //}
                        //else
                        //{
                        Console.WriteLine("Start Smug {0} {1} {2} ", DateTime.Now, Path.GetFileName(uri.LocalPath), byteArray.Length);
                        uploader.UploadImage(Path.GetFileName(uri.LocalPath), caption, byteArray);
                        Console.WriteLine("Complete Smug {0} {1}  ", DateTime.Now, Path.GetFileName(uri.LocalPath));

                        // }
                    }



                    // myAlbum.UploadImageFromURL(sourceurl, 0, bytecount, caption, "", "", 0, 0, "");
                } // foreach


                Album  myAlbumInfo = myAlbum.GetInfo();
                int    albumId     = (int)myAlbumInfo.id;
                string albumKey    = myAlbumInfo.Key;
                DataMine.spExecute("LoadSmugGallery", ref message, "@article_uid", article_uid, "@AlbumId", albumId, "@AlbumKey", albumKey);
                if (message.Length > 0)
                {
                    writetolog(string.Format("article uid: {0} {1}", article_uid, message));
                }
                else
                {
                    Console.WriteLine("{0} row: {1} article: {2} id: {3} key: {4}", DateTime.Now, idx, article_uid, albumId, albumKey);
                }
            }
            catch (SmugMugException sme)
            {
                sent = false;
                Console.WriteLine("Smug mug exception {0} {1} ", sme.Message, article_uid);
            }
            catch (WebException ex)
            {
                sent = false;
                Console.WriteLine("smug mug webexception {0}", ex.Message, article_uid);
            }
            catch (Exception ex2) {
                sent = false;
                Console.WriteLine("exception {0}", ex2.Message);
            }
            finally
            {
                if (sent == false && myAlbum != null)
                {
                    myAlbum.Delete();
                }
            }
            return(sent);
        }