public void WidthTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry); 
     int expected = 5; // TODO: Initialize to an appropriate value
     int actual;
     target.Width = expected;
     actual = target.Width;
     Assert.AreEqual(expected, actual);
 }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>tries to insert a photo using MIME multipart</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void InsertMimePhotoTest()
        {
            Tracing.TraceMsg("Entering InsertMimePhotoTest");

            AlbumQuery query = new AlbumQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);

                PicasaFeed feed = service.Query(query);
                if (feed != null)
                {
                    
                    Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries");
                    Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry");

                    PicasaEntry album = feed.Entries[0] as PicasaEntry;

                    PhotoEntry newPhoto = new PhotoEntry();
                    newPhoto.Title.Text = "this is a title";
                    newPhoto.Summary.Text = "A lovely shot in the ocean";

                    newPhoto.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");

                    Uri postUri = new Uri(album.FeedUri.ToString());

                    PicasaEntry entry = service.Insert(postUri, newPhoto) as PicasaEntry;

                    Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry");

                    entry.Title.Text = "This is a new Title";
                    entry.Summary.Text = "A lovely shot in the shade";
                    entry.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");
                    PicasaEntry updatedEntry = entry.Update() as PicasaEntry;
                    Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry");
                    Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical");
                    Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical");


                }
            }
        }
示例#3
0
        private void UploadPhoto_Click(object sender, System.EventArgs e)
        {
            DialogResult result = openFileDialog.ShowDialog();
 
            if( result == DialogResult.OK )
            {
                string[] files = openFileDialog.FileNames;
                // Open each file and display the image in PictureBox1.
                // Call Application.DoEvents to force a repaint after each
                // file is read.        
                foreach (string file in files )
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
                    System.IO.FileStream fileStream = fileInfo.OpenRead();

                    this.FileInfo.Text = "Starting upload....";
                    PicasaEntry entry = new PhotoEntry();

                    UserState ut = new UserState();
                    ut.opType = UserState.OperationType.upload;
                    this.states.Add(ut);
                    entry.MediaSource = new Google.GData.Client.MediaFileSource(fileStream, file, "image/jpeg");
                    this.picasaService.InsertAsync(new Uri(this.photoFeed.Post), entry, ut);
                }
            }
        }
 public void TimestampTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     ulong expected = 122; // TODO: Initialize to an appropriate value
     ulong actual;
     target.Timestamp = expected;
     actual = target.Timestamp;
     Assert.AreEqual(expected, actual);
 }
 public void VersionTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     string expected = "TestValue"; 
     string actual;
     target.Version = expected;
     actual = target.Version;
     Assert.AreEqual(expected, actual);
 }
 public void CommentingEnabledTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     bool expected = true;
     bool actual;
     target.CommentingEnabled = expected;
     actual = target.CommentingEnabled;
     Assert.AreEqual(expected, actual);
 }
 public void CommentCountTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     uint expected = 12; // TODO: Initialize to an appropriate value
     uint actual;
     target.CommentCount = expected;
     actual = target.CommentCount;
     Assert.AreEqual(expected, actual);
 }
 public void SizeTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     long expected = 12; // TODO: Initialize to an appropriate value
     long actual;
     target.Size = expected;
     actual = target.Size;
     Assert.AreEqual(expected, actual);
 }
 public void LatitudeTest()
 {
     PicasaEntry entry = new PhotoEntry();
     PhotoAccessor target = new PhotoAccessor(entry);
     double expected = 12.5F; // TODO: Initialize to an appropriate value
     double actual;
     target.Latitude = expected;
     actual = target.Latitude;
     Assert.AreEqual(expected, actual);
 }
        /// <summary>
        /// Syncs a local file to an online Picasa Web Album location
        /// </summary>
        /// <param name="sourceFile">The image to sync.</param>
        /// <param name="targetAlbum">The target Picasa Web Album.</param>
        /// <param name="targetAlbumPhotoFeed">The target Picasa Web Album photo feed listing existing photos.</param>
        /// <param name="session">The current authenticated Picasa session.</param>
        private void AddFileToAlbum(FileInfo sourceFile, Album targetAlbum, PicasaFeed targetAlbumPhotoFeed, PicasaService session)
        {
            try
            {
                PicasaEntry existingPhotoEntry = (PicasaEntry)targetAlbumPhotoFeed.Entries.FirstOrDefault(
                    p => p.Title.Text == sourceFile.Name && p.Summary.Text != ENTRY_DELETED_SUMMARY);

                if (existingPhotoEntry != null)
                {
                    WriteOutput(string.Format("Skipping File: {0} (already exists)", sourceFile.Name), true);
                    m_fileSkipCount++;
                }
                else
                {
                    ImageFormat imageFormat;
                    string contentType;
                    bool isImage;
                    bool isVideo;
                    GetFileInfo(sourceFile, out isImage, out isVideo, out imageFormat, out contentType);

                    Stream postResponseStream = null;
                    Stream postFileStream = null;
                    string souceFilePath = sourceFile.FullName;

                    try
                    {
                        if (isVideo && this.ResizeVideos)
                        {
                            WriteOutput(string.Concat("Resizing Video: ", sourceFile.FullName), true);
                            string resizedVideoPath = VideoResizer.ResizeVideo(sourceFile, this.ResizeVideosCommand);
                            //change souceFilePath to resized video file location
                            souceFilePath = resizedVideoPath;
                        }

                        using (Stream sourceFileStream = new FileStream(souceFilePath, FileMode.Open, FileAccess.Read))
                        {
                            postFileStream = sourceFileStream;

                            if (isImage && this.ResizePhotos)
                            {
                                WriteOutput(string.Concat("Resizing Photo: ", sourceFile.FullName), true);
                                postFileStream = ImageResizer.ResizeImage(postFileStream, imageFormat, this.ResizePhotosMaxSize);
                            }

                            WriteOutput(string.Format("Uploading File: {0}", sourceFile.FullName), true);
                            Uri insertPhotoFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername, targetAlbum.Id));

                            PhotoEntry newFileEntry = new PhotoEntry();
                            newFileEntry.Title.Text = sourceFile.Name;
                            newFileEntry.Summary.Text = string.Empty;
                            newFileEntry.MediaSource = new MediaFileSource(postFileStream, sourceFile.Name, contentType);

                            //upload file using multipart request
                            postResponseStream = session.EntrySend(insertPhotoFeedUri, newFileEntry, GDataRequestType.Insert);
                            newFileEntry.MediaSource.GetDataStream().Dispose();
                        }

                        m_fileCreateCount++;

                    }
                    finally
                    {
                        if (postResponseStream != null)
                        {
                            postResponseStream.Dispose();
                        }

                        if (postFileStream != null)
                        {
                            postFileStream.Dispose();
                        }
                    }

                    if (isVideo && this.ResizeVideos)
                    {
                        //video was resized and souceFilePath should be temp/resized video path
                        try
                        {
                            File.Delete(souceFilePath);
                        }
                        catch (Exception ex)
                        {
                            WriteOutput(string.Format("Error Deleting Resized Video: {0} (Error - {1})", sourceFile.FullName, ex.Message), true);
                        }
                    }
                }
            }
            catch (GDataRequestException gdex)
            {
                WriteOutput(string.Format("Skipping File: {0} (Error - {1})", sourceFile.Name, gdex.ResponseString), true);
                m_errorsCount++;
            }
            catch (Exception ex)
            {
                WriteOutput(string.Format("Skipping File: {0} (Error - {1})", sourceFile.Name, ex), true);
                m_errorsCount++;
            }
        }
示例#11
0
        public void UploadFile(Stream file, string title, string mimeType)
        {
            if (String.IsNullOrEmpty(mimeType))
                throw new ArgumentException("mimeType is null or empty.", "mimeType");
            if (String.IsNullOrEmpty(title))
                throw new ArgumentException("title is null or empty.", "title");
            if (file == null)
                throw new ArgumentNullException("file", "file is null.");

            PhotoEntry entry = new PhotoEntry();
            entry.Title = new AtomTextConstruct(AtomTextConstructElementType.Title, title);
            MediaFileSource fileSource = new MediaFileSource(file, title, mimeType);
            entry.MediaSource = fileSource;

            _picasaService.Insert(new Uri(PhotoQuery.CreatePicasaUri(_picasaService.Credentials.Username, Id)),
                           entry);
        }
示例#12
0
        public void UploadPhoto(Site e, IEnumerable<HttpPostedFileBase> files, string[] noteList)
        {
            if (files == null
                || files.Count() == 0
                || files.Where(r => r != null).Count() == 0)
            {
                return;
            }

            PicasaService service = InitPicasaService();

            if (string.IsNullOrEmpty(e.AlbumUrl))
            {
                e.AlbumUrl = CreateAlbum(e.ID.ToString());
            }

            Uri postUri = new Uri(e.AlbumUrl.Replace("entry", "feed"));

            for (int i = 0; i < files.Count(); i++)
            {
                var item = files.ElementAt(i);

                if (item != null)
                {
                    DateTime? takenDate = GetMetadata_TakenDate(item);

                    MemoryStream mStream = new MemoryStream();

                    item.InputStream.Position = 0;
                    item.InputStream.CopyTo(mStream);
                    mStream.Position = 0;

                    //PicasaEntry entry = (PicasaEntry)service.Insert(postUri, mStream, "image/jpeg", "");
                    //PicasaEntry entry = (PicasaEntry)service.Insert(postUri, item.InputStream, "image/jpeg", "");
                    //photoUriList.Add(entry.Media.Content.Url);

                    PicasaEntry entry = new PhotoEntry();
                    entry.MediaSource = new Google.GData.Client.MediaFileSource(mStream, Path.GetFileName(item.FileName), "image/jpeg");
                    entry.Title = new AtomTextConstruct(AtomTextConstructElementType.Title, noteList[i]);
                    entry.Summary = new AtomTextConstruct(AtomTextConstructElementType.Summary, noteList[i]);

                    //service.InsertAsync(postUri, entry, new { SiteID = e.ID, AM = asyncManager });
                    PicasaEntry createdEntry = service.Insert(postUri, entry);

                    if (createdEntry != null)
                    {
                        SitePhoto photo = new SitePhoto();

                        photo.Url = createdEntry.Media.Content.Url;
                        photo.AtomUrl = createdEntry.EditUri.Content;
                        photo.TakenDate = takenDate;
                        photo.Note = noteList[i];
                        e.SitePhotoes.Add(photo);
                    }
                }
            }
        }
示例#13
0
        public void UploadPhotoToBackupAlbum(SiteMonitoring e, Stream stream)
        {
            PicasaService service = InitPicasaService();

            if (string.IsNullOrEmpty(e.BackupAlbumUrl))
            {
                e.BackupAlbumUrl = CreateAlbum("M" + e.ID.ToString(), true);
            }

            Uri postUri = new Uri(e.BackupAlbumUrl.Replace("entry", "feed"));

            stream.Position = 0;

            PicasaEntry entry = new PhotoEntry();
            entry.MediaSource = new Google.GData.Client.MediaFileSource(stream, "backup", "image/jpeg");

            PicasaEntry createdEntry = service.Insert(postUri, entry);
        }
 public void PhotoEntryConstructorTest()
 {
     PhotoEntry target = new PhotoEntry();
     Assert.IsNotNull(target);
 }