///////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Takes a given feed, and does a batch post of that feed
 /// against the batchUri parameter. If that one is NULL
 /// it will try to use the batch link URI in the feed
 /// </summary>
 /// <param name="feed">the feed to post</param>
 /// <param name="batchUri">the URI to user</param>
 /// <returns>the returned AtomFeed</returns>
 ///////////////////////////////////////////////////////////////////////
 public GBaseFeed Batch(GBaseFeed feed, Uri batchUri)
 {
     // Sets the flag g:application in even entries
     foreach (AtomEntry entry in feed.Entries)
     {
         new GBaseAttributes(entry.ExtensionElements).Application
             = applicationName;
     }
     return(Batch((AtomFeed)feed, batchUri) as GBaseFeed);
 }
 //////////////////////////////////////////////////////////////////////
 /// <summary>Reads a feed or entry from stdin.</summary>
 //////////////////////////////////////////////////////////////////////
 protected GBaseFeed ReadFromStandardInput()
 {
     GBaseFeed feed = new GBaseFeed(uriFactory.ItemsFeedUri, service);
     Stream stdin = Console.OpenStandardInput();
     try
     {
         feed.Parse(stdin, AlternativeFormat.Atom);
         return feed;
     }
     finally
     {
         stdin.Close();
     }
 }
        //////////////////////////////////////////////////////////////////////
        /// <summary>Prints the results to standard output.</summary>
        //////////////////////////////////////////////////////////////////////
        private void PrintResult(GBaseFeed result)
        {
            if (result.TotalResults == 0)
            {
                System.Console.WriteLine("No matches.");
                return;
            }

            foreach (GBaseEntry entry in result.Entries)
            {
                System.Console.WriteLine(entry.GBaseAttributes.ItemType +
                                         ": " + entry.Title.Text +
                                         " - " + entry.Id.Uri);
            }
        }
 private void CheckParsedFeedEntries(GBaseFeed feed)
 {
     GBaseEntry entry = feed.Entries[0] as GBaseEntry;
     Assert.IsNotNull(entry, "entry");
     GBaseAttributes attrs = entry.GBaseAttributes;
     Assert.AreEqual("Recipes", attrs.ItemType, "item type");
     Assert.AreEqual("Mountain View, CA 94043", attrs.Location, "location");
     String[] labels = attrs.Labels;
     Assert.AreEqual("kung pao chicken", labels[0], "label");
     Assert.AreEqual("chinese cuisine", labels[1], "label");
     Assert.AreEqual("recipes", labels[2], "label");
     Assert.AreEqual("asian", labels[3], "label");
     Assert.AreEqual("sichuan", labels[4], "label");
     Assert.AreEqual(5f, attrs.GetNumberAttribute("serving count", 0f));
     Assert.IsNotNull(entry.Stats, "gm:stats");
     Assert.AreEqual(100, entry.Stats.Impressions.Total, "gm:impressions");
 }
        ///////////////////////////////////////////////////////////////////////
        /// <summary>Gets a specific entry from the server.</summary>
        /// <param name="entryUri">the Uri of a entry, usually created
        /// by <see cref="GBaseUriFactory"/></param>
        /// <returns>the entry</returns>
        ///////////////////////////////////////////////////////////////////////
        public GBaseEntry GetEntry(Uri entryUri)
        {
            Stream feedStream = Query(entryUri);

            try
            {
                GBaseFeed feed = new GBaseFeed(entryUri, this);
                feed.Parse(feedStream, AlternativeFormat.Atom);
                if (feed.Entries.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(feed.Entries[0] as GBaseEntry);
                }
            }
            finally
            {
                feedStream.Close();
            }
        }
 private GBaseFeed Parse(String xml)
 {
     byte[] bytes = new UTF8Encoding().GetBytes(xml);
     GBaseFeed feed = new GBaseFeed(FeedUri, new GBaseService("Test", "boguskey"));
     feed.Parse(new MemoryStream(bytes), AlternativeFormat.Atom);
     return feed;
 }
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Gets a specific entry from the server.</summary>
 /// <param name="entryUri">the Uri of a entry, usually created
 /// by <see cref="GBaseUriFactory"/></param>
 /// <returns>the entry</returns>
 ///////////////////////////////////////////////////////////////////////
 public GBaseEntry GetEntry(Uri entryUri)
 {
     Stream feedStream = Query(entryUri);
     try
     {
         GBaseFeed feed = new GBaseFeed(entryUri, this);
         feed.Parse(feedStream, AlternativeFormat.Atom);
         if (feed.Entries.Count == 0)
         {
             return null;
         }
         else
         {
             return feed.Entries[0] as GBaseEntry;
         }
     }
     finally
     {
         feedStream.Close();
     }
 }
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Inserts an entry into a feed.</summary>
 /// <param name="feed">a feed object you got from a previous
 /// query</param>
 /// <param name="entry">the entry to add to the feed</param>
 /// <returns>the same entry, with a new id, as it has been added
 /// into the feed</returns>
 ///////////////////////////////////////////////////////////////////////
 public GBaseEntry Insert(GBaseFeed feed, GBaseEntry entry)
 {
     entry.GBaseAttributes.Application = applicationName;
     return base.Insert((AtomFeed)feed, (AtomEntry)entry) as GBaseEntry;
 }
 ///////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Takes a given feed, and does a batch post of that feed
 /// against the batchUri parameter. If that one is NULL
 /// it will try to use the batch link URI in the feed
 /// </summary>
 /// <param name="feed">the feed to post</param>
 /// <param name="batchUri">the URI to user</param>
 /// <returns>the returned AtomFeed</returns>
 ///////////////////////////////////////////////////////////////////////
 public GBaseFeed Batch(GBaseFeed feed, Uri batchUri)
 {
     // Sets the flag g:application in even entries
     foreach (AtomEntry entry in feed.Entries)
     {
         new GBaseAttributes(entry.ExtensionElements).Application
         = applicationName;
     }
     return Batch((AtomFeed)feed, batchUri) as GBaseFeed;
 }
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Inserts an entry into a feed.</summary>
 /// <param name="feed">a feed object you got from a previous
 /// query</param>
 /// <param name="entry">the entry to add to the feed</param>
 /// <returns>the same entry, with a new id, as it has been added
 /// into the feed</returns>
 ///////////////////////////////////////////////////////////////////////
 public GBaseEntry Insert(GBaseFeed feed, GBaseEntry entry)
 {
     entry.GBaseAttributes.Application = applicationName;
     return(base.Insert((AtomFeed)feed, (AtomEntry)entry) as GBaseEntry);
 }
Ejemplo n.º 11
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Creates a query for the given feed.</summary>
 /// <param name="feed">a feed that must have its Feed link set</param>
 ///////////////////////////////////////////////////////////////////////
 public GBaseQuery(GBaseFeed feed)
         : this(feed.Feed)
 {
 }
 ///////////////////////////////////////////////////////////////////////
 /// <summary>Creates a query for the given feed.</summary>
 /// <param name="feed">a feed that must have its Feed link set</param>
 ///////////////////////////////////////////////////////////////////////
 public GBaseQuery(GBaseFeed feed)
     : this(feed.Feed)
 {
 }