/// <summary> /// Queries a particular Google service using query parameters. /// </summary> /// <typeparam name="TFeed">Type of feed for the service.</typeparam> /// <typeparam name="TEntry">Type of feed entry for the service.</typeparam> /// <param name="query"><seealso cref="IGQuery"/> object, filled with data.</param> /// <returns>An atom feed for the particular Google service.</returns> protected virtual TFeed Query <TFeed, TEntry>(IGQuery query) where TFeed : GFeed <TEntry>, new() where TEntry : GEntry, new() { if (String.IsNullOrEmpty(GUrl)) { throw new ArgumentNullException(GUrl, "Feed Url is not provided. Please provide Feed url first through GUrl Property."); } string queryUrl = GUrl + "?" + query.GetQueryUrl(); var queryUri = new Uri(queryUrl); var request = WebRequest.Create(queryUri) as HttpWebRequest; if (request != null) { if (ProxySettings != null) { request.Proxy = ProxySettings; } request.Credentials = new NetworkCredential(GUserName, GPassword); var webData = new GWebAsyncData <TFeed, TEntry> { Request = request, ResetEvent = new ManualResetEvent(false) }; IAsyncResult result = request.BeginGetResponse(AsyncManager <TFeed, TEntry> .AsyncDownloadAllFeeds, webData); ((GWebAsyncData <TFeed, TEntry>)result.AsyncState).ResetEvent.WaitOne(); return(((GWebAsyncData <TFeed, TEntry>)result.AsyncState).FeedResult); } throw new OutOfMemoryException("Unable to create new WebRequest"); }
/// <summary> /// Submits a new atom entry to a particular Google service. /// </summary> /// <typeparam name="TFeed">Type of feed for the service.</typeparam> /// <typeparam name="TEntry">Type of feed entry for the service.</typeparam> /// <param name="entry">The atom entry object containing the data to submit.</param> /// <param name="applicationName">The name of the application which invokes this method.</param> /// <returns>A new atom entry containing some additional data like id, published date etc.</returns> protected virtual TEntry SubmitNewEntry <TFeed, TEntry>(TEntry entry, string applicationName) where TFeed : GFeed <TEntry>, new() where TEntry : GEntry, new() { if (String.IsNullOrEmpty(GUrl)) { throw new ArgumentNullException(GUrl, "Feed Url is not provided. Please provide Feed url first through GUrl Property."); } var request = WebRequest.Create(GUrl) as HttpWebRequest; if (request != null) { var serializer = new XObjectSerializer <TEntry>(); string xml = serializer.StringSerialize(entry); long length = xml.ToCharArray().LongLength; var gc = new GDataCredentials(GUserName, GPassword) { AccountType = "GOOGLE" }; string header = GAuthManager.RequestClientLoginHeader(gc, "code", applicationName, true, GoogleAuthentication.URI_HANDLER, ProxySettings); if (ProxySettings != null) { request.Proxy = ProxySettings; } request.Method = "POST"; request.Credentials = new NetworkCredential { UserName = GUserName, Password = GPassword }; request.ContentType = "application/atom+xml"; request.ContentLength = length; request.Headers.Add(header); var sw = new StreamWriter(request.GetRequestStream()); sw.Write(xml); sw.Close(); var webData = new GWebAsyncData <TFeed, TEntry> { Request = request, ResetEvent = new ManualResetEvent(false) }; IAsyncResult result = request.BeginGetResponse(AsyncManager <TFeed, TEntry> .AsyncSubmitNewEntry, webData); ((GWebAsyncData <TFeed, TEntry>)result.AsyncState).ResetEvent.WaitOne(); return(((GWebAsyncData <TFeed, TEntry>)result.AsyncState).EntryResult); } throw new OutOfMemoryException("Unable to create new WebRequest"); }