public void RequestFactoryTest() { Service target = new Service(); // TODO: Initialize to an appropriate value IGDataRequestFactory expected = new GDataGAuthRequestFactory("cl", "test"); IGDataRequestFactory actual; target.RequestFactory = expected; actual = target.RequestFactory; Assert.AreEqual(expected, actual); }
public void UserAgentTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value string expected = "TestValue"; string actual; target.UserAgent = expected; actual = target.UserAgent; Assert.AreEqual(expected, actual); }
/// <summary> /// if the service is using a Google Request Factory it will use that /// assuming credentials are set to retrieve the authentication token /// for those credentials /// /// Note that this only works for ClientLogin, not for any other type of authentication /// </summary> /// <returns>string</returns> public string QueryClientLoginToken() { if (this.Credentials != null) { GDataGAuthRequestFactory factory = this.factory as GDataGAuthRequestFactory; if (factory != null) { return(factory.QueryAuthToken(this.Credentials)); } } return(null); }
/// <summary> /// if the service is using a Google Request Factory it will set the passed /// in token to the factory. NET CF does not support authsubtokens here /// </summary> /// <returns>string</returns> public void SetAuthenticationToken(string token) { GDataGAuthRequestFactory factory = this.factory as GDataGAuthRequestFactory; if (factory != null) { factory.GAuthToken = token; } else { GAuthSubRequestFactory f = this.factory as GAuthSubRequestFactory; if (f != null) { f.Token = token; } } }
// Validates a username/pass by attempting to login to calendar public static bool checkPw(string username, string password) { GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("cl", "Seadragon"); authFactory.AccountType = "HOSTED"; CalendarService client = new CalendarService(authFactory.ApplicationName); client.RequestFactory = authFactory; client.setUserCredentials(username + "@" + DOMAIN, password); try { client.QueryClientLoginToken(); // Authenticate the user immediately } catch (WebException) // Invalid login { return false; } return true; }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataGAuthRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory) : base(type, uriTarget, factory as GDataRequestFactory) { // need to remember the factory, so that we can pass the new authtoken back there if need be this.factory = factory; }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataLoggingRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory, string strInputFileName, string strOutputFileName, string strCombinedLogFileName) : base(type, uriTarget, factory) { this.strInput = strInputFileName; this.strOutput = strOutputFileName; this.strCombined = strCombinedLogFileName; }
////////////////////////////////////////////////////////////////////// /// <summary>default constructor</summary> ////////////////////////////////////////////////////////////////////// internal GDataLoggingRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory, string strInputFileName, string strOutputFileName, string strCombinedLogFileName) : base(type, uriTarget, factory) { this.strInput = strInputFileName; this.strOutput = strOutputFileName; this.strCombined = strCombinedLogFileName; }
/// <summary>default constructor</summary> internal GDataGAuthRequest(GDataRequestType type, Uri uriTarget, GDataGAuthRequestFactory factory) : base(type, uriTarget, factory as GDataRequestFactory) { // need to remember the factory, so that we can pass the new authtoken back there if need be this.factory = factory; }
/* 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; }
public List<PicasaWebPhoto> QueryPhoto(string tags) { List<PicasaWebPhoto> retval = new List<PicasaWebPhoto>(); GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName); authFactory.AccountType = "GOOGLE_OR_HOSTED"; this.m_photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.m_userName, this.m_albumName)); this.m_photoQuery.Tags = tags; this.m_photoService = new PicasaService(authFactory.ApplicationName); this.m_photoService.RequestFactory = authFactory; //this.m_photoService.setUserCredentials(this.m_userName, this.m_password); this.m_photoService.SetAuthenticationToken(this.mUserToken); CreatePhotoProxy(); try { this.m_photoFeed = this.m_photoService.Query(this.m_photoQuery); foreach (PicasaEntry photo in this.m_photoFeed.Entries) { retval.Add(new PicasaWebPhoto(photo, this.m_albumName)); } } catch (Exception e) { throw new Exception("Query Photo Exception", e); } finally { this.m_photoQuery = null; this.m_photoService.RequestFactory = null; this.m_photoService = null; this.m_photoFeed = null; } return retval; }
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; }
public void StrictRedirectTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value bool expected = true; // TODO: Initialize to an appropriate value bool actual; target.StrictRedirect = expected; actual = target.StrictRedirect; Assert.AreEqual(expected, actual); }
public void NumberOfRetriesTest() { string service = "TestValue"; // TODO: Initialize to an appropriate value string applicationName = "TestValue"; // TODO: Initialize to an appropriate value GDataGAuthRequestFactory target = new GDataGAuthRequestFactory(service, applicationName); // TODO: Initialize to an appropriate value int expected = 2; // TODO: Initialize to an appropriate value int actual; target.NumberOfRetries = expected; actual = target.NumberOfRetries; Assert.AreEqual(expected, actual); }