コード例 #1
0
        public string AddToGoogleBase()
        {
            UpdateEntry();
            // try insert
            string gbaseId = "";
            bool hasError = false;
            try
            {
                entry = service.Insert(feed, entry);
                gbaseId = entry.Id.AbsoluteUri;
            }
            catch (WebException ex)
            {
                var resp = ex.Response;
                hasError = true;
                if (resp != null)
                {
                    using (var sr = new StreamReader(resp.GetResponseStream()))
                    {
                        var err = sr.ReadToEnd();
                        Syslog.Write(string.Concat("ADD: ", err, " ", hostName, " ", ProductId));
                    }
                }
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                Syslog.Write(string.Concat("ADD: ", ex.Message, " ", hostName, " ", ProductId));
                hasError = true;
            }

            if (hasError && ownerid.HasValue)
            {
                using (var repository = new TradelrRepository())
                {
                    repository.AddActivity(ownerid.Value,
                                   new ActivityMessage(ProductId, ownerid,
                                               ActivityMessageType.AUTOPOST_GBASE_FAIL,
                                               string.Format("<a href='{0}'>{1}</a>", producturl, productname)),
                                               subdomainid);
                    repository.Save(); 
                }
                
            }

            return gbaseId;
        }
コード例 #2
0
        private static void RunSample(string username, string password, string accountId)
        {
            // Connect to the service
            ContentForShoppingService service = new ContentForShoppingService("ContentForShopping-Sample");

            service.setUserCredentials(username, password);

            // Retrieve the list of all existing products
            string       projection = "schema";
            ProductQuery query      = new ProductQuery(projection, accountId);
            ProductFeed  feed       = service.Query(query);

            // Display title and id for each product
            Console.WriteLine("Listing all products");
            foreach (ProductEntry p in feed.Entries)
            {
                Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")");
            }

            // Create a new product
            ProductEntry entry = new ProductEntry();

            entry.Title.Text = "Wool sweater";
            AtomContent c = new AtomContent();

            c.Content             = "Comfortable and soft, this sweater will keep you warm on those cold winter nights. Red and blue stripes.";
            entry.Content         = c;
            entry.ProductId       = "123457";
            entry.Language        = "it";
            entry.TargetCountry   = "US";
            entry.ContentLanguage = "en";
            entry.Brand           = "ACME";
            entry.Condition       = "new";
            entry.Price           = new Price("usd", "25");
            entry.ProductType     = "Clothing & Accessories > Clothing > Outerwear > Sweaters";
            entry.Quantity        = 3;
            entry.ShippingWeight  = new ShippingWeight("lb", "0.1");
            entry.ImageLink       = new ImageLink("http://www.example.com/image.jpg");
            entry.Availability    = "available for order";
            entry.Channel         = "online";
            entry.Gender          = "female";
            entry.Material        = "wool";
            entry.Pattern         = "Red and blue stripes";
            entry.Color           = "red";

            AtomLink link = new AtomLink();

            link.HRef = "http://www.example.com";
            link.Rel  = "alternate";
            link.Type = "text/html";
            entry.Links.Add(link);

            // Shipping rules
            Shipping s1 = new Shipping();

            s1.Country = "US";
            s1.Region  = "MA";
            s1.Service = "Speedy Shipping - Ground";
            s1.Price   = new ShippingPrice("usd", "5.95");

            Shipping s2 = new Shipping();

            s2.Country = "US";
            s2.Region  = "024*";
            s2.Service = "Speedy Shipping - Air";
            s2.Price   = new ShippingPrice("usd", "7.95");

            entry.ShippingRules.Add(s1);
            entry.ShippingRules.Add(s2);

            // Tax rules
            Tax t1 = new Tax();

            t1.Country = "US";
            t1.Region  = "CA";
            t1.Rate    = "8.25";
            t1.Ship    = true;

            Tax t2 = new Tax();

            t2.Country = "US";
            t2.Region  = "926*";
            t2.Rate    = "8.75";
            t2.Ship    = false;

            entry.TaxRules.Add(t1);
            entry.TaxRules.Add(t2);

            // Additional Image Links
            AdditionalImageLink il1 = new AdditionalImageLink("http://www.example.com/1.jpg");

            entry.AdditionalImageLinks.Add(il1);
            AdditionalImageLink il2 = new AdditionalImageLink("http://www.example.com/2.jpg");

            entry.AdditionalImageLinks.Add(il2);

            // Add the product to the server feed
            Console.WriteLine("Inserting product");
            ProductEntry inserted = service.Insert(feed, entry);

            // Update the product we just inserted
            inserted.Title.Text = "2011 Wool sweater";
            Console.WriteLine("Updating product");
            ProductEntry updated = service.Update(inserted);

            // Retrieve the new list of products
            feed = service.Query(query);

            // Display title and id for each product
            Console.WriteLine("Listing all products again");
            foreach (ProductEntry p in feed.Entries)
            {
                Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")");
            }

            // Delete the item we inserted and updated
            Console.WriteLine("Deleting product");
            service.Delete(updated);
        }