public void ProcessImage(Stream imageStream, PhotoEntry entry)
        {
            var imageName = Guid.NewGuid().ToString();

            this.UploadImageToStorage(imageStream, imageName);
            this.SubmitImageForProcessing(entry.Id, imageName);
        }
        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);
                }
            }
        }
Beispiel #3
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);
                    }
                }
            }
        }
Beispiel #4
0
        private static string GetImageUrlForEntry(PhotoEntry entry, string containerUrl, string suffix)
        {
            if (entry.ImageId == null)
            {
                return("/Content/images/no-image.png");
            }

            return(containerUrl + entry.ImageId + suffix);
        }
        public List <PicasaEntry> UploadPhoto2(IEnumerable <HttpPostedFileBase> files, string[] noteList = null)
        {
            if (files == null ||
                files.Count() == 0 ||
                files.Where(r => r != null).Count() == 0)
            {
                return(null);
            }

            List <PicasaEntry> l = new List <PicasaEntry>();

            Update_AlbumAtomUrl();

            Uri postUri = new Uri(AppSetting.AlbumAtomUrl.Replace("entry", "feed").ToHttpsUri());

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

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

                    float?lng = null;
                    float?lat = null;
                    GetMetadata_GPS(item, out lng, out lat);

                    MemoryStream mStream = new MemoryStream();

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

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

                    try
                    {
                        PicasaEntry createdEntry = PicasaService.Insert(postUri, entry);
                        l.Add(createdEntry);
                    }
                    catch (Exception)
                    {
                        totalPhotos = 0;
                        throw;
                    }
                }
            }

            return(l);
        }
Beispiel #6
0
        public JsonResult Upload(FormCollection collection)
        {
            var model = new PhotoEntry();

            //获取上传文件队列
            var oFile = Request.Files["Filedata"];

            if (oFile != null)
            {
                string topDir = collection["folder"];  // 获取uploadify的folder配置,在此示例中,客户端配置了上传到 Files/ 文件夹
                // 检测并创建目录:当月上传的文件放到以当月命名的文件夹中,例如2011年11月的文件放到网站根目录下的 /Files/201111 里面

                string dateFolder      = Utility.GetUploadBasePath(topDir) + @"/" + DateTime.Now.Date.ToString("yyyyMM");
                string thumbnailFolder = dateFolder + @"/thumbnail";
                if (!Directory.Exists(dateFolder))         // 检测是否存在磁盘目录
                {
                    Directory.CreateDirectory(dateFolder); // 不存在的情况下,创建这个文件目录 例如 C:/wwwroot/Files/201111/
                }
                if (!Directory.Exists(thumbnailFolder))
                {
                    Directory.CreateDirectory(thumbnailFolder);
                }

                // 使用Guid命名文件,确保每次文件名不会重复
                string guidFileName = Guid.NewGuid() + Path.GetExtension(oFile.FileName).ToLower();
                // 保存文件,注意这个可是完整路径,例如C:/wwwroot/Files/201111/92b2ce5b-88af-405e-8262-d04b552f48cf.jpg
                var originalPath = dateFolder + @"/" + guidFileName;
                oFile.SaveAs(originalPath);

                var original = new DirectoryInfo(originalPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //////// TODO 在此,您可以添加自己的业务逻辑,比如保存这个文件信息到数据库
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                var thumbnailPath = thumbnailFolder + @"/" + guidFileName;

                using (var file = System.IO.File.OpenRead(originalPath))
                {
                    PhotoUtils.CutForCustom(file, thumbnailPath, 380, 252, 50);
                }

                string thumbnail = new DirectoryInfo(thumbnailPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                var    newsId    = DataCast.Get <int>(collection["NewsId"]);


                model.Description = "请添加描述";
                model.NewsId      = newsId;
                model.Original    = @"~\" + original;
                model.Thumbnail   = @"~\" + thumbnail;
                _photo.Add(model);
            }

            return(Json(model));
        }
Beispiel #7
0
        private PhotoEntryViewModel PhotoEntryViewModelFromEntity(PhotoEntry entity, string imageContainerUrl)
        {
            var viewModel = new PhotoEntryViewModel()
            {
                Description = entity.Description,
                Id          = entity.Id,
                Title       = entity.Title,
                ImageUrl    = GetImageUrlForEntry(entity, imageContainerUrl, ".jpg"),
            };

            return(viewModel);
        }
        public PhotoEntryViewModel(PhotoEntry entry, int index)
        {
            _entry = entry;
            Index  = index + 1;

            CreateThumbnailImage();

            ExportCommand = new RelayCommand(o =>
            {
                var fd             = FileDialog.Factory(Window, FileDialog.Behavior.Save, ("Jpeg image", "jpg"));
                fd.DefaultFileName = $"Kingdom Hearts III - Photo {Index}.jpg";

                if (fd.ShowDialog() == true)
                {
                    try
                    {
                        Export(fd.FileName);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(Window, $"Unable to export the photo due to the following error:\n{e.Message}", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
            }, x => true);

            ImportCommand = new RelayCommand(o =>
            {
                var fd             = FileDialog.Factory(Window, FileDialog.Behavior.Open, ("Jpeg image", "jpg"));
                fd.DefaultFileName = $"Kingdom Hearts III - Photo {Index}.jpg";

                if (fd.ShowDialog() == true)
                {
                    try
                    {
                        Import(fd.FileName);
                    }
                    catch (ImageTooLargeException e)
                    {
                        MessageBox.Show(Window, e.Message, "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(Window, $"Unable to import the photo due to the following error:\n{e.Message}", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
            }, x => true);
        }
Beispiel #9
0
        public JsonResult EditPhoto(PhotoEntry model)
        {
            var i = _photo.Update(model);

            if (i > 0)
            {
                return(Json(model));
            }
            else
            {
                model = _photo.GetById(model.PhotoId);
                return(Json(model));
            }
        }
Beispiel #10
0
        private IEnumerable <PhotoEntry> GetEntries()
        {
            var table   = this.GetEntriesTable();
            var query   = new TableQuery <PhotoEntryTableEntity>();
            var entries = new List <PhotoEntry>();

            foreach (PhotoEntryTableEntity entity in table.ExecuteQuery(query))
            {
                var entry = new PhotoEntry(entity.RowKey, entity.Title, entity.Description, entity.PublishedOn);
                entry.SetImage(entity.ImageId);

                entries.Add(entry);
            }

            return(entries);
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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");
                }
            }
        }
        public PhotoEntryViewModel(PhotoEntry entry, int index)
        {
            _entry = entry;
            Index  = index + 1;

            CreateThumbnailImage();

            ExportCommand = new RelayCommand(o =>
            {
                FileDialog.OnSave(fileName =>
                {
                    try
                    {
                        Export(fileName);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(Window, $"Unable to export the photo due to the following error:\n{e.Message}", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }, Filters, $"Kingdom Hearts III - Photo {Index}.jpg", Window);
            }, x => true);

            ImportCommand = new RelayCommand(o =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    try
                    {
                        Import(fileName);
                    }
                    catch (ImageTooLargeException e)
                    {
                        MessageBox.Show(Window, e.Message, "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(Window, $"Unable to import the photo due to the following error:\n{e.Message}", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }, Filters, $"Kingdom Hearts III - Photo {Index}.jpg", Window);
            }, x => true);
        }
Beispiel #13
0
        public void UploadPhotoToBackupAlbum(Site e, Stream stream)
        {
            PicasaService service = InitPicasaService();

            if (string.IsNullOrEmpty(e.BackupAlbumUrl))
            {
                e.BackupAlbumUrl = CreateAlbum(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);
        }
Beispiel #14
0
        public void UploadPhotoTo(string albumId, string filename)
        {
            var service = new PicasaService("GPhotoSync");

            service.SetAuthenticationToken(_credentials.AccessToken);

            var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(_credentials.User, albumId));
            var feed  = service.Query(query);

            var media = new MediaFileSource(filename, MimeTypes.GetMimeType(Path.GetExtension(filename)));
            var photo = new PhotoEntry();

            photo.Title = new AtomTextConstruct {
                Text = Path.GetFileNameWithoutExtension(filename)
            };
            photo.MediaSource = media;

            service.Insert(feed, photo);
        }
Beispiel #15
0
        public ActionResult SubmitPost(SubmitPhotoEntryViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var entryService = new PhotoEntryService(this.Server);
            var newEntry     = PhotoEntry.New(model.PhotoTitle, model.PhotoDescription);

            entryService.SaveNewEntry(newEntry);

            if (model.Image != null)
            {
                var imageService = new ImageProcessingService(this.Server);
                imageService.ProcessImage(model.Image.InputStream, newEntry);
            }

            return(this.RedirectToAction("Index", "Photos"));
        }
Beispiel #16
0
 public JsonResult EditPhoto(PhotoEntry model)
 {
     var i = _photo.Update(model);
     if (i > 0)
     {
         return Json(model);
     }
     else
     {
         model = _photo.GetById(model.PhotoId);
         return Json(model);
     }
 }
Beispiel #17
0
        public JsonResult Upload(FormCollection collection)
        {
            var model = new PhotoEntry();

            //获取上传文件队列  
            var oFile = Request.Files["Filedata"];
            if (oFile != null)
            {
                string topDir = collection["folder"];  // 获取uploadify的folder配置,在此示例中,客户端配置了上传到 Files/ 文件夹
                // 检测并创建目录:当月上传的文件放到以当月命名的文件夹中,例如2011年11月的文件放到网站根目录下的 /Files/201111 里面
                string dateFolder = Utility.GetUploadBasePath(topDir) + "/" + DateTime.Now.Date.ToString("yyyyMM");
                string thumbnailFolder = dateFolder + "/thumbnail";
                if (!Directory.Exists(dateFolder))  // 检测是否存在磁盘目录
                {
                    Directory.CreateDirectory(dateFolder);  // 不存在的情况下,创建这个文件目录 例如 C:/wwwroot/Files/201111/
                }
                if (!Directory.Exists(thumbnailFolder))
                {
                    Directory.CreateDirectory(thumbnailFolder);
                }

                // 使用Guid命名文件,确保每次文件名不会重复
                string guidFileName = Guid.NewGuid() + Path.GetExtension(oFile.FileName).ToLower();
                // 保存文件,注意这个可是完整路径,例如C:/wwwroot/Files/201111/92b2ce5b-88af-405e-8262-d04b552f48cf.jpg
                var originalPath = dateFolder + "/" + guidFileName;
                oFile.SaveAs(originalPath);

                var original = new DirectoryInfo(originalPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //////// TODO 在此,您可以添加自己的业务逻辑,比如保存这个文件信息到数据库
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                var thumbnailPath = thumbnailFolder + "/" + guidFileName;

                using (var file = System.IO.File.OpenRead(originalPath))
                {
                    PhotoUtils.CutForCustom(file, thumbnailPath, 380, 252, 50);
                }

                string thumbnail = new DirectoryInfo(thumbnailPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                var newsId = DataCast.Get<int>(collection["NewsId"]);


                model.Description = "请添加描述";
                model.NewsId = newsId;
                model.Original = @"~\" + original;
                model.Thumbnail = @"~\" + thumbnail;
                _photo.Add(model);
            }

            return Json(model);
        }
Beispiel #18
0
        public void SaveNewEntry(PhotoEntry entry)
        {
            var tableEntity = PhotoEntryTableEntity.FromEntity(entry);

            StoreEntryEntity(tableEntity);
        }
        public void PhotoEntryConstructorTest()
        {
            PhotoEntry target = new PhotoEntry();

            Assert.IsNotNull(target);
        }
        /// <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++;
            }
        }