Author: fmantek
Date: Mon Dec 17 11:10:04 2007
New Revision: 357
Modified:
trunk/clients/cs/RELEASE_NOTES.HTML
trunk/clients/cs/src/core/exceptions.cs
trunk/clients/cs/src/core/request.cs
trunk/clients/cs/src/core/service.cs
trunk/clients/cs/src/core/serviceinterface.cs
Log:
Added conditional get support.
Modified: trunk/clients/cs/RELEASE_NOTES.HTML
==============================================================================
--- trunk/clients/cs/RELEASE_NOTES.HTML (original)
+++ trunk/clients/cs/RELEASE_NOTES.HTML Mon Dec 17 11:10:04 2007
@@ -6,7 +6,8 @@
<ul>
<li>Features</li>
<ul>
- <li>None yet.</li>
+ <li>Added conditional Get support. The service object has an
overloaded Query method now,
+ that allows you to pass a ifModifiedSince DateTime object into
it.s</li>
</ul>
<li>Bugfixes/changes</li>
Modified: trunk/clients/cs/src/core/exceptions.cs
==============================================================================
--- trunk/clients/cs/src/core/exceptions.cs (original)
+++ trunk/clients/cs/src/core/exceptions.cs Mon Dec 17 11:10:04 2007
@@ -440,4 +440,23 @@
}
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>exception class thrown when we encounter a not-modified
+ /// response (HttpStatusCode.NotModified) when accessing a server
+ /// </summary>
+ //////////////////////////////////////////////////////////////////////
+ public class GDataNotModifiedException : GDataRequestException
+ {
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>constructs a not modified exception</summary>
+ /// <param name="msg"> the exception message as a string</param>
+ /// <param name="response"> the webresponse object that caused
the exception</param>
+ //////////////////////////////////////////////////////////////////////
+ public GDataNotModifiedException(string msg, WebResponse response)
+ : base(msg)
+ {
+ this.webResponse = response;
+ }
+
+ }
} /////////////////////////////////////////////////////////////////////////////
Modified: trunk/clients/cs/src/core/request.cs
==============================================================================
--- trunk/clients/cs/src/core/request.cs (original)
+++ trunk/clients/cs/src/core/request.cs Mon Dec 17 11:10:04 2007
@@ -270,13 +270,14 @@
protected bool disposed;
/// <summary>set wheter or not this request should use GZip</summary>
private bool useGZip;
+ /// <summary>holds the timestamp for conditional GET</summary>
+ private DateTime ifModifiedSince = DateTime.MinValue;
/// <summary>stream from the response</summary>
private Stream responseStream;
/// <summary>holds the contenttype to use if overridden</summary>
private string contentType;
/// <summary>holds the slugheader to use if overridden</summary>
private string slugHeader;
-
//////////////////////////////////////////////////////////////////////
/// <summary>default constructor</summary>
@@ -327,7 +328,17 @@
set { this.useGZip = value; }
}
//////////////////////////////////////////////////////////////////////
-
+
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>set a timestamp for conditional GET</summary>
+ //////////////////////////////////////////////////////////////////////
+ public DateTime IfModifiedSince
+ {
+ get { return (this.ifModifiedSince); }
+ set { this.ifModifiedSince = value; }
+ }
+ //////////////////////////////////////////////////////////////////////
+
//////////////////////////////////////////////////////////////////////
/// <summary>does the real disposition</summary>
/// <param name="disposing">indicates if dispose called it or
finalize</param>
@@ -471,6 +482,9 @@
if (this.useGZip == true)
web.Headers.Add("Accept-Encoding", "gzip");
+ if (this.IfModifiedSince != DateTime.MinValue)
+ web.IfModifiedSince = this.IfModifiedSince;
+
web.ContentType = this.ContentType;
web.UserAgent = this.factory.UserAgent;
web.KeepAlive = this.factory.KeepAlive;
@@ -580,6 +594,11 @@
this.targetUri.ToString() + response.StatusCode.ToString(), this.webResponse);
}
+ if (this.IfModifiedSince != DateTime.MinValue &&
response.StatusCode == HttpStatusCode.NotModified)
+ {
+ // Throw an exception for conditional GET
+ throw new GDataNotModifiedException("Content not
modified: " + this.targetUri.ToString(), this.webResponse);
+ }
if (response.StatusCode == HttpStatusCode.Redirect ||
response.StatusCode == HttpStatusCode.Found ||
Modified: trunk/clients/cs/src/core/service.cs
==============================================================================
--- trunk/clients/cs/src/core/service.cs (original)
+++ trunk/clients/cs/src/core/service.cs Mon Dec 17 11:10:04 2007
@@ -220,19 +220,46 @@
//////////////////////////////////////////////////////////////////////
public Stream Query(Uri queryUri)
{
- Tracing.TraceCall("Enter");
- if (queryUri == null)
- {
- throw new System.ArgumentNullException("queryUri");
- }
- IGDataRequest request =
this.RequestFactory.CreateRequest(GDataRequestType.Query, queryUri);
- request.Credentials = this.Credentials;
+ return Query(queryUri, DateTime.MinValue);
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>the basic interface. Take a URI and just get it</summary>
+ /// <param name="queryUri">the URI to execute</param>
+ /// <param name="ifModifiedSince">used to set a precondition
date that
+ /// indicates the feed should be returned only if it has been modified
+ /// after the specified date. A value of DateTime.MinValue
indicates no
+ /// precondition.</param>
+ /// <returns> a webresponse object</returns>
+ //////////////////////////////////////////////////////////////////////
+ public Stream Query(Uri queryUri, DateTime ifModifiedSince)
+ {
+ Tracing.TraceCall("Enter");
+ if (queryUri == null)
+ {
+ throw new System.ArgumentNullException("queryUri");
+ }
+ IGDataRequest request =
this.RequestFactory.CreateRequest(GDataRequestType.Query, queryUri);
+ request.Credentials = this.Credentials;
+ request.IfModifiedSince = ifModifiedSince;
+ try
+ {
request.Execute();
- // return the response
- Tracing.TraceCall("Exit");
- return request.GetResponseStream();
+ }
+ catch (Exception e)
+ {
+ // Prevent connection leaks
+ if (request.GetResponseStream() != null)
+ request.GetResponseStream().Close();
+
+ throw e;
+ }
+ // return the response
+ Tracing.TraceCall("Exit");
+ return request.GetResponseStream();
}
+
/////////////////////////////////////////////////////////////////////////////
@@ -268,43 +295,59 @@
//////////////////////////////////////////////////////////////////////
public AtomFeed Query(FeedQuery feedQuery)
{
- AtomFeed feed = null;
- Tracing.TraceCall("Enter");
+ return Query(feedQuery, DateTime.MinValue);
+ }
+
/////////////////////////////////////////////////////////////////////////////
+
+
+ //////////////////////////////////////////////////////////////////////
+ /// <summary>executes the query and returns an AtomFeed object
tree</summary>
+ /// <param name="feedQuery">the query parameters as a
FeedQuery object </param>
+ /// <param name="ifModifiedSince">used to set a precondition
date that
+ /// indicates the feed should be returned only if it has been modified
+ /// after the specified date. A value of null indicates no
+ /// precondition.</param>
+ /// <returns>AtomFeed object tree</returns>
+ //////////////////////////////////////////////////////////////////////
+ public AtomFeed Query(FeedQuery feedQuery, DateTime ifModifiedSince)
+ {
+ AtomFeed feed = null;
+ Tracing.TraceCall("Enter");
- if (feedQuery == null)
- {
- throw new
System.ArgumentNullException("feedQuery", "The query argument MUST not
be null");
- }
- // Create a new request to the Uri in the query object...
- Uri targetUri = null;
-
- try
- {
- targetUri = feedQuery.Uri;
-
- }
- catch (System.UriFormatException)
- {
- throw new System.ArgumentException("The query argument
MUST contain a valid Uri", "feedQuery");
- }
-
- Tracing.TraceInfo("Service:Query - about to query");
-
- Stream responseStream = Query(targetUri);
-
- Tracing.TraceInfo("Service:Query - query done");
- if (responseStream != null)
- {
- Tracing.TraceCall("Using Atom always.... ");
- feed = createFeed(feedQuery.Uri);
-
- feed.NewAtomEntry += new
FeedParserEventHandler(this.OnParsedNewEntry);
- feed.NewExtensionElement += new
ExtensionElementEventHandler(this.OnNewExtensionElement);
- feed.Parse(responseStream, AlternativeFormat.Atom);
- responseStream.Close();
- }
- Tracing.TraceCall("Exit");
- return feed;
+ if (feedQuery == null)
+ {
+ throw new System.ArgumentNullException("feedQuery", "The
query argument MUST not be null");
+ }
+ // Create a new request to the Uri in the query object...
+ Uri targetUri = null;
+
+ try
+ {
+ targetUri = feedQuery.Uri;
+
+ }
+ catch (System.UriFormatException)
+ {
+ throw new System.ArgumentException("The query argument
MUST contain a valid Uri", "feedQuery");
+ }
+
+ Tracing.TraceInfo("Service:Query - about to query");
+
+ Stream responseStream = Query(targetUri, ifModifiedSince);
+
+ Tracing.TraceInfo("Service:Query - query done");
+ if (responseStream != null)
+ {
+ Tracing.TraceCall("Using Atom always.... ");
+ feed = createFeed(feedQuery.Uri);
+
+ feed.NewAtomEntry += new
FeedParserEventHandler(this.OnParsedNewEntry);
+ feed.NewExtensionElement += new
ExtensionElementEventHandler(this.OnNewExtensionElement);
+ feed.Parse(responseStream, AlternativeFormat.Atom);
+ responseStream.Close();
+ }
+ Tracing.TraceCall("Exit");
+ return feed;
}
/////////////////////////////////////////////////////////////////////////////
Modified: trunk/clients/cs/src/core/serviceinterface.cs
==============================================================================
--- trunk/clients/cs/src/core/serviceinterface.cs (original)
+++ trunk/clients/cs/src/core/serviceinterface.cs Mon Dec 17 11:10:04 2007
@@ -54,6 +54,8 @@
/// <summary>the minimal query implementation</summary>
AtomFeed Query(FeedQuery feedQuery);
+ /// <summary>the minimal query implementation with conditional
GET</summary>
+ AtomFeed Query(FeedQuery feedQuery, DateTime ifModifiedSince);
/// <summary>simple update for atom resources</summary>
AtomEntry Update(AtomEntry entry);
/// <summary>simple insert for atom entries, based on a feed</summary>
@@ -123,6 +125,12 @@
}
/// <summary>set wether or not to use gzip for this request</summary>
bool UseGZip
+ {
+ get;
+ set;
+ }
+ /// <summary>set a timestamp for conditional GET</summary>
+ DateTime IfModifiedSince
{
get;
set;
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---