コード例 #1
0
        private void SpawnCategoryView()
        {
            ICategoryCoordinator cCoor   = CoordinatorManager.Instance.CoordinatorOfType <ICategoryCoordinator>();
            CategoryManagerView  catView = new CategoryManagerView();

            new CategoryManagerPresenter(catView, cCoor.RootCategory);
            catView.Show();
        }
コード例 #2
0
ファイル: ItemParser.cs プロジェクト: robertodellapenna/CSB
            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));
            }