Example #1
0
        public PicasaService initializePicasa()
        {
            PicasaService service = new PicasaService("BlueTube");

            service.setUserCredentials(username, password);
            return(service);
        }
Example #2
0
        public static IEnumerable <PicasaAlbum> GetAlbums()
        {
            var           albums  = new List <PicasaAlbum>();
            PicasaService service = new PicasaService("PicasaUnlistedAlbums");

            service.setUserCredentials(WebConfigurationManager.AppSettings["Username"], WebConfigurationManager.AppSettings["Password"]);
            AlbumQuery query           = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            PicasaFeed feed            = service.Query(query);
            var        albumsToExclude = WebConfigurationManager.AppSettings["AlbumsToExclude"].Split(',').ToList();

            foreach (var atomEntry in feed.Entries)
            {
                var entry = (PicasaEntry)atomEntry;
                if (albumsToExclude.Contains(entry.Title.Text) || entry.Title.Text.Contains("Hangout"))
                {
                    continue;
                }
                var album = new PicasaAlbum
                {
                    Title     = entry.Title.Text,
                    Thumbnail = entry.Media.Thumbnails[0].Url,
                    Link      = entry.AlternateUri.Content
                };
                albums.Add(album);
            }
            return(albums);
        }
Example #3
0
        public Picture AddPictureToAlbum(string albumID, Stream image, string imageName, string title, string description, DateTime?positionDateTime, Position position)
        {
            var service = new PicasaService(PicasaConfiguration.Settings.Application.Name);

            service.setUserCredentials(PicasaConfiguration.Settings.Authentication.Username, PicasaConfiguration.Settings.Authentication.Password);

            var postUri = new Uri(PicasaQuery.CreatePicasaUri(PicasaConfiguration.Settings.Authentication.Username, albumID));

            var entry = (PicasaEntry)service.Insert(postUri, image, "image/jpeg", imageName);

            entry.Title.Text   = title;
            entry.Summary.Text = description;

            if (positionDateTime != null)
            {
                entry.SetPhotoExtensionValue("timestamp", Convert.ToTimestamp(positionDateTime.Value));
            }

            if (position != null)
            {
                entry.Location           = new GeoRssWhere();
                entry.Location.Latitude  = position.Latitude;
                entry.Location.Longitude = position.Longitude;
            }

            entry = (PicasaEntry)entry.Update();

            return(PicasaDataMapper.MapPicasaImage(entry));
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                if (Session["user"] != null && Request.QueryString["album"] != null)
                {
                    PhotoQuery query = new PhotoQuery(PicasaQuery.CreatePicasaUri(((User)Session["user"]).Username, Request.QueryString["album"] as string));

                    PicasaService tmp  = Session["service"] as PicasaService;
                    PicasaFeed    feed = tmp.Query(query);

                    List <object> data = new List <object>(feed.Entries.Count);
                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        data.Add(new
                        {
                            name = entry.Title.Text,
                            url  = entry.Content.AbsoluteUri,
                        });
                    }
                    //this.Store1.T
                    this.Store1.DataSource = data;
                    this.Store1.DataBind();
                }
            }
        }
Example #5
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);
                }
            }
        }
        public List <string> QueryTag(PicasaWebPhoto photo)
        {
            List <string> retval = new List <string>();

            this.m_tagQuery   = new TagQuery(TagQuery.CreatePicasaUri(this.m_userName, this.m_albumName, photo.AccessId));
            this.m_tagService = new PicasaService("Tags");
            //this.m_tagService.setUserCredentials(this.m_userName, this.m_password);
            this.m_tagService.SetAuthenticationToken(this.mUserToken);
            CreateTagProxy();
            try
            {
                this.m_tagFeed = this.m_tagService.Query(this.m_tagQuery);

                foreach (PicasaEntry entry in m_tagFeed.Entries)
                {
                    retval.Add(entry.Title.Text);
                }
            }
            catch (Exception e)
            {
                this.m_tagQuery = null;
                this.m_tagService.RequestFactory = null;
                this.m_tagService = null;
                this.m_tagFeed    = null;
                throw new Exception("Query Tag Exception", e);
            }


            this.m_tagQuery = null;
            this.m_tagService.RequestFactory = null;
            this.m_tagService = null;
            this.m_tagFeed    = null;
            return(retval);
        }
Example #7
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);
                }
            }
        }
Example #8
0
        /*public void searchForDevices()
         * {
         *  while (true)
         *  {
         *      BluetoothDeviceInfo[] array = bc.DiscoverDevices();
         *      foreach (BluetoothDeviceInfo bti in array)
         *      {
         *          fileList.Items.Add(bti.DeviceName);
         *      }
         *      fileList.Clear();
         *  }
         *
         * }*/

        public BlueTube()
        {
            InitializeComponent();
            request       = initializeYoutube();
            picasaService = initializePicasa();

            ol = new ObexListener(ObexTransport.Bluetooth);
            bc = new InTheHand.Net.Sockets.BluetoothClient();
            try
            {
                ol.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                System.Windows.Forms.MessageBox.Show("Bluetube failed to start, enable a compatible bluetooth adapter");
                Environment.Exit(0);
            }

            Thread t1 = new Thread(new System.Threading.ThreadStart(DealWithRequest));

            t1.Start();

            //BluetoothDeviceInfo[] array = bc.DiscoverDevices();
            //deviceList.Items.Add(""+array.Length);
            //for (int i = 0; i < array.Length; i++)
            //{
            //    deviceList.Items.Add(array[i].DeviceName);
            //}
        }
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void PhotosAuthenticationTest()
        {
            Tracing.TraceMsg("Entering PhotosAuthenticationTest");

            PicasaQuery   query   = new PicasaQuery();
            PicasaService service = new PicasaService("unittests");

            query.KindParameter = "album,tag";

            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);
                AtomFeed feed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(feed, CreateDumpFileName("PhotoAuthTest"));

                if (feed != null && feed.Entries.Count > 0)
                {
                    Tracing.TraceMsg("Found a Feed " + feed.ToString());
                    DisplayExtensions(feed);

                    foreach (AtomEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);
                    }
                }
            }
        }
        public ActionResult About()
        {
            string user = "******";

            PicasaService service = new PicasaService("PhotoBrowser");

            service.setUserCredentials(user, "**********");

            AlbumQuery query = new AlbumQuery();

            query.Uri = new Uri(PicasaQuery.CreatePicasaUri(user));

            PicasaFeed picasaFeed = service.Query(query);

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

            if (picasaFeed != null && picasaFeed.Entries.Count > 0)
            {
                foreach (PicasaEntry entry in picasaFeed.Entries)
                {
                    result.Add(entry);
                }
            }

            return(View(result));
        }
Example #11
0
        public List <Photo> GetListFor(string albumId)
        {
            var service = new PicasaService("GPhotoSync");

            service.SetAuthenticationToken(_credentials.AccessToken);

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

            query.ExtraParameters = "imgmax=d";
            var feed = service.Query(query);

            if (feed != null)
            {
                var list = feed.Entries
                           .OfType <PicasaEntry>()
                           .Select(x =>
                {
                    var accessor = new PhotoAccessor(x);

                    return(new Photo
                    {
                        Id = accessor.Id,
                        Title = accessor.PhotoTitle,
                        Path = x.Media.Content.Url
                    });
                });

                return(list.OfType <Photo>().ToList());
            }
            else
            {
                return(new List <Photo>());
            }
        }
Example #12
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);
    }
Example #13
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);
        }
Example #14
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);
                    }
                }
            }
        }
Example #15
0
        private static PicasaFeed GetPicasaFeed(KindQuery query)
        {
            var service = new PicasaService(PicasaConfiguration.Settings.Application.Name);

            service.setUserCredentials(PicasaConfiguration.Settings.Authentication.Username, PicasaConfiguration.Settings.Authentication.Password);

            return(service.Query(query));
        }
Example #16
0
        public PicasaService InitPicasaService()
        {
            PicasaService service = new PicasaService("OAMS");

            service.setUserCredentials(OAMSSetting.GoogleUsername, OAMSSetting.GooglePassword);

            service.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(service_AsyncOperationCompleted);
            return(service);
        }
 public NewAlbumDialog(PicasaService service, PicasaFeed feed)
 {
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     this.service = service;
     this.feed    = feed;
 }
        private void UpdateAlbumAccess(PicasaService session, Album albumToUpdate, AlbumAccessEnum albumAccess)
        {
            //update existing album
            WriteOutput(string.Concat("Updating Album: ", albumToUpdate.AtomEntry.Title.Text), true);
            albumToUpdate.Updated = DateTime.Now;
            albumToUpdate.Access  = albumAccess.ToString().ToLower();

            albumToUpdate.AtomEntry = (PicasaEntry)albumToUpdate.AtomEntry.Update();
            m_albumUpdateCount++;
        }
        public List <PicasaWebAlbum> QueryAlbums(BackgroundWorker worker, int overallJobPercent)
        {
            // Create an authentication factory to deal with logging in.
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);

            authFactory.AccountType = "GOOGLE_OR_HOSTED";


            this.m_albumQuery                  = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            this.m_albumQuery.Access           = PicasaQuery.AccessLevel.AccessAll;
            this.m_albumService                = new PicasaService(authFactory.ApplicationName);
            this.m_albumService.RequestFactory = authFactory;
            // this.m_albumService.setUserCredentials(this.m_userName, this.m_password);
            //string token = this.m_albumService.QueryAuthenticationToken();
            this.m_albumService.SetAuthenticationToken(this.mUserToken);
            List <PicasaWebAlbum> retval = new List <PicasaWebAlbum>();
            decimal count      = ((decimal)overallJobPercent / 100) * 10;
            int     smallCount = (int)count;

            try
            {
                worker.ReportProgress(0, (object)"Creating proxy");
                CreateAlbumProxy();
                worker.ReportProgress(smallCount, (object)"Proxy created");
                worker.ReportProgress(0, (object)"Querying google");
                this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
                worker.ReportProgress(smallCount, (object)"Done");
            }
            catch (Exception e)
            {
                this.m_albumQuery = null;
                this.m_albumService.RequestFactory = null;
                this.m_albumService = null;
                this.m_albumFeed    = null;
                retval = null;
                throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e);
            }
            if (this.m_albumFeed.Entries.Count > 0)
            {
                int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_albumFeed.Entries.Count), 0);
                worker.ReportProgress(0, (object)"Processing album data");
                foreach (PicasaEntry entry in this.m_albumFeed.Entries)
                {
                    AlbumAccessor ac = new AlbumAccessor(entry);

                    retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id)));
                    worker.ReportProgress(percent, null);
                }
            }
            this.m_albumQuery = null;
            this.m_albumService.RequestFactory = null;
            this.m_albumService = null;
            this.m_albumFeed    = null;
            return(retval);
        }
Example #20
0
        public Downloader(Settings settings)
        {
            this.DestinationRootPath = settings.DestinationRootPath;
            Username = settings.Username;
            string password = settings.Password;

            this.DestinationRootPath = Path.Combine(settings.DestinationRootPath, settings.Username);

            Service = new PicasaService(ApplicationName);
            Service.setUserCredentials(Username, password);

            this.Albums = new List <Album>();
        }
        /// <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));
        }
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="folderPath">The source folder to sync.</param>
        public void SyncFolder(string folderPath)
        {
            ResetCounters();
            PicasaService session = new PicasaService("PicasaWebSync");

            session.setUserCredentials(this.PicasaUsername, this.PicasaPassword);
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername));

            try
            {
                WriteOutput("[Connecting to Picasa web service]");
                //fetch all albums
                PicasaFeed albumFeed = session.Query(query);

                WriteOutput("[Starting sync]");

                folderPath = folderPath.TrimEnd(new char[] { '\\' });
                DirectoryInfo sourceFolder = new DirectoryInfo(folderPath);
                m_baseDirectoryName = sourceFolder.Name;

                SyncFolder(sourceFolder, null, this.AlbumAccess, this.IncludeSubFolders, session, albumFeed);
            }
            catch (GDataRequestException gdrex)
            {
                if (gdrex.ResponseString.Contains(GDATA_RESPONSE_BADAUTH))
                {
                    throw new AuthenticationException("Picasa error - username and/or password is incorrect!  Check the config file values.");
                }
                else
                {
                    throw new Exception(string.Format("Picasa error - {0}", gdrex.ResponseString));
                }
            }

            WriteOutput("[Done]");
            WriteOutput(string.Empty);
            WriteOutput("Summary:");
            WriteOutput(string.Format("  Folders skipped: {0}", m_folderSkipCount.ToString()));
            WriteOutput(string.Format("   Albums created: {0}", m_albumCreateCount.ToString()));
            WriteOutput(string.Format("   Albums updated: {0}", m_albumUpdateCount.ToString()));
            WriteOutput(string.Format("   Albums deleted: {0}", m_albumDeleteCount.ToString()));
            WriteOutput(string.Format("   Files uploaded: {0}", m_fileCreateCount.ToString()));
            WriteOutput(string.Format("    Files removed: {0}", m_fileDeleteCount.ToString()));
            WriteOutput(string.Format("    Files skipped: {0}", m_fileSkipCount.ToString()));
            WriteOutput(string.Format("   Errors occured: {0}", m_errorsCount.ToString()));
            WriteOutput(string.Format("     Elapsed time: {0}", (DateTime.Now - m_startTime).ToString()));
        }
Example #23
0
        public string CreateAlbum(string name, bool isBackup = false)
        {
            PicasaService service = InitPicasaService();

            AlbumEntry newEntry = new AlbumEntry();

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

            Uri feedUri = new Uri(PicasaQuery.CreatePicasaUri(OAMSSetting.GoogleUsername));

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

            //5507469898148065681
            return(createdEntry.EditUri.Content);
            //return createdEntry.Id.AbsoluteUri;
        }
Example #24
0
        private static string GetAlbum(string album)
        {
            string retVal;

            try
            {
                var service = new PicasaService("exampleCo-exampleApp-1");

                string usr = Settings.GetSingleValue("Account") + "@gmail.com";
                string pwd = Settings.GetSingleValue("Password");

                service.setUserCredentials(usr, pwd);

                var        query = new PhotoQuery(PicasaQuery.CreatePicasaUri(usr, album));
                PicasaFeed feed  = service.Query(query);

                retVal = "<ul id=\"AlbumList\">";
                foreach (PicasaEntry entry in feed.Entries)
                {
                    var    firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
                    string thumGrp       = "/s" + Settings.GetSingleValue("PicWidth") + "/";

                    if (firstThumbUrl != null)
                    {
                        firstThumbUrl = firstThumbUrl.Replace("/s72/", thumGrp);
                    }

                    var contentUrl = entry.Media.Content.Attributes["url"] as string;

                    if (contentUrl != null)
                    {
                        contentUrl = contentUrl.Substring(0, contentUrl.LastIndexOf("/"));
                    }

                    contentUrl += "/s640/" + entry.Title.Text;

                    retVal += string.Format(Img, firstThumbUrl, contentUrl);
                }
                retVal += "</ul>";
            }
            catch (Exception qex)
            {
                retVal = qex.Message;
            }
            return(retVal);
        }
Example #25
0
        private static List <PhotoMessage> GetPhotos()
        {
            List <PhotoMessage> ans = new List <PhotoMessage>();

            try
            {
                string     fileName;
                Uri        uriPath;
                WebClient  HttpClient = new WebClient();
                PhotoQuery query      = new PhotoQuery();
                query.Uri = new Uri(PhotoQuery.CreatePicasaUri("hagit.oded", "5780002529047522017"));
                PicasaService service = new PicasaService("PicasaAlbumDownloader");
                PicasaFeed    feed    = (PicasaFeed)service.Query(query);
                Directory.SetCurrentDirectory("C:\\Photos\\");
                foreach (AtomEntry aentry in feed.Entries)
                {
                    uriPath  = new Uri(aentry.Content.Src.ToString());
                    fileName = uriPath.LocalPath.Substring(uriPath.LocalPath.LastIndexOf('/') + 1);
                    try
                    {
                        Console.WriteLine("Downloading: " + fileName);
                        HttpClient.DownloadFile(aentry.Content.Src.ToString(), fileName);
                        ans.Add(new PhotoMessage("C:\\Photos\\" + fileName));
                    }
                    catch (WebException we)
                    {
                        try
                        {
                            HttpClient.DownloadFile(aentry.Content.Src.ToString(), fileName);
                            ans.Add(new PhotoMessage("C:\\Photos\\" + fileName));
                        }
                        catch (WebException we2)
                        {
                            Console.WriteLine(we2.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
                System.Diagnostics.EventLog.WriteEntry("WeddApp", ex.Message, System.Diagnostics.EventLogEntryType.Error, 626);
            }

            return(ans);
        }
        public List <PicasaWebPhoto> QueryPhoto(BackgroundWorker worker, int overallJobPercent)
        {
            List <PicasaWebPhoto> retval = new List <PicasaWebPhoto>();

            this.m_photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.m_userName, this.m_albumName));

            this.m_photoService = new PicasaService(this.m_serviceName);
            //this.m_photoService.setUserCredentials(this.m_userName, this.m_password);
            this.m_photoService.SetAuthenticationToken(this.mUserToken);
            decimal count      = ((decimal)overallJobPercent / 100) * 10;
            int     smallCount = (int)count;

            worker.ReportProgress(0, (object)"Creating proxy");
            CreatePhotoProxy();
            try
            {
                worker.ReportProgress(smallCount, (object)"Proxy created");
                worker.ReportProgress(0, (object)"Querying google");
                this.m_photoFeed = this.m_photoService.Query(this.m_photoQuery);
                worker.ReportProgress(smallCount, (object)"Done");
                if (this.m_photoFeed.Entries.Count > 0)
                {
                    int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_photoFeed.Entries.Count), 0);
                    worker.ReportProgress(0, (object)"Processing photo data");
                    foreach (PicasaEntry photo in this.m_photoFeed.Entries)
                    {
                        retval.Add(new PicasaWebPhoto(photo, this.m_albumName));
                        worker.ReportProgress(percent, null);
                    }
                }
            }
            catch (Exception e)
            {
                this.m_photoQuery = null;
                this.m_photoService.RequestFactory = null;
                this.m_photoService = null;
                this.m_photoFeed    = null;
                throw new Exception("Query Photo Exception", e);
            }

            this.m_photoQuery = null;
            this.m_photoService.RequestFactory = null;
            this.m_photoService = null;
            this.m_photoFeed    = null;
            return(retval);
        }
        public List <string> QueryTag(PicasaWebPhoto photo, BackgroundWorker worker, int overallJobPercent)
        {
            List <string> retval = new List <string>();

            this.m_tagQuery   = new TagQuery(TagQuery.CreatePicasaUri(this.m_userName, this.m_albumName, photo.AccessId));
            this.m_tagService = new PicasaService("Tags");
            //this.m_tagService.setUserCredentials(this.m_userName, this.m_password);
            this.m_tagService.SetAuthenticationToken(this.mUserToken);
            decimal count      = ((decimal)overallJobPercent / 100) * 10;
            int     smallCount = (int)count;

            worker.ReportProgress(0, (object)"Creating proxy");
            CreateTagProxy();
            try
            {
                worker.ReportProgress(smallCount, (object)"Proxy created");
                worker.ReportProgress(0, (object)"Querying google");
                this.m_tagFeed = this.m_tagService.Query(this.m_tagQuery);
                worker.ReportProgress(smallCount, (object)"Done");
                if (this.m_tagFeed.Entries.Count > 0)
                {
                    int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_tagFeed.Entries.Count), 0);
                    worker.ReportProgress(0, (object)"Processing tag data");
                    foreach (PicasaEntry entry in m_tagFeed.Entries)
                    {
                        retval.Add(entry.Title.Text);
                        worker.ReportProgress(percent, null);
                    }
                }
            }
            catch (Exception e)
            {
                this.m_tagQuery = null;
                this.m_tagService.RequestFactory = null;
                this.m_tagService = null;
                this.m_tagFeed    = null;
                throw new Exception("Query Tag Exception", e);
            }


            this.m_tagQuery = null;
            this.m_tagService.RequestFactory = null;
            this.m_tagService = null;
            this.m_tagFeed    = null;
            return(retval);
        }
Example #28
0
        public List <Album> GetList()
        {
            var service = new PicasaService("GPhotoSync");

            service.SetAuthenticationToken(_credentials.AccessToken);

            var query = new AlbumQuery();

            query.Thumbsize = "180";
            query.Uri       = new Uri(PicasaQuery.CreatePicasaUri(_credentials.User));

            var feed = service.Query(query);

            if (feed != null)
            {
                var list = feed.Entries
                           .OfType <PicasaEntry>()
                           .Where(x => !IsPostEntry(x))
                           .OrderBy(x => x.Title.Text)
                           .Select(x =>
                {
                    var accessor = new AlbumAccessor(x);

                    var thumb = x.Media.Thumbnails[0];
                    using (var stream = service.Query(new Uri(thumb.Attributes["url"] as string)))
                    {
                        var ms = new MemoryStream();
                        stream.CopyTo(ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        return(new Album
                        {
                            Id = accessor.Id,
                            Title = accessor.AlbumTitle,
                            ImageStream = ms,
                            PhotoCount = (int)accessor.NumPhotos
                        });
                    }
                })
                           .ToList();
                return(list);
            }
            else
            {
                return(new List <Album>());
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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 static PicasaEntry RetrievePicasaEntry(string id)
        {
            PicasaService service = new PicasaService(Picasa_APPLICATION_NAME);

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

            PhotoQuery photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(config.Username, string.Empty, id));

            photoQuery.NumberToRetrieve = 1;
            PicasaFeed picasaFeed = service.Query(photoQuery);

            if (picasaFeed.Entries.Count > 0)
            {
                return((PicasaEntry)picasaFeed.Entries[0]);
            }

            return(null);
        }