Example #1
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>takes the updated entry returned and sets the properties to this object</summary>
        /// <param name="updatedEntry"> </param>
        //////////////////////////////////////////////////////////////////////
        protected void CopyEntry(AtomEntry updatedEntry)
        {
            Tracing.Assert(updatedEntry != null, "updatedEntry should not be null");
            if (updatedEntry == null)
            {
                throw new ArgumentNullException("updatedEntry");
            }

            this.title           = updatedEntry.Title;
            this.authors         = updatedEntry.Authors;
            this.id              = updatedEntry.Id;
            this.links           = updatedEntry.Links;
            this.lastUpdateDate  = updatedEntry.Updated;
            this.publicationDate = updatedEntry.Published;
            this.authors         = updatedEntry.Authors;
            this.rights          = updatedEntry.Rights;
            this.categories      = updatedEntry.Categories;
            this.summary         = updatedEntry.Summary;
            this.content         = updatedEntry.Content;
            this.source          = updatedEntry.Source;

            this.ExtensionElements.Clear();

            foreach (IExtensionElementFactory extension in updatedEntry.ExtensionElements)
            {
                this.ExtensionElements.Add(extension);
            }
        }
Example #2
0
 public void TypeTest()
 {
     AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value
     string expected = "TestValue";            
     string actual;
     target.Type = expected;
     actual = target.Type;
     Assert.AreEqual(expected, actual);
 }
        ///<summary>Standard type converter method</summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType)
        {
            AtomContent content = value as AtomContent;

            if (destinationType == typeof(System.String) && content != null)
            {
                return("Content-type: " + content.Type);
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
        private static void RunSample(string username, string password, string accountId) {
            // Connect to the service
            ContentForShoppingService service = new ContentForShoppingService("ManagedAccounts-Sample", accountId);
            service.setUserCredentials(username, password);

            // Retrieve the list of all existing accounts
            ManagedAccountsFeed feed = service.QueryManagedAccounts();

            // Display title and id for each managed account
            Console.WriteLine("Listing all managed accounts returned");
            foreach (ManagedAccountsEntry m in feed.Entries) {
                Console.WriteLine("Managed Account: " + m.Title.Text + " (" + m.InternalId + ")");
            }

            // Create a new subaccount entry
            ManagedAccountsEntry entry = new ManagedAccountsEntry();
            entry.Title.Text = "Bob\'s Shirts";
            AtomContent c = new AtomContent();
            c.Content = "Founded in 1980, Bob has been selling shirts that you don\'t want for over 30 years.";
            entry.Content = c;
            entry.AdultContent = "no";
            entry.InternalId = "Subaccount100";
            entry.ReviewsUrl = "http://my.site.com/reviews?mo=user-rating&user=Subaccount100";

            // Add the subaccount entry
            Console.WriteLine("Inserting managed account");
            ManagedAccountsEntry inserted = service.InsertManagedAccount(entry);

            // Update the managed account we just inserted
            c = new AtomContent();
            c.Content = "Founded in 1980, Bob has been selling shirts that you love for over 30 years.";
            inserted.Content = c;
            Console.WriteLine("Updating managed account");
            ManagedAccountsEntry updated = service.UpdateManagedAccount(inserted);

            // Retrieve the new list of managed accounts
            feed = service.QueryManagedAccounts();

            // Display title and id for each managed account
            Console.WriteLine("Listing all managed accounts returned");
            foreach (ManagedAccountsEntry m in feed.Entries) {
                Console.WriteLine("Managed Account: " + m.Title.Text + " (" + m.InternalId + ")");
            }

            // Delete the managed account we inserted and updated
            Console.WriteLine("Deleting product");
            service.DeleteManagedAccount(updated);
        }
Example #5
0
       /////////////////////////////////////////////////////////////////////////////

       //////////////////////////////////////////////////////////////////////
       /// <summary>compares 2 content objects</summary> 
       /// <param name="theOne">the One content </param>
       /// <param name="theOther">the Other content</param>
       /// <returns>true if identical </returns>
       //////////////////////////////////////////////////////////////////////
       public static bool IsContentIdentical(AtomContent theOne, AtomContent theOther)
       {
           if (theOne == null && theOther == null)
           {
               return true;
           }


           if (ObjectModelHelper.IsBaseIdentical(theOne, theOther)==false)
           {
               return false;
           }
           if (String.Compare(theOne.Type, theOther.Type)!= 0)
           {
               return false;
           }
           if (AtomUri.Compare(theOther.Src, theOther.Src)!= 0)
           {
               return false;
           }
           if (String.Compare(theOne.Content, theOther.Content)!= 0)
           {
               return false;
           }

           return true;
       }
Example #6
0
        /// <summary>takes the updated entry returned and sets the properties to this object</summary> 
        /// <param name="updatedEntry"> </param>
        protected void CopyEntry(AtomEntry updatedEntry) {
            Tracing.Assert(updatedEntry != null, "updatedEntry should not be null");
            if (updatedEntry == null) {
                throw new ArgumentNullException("updatedEntry");
            }

            this.title = updatedEntry.Title;
            this.authors = updatedEntry.Authors;
            this.id = updatedEntry.Id;
            this.links = updatedEntry.Links;
            this.lastUpdateDate = updatedEntry.Updated;
            this.publicationDate = updatedEntry.Published;
            this.authors = updatedEntry.Authors;
            this.rights = updatedEntry.Rights;
            this.categories = updatedEntry.Categories;
            this.summary = updatedEntry.Summary;
            this.content = updatedEntry.Content;
            this.source = updatedEntry.Source;

            this.ExtensionElements.Clear();

            foreach (IExtensionElementFactory extension in updatedEntry.ExtensionElements) {
                this.ExtensionElements.Add(extension);
            }
        }
		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);
		}
        /// <summary>
        /// Get the content of possibly null AtomContent
        /// </summary>
        /// <param name="content">The Google AtomContent</param>
        /// <returns>The content or empty string if the content or it's Content was null</returns>
        public static string SafeGetContent(AtomContent content)
        {
            if (content == null)
            {
                return string.Empty;
            }

            return content.Content ?? string.Empty;
        }
        /// <summary>creates an AtomContent object by parsing an xml stream</summary>
        /// <param name="reader">a XMLReader positioned correctly </param>
        /// <param name="owner">the container element</param>
        /// <returns> null or an AtomContent object</returns>
        protected AtomContent ParseContent(XmlReader reader, AtomBase owner)
        {
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            AtomContent content = owner.CreateAtomSubElement(reader, this) as AtomContent;

            Tracing.TraceCall();
            if (content != null)
            {
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        object localname = reader.LocalName;
                        if (localname.Equals(this.nameTable.Type))
                        {
                            content.Type = Utilities.DecodedValue(reader.Value);
                        }
                        else if (localname.Equals(this.nameTable.Src))
                        {
                            content.Src = new AtomUri(reader.Value);
                        }
                        else
                        {
                            ParseBaseAttributes(reader, content);
                        }
                    }
                }

                if (MoveToStartElement(reader))
                {
                    if (content.Type.Equals("text") ||
                        content.Type.Equals("html") ||
                        content.Type.StartsWith("text/"))
                    {
                        // if it's text it get's just the string treatment. No
                        // subelements are allowed here
                        content.Content = Utilities.DecodedValue(reader.ReadString());
                    }
                    else if (content.Type.Equals("xhtml") ||
                             content.Type.Contains("/xml") ||
                             content.Type.Contains("+xml"))
                    {
                        // do not get childlists if the element is empty. That would skip to the next element
                        if (!reader.IsEmptyElement)
                        {
                            // everything else will be nodes in the extension element list
                            // different media type. Create extension elements
                            int lvl = -1;
                            while (NextChildElement(reader, ref lvl))
                            {
                                ParseExtensionElements(reader, content);
                            }
                        }
                    }
                    else
                    {
                        // everything else SHOULD be base 64 encoded, so one big string
                        // i know the if statement could be combined with the text handling
                        // but i consider it clearer to make a 3 cases statement than combine them
                        content.Content = Utilities.DecodedValue(reader.ReadString());
                    }
                }
            }
            return(content);
        }
 public void ContentTest()
 {
     AtomEntry target = new AtomEntry(); // TODO: Initialize to an appropriate value
     AtomContent expected = new AtomContent();
     AtomContent actual;
     target.Content = expected;
     actual = target.Content;
     Assert.AreEqual(expected, actual);
 }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>compares 2 content objects</summary> 
        /// <param name="theOne">the One content </param>
        /// <param name="theOther">the Other content</param>
        /// <returns>true if identical </returns>
        //////////////////////////////////////////////////////////////////////
        public static bool IsContentIdentical(AtomContent theOne, AtomContent theOther)
        {
            if (theOne == null && theOther == null)
            {
                return true;
            }


            if (!ObjectModelHelper.IsBaseIdentical(theOne, theOther))
            {
                return false;
            }
            if (String.Compare(theOne.Type, theOther.Type) != 0)
            {
                return false;
            }
            if (AtomUri.Compare(theOther.Src, theOther.Src) != 0)
            {
                return false;
            }

            String content = theOther.Content == null ? "" : theOther.Content;
            String other = theOne.Content == null ? "" : theOne.Content;


            if (String.Compare(content, other) != 0)
            {
                return false;
            }

            return true;
        }
Example #12
0
 public void SrcTest()
 {
     AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value
     AtomUri expected = new AtomUri("http://www.test.com/");
     AtomUri actual;
     target.Src = expected;
     actual = target.Src;
     Assert.AreEqual(expected, actual);
 }
Example #13
0
 public void XmlNameTest()
 {
     AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value
     Assert.AreEqual(AtomParserNameTable.XmlContentElement, target.XmlName);
 }
Example #14
0
 public void AtomContentConstructorTest()
 {
     AtomContent target = new AtomContent();
     Assert.IsNotNull(target);
     Assert.IsNull(target.Content);
     Assert.IsNull(target.Src);
     Assert.IsTrue(target.Type == "text");
 }
Example #15
0
 public void AbsoluteUriTest()
 {
     AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value
     AtomUri expected = new AtomUri("http://www.test.com/");
     target.Src = expected;
     string actual;
     actual = target.AbsoluteUri;
     Assert.AreEqual(actual, "http://www.test.com/");
 }