예제 #1
0
        private void Execute(string[] args)
        {
            string queryString = null;

            if (args.Length == 3)
            {
                args        = Init(args, "Google-CsharpQueryExample-1.0");
                queryString = args[0];
            }
            else
            {
                FatalError("Invalid argument count. Usage:\n" +
                           "  queryexample.exe --key <key> \"<query>\"");
            }

            // Creates a query on the snippets feed.
            GBaseQuery query = new GBaseQuery(uriFactory.SnippetsFeedUri);

            query.GoogleBaseQuery  = queryString;
            query.NumberToRetrieve = MAX_RESULTS;

            System.Console.WriteLine("Sending request to: " + query.Uri);

            // Connects to the server and gets the result, which is
            // then parsed to create a GBaseFeed object.
            GBaseFeed result = service.Query(query);

            PrintResult(result);
        }
예제 #2
0
        public int run()
        {
            if (debug)
            {
                Console.WriteLine("GoogleTestRun.run() called");
            }

            // Creates a query on the snippets feed.
            GBaseQuery query = new GBaseQuery(uriFactory.SnippetsFeedUri);

            for (int i = 0; i < queryArr.GetLength(0); i++)
            {
                query.GoogleBaseQuery  = queryArr[i];
                query.NumberToRetrieve = MAX_RESULTS;

                System.Console.WriteLine("Sending request to: " + query.Uri);

                // Connects to the server and gets the result, which is
                // then parsed to create a GBaseFeed object.
                GBaseFeed result = service.Query(query);

                PrintResult(result);
            }
            return(1);
        }
예제 #3
0
        public void Execute()
        {
            GBaseFeed feed   = ReadFromStandardInput();
            GBaseFeed result = service.Batch(feed, uriFactory.ItemsFeedBatchUri);

            WriteToStandardOutput(result);
        }
        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);
        }
예제 #5
0
        public void Execute()
        {
            GBaseFeed feed = ReadFromStandardInput();

            GBaseEntry result = service.Insert(uriFactory.ItemsFeedUri,
                                               feed.Entries[0] as GBaseEntry);

            WriteToStandardOutput(result);
        }
예제 #6
0
        public void Execute()
        {
            GBaseFeed  feed  = ReadFromStandardInput();
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            entry.EditUri = entry.Id.Uri;
            service.Update(entry);

            Console.WriteLine("Item updated: " + entry.Id.Uri);
        }
예제 #7
0
        public void Execute()
        {
            GBaseFeed feed = service.Query(new GBaseQuery(new Uri(url)));

            if (feed.Entries.Count == 1)
            {
                // It was most probably a single entry Uri
                WriteToStandardOutput(feed.Entries[0]);
            }
            else
            {
                WriteToStandardOutput(feed);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        //////////////////////////////////////////////////////////////////////
        /// <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();
            }
        }
        public void ReadItemTypesFeedFromXml()
        {
            string xml = "<?xml version='1.0' encoding='UTF-8'?>\n" +
                         "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-metadata/1.0'>\n" +
                         "  <id>http://www.google.com/base/feeds/itemtypes/en_US</id>\n" +
                         "  <updated>2006-08-24T14:32:27.228Z</updated>\n" +
                         "  <title type='text'>Item types for locale en_US</title>\n" +
                         "  <link rel='alternate' type='text/html' href='http://www.google.com'/>\n" +
                         "  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/base/feeds/itemtypes/en_US'/>\n" +
                         "  <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/itemtypes/en_US?max-results=1&amp;key=ABQIAAAAfW6XRFfnNGUiegdqIq0KExT2yXp_ZAY8_ufC3CFXhHIE1NvwkxS8MfEf7Ag6UI0Ony8Yq3gZHm6c9w'/>\n" +
                         "  <author>\n" +
                         "    <name>Google Inc.</name>\n" +
                         "    <email>[email protected]</email>\n" +
                         "  </author>\n" +
                         "  <generator version='1.0' uri='http://www.google.com'>GoogleBase</generator>\n" +
                         "  <openSearch:totalResults>1</openSearch:totalResults>\n" +
                         "  <openSearch:itemsPerPage>1</openSearch:itemsPerPage>\n" +
                         "  <entry>\n" +
                         "    <id>http://www.google.com/base/feeds/itemtypes/en_US/products</id>\n" +
                         "    <updated>2006-08-24T14:32:27.233Z</updated>\n" +
                         "    <category scheme='http://www.google.com/categories/itemtypes' term='products'/>\n" +
                         "    <title type='text'>products</title>\n" +
                         "    <content type='text'>products</content>\n" +
                         "    <gm:item_type>products</gm:item_type>\n" +
                         "    <gm:attributes>\n" +
                         "      <gm:attribute name='product type' type='text'/>\n" +
                         "      <gm:attribute name='condition' type='text'/>\n" +
                         "      <gm:attribute name='count' type='int'/>\n" +
                         "    </gm:attributes>\n" +
                         "  </entry>\n" +
                         "</feed>";
            GBaseFeed  feed  = Parse(xml);
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            Assert.IsNotNull(entry, "entry");

            ItemTypeDefinition def = entry.ItemTypeDefinition;

            Assert.IsNotNull(def, "ItemTypeDefinition");
            Assert.AreEqual("products", def.ItemType);
            Assert.AreEqual(3, def.Attributes.Count);
            Assert.AreEqual("product type", def.Attributes[0].Name);
            Assert.AreEqual(GBaseAttributeType.Text, def.Attributes[0].Type);
            Assert.AreEqual("condition", def.Attributes[1].Name);
            Assert.AreEqual(GBaseAttributeType.Text, def.Attributes[1].Type);
            Assert.AreEqual("count", def.Attributes[2].Name);
            Assert.AreEqual(GBaseAttributeType.Int, def.Attributes[2].Type);
        }
        public void ParseGenerateAndReparse()
        {
            GBaseFeed feed = Parse(SAMPLE_FEED);

            StringWriter sw        = new StringWriter();
            XmlWriter    xmlWriter = new XmlTextWriter(sw);

            feed.SaveToXml(xmlWriter);
            xmlWriter.Close();

            Tracing.TraceMsg(sw.ToString());

            GBaseFeed reparsed = Parse(sw.ToString());

            CheckParsedFeedEntries(reparsed);
        }
        public void ReadAttributesFeedFromXml()
        {
            string xml = "<?xml version='1.0' encoding='UTF-8'?>" +
                         "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gm='http://base.google.com/ns-metadata/1.0'>" +
                         "  <id>http://www.google.com/base/feeds/attributes</id>" +
                         "  <updated>2006-08-24T14:26:45.558Z</updated>" +
                         "  <title type='text'>Attribute histogram for query: </title>" +
                         "  <link rel='alternate' type='text/html' href='http://www.google.com'/>" +
                         "  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes'/>" +
                         "  <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes?max-results=1&amp;key=ABQIAAAA7VerLsOcLuBYXR7vZI2NjhTRERdeAiwZ9EeJWta3L_JZVS0bOBRIFbhTrQjhHE52fqjZvfabYYyn6A'/>" +
                         "  <generator version='1.0' uri='http://www.google.com'>GoogleBase</generator>" +
                         "  <openSearch:totalResults>1</openSearch:totalResults>" +
                         "  <openSearch:itemsPerPage>1</openSearch:itemsPerPage>" +
                         "  <entry>" +
                         "    <id>http://www.google.com/base/feeds/attributes/label%28text%29N</id>" +
                         "    <updated>2006-08-24T14:26:45.651Z</updated>" +
                         "    <title type='text'>label(text)</title>" +
                         "    <content type='text'>Attribute label of type text.</content>" +
                         "    <link rel='self' type='application/atom+xml' href='http://www.google.com/base/feeds/attributes/label%28text%29N'/>" +
                         "    <gm:attribute name='label' type='text' count='158778'>" +
                         "      <gm:value count='47544'>housing</gm:value>" +
                         "      <gm:value count='36954'>reviews</gm:value>" +
                         "    </gm:attribute>" +
                         "  </entry>" +
                         "</feed>";
            GBaseFeed  feed  = Parse(xml);
            GBaseEntry entry = feed.Entries[0] as GBaseEntry;

            Assert.IsNotNull(entry, "entry");

            AttributeHistogram hist = entry.AttributeHistogram;

            Assert.AreEqual("label", hist.Name, "name");
            Assert.AreEqual(GBaseAttributeType.Text, hist.Type, "type");
            Assert.AreEqual(158778, hist.Count, "count");

            List <HistogramValue> values = hist.Values;

            Assert.AreEqual(2, values.Count, "values.Length");
            Assert.AreEqual("housing", values[0].Content);
            Assert.AreEqual(47544, values[0].Count);
            Assert.AreEqual("reviews", values[1].Content);
            Assert.AreEqual(36954, values[1].Count);
        }
        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");
        }
        public void ReadFeedFromXmlRegenerateAndReparse()
        {
            GBaseFeed feed = Parse(SAMPLE_FEED);

            CheckParsedFeedEntries(feed);
        }