예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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&lt;Playlist&gt; feed = f.GetPlaylistsFeed(null);
        ///             Feed&lt;Playlist&gt; next = f.Get&lt;Playlist&gt;(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);
        }
예제 #5
0
        /// <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]);
        }
예제 #6
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();
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
        /// <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);
        }
예제 #10
0
        /// <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;
                }
            }
        }
예제 #11
0
        /// <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);
        }
예제 #12
0
        /// <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&lt;Playlist&gt; feed = f.GetPlaylistsFeed(null);
        ///             Feed&lt;Playlist&gt; next = f.Get&lt;Playlist&gt;(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);
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        /// <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);
        }
예제 #16
0
 /// <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));
 }
예제 #17
0
 public AtomFeed Query(FeedQuery feedQuery, DateTime ifModifiedSince)
 {
     feedQuery.ModifiedSince = ifModifiedSince;
     return(Query(feedQuery));
 }
예제 #18
0
        /// <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));
        }
예제 #19
0
 /// <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;
 }
예제 #20
0
        public void Delete(Uri targetUrl, string eTag)
        {
            FeedQuery q = PrepareQuery <FeedQuery>(targetUrl.AbsoluteUri);

            this.Service.Delete(q.Uri, eTag);
        }
예제 #21
0
 /// <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));
 }
예제 #22
0
 /// <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);
 }