예제 #1
0
 public CategorizableItem(string id, PriceDescriptor baseDescriptor, Dictionary <ICategory, PriceDescriptor> properties)
     : base(id, baseDescriptor)
 {
     #region Precondizioni
     if (properties == null)
     {
         throw new ArgumentException("properties null");
     }
     #endregion
     _properties = properties;
 }
예제 #2
0
 public AbstractItem(string id, PriceDescriptor descriptor)
 {
     #region Precondizioni
     if (descriptor == null)
     {
         throw new ArgumentException("descriptor null");
     }
     if (String.IsNullOrWhiteSpace(id))
     {
         throw new ArgumentException("id null or blank");
     }
     #endregion
     _descriptor = descriptor;
     _identifier = id;
 }
예제 #3
0
 public Sector(PriceDescriptor descriptor, int numRows, int numColumns)
 {
     #region Precondizioni
     if (numRows < 0)
     {
         throw new ArgumentException("invalid number of rows");
     }
     if (numColumns < 0)
     {
         throw new ArgumentException("invalid number of columns");
     }
     #endregion
     _descriptor = descriptor;
     _numRows    = numRows;
     _numColumns = numColumns;
 }
예제 #4
0
 public BasicItem(string id, PriceDescriptor priceDescriptor) : base(id, priceDescriptor)
 {
 }
예제 #5
0
            public static CategorizableItem Parse(XmlNode itemToParse)
            {
                #region Precondizioni
                if (itemToParse == null)
                {
                    throw new ArgumentNullException("itemToParse null");
                }
                ICategoryCoordinator coor = CoordinatorManager.Instance.CoordinatorOfType <ICategoryCoordinator>();
                if (coor == null)
                {
                    throw new ApplicationException("Non è disponibile un category coordinator");
                }
                #endregion

                string id, name, description, categoryName;
                double price;
                Dictionary <ICategory, PriceDescriptor> properties = new Dictionary <ICategory, PriceDescriptor>();

                //Devono esserci almeno 4 elementi, id, name, description, price.
                //Possono esserci da 0 a N categorie.

                try
                {
                    name        = ParserUtils.RetrieveValues <String>(itemToParse, "Name")[0];
                    description = ParserUtils.RetrieveValues <String>(itemToParse, "Description")[0];
                    price       = ParserUtils.RetrieveValues <double>(itemToParse, "Price")[0];
                    id          = ParserUtils.RetrieveValues <String>(itemToParse, "Identifier")[0];
                }
                catch (ParsingException e)
                {
                    throw new ItemDescriptorException(e.Message);
                }

                PriceDescriptor priceDescriptor = new PriceDescriptor(name, description, price);

                XmlNodeList categoryNode = itemToParse.SelectNodes("Category");
                ICategory   category;
                for (int i = 0; i < categoryNode.Count; i++)
                {
                    try
                    {
                        name         = ParserUtils.RetrieveValues <String>(categoryNode[i], "Name")[0];
                        description  = ParserUtils.RetrieveValues <String>(categoryNode[i], "Description")[0];
                        price        = ParserUtils.RetrieveValues <double>(categoryNode[i], "Price")[0];
                        categoryName = ParserUtils.RetrieveValues <String>(categoryNode[i], "Path")[0];
                    }
                    catch (ParsingException e)
                    {
                        throw new ItemDescriptorException(e.Message);
                    }
                    category = coor.getCategoryByPath(categoryName);
                    if (category == null)
                    {
                        throw new ApplicationException("Non è stata trovata la categoria " + categoryName);
                    }

                    if (properties.ContainsKey(category))
                    {
                        throw new ItemDescriptorException("Una categoria è presente più di una volta");
                    }

                    properties.Add(category, new PriceDescriptor(name, description, price));
                }
                return(new CategorizableItem(id, priceDescriptor, properties));
            }
예제 #6
0
 public CategorizableItem(string id, PriceDescriptor baseDescriptor) :
     this(id, baseDescriptor, new Dictionary <ICategory, PriceDescriptor>())
 {
 }