Beispiel #1
0
        protected void SetProductAttribute(ProductVariant product, string attr, string value, out object newValue, out object oldValue)
        {
            oldValue = newValue = null;

            if (String.IsNullOrEmpty(value))
            {
                return;
            }
            var propInfo = product.GetType().GetProperty(attr);

            switch (attr)
            {
            case "Price":
                newValue = Convert.ToDecimal(value);
                break;

            case "StockQuantity":
                newValue = Convert.ToInt32(value);
                break;

            default:
                newValue = value;
                break;
            }
            oldValue = propInfo.GetValue(product, null);
            if (propInfo == null)
            {
                throw new Exception(String.Format("Sku #{0}. Unknown property '{1}'.", product.Sku, attr));
            }
            propInfo.SetValue(product, newValue, null);
        }
Beispiel #2
0
        public ProductVariant Get(ProductVariant dummy)
        {
            var filepath = GetFilePath(dummy.UUID);

            if (File.Exists(filepath))
            {
                locker.EnterReadLock();
                try
                {
                    var item = (ProductVariant)Serialization.Deserialize(dummy.GetType(), KnownTypes, filepath);
                    return(item);
                }
                finally
                {
                    locker.ExitReadLock();
                }
            }
            return(default(ProductVariant));
        }