示例#1
0
        public void on_Click(object sender, DirectEventArgs e)
        {
            if (Session["service"] != null && Session["user"] != null)
            {
                //String name = ComboBox1.SelectedItem.Value;

                string path = this.FileUploadField1.FileName;
                path = Server.MapPath(path);

                User u       = Session["user"] as User;
                Uri  postUri = new Uri(PicasaQuery.CreatePicasaUri("diegoturciostc", "5680246730142935889"));

                System.IO.Stream fileInfo = this.FileUploadField1.PostedFile.InputStream;
                int buffer = 1024 * 1024;
                System.IO.FileStream filestream = null;//new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                filestream = System.IO.File.Create(path);

                filestream.SetLength(fileInfo.Length);
                int    bytesRead = -1;
                byte[] bytes     = new byte[buffer];
                while ((bytesRead = fileInfo.Read(bytes, 0, buffer)) > 0)
                {
                    filestream.Write(bytes, 0, bytesRead);
                }
                PicasaService tmp = Session["service"] as PicasaService;

                PicasaEntry entry = (PicasaEntry)tmp.Insert(postUri, filestream, "image/jpeg", path);
                filestream.Close();

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    string[] filePaths = Directory.GetFiles(@"C:\WeddApp\upload");
                    DateTime current   = new DateTime();
                    for (int i = 0; i < filePaths.Length; i++)
                    {
                        PicasaService myPicasa = new PicasaService("Vikash-Test-Picasa");
                        //Passing GMail credentials(EmailID and Password)
                        myPicasa.setUserCredentials("*****@*****.**", "0542686874");

                        //User ID and AlbumID has been used to create new URL
                        Uri newURI = new Uri(PicasaQuery.CreatePicasaUri("hagit.oded", "5780002529047522017"));

                        //Image path which we are uploading
                        current = DateTime.Now;
                        System.IO.FileInfo   newFile   = new System.IO.FileInfo(filePaths[i]);
                        System.IO.FileStream neFStream = newFile.OpenRead();
                        PicasaEntry          newEntry  = (PicasaEntry)myPicasa.Insert(newURI, neFStream, "Image/jpeg", Convert.ToString(current));
                        Console.Out.WriteLine("Image " + newFile.Name + " uploaded");
                        neFStream.Close();
                        File.Delete(filePaths[i]);
                    }
                    Thread.Sleep(ts);
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine(ex.Message);
                    System.Diagnostics.EventLog.WriteEntry("WeddApp", ex.Message, System.Diagnostics.EventLogEntryType.Error, 626);
                }
            }
        }
示例#3
0
        public static DiscretePicasaAlbum DecodeGoogleAlbumName(PicasaEntry picasaAlbum)
        {
            string input = picasaAlbum.Title.Text;
            Regex  regex;
            Match  match;

            regex = new Regex(@"\[([^\]]+)\] \(([0-9]+)\)");
            match = regex.Match(input);
            if (match.Success)
            {
                string albumName  = match.Groups [1].Value;
                int    albumIndex = int.Parse(match.Groups [2].Value);
                return(new DiscretePicasaAlbum(entry: picasaAlbum, name: albumName, index: albumIndex));
            }

            regex = new Regex(@"\[([^\]]+)\]");
            match = regex.Match(input);
            if (match.Success)
            {
                string    albumName  = match.Groups [1].Value;
                const int albumIndex = 1;
                return(new DiscretePicasaAlbum(entry: picasaAlbum, name: albumName, index: albumIndex));
            }

            if (input == SPECIAL_ALBUM_AUTO_BACKUP || input.StartsWith(SPECIAL_ALBUM_HANGOUT))
            {
                string    albumName  = input;
                const int albumIndex = 1;
                return(new DiscretePicasaAlbum(entry: picasaAlbum, name: albumName, index: albumIndex));
            }

            return(null);
        }
示例#4
0
 private void setSelection(PicasaEntry entry)
 {
     if (entry != null)
     {
         this.Cursor = Cursors.WaitCursor;
         MediaThumbnail thumb = entry.Media.Thumbnails[0];
         try
         {
             Stream stream = this.picasaService.Query(new Uri(thumb.Attributes["url"] as string));
             this.AlbumPicture.Image = new Bitmap(stream);
         }
         catch
         {
             Icon error = new Icon(SystemIcons.Exclamation, 40, 40);
             this.AlbumPicture.Image = error.ToBitmap();
         }
         Album a = new Album();
         a.AtomEntry = entry;
         this.AlbumInspector.SelectedObject = a;
         this.Cursor = Cursors.Default;
     }
     else
     {
         this.AlbumPicture.Image            = null;
         this.AlbumInspector.SelectedObject = null;
     }
 }
示例#5
0
        private void DownloadPhotoDetails(PicasaEntry entry, PicasaService service, string destinationFolder)
        {
            if (!Directory.Exists(destinationFolder))
            {
                Directory.CreateDirectory(destinationFolder);
            }

            string destinationFilePath = Path.Combine(destinationFolder, Utils.ScrubStringForFileSystem(entry.Title.Text));
            string url = entry.Media.Contents.First().Url;

            this.OnBeforeDownloadingEvent.Invoke(entry.Title.Text, url);

            if (File.Exists(destinationFilePath))
            {
                Console.WriteLine("\tSkipping {0}", entry.Title.Text);
            }
            else
            {
                Console.Write("\tDownloading {0}", entry.Title.Text);

                WebClient webClient = new WebClient();

                webClient.DownloadFile(url, destinationFilePath);
                Console.WriteLine(" [Done]");
            }

            OnAfterDownloadCompleteEvent.Invoke(entry.Title.Text, destinationFilePath);
        }
示例#6
0
    public string uploadImageToGoogle(string path, string username, string password, string blogId)
    {
        if (!System.IO.File.Exists(path))
        {
            return("Error! Image file not found");
        }
        ///////////////////////token session and shits...///////////
        PicasaService service = new PicasaService("HowToFixPRO");

        service.setUserCredentials(username, password);
        /////////////////cdefault album is dropBox or something////
        Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(username));

        System.IO.FileInfo   fileInfo   = new System.IO.FileInfo(path);
        System.IO.FileStream fileStream = fileInfo.OpenRead();

        PicasaEntry entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/png", "nameOfYourFile");

        fileStream.Close();

        PhotoAccessor ac         = new PhotoAccessor(entry);
        string        contentUrl = entry.Media.Content.Attributes["url"] as string;

        return(contentUrl);
    }
 private void setSelection(PicasaEntry entry)
 {
     if (entry != null)
     {
         this.Cursor = Cursors.WaitCursor;
         try
         {
             Stream stream = this.picasaService.Query(new Uri(findLargestThumbnail(entry.Media.Thumbnails)));
             this.PhotoPreview.Image = new Bitmap(stream);
         }
         catch
         {
             Icon error = new Icon(SystemIcons.Exclamation, 40, 40);
             this.PhotoPreview.Image = error.ToBitmap();
         }
         Photo photo = new Photo();
         photo.AtomEntry = entry;
         this.PhotoInspector.SelectedObject = photo;
         this.Cursor = Cursors.Default;
         this.DownloadPhoto.Enabled = true;
     }
     else
     {
         this.PhotoPreview.Image            = null;
         this.PhotoInspector.SelectedObject = null;
         this.DownloadPhoto.Enabled         = false;
     }
 }
示例#8
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);
                    }
                }
            }
        }
示例#9
0
 private void SaveAlbumData_Click(object sender, System.EventArgs e)
 {
     foreach (ListViewItem item in this.AlbumList.SelectedItems)
     {
         PicasaEntry entry = item.Tag as PicasaEntry;
         entry.Update();
     }
 }
示例#10
0
 private void AlbumList_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     foreach (ListViewItem item in this.AlbumList.SelectedItems)
     {
         PicasaEntry entry = item.Tag as PicasaEntry;
         setSelection(entry);
     }
 }
 /// <summary>
 /// constructs a tag accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public TagAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsTag == false)
     {
         throw new ArgumentException("Entry is not a tag", "entry");
     }
 }
示例#12
0
 /// <summary>
 /// constructs a tag accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public TagAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsTag == false)
     {
         throw new ArgumentException("Entry is not a tag", "entry");
     }
 }
        public void TagAccessorConstructorTest()
        {
            PicasaEntry entry = new PicasaEntry();

            entry.IsTag = true;
            TagAccessor target = new TagAccessor(entry);

            Assert.IsNotNull(target);
        }
        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);
        }
示例#15
0
        private bool IsPostEntry(PicasaEntry entry)
        {
            var regExA = @"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$";
            var regExB = @"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\d\d$";
            var regExC = @"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$";

            return(Regex.IsMatch(entry.Title.Text, regExA) ||
                   Regex.IsMatch(entry.Title.Text, regExB) ||
                   Regex.IsMatch(entry.Title.Text, regExC));
        }
        public void DeletePhoto(string photoAtomUrl)
        {
            var         atom = PicasaService.Get(photoAtomUrl.ToHttpsUri());
            PicasaEntry a    = (PicasaEntry)atom;

            a.Title   = new AtomTextConstruct(AtomTextConstructElementType.Title, "X_" + a.Title.Text);
            a.Summary = new AtomTextConstruct(AtomTextConstructElementType.Summary, "X_" + a.Summary.Text);

            a.Update();
        }
示例#17
0
        public void LocationTest()
        {
            PicasaEntry target   = new PicasaEntry(); // TODO: Initialize to an appropriate value
            GeoRssWhere expected = new GeoRssWhere();
            GeoRssWhere actual;

            target.Location = expected;
            actual          = target.Location;
            Assert.AreEqual(expected, actual);
        }
示例#18
0
        public void ExifTest()
        {
            PicasaEntry target   = new PicasaEntry(); // TODO: Initialize to an appropriate value
            ExifTags    expected = new ExifTags();
            ExifTags    actual;

            target.Exif = expected;
            actual      = target.Exif;
            Assert.AreEqual(expected, actual);
        }
示例#19
0
        public void MediaTest()
        {
            PicasaEntry target   = new PicasaEntry(); // TODO: Initialize to an appropriate value
            MediaGroup  expected = new MediaGroup();
            MediaGroup  actual;

            target.Media = expected;
            actual       = target.Media;
            Assert.AreEqual(expected, actual);
        }
        public void CreateFeedEntryTest()
        {
            Uri         uriBase  = new Uri("http://www.google.com");
            IService    iService = null;                              // TODO: Initialize to an appropriate value
            PicasaFeed  target   = new PicasaFeed(uriBase, iService); // TODO: Initialize to an appropriate value
            PicasaEntry expected = null;

            expected = target.CreateFeedEntry() as PicasaEntry;
            Assert.IsNotNull(expected);
        }
示例#21
0
        public void getPhotoExtensionValueTest()
        {
            PicasaEntry target    = new PicasaEntry(); // TODO: Initialize to an appropriate value
            string      extension = GPhotoNameTable.Photoid;
            string      newValue  = "theid";
            string      actual    = null;

            target.SetPhotoExtensionValue(extension, newValue);
            actual = target.GetPhotoExtensionValue(extension);
            Assert.AreEqual(newValue, actual);
        }
示例#22
0
        public void setPhotoExtensionTest()
        {
            PicasaEntry   target    = new PicasaEntry(); // TODO: Initialize to an appropriate value
            string        extension = GPhotoNameTable.Photoid;
            string        newValue  = "theid";
            SimpleElement actual;

            actual = target.SetPhotoExtensionValue(extension, newValue);
            Assert.IsTrue(actual is GPhotoPhotoId);
            Assert.AreEqual(newValue, actual.Value);
        }
示例#23
0
        public void IsAlbumTest()
        {
            PicasaEntry target   = new PicasaEntry(); // TODO: Initialize to an appropriate value
            bool        expected = true;              // TODO: Initialize to an appropriate value
            bool        actual;

            target.IsAlbum = expected;
            actual         = target.IsAlbum;
            Assert.AreEqual(expected, actual);
            Assert.IsTrue(target.Categories.Contains(PicasaEntry.ALBUM_CATEGORY));
        }
        public void WeightTest()
        {
            PicasaEntry entry = new PicasaEntry();

            entry.IsTag = true;
            TagAccessor target   = new TagAccessor(entry); // TODO: Initialize to an appropriate value
            uint        expected = 5;                      // TODO: Initialize to an appropriate value
            uint        actual;

            target.Weight = expected;
            actual        = target.Weight;
            Assert.AreEqual(expected, actual);
        }
        public void DoSaveImageFile(PicasaEntry entry, string filename)
        {
            if (entry.Media != null &&
                entry.Media.Content != null)
            {
                UserState ut = new UserState();
                ut.opType   = UserState.OperationType.download;
                ut.filename = filename;
                this.states.Add(ut);

                this.picasaService.QueryStreamAync(new Uri(entry.Media.Content.Attributes["url"] as string), DateTime.MinValue, ut);
            }
        }
示例#26
0
 private void OnBrowseAlbum(object sender, System.EventArgs e)
 {
     foreach (ListViewItem item in this.AlbumList.SelectedItems)
     {
         PicasaEntry entry    = item.Tag as PicasaEntry;
         string      photoUri = entry.FeedUri;
         if (photoUri != null)
         {
             PictureBrowser b = new PictureBrowser(this.picasaService, false);
             b.Show();
             b.StartQuery(photoUri, entry.Title.Text);
         }
     }
 }
示例#27
0
 private void DeleteAlbum_Click(object sender, System.EventArgs e)
 {
     if (MessageBox.Show("Are you really sure? This is not undoable.",
                         "Delete this Album", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         foreach (ListViewItem item in this.AlbumList.SelectedItems)
         {
             PicasaEntry entry = item.Tag as PicasaEntry;
             entry.Delete();
             this.AlbumList.Items.Remove(item);
             setSelection(null);
         }
     }
 }
        public string CreateAlbum(string name, bool isBackup = false)
        {
            AlbumEntry newEntry = new AlbumEntry();

            newEntry.Title.Text   = name + (isBackup ? "B" : "");
            newEntry.Summary.Text = newEntry.Title.Text;

            Uri feedUri = new Uri(PicasaQuery.CreatePicasaUri(AppSetting.GoogleUsername).ToHttpsUri());

            PicasaEntry createdEntry = (PicasaEntry)PicasaService.Insert(feedUri, newEntry);

            //5507469898148065681
            return(createdEntry.EditUri.Content);
        }
        /// <summary>
        /// Do the actual upload to Picasa
        /// For more details on the available parameters, see: http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_dotnet.html
        /// </summary>
        /// <param name="imageData">byte[] with image data</param>
        /// <returns>PicasaResponse</returns>
        public static PicasaInfo UploadToPicasa(byte[] imageData, string title, string filename, string contentType)
        {
            PicasaService service = new PicasaService(Picasa_APPLICATION_NAME);

            service.setUserCredentials(config.Username, config.Password);

            Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(config.Username));

            // build the data stream
            Stream data = new MemoryStream(imageData);

            PicasaEntry entry = (PicasaEntry)service.Insert(postUri, data, contentType, filename);

            return(RetrievePicasaInfo(entry));
        }
示例#30
0
        public PicasaWebPhoto(PicasaEntry photo, string albumName)
        {
            PhotoAccessor pa = new PhotoAccessor(photo);

            this.m_accessId  = pa.Id;
            this.m_media     = photo.Media;
            this.m_id        = photo.Id.Uri.ToString();
            this.m_title     = photo.Title.Text;
            this.m_albumName = albumName;
            this.m_height    = pa.Height;
            this.m_width     = pa.Width;
            this.m_uploaded  = photo.Updated.ToShortDateString() + " " + photo.Updated.ToShortTimeString();
            this.m_location  = (string)photo.Media.Content.Attributes["url"];
            pa = null;
        }
        public static void DeletePicasaImage(PicasaInfo picasaInfo)
        {
            // Make sure we remove it from the history, if no error occured
            config.runtimePicasaHistory.Remove(picasaInfo.ID);
            config.PicasaUploadHistory.Remove(picasaInfo.ID);

            PicasaEntry picasaEntry = RetrievePicasaEntry(picasaInfo.ID);

            if (picasaEntry != null)
            {
                picasaEntry.Delete();
            }

            picasaInfo.Image = null;
        }