/// <summary> /// sends the data back to the server. /// </summary> /// <returns>the reflected entry from the server if any given</returns> public Y Update <Y>(Y entry) where Y : Entry, new() { if (entry == null) { throw new ArgumentNullException("Entry was null"); } if (entry.AtomEntry == null) { throw new ArgumentNullException("Entry.AtomEntry was null"); } Y r = null; FeedQuery q = PrepareQuery <FeedQuery>(entry.AtomEntry.EditUri.ToString()); Stream s = this.Service.EntrySend(q.Uri, entry.AtomEntry, GDataRequestType.Update, null); AtomEntry ae = this.Service.CreateAndParseEntry(s, new Uri(entry.AtomEntry.EditUri.ToString())); if (ae != null) { r = new Y(); r.AtomEntry = ae; } return(r); }
/// <summary>Constructor, given a category as a string from the URI.</summary> public QueryCategory(string strCategory, QueryCategoryOperator op) { Tracing.TraceMsg("Depersisting category from: " + strCategory); this.categoryOperator = op; strCategory = FeedQuery.CleanPart(strCategory); // let's parse the string if (strCategory[0] == '-') { // negator this.isExcluded = true; // remove him strCategory = strCategory.Substring(1, strCategory.Length - 1); } // let's extract the scheme if there is one... int iStart = strCategory.IndexOf('{'); int iEnd = strCategory.IndexOf('}'); AtomUri scheme = null; if (iStart != -1 && iEnd != -1) { iEnd++; iStart++; scheme = new AtomUri(strCategory.Substring(iStart, iEnd - iStart - 1)); // the rest is then strCategory = strCategory.Substring(iEnd, strCategory.Length - iEnd); } Tracing.TraceMsg("Category found: " + strCategory + " - scheme: " + scheme); this.category = new AtomCategory(strCategory, scheme); }
/// <summary> /// takes the given Entry and inserts its into the server /// </summary> /// <returns>the reflected entry from the server if any given</returns> public Y Insert <Y>(Uri address, Y entry) where Y : Entry, new() { if (entry == null) { throw new ArgumentNullException("Entry was null"); } if (entry.AtomEntry == null) { throw new ArgumentNullException("Entry.AtomEntry was null"); } if (address == null) { throw new ArgumentNullException("Address was null"); } Y r = null; FeedQuery q = PrepareQuery <FeedQuery>(address.AbsoluteUri); AtomEntry ae = this.Service.Insert(q.Uri, entry.AtomEntry); if (ae != null) { r = new Y(); r.AtomEntry = ae; } return(r); }
/// <summary> /// returns a refreshed version of the entry you passed in, by going back to the server and /// requesting this resource again /// </summary> /// <example> /// The following code illustrates a possible use of /// the <c>Get</c> method: /// <code> /// YouTubeRequestSettings settings = new YouTubeRequestSettings("yourApp", "yourClient", "yourKey", "username", "pwd"); /// YouTubeRequest f = new YouTubeRequest(settings); /// Feed<Playlist> feed = f.GetPlaylistsFeed(null); /// Feed<Playlist> next = f.Get<Playlist>(feed, FeedRequestType.Next); /// </code> /// </example> /// <param name="entry">the entry to get again</param> /// <returns></returns> public Y Retrieve <Y>(Y entry) where Y : Entry, new() { if (entry == null) { throw new ArgumentNullException("entry was null"); } if (entry.AtomEntry == null) { throw new ArgumentNullException("entry.AtomEntry was null"); } string spec = entry.AtomEntry.SelfUri.ToString(); if (!String.IsNullOrEmpty(spec)) { FeedQuery q = new FeedQuery(spec); ISupportsEtag ise = entry.AtomEntry as ISupportsEtag; if (ise != null && ise.Etag != null) { q.Etag = ise.Etag; } return(Retrieve <Y>(q)); } return(null); }
/// <summary> /// Returns a single Atom entry based upon its unique URI. /// </summary> /// <param name="entryUri">The URI of the Atom entry.</param> /// <returns>AtomEntry representing the entry.</returns> public AtomEntry Get(string entryUri) { FeedQuery query = new FeedQuery(entryUri); AtomFeed resultFeed = Query(query); return(resultFeed.Entries[0]); }
/// <summary>Passing in a complete URI, we strip all the /// GData query-related things and then treat the rest /// as the base URI. For this we create a service.</summary> /// <param name="uri">a complete URI</param> /// <param name="service">the new GData service for this URI</param> /// <param name="query">the parsed query object for this URI</param> //public static void Parse(Uri uri, out Service service, out FeedQuery query) //{ // query = new FeedQuery(); // query.ParseUri(uri); // service = new Service(); //} public static void Parse(Uri uri, out object service, out FeedQuery query) { query = new FeedQuery(); query.ParseUri(uri); service = null; // new Service(); }
/// <summary> /// creates a feed of Y object based on the query and the settings /// </summary> /// <typeparam name="Y"></typeparam> /// <param name="q"></param> /// <returns></returns> protected virtual Feed <Y> PrepareFeed <Y>(FeedQuery q) where Y : Entry, new() { PrepareQuery(q); Feed <Y> f = CreateFeed <Y>(q); f.Settings = this.settings; f.AutoPaging = this.settings.AutoPaging; f.Maximum = this.settings.Maximum; return(f); }
/// <summary> /// returns the entry the Uri pointed to /// </summary> /// <param name="entryUri">the Uri of the entry</param> /// <returns></returns> public Y Retrieve <Y>(Uri entryUri) where Y : Entry, new() { string spec = entryUri.AbsoluteUri; if (!String.IsNullOrEmpty(spec)) { FeedQuery q = new FeedQuery(spec); return(Retrieve <Y>(q)); } return(null); }
/// <summary> /// returns a the entry the Uri pointed to /// </summary> /// <example> /// <param name="entryUri">the Uri of the entry</param> /// <returns></returns> public Y Retrieve <Y>(FeedQuery query) where Y : Entry, new() { Feed <Y> f = null; Y r = null; f = PrepareFeed <Y>(query); // this should be a feed of one... foreach (Y y in f.Entries) { r = y; } return(r); }
/// <summary> /// helper method to setup a query object with some parameters /// based on a requestsettings /// </summary> /// <param name="q"></param> /// <param name="settings"></param> internal static void PrepareQuery(FeedQuery q, RequestSettings settings) { if (settings.PageSize != -1) { q.NumberToRetrieve = settings.PageSize; } if (settings.OAuthUser != null) { q.OAuthRequestorId = settings.OAuthUser; if (settings.OAuthDomain != null) { q.OAuthRequestorId += "@" + settings.OAuthDomain; } } }
/// <summary> /// helper to format a DateTime parameter into the query /// </summary> /// <param name="value"></param> /// <param name="parameterName"></param> /// <param name="connect"></param> /// <param name="builder"></param> /// <returns></returns> protected static char AppendQueryPart(DateTime value, string parameterName, char connect, StringBuilder builder) { if (builder == null) { throw new ArgumentNullException("builder"); } if (builder.ToString().IndexOf(parameterName + "=") == -1) { if (Utilities.IsPersistable(value)) { return(FeedQuery.AppendQueryPart(Utilities.LocalDateTimeInUTC(value), parameterName, connect, builder)); } } return(connect); }
/// <summary> /// returns a new feed based on the operation passed in. This is useful if you either do not use /// autopaging, or want to move to previous parts of the feed, or get a refresh of the current feed /// </summary> /// <example> /// The following code illustrates a possible use of /// the <c>Get</c> method: /// <code> /// YouTubeRequestSettings settings = new YouTubeRequestSettings("yourApp", "yourClient", "yourKey", "username", "pwd"); /// YouTubeRequest f = new YouTubeRequest(settings); /// Feed<Playlist> feed = f.GetPlaylistsFeed(null); /// Feed<Playlist> next = f.Get<Playlist>(feed, FeedRequestType.Next); /// </code> /// </example> /// <param name="feed">the original feed</param> /// <param name="operation">an requesttype to indicate what to retrieve</param> /// <returns></returns> public Feed <Y> Get <Y>(Feed <Y> feed, FeedRequestType operation) where Y : Entry, new() { Feed <Y> f = null; string spec = null; if (feed == null) { throw new ArgumentNullException("feed was null"); } if (feed.AtomFeed == null) { throw new ArgumentNullException("feed.AtomFeed was null"); } switch (operation) { case FeedRequestType.Next: spec = feed.AtomFeed.NextChunk; break; case FeedRequestType.Prev: spec = feed.AtomFeed.PrevChunk; break; case FeedRequestType.Refresh: spec = feed.AtomFeed.Self; break; } if (!String.IsNullOrEmpty(spec)) { FeedQuery q = new FeedQuery(spec); if (operation == FeedRequestType.Refresh) { ISupportsEtag ise = feed.AtomFeed as ISupportsEtag; if (ise != null && ise.Etag != null) { q.Etag = ise.Etag; } } f = PrepareFeed <Y>(q); } return(f); }
/// <summary>executes the query and returns an AtomFeed object tree</summary> /// <param name="feedQuery">the query parameters as a FeedQuery object </param> /// <returns>AtomFeed object tree</returns> public AtomFeed Query(FeedQuery feedQuery) { 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 = null; if (feedQuery.Etag != null) { responseStream = Query(targetUri, feedQuery.Etag); } else { responseStream = Query(targetUri, feedQuery.ModifiedSince); } Tracing.TraceInfo("Service:Query - query done"); if (responseStream != null) { feed = CreateAndParseFeed(responseStream, feedQuery.Uri); } Tracing.TraceCall("Exit"); return(feed); }
/// <summary> /// deletes the Entry from the Server /// </summary> public void Delete <Y>(Y entry) where Y : Entry, new() { if (entry == null) { throw new ArgumentNullException("Entry was null"); } if (entry.AtomEntry == null) { throw new ArgumentNullException("Entry.AtomEntry was null"); } if (entry.AtomEntry.EditUri == null) { throw new ArgumentNullException("The AtomEntry has no EditUri"); } FeedQuery q = PrepareQuery <FeedQuery>(entry.AtomEntry.EditUri.ToString()); this.Service.Delete(q.Uri, entry.ETag); }
/// <summary> /// performs a batch operation. /// </summary> /// <param name="batchUri">the batch endpoint of the service</param> /// <param name="entries">List of entries of type Y, that are to be batched</param> /// <param name="defaultOperation">The default operation to be used for all entries</param> /// <returns></returns> public Feed <Y> Batch <Y>(List <Y> entries, Uri batchUri, GDataBatchOperationType defaultOperation) where Y : Entry, new() { if (entries.Count > 0) { AtomFeed batchFeed = new AtomFeed(batchUri, null); batchFeed.BatchData = new GDataBatchFeedData(); batchFeed.BatchData.Type = defaultOperation; foreach (Y e in entries) { batchFeed.Entries.Add(e.AtomEntry); } FeedQuery q = PrepareQuery <FeedQuery>(batchUri.AbsoluteUri); AtomFeed resultFeed = this.Service.Batch(batchFeed, q.Uri); Feed <Y> f = new Feed <Y>(resultFeed); return(f); } return(null); }
/// <summary> /// gets a feed object of type T /// </summary> /// <typeparam name="Y"></typeparam> /// <param name="q"></param> /// <returns></returns> public Feed <Y> Get <Y>(FeedQuery q) where Y : Entry, new() { return(PrepareFeed <Y>(q)); }
public AtomFeed Query(FeedQuery feedQuery, DateTime ifModifiedSince) { feedQuery.ModifiedSince = ifModifiedSince; return(Query(feedQuery)); }
/// <summary> /// gets a feed object of type T /// </summary> /// <typeparam name="Y"></typeparam> /// <param name="uri">The Uri to retrieve</param> /// <returns></returns> public Feed <Y> Get <Y>(Uri uri) where Y : Entry, new() { FeedQuery q = new FeedQuery(uri.AbsoluteUri); return(PrepareFeed <Y>(q)); }
/// <summary> /// constructs a new feed object based on a service and a query /// </summary> /// <param name="service"></param> /// <param name="q"></param> public Feed(Service service, FeedQuery q) { this.service = service; this.query = q; }
public void Delete(Uri targetUrl, string eTag) { FeedQuery q = PrepareQuery <FeedQuery>(targetUrl.AbsoluteUri); this.Service.Delete(q.Uri, eTag); }
/// <summary> /// the virtual creator function for feeds, so that we can create feedsubclasses in /// in subclasses of the request /// </summary> /// <param name="q"></param> /// <returns></returns> protected virtual Feed <Y> CreateFeed <Y>(FeedQuery q) where Y : Entry, new() { return(new Feed <Y>(this.atomService, q)); }
/// <summary> /// prepares the passed in query objects properties based on the settings /// </summary> /// <param name="q"></param> protected void PrepareQuery(FeedQuery q) { FeedQuery.PrepareQuery(q, this.settings); }