using System; using System.Collections.Generic; namespace CIG { public class StoreProduct : IComparable { public StoreProduct(Dictionary props) { this.Update(props); } public StoreProduct(StoreProduct storeProduct) : this(storeProduct.Serialize()) { } public virtual void Update(Dictionary props) { this.Identifier = (string)props["ProductIdentifier"]; this.Title = this.GetValue(props, "ProductTitle", string.Empty); this.Description = this.GetValue(props, "ProductDescription", string.Empty); this.CurrencyCode = this.GetValue(props, "ProductCurrencyCode", string.Empty); this.FormattedPrice = this.GetValue(props, "ProductFormattedPrice", string.Empty); this.Price = this.GetValue(props, "ProductPrice", 0m); this.DollarPrice = this.GetValue(props, "ProductDollarPrice", 0m); this.EuroPrice = this.GetValue(props, "ProductEuroPrice", 0m); this.Available = this.GetValue(props, "Available", false); if (this.Price == 0m) { if (this.DollarPrice != 0m) { this.Price = this.DollarPrice; } else if (this.EuroPrice != 0m) { this.Price = this.EuroPrice; } } object obj; if (props.TryGetValue("CustomProperties", out obj)) { Dictionary dictionary = obj as Dictionary; if (dictionary != null) { this.CustomProperties = new Dictionary(); foreach (KeyValuePair keyValuePair in dictionary) { this.CustomProperties.Add(keyValuePair.Key, (string)keyValuePair.Value); } } else { this.CustomProperties = (Dictionary)obj; } } else { this.CustomProperties = new Dictionary(); } } public int CompareTo(StoreProduct other) { int num = this.Price.CompareTo(other.Price); if (num == 0) { num = this.EuroPrice.CompareTo(other.EuroPrice); if (num == 0) { num = this.DollarPrice.CompareTo(other.DollarPrice); } } return num; } public override string ToString() { return string.Format("[StoreProduct: {0}; Available: {1}]", this.Identifier, this.Available); } public bool Available { get; set; } public string Identifier { get; private set; } public int StorePosition { get; set; } public string Title { get; private set; } public string Description { get; private set; } public decimal Price { get; private set; } public string CurrencyCode { get; private set; } public string FormattedPrice { get; private set; } public decimal DollarPrice { get; private set; } public decimal EuroPrice { get; private set; } public Dictionary CustomProperties { get; private set; } private T GetValue(Dictionary dict, string key, T defaultValue) { object obj; if (dict.TryGetValue(key, out obj) && obj != null) { return (T)((object)obj); } return defaultValue; } public Dictionary Serialize() { Dictionary dictionary = new Dictionary(); dictionary["ProductIdentifier"] = this.Identifier; dictionary["ProductTitle"] = this.Title; dictionary["ProductDescription"] = this.Description; dictionary["ProductPrice"] = this.Price; dictionary["ProductCurrencyCode"] = this.CurrencyCode; dictionary["ProductFormattedPrice"] = this.FormattedPrice; dictionary["ProductEuroPrice"] = this.EuroPrice; dictionary["ProductDollarPrice"] = this.DollarPrice; Dictionary dictionary2 = new Dictionary(); foreach (KeyValuePair keyValuePair in this.CustomProperties) { dictionary2.Add(keyValuePair.Key, keyValuePair.Value); } dictionary["CustomProperties"] = dictionary2; dictionary["Available"] = this.Available; return dictionary; } public const string IdentifierKey = "ProductIdentifier"; public const string TitleKey = "ProductTitle"; public const string DescriptionKey = "ProductDescription"; public const string PriceKey = "ProductPrice"; public const string CurrencyCodeKey = "ProductCurrencyCode"; public const string FormattedPriceKey = "ProductFormattedPrice"; public const string EuroPriceKey = "ProductEuroPrice"; public const string DollarPriceKey = "ProductDollarPrice"; public const string CustomPropertiesKey = "CustomProperties"; public const string AvailableKey = "Available"; } }