Exemplo n.º 1
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);
        }