Пример #1
0
        public void ItemListTests()
        {
            Parser p = new Parser();

            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Boolean", "true", parentProject.FullPath));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary <ProjectPropertyInstance>(), itemBag, FileSystems.Default);

            AssertParseEvaluate(p, "@(Compile) == 'foo.cs;bar.cs;baz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile,' ') == 'foo.cs bar.cs baz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile,'') == 'foo.csbar.csbaz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Filename)') == 'foo;bar;baz'", expander, true);
            AssertParseEvaluate(p, "@(Compile -> 'temp\\%(Filename).xml', ' ') == 'temp\\foo.xml temp\\bar.xml temp\\baz.xml'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'', '') == ''", expander, true);
            AssertParseEvaluate(p, "@(Compile->'') == ';;'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)', '') == ''", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)') == ';;'", expander, true);
            AssertParseEvaluate(p, "@(Boolean)", expander, true);
            AssertParseEvaluate(p, "@(Boolean) == true", expander, true);
            AssertParseEvaluate(p, "'@(Empty, ';')' == ''", expander, true);
        }
Пример #2
0
        public void StringExpansionTests()
        {
            Parser p = new Parser();

            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("TestQuote", "Contains'Quote'"));
            propertyBag.Set(ProjectPropertyInstance.Create("AnotherTestQuote", "Here's Johnny!"));
            propertyBag.Set(ProjectPropertyInstance.Create("Atsign", "Test the @ replacement"));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default);

            AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", expander, true);
            AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", expander, true);
            AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", expander, true);
        }
Пример #3
0
        public void OldSyntaxTests()
        {
            Parser          p             = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default);

            AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", expander, true);
        }
Пример #4
0
        public void SecondaryItemNotShadowedByPrimaryItem()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
            table1.Add(new ProjectItemInstance(project, "i2", "a%3b1", project.FullPath));
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            Lookup.Scope enteredScope = lookup.EnterScope("x");

            // Should return item from the secondary table.
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal("a;1", lookup.GetItems("i2").First().EvaluatedInclude);
        }
Пример #5
0
        /// <summary>
        ///     The item.
        /// </summary>
        /// <param name="name">
        ///     The name.
        /// </param>
        /// <param name="makeChampionUniq">
        ///     The make champion unique.
        /// </param>
        /// <returns>
        ///     The <see cref="MenuItem" />.
        /// </returns>
        public MenuItem Item(string name, bool makeChampionUniq = false)
        {
            if (makeChampionUniq && ObjectManager.LocalHero != null)
            {
                name = ObjectManager.LocalHero.StoredName() + name;
            }

            var      id = this.Name + name + (this.Parent != null ? this.Parent.Name : string.Empty);
            MenuItem tempItem;

            if (ItemDictionary.TryGetValue(id, out tempItem))
            {
                return(tempItem);
            }

            tempItem = this.Items.FirstOrDefault(x => x.Name == name)
                       ?? (from subMenu in this.Children where subMenu.Item(name) != null select subMenu.Item(name))
                       .FirstOrDefault();
            if (tempItem != null)
            {
                ItemDictionary.Add(id, tempItem);
            }

            return(tempItem);
        }
        private void AddToItems(T item, Point cell)
        {
            List <Point> pl;

            ItemDictionary.TryGetValue(item, out pl);
            if (pl == null)
            {
                if (ListOfPointQueue.Count > 0)
                {
                    pl = ListOfPointQueue.Dequeue();
                }
                else
                {
                    pl = new List <Point>();
                }
                pl.Add(cell);
                ItemDictionary.Add(item, pl);
            }
            else
            {
                if (!pl.Contains(cell))
                {
                    pl.Add(cell);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1" /> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted.</param>
        /// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1" />.</param>
        public void Insert(int index, TItem item)
        {
            ItemList.Insert(index, item);
            ++m_VersionTag;

            if (HasKey)
            {
                ItemDictionary.Add(ExtractKey(item), item);
            }
        }
Пример #8
0
        /// <summary>
        /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
        public void Add(TItem item)
        {
            ItemList.Add(item);
            ++m_VersionTag;

            if (HasKey)
            {
                ItemDictionary.Add(ExtractKey(item), item);
            }
        }
Пример #9
0
        public ItemDictionary <int, TaskWrapper> GetNearestTask(IEnumerable <int> contactid)
        {
            var sqlResult = DaoFactory.GetTaskDao().GetNearestTask(contactid.ToArray());
            var result    = new ItemDictionary <int, TaskWrapper>();

            foreach (var item in sqlResult)
            {
                result.Add(item.Key, ToTaskWrapper(item.Value));
            }

            return(result);
        }
Пример #10
0
        public void InvalidItemInConditionEvaluation()
        {
            Parser p = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "a", parentProject.FullPath));

            PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag);

            AssertParseEvaluateThrow(p, "@(Compile) > 0", expander, null);
        }
Пример #11
0
        private void GetComponents(string lang)
        {
            var componentDocumentationPages = DocPages.FindAll(x => x is ComponentDocumentationPage).Select(x => (ComponentDocumentationPage)x);

            var query = from pages in componentDocumentationPages
                        orderby pages.Name
                        select pages;

            try
            {
                foreach (var page in query)
                {
                    var linkedLang = page.Localizations.ContainsKey(lang) ? lang : "en";
                    var pp         = (LocalizedComponentDocumentationPage)page.Localizations[linkedLang];
                    var pinfo      = pp.PluginType.GetPluginInfoAttribute();
                    FunctionListAttribute[] flas = (FunctionListAttribute[])pp.PluginType.GetCustomAttributes(typeof(FunctionListAttribute), false);

                    switch (page.Category)
                    {
                    case ComponentCategory.Undefined:
                        itemlist.Add(pp.Name, ItemType.Tutorial, Properties.Resources.FL_Tutorial + "\\ " + pp.Name);
                        foreach (var fla in flas)
                        {
                            fla.PluginType = pinfo.PluginType;
                            itemlist.Add(fla.Function, ItemType.Tutorial, Properties.Resources.FL_Tutorial + "\\ " + pp.Name + "\\ " + fla.Path);
                        }
                        break;

                    default:
                        string catpath = GetComponentCategory(page.Category) + "\\ " + pp.Name;
                        itemlist.Add(pp.Name, ItemType.Component, catpath);
                        foreach (var fla in flas)
                        {
                            fla.PluginType = pinfo.PluginType;
                            string path = (fla.Path != "") ? fla.Path : catpath;
                            itemlist.Add(fla.Function, ItemType.Component, path);
                        }
                        break;
                    }

                    foreach (var tmpl in pp.Templates.Templates)
                    {
                        var p = tmpl.CurrentLocalization.CategoryPath() + "\\ " + tmpl.CurrentLocalization.Name;
                        itemlist.Add(pp.Name, ItemType.Template, p);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #12
0
 public RefiningVM(Game game, CommandReferences cmdRef, RefiningDB refiningDB)
 {
     _staticData   = game.StaticData;
     _refineDB     = refiningDB;
     _orderHandler = game.OrderHandler;
     _factionGuid  = refiningDB.OwningEntity.FactionOwner;
     _cmdRef       = cmdRef;
     foreach (var kvp in _staticData.CargoGoods.GetMaterials())
     {
         ItemDictionary.Add(kvp.Key, kvp.Value.Name);
     }
     ItemDictionary.SelectedIndex = 0;
     NewJobBatchCount             = 1;
     NewJobRepeat = false;
 }
Пример #13
0
        public IEnumerable <SecurityWrapper> SetAccessToWebItems(IEnumerable <ItemKeyValuePair <String, Boolean> > items)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var itemList = new ItemDictionary <String, Boolean>();

            foreach (ItemKeyValuePair <String, Boolean> item in items)
            {
                if (!itemList.ContainsKey(item.Key))
                {
                    itemList.Add(item.Key, item.Value);
                }
            }

            var defaultPageSettings = StudioDefaultPageSettings.Load();

            foreach (var item in itemList)
            {
                Guid[] subjects  = null;
                var    productId = new Guid(item.Key);

                if (item.Value)
                {
                    var webItem = WebItemManager.Instance[productId] as IProduct;
                    if (webItem != null)
                    {
                        var productInfo    = WebItemSecurity.GetSecurityInfo(item.Key);
                        var selectedGroups = productInfo.Groups.Select(group => group.ID).ToList();
                        var selectedUsers  = productInfo.Users.Select(user => user.ID).ToList();
                        selectedUsers.AddRange(selectedGroups);
                        if (selectedUsers.Count > 0)
                        {
                            subjects = selectedUsers.ToArray();
                        }
                    }
                }
                else if (productId == defaultPageSettings.DefaultProductID)
                {
                    (defaultPageSettings.GetDefault() as StudioDefaultPageSettings).Save();
                }

                WebItemSecurity.SetSecurity(item.Key, item.Value, subjects);
            }

            MessageService.Send(Request, MessageAction.ProductsListUpdated);

            return(GetWebItemSecurityInfo(itemList.Keys.ToList()));
        }
Пример #14
0
        private static ItemDictionary <ProjectItemInstance> ToItemDictionary(Dictionary <string, string[]> itemTypes)
        {
            var itemDictionary = new ItemDictionary <ProjectItemInstance>();

            var dummyProject = ProjectHelpers.CreateEmptyProjectInstance();

            foreach (var itemType in itemTypes)
            {
                foreach (var item in itemType.Value)
                {
                    itemDictionary.Add(new ProjectItemInstance(dummyProject, itemType.Key, item, dummyProject.FullPath));
                }
            }

            return(itemDictionary);
        }
Пример #15
0
        /// <summary>
        /// Gets or Sets the element at the specified index in the list.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>TItem.</returns>
        public new TItem this[int index]
        {
            get { return(ItemList[index]); }
            set
            {
                var existing = ItemList[index];
                ItemList[index] = value;
                ++m_VersionTag;

                if (HasKey)
                {
                    ItemDictionary.Remove(ExtractKey(existing));
                    ItemDictionary.Add(ExtractKey(value), value);
                }
            }
        }
        /// <summary>
        /// Set up expression tests by creating files for existence checks.
        /// </summary>
        public ExpressionTest(ITestOutputHelper output)
        {
            this.output = output;

            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            // Dummy project instance to own the items.
            ProjectRootElement xml = ProjectRootElement.Create();

            xml.FullPath = @"c:\abc\foo.proj";

            ProjectInstance parentProject = new ProjectInstance(xml);

            itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));

            PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
            propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
            propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_semi_c", "a;c"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
            propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
            propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));

            Dictionary <string, string> metadataDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            metadataDictionary["Culture"] = "french";
            StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);

            _expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata, FileSystems.Default);

            foreach (string file in FilesWithExistenceChecks)
            {
                using (StreamWriter sw = File.CreateText(file)) {; }
            }
        }
Пример #17
0
        public IEnumerable <SecurityWrapper> SetAccessToWebItems(IEnumerable <ItemKeyValuePair <String, Boolean> > items)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var itemList = new ItemDictionary <String, Boolean>();

            foreach (ItemKeyValuePair <String, Boolean> item in items)
            {
                if (!itemList.ContainsKey(item.Key))
                {
                    itemList.Add(item.Key, item.Value);
                }
            }
            foreach (var item in itemList)
            {
                Guid[] subjects = null;

                if (item.Value)
                {
                    var webItem = WebItemManager.Instance[new Guid(item.Key)] as IProduct;
                    if (webItem != null)
                    {
                        var productInfo    = WebItemSecurity.GetSecurityInfo(item.Key);
                        var selectedGroups = productInfo.Groups.Select(group => group.ID).ToList();
                        var selectedUsers  = productInfo.Users.Select(user => user.ID).ToList();
                        selectedUsers.AddRange(selectedGroups);
                        if (selectedUsers.Count > 0)
                        {
                            subjects = selectedUsers.ToArray();
                        }
                    }
                }

                WebItemSecurity.SetSecurity(item.Key, item.Value, subjects);
            }

            return(GetWebItemSecurityInfo(itemList.Keys.ToList()));
        }
Пример #18
0
        private static void Initialize()
        {
            LoadItemCodes();
            var sets    = LoadSets();
            var uniques = LoadUniques();
            var names   = LoadItemNames();

            for (uint i = 1; i <= maxTxtCode + 1; ++i)
            {
                var itemInfo = new ItemInfo();
                itemInfo.Id = i - 1;

                if (i >= 1 && i <= 86 ||    //normal weapons
                    //i >= 89 && i <= 92 || //quest weapons
                    i >= 94 && i <= 173 ||  //exc weapons
                    //i == 174 || i == 175 || //khalim's crap
                    i >= 176 && i <= 196 || //katars
                    i >= 197 && i <= 276 || //elite weapons
                    i >= 277 && i <= 306 || //soso and ama weapons
                    i == 527 || i == 529 || //arrows and bolts
                    i >= 81 && i <= 86)     //potions
                {
                    itemInfo.BodyLocation = ItemBodyLocation.Weapon;
                }
                else if (i >= 307 && i <= 352 || //normal armor
                         i >= 353 && i <= 398 || //exc armor
                         i >= 399 && i <= 418 || //normal dudu baba pala necro njip-specific
                         i >= 419 && i <= 422 || //circlets
                         i >= 423 && i <= 468 || //elite armors
                         i >= 469 && i <= 508 || //exc and elite dudu baba pala necro class-specific
                         i == 521 || i == 523)   //amulet and ring
                {
                    itemInfo.BodyLocation = ItemBodyLocation.Armor;
                }
                else
                {
                    itemInfo.BodyLocation = ItemBodyLocation.Other;
                }

                if (i >= 1 && i <= 80 ||    //normal weapons
                    i >= 176 && i <= 182 || //normal katars
                    i >= 307 && i <= 352 || //normal armor
                    i >= 399 && i <= 418 || //normal class-specific
                    i == 419 || i == 420)   //circlet and coronet
                {
                    itemInfo.Rarity = ItemRarity.Normal;
                }
                else if (i >= 94 && i <= 173 ||  //exc weapons
                         i >= 287 && i <= 296 || //exc soso and ama weap
                         i >= 353 && i <= 398 || //exc armor
                         i >= 469 && i <= 488 || //exc dudu baba pala necro class-specific
                         i == 421)               //tiara
                {
                    itemInfo.Rarity = ItemRarity.Exceptional;
                }
                else if (i >= 190 && i <= 196 || //elite katars
                         i >= 197 && i <= 276 || //elite weap
                         i >= 297 && i <= 306 || //elite soso and ama weap
                         i == 422 ||             //diadem
                         i >= 423 && i <= 468 || //elite armor
                         i >= 489 && i <= 508)   //elite dudu baba pala necro class-specific
                {
                    itemInfo.Rarity = ItemRarity.Elite;
                }
                else if (i >= 87 && i <= 93 ||   //
                         i == 174 || i == 175 || //khalim's crap
                         i == 522 ||             //top of the staff
                         i == 525 || i == 526 || //infus, key to stones
                         i >= 546 && i <= 556 || //
                         i == 645 ||             //malahs potion
                         i >= 648 && i <= 654)   //pandemonium items
                {
                    itemInfo.Rarity = ItemRarity.Quest;
                }
                else
                {
                    itemInfo.Rarity = ItemRarity.Misc;
                }


                if (itemInfo.BodyLocation == ItemBodyLocation.Weapon)
                {
                    if (i >= 1 && i <= 10 ||
                        i >= 94 && i <= 103 ||
                        i >= 197 && i <= 206)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Axe;
                    }
                    else if (i >= 11 && i <= 14 ||
                             i >= 104 && i <= 107 || //+93
                             i >= 207 && i <= 210)   //+103
                    {
                        itemInfo.WeaponType = ItemWeaponType.Wand;
                    }
                    else if (i >= 15 && i <= 25 ||
                             i >= 108 && i <= 118 ||
                             i >= 211 && i <= 221)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Mace;
                    }
                    else if (i >= 26 && i <= 39 ||
                             i >= 119 && i <= 132 ||
                             i >= 222 && i <= 235)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Sword;
                    }
                    else if (i >= 40 && i <= 43 ||
                             i >= 133 && i <= 136 ||
                             i >= 236 && i <= 239)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Dagger;
                    }
                    else if (i >= 44 && i <= 47 ||
                             i >= 137 && i <= 140 ||
                             i >= 240 && i <= 243)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Thrown;
                    }
                    else if (i >= 48 && i <= 52 ||
                             i >= 141 && i <= 145 ||
                             i >= 244 && i <= 248)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Javelin;
                    }
                    else if (i >= 53 && i <= 57 ||   //+93
                             i >= 146 && i <= 150 || //+103
                             i >= 249 && i <= 253)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Spear;
                    }
                    else if (i >= 58 && i <= 63 ||
                             i >= 151 && i <= 156 ||
                             i >= 254 && i <= 259)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Polearm;
                    }
                    else if (i >= 64 && i <= 68 ||
                             i >= 157 && i <= 161 ||
                             i >= 260 && i <= 264)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Staff;
                    }
                    else if (i >= 69 && i <= 76 ||
                             i >= 162 && i <= 169 ||
                             i >= 265 && i <= 272)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Bow;
                    }
                    else if (i >= 77 && i <= 80 ||
                             i >= 170 && i <= 173 ||
                             i >= 273 && i <= 276)
                    {
                        itemInfo.WeaponType = ItemWeaponType.Crossbow;
                    }
                    else if (i >= 176 && i <= 196)
                    {
                        itemInfo.WeaponType = ItemWeaponType.AssKatar;
                    }
                    else if (i >= 277 && i <= 281 ||
                             i >= 287 && i <= 291 ||
                             i >= 297 && i <= 301)
                    {
                        itemInfo.WeaponType = ItemWeaponType.SorcOrb;
                    }
                    else if (i == 282 || i == 283 ||
                             i == 292 || i == 293 ||
                             i == 302 || i == 303)
                    {
                        itemInfo.WeaponType = ItemWeaponType.AmaBow;
                    }
                    else if (i >= 284 && i <= 286 ||
                             i >= 294 && i <= 296 ||
                             i >= 304 && i <= 306)
                    {
                        itemInfo.WeaponType = ItemWeaponType.AmaJavelin;
                    }
                    else if (i >= 81 && i <= 86)
                    {
                        itemInfo.WeaponType = ItemWeaponType.ThrowingPotion;
                    }
                    else if (i == 527 || i == 529) //bolts and arrows
                    {
                        itemInfo.WeaponType = ItemWeaponType.Ammunition;
                    }
                }
                else if (itemInfo.BodyLocation == ItemBodyLocation.Armor)
                {
                    if (i >= 307 && i <= 313 || //+46
                        i >= 353 && i <= 359 || //+70
                        i >= 423 && i <= 429 ||
                        i == 350 || i == 396 ||
                        i == 466)
                    {
                        itemInfo.ArmorType = ItemArmorType.Helm;
                    }
                    else if (i >= 314 && i <= 328 ||
                             i >= 360 && i <= 374 ||
                             i >= 430 && i <= 444)
                    {
                        itemInfo.ArmorType = ItemArmorType.BodyArmor;
                    }
                    else if (i >= 329 && i <= 334 ||
                             i == 351 || i == 352 ||
                             i >= 375 && i <= 380 ||
                             i == 397 || i == 398 ||
                             i >= 445 && i <= 450 ||
                             i == 467 || i == 468)
                    {
                        itemInfo.ArmorType = ItemArmorType.Shield;
                    }
                    else if (i >= 335 && i <= 339 ||
                             i >= 381 && i <= 385 ||
                             i >= 451 && i <= 455)
                    {
                        itemInfo.ArmorType = ItemArmorType.Gloves;
                    }
                    else if (i >= 340 && i <= 344 ||
                             i >= 386 && i <= 390 ||
                             i >= 456 && i <= 460)
                    {
                        itemInfo.ArmorType = ItemArmorType.Boots;
                    }
                    else if (i >= 345 && i <= 349 ||
                             i >= 391 && i <= 395 ||
                             i >= 461 && i <= 465)
                    {
                        itemInfo.ArmorType = ItemArmorType.Belt;
                    }
                    else if (i >= 399 && i <= 403 || //+70
                             i >= 469 && i <= 473 || //+20
                             i >= 489 && i <= 493)
                    {
                        itemInfo.ArmorType = ItemArmorType.DruidHelm;
                    }
                    else if (i >= 404 && i <= 408 ||
                             i >= 474 && i <= 478 ||
                             i >= 494 && i <= 498)
                    {
                        itemInfo.ArmorType = ItemArmorType.BarbHelm;
                    }
                    else if (i >= 409 && i <= 413 ||
                             i >= 479 && i <= 483 ||
                             i >= 499 && i <= 503)
                    {
                        itemInfo.ArmorType = ItemArmorType.PalaShield;
                    }
                    else if (i >= 414 && i <= 418 ||
                             i >= 484 && i <= 488 ||
                             i >= 504 && i <= 508)
                    {
                        itemInfo.ArmorType = ItemArmorType.NecroShield;
                    }

                    if (i >= 419 && i <= 422)
                    {
                        itemInfo.ArmorType = ItemArmorType.Circlet;
                    }
                    else if (i == 521)
                    {
                        itemInfo.ArmorType = ItemArmorType.Amulet;
                    }
                    else if (i == 523)
                    {
                        itemInfo.ArmorType = ItemArmorType.Ring;
                    }
                }
                else if (itemInfo.BodyLocation == ItemBodyLocation.Other)
                {
                    if (i >= 514 && i <= 518 ||
                        i >= 588 && i <= 597)
                    {
                        itemInfo.MiscType = ItemMiscType.Potion;
                    }
                    else if (i >= 558 && i <= 587 ||
                             i >= 598 && i <= 602)
                    {
                        itemInfo.MiscType = ItemMiscType.Gem;
                    }
                    else if (i >= 604 && i <= 606)
                    {
                        itemInfo.MiscType = ItemMiscType.Charm;
                    }
                    else if (i >= 611 && i <= 643)
                    {
                        itemInfo.MiscType = ItemMiscType.Rune;
                    }
                    else if (i == 644)
                    {
                        itemInfo.MiscType = ItemMiscType.Jewel;
                    }
                    else
                    {
                        itemInfo.MiscType = ItemMiscType.Misc;
                    }
                }
                else
                {
                    itemInfo.MiscType = ItemMiscType.Misc;
                }

                itemInfo.Code = codeByIds[i - 1];

                var tempSets = sets.FindAll(it => it.Key == itemInfo.Code);
                foreach (var tmp in tempSets)
                {
                    itemInfo.PossibleSets.Add(tmp.Value);
                }

                var tempUniques = uniques.FindAll(it => it.Key == itemInfo.Code);
                foreach (var tmp in tempUniques)
                {
                    itemInfo.PossibleUniques.Add(tmp.Value);
                }

                var tempName = names.Find(it => it.Key == itemInfo.Code);
                if (tempName.Value != "")
                {
                    itemInfo.Name = tempName.Value;
                }

                itemInfos.Add(i - 1, itemInfo);
            }
        }
Пример #19
0
        public IEnumerable<SecurityWrapper> SetAccessToWebItems(IEnumerable<ItemKeyValuePair<String, Boolean>> items)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var itemList = new ItemDictionary<String, Boolean>();

            foreach (ItemKeyValuePair<String, Boolean> item in items)
            {
                if (!itemList.ContainsKey(item.Key))
                    itemList.Add(item.Key, item.Value);
            }
            foreach (var item in itemList)
            {
                Guid[] subjects = null;

                if (item.Value)
                {
                    var webItem = WebItemManager.Instance[new Guid(item.Key)] as IProduct;
                    if (webItem != null)
                    {
                        var productInfo = WebItemSecurity.GetSecurityInfo(item.Key);
                        var selectedGroups = productInfo.Groups.Select(group => group.ID).ToList();
                        var selectedUsers = productInfo.Users.Select(user => user.ID).ToList();
                        selectedUsers.AddRange(selectedGroups);
                        if (selectedUsers.Count > 0)
                        {
                            subjects = selectedUsers.ToArray();
                        }
                    }
                }

                WebItemSecurity.SetSecurity(item.Key, item.Value, subjects);

            }

            return GetWebItemSecurityInfo(itemList.Keys.ToList());
        }
Пример #20
0
        public void BasicItemDictionary()
        {
            ItemDictionary <ProjectItemInstance> items = new ItemDictionary <ProjectItemInstance>();

            // Clearing empty collection
            items.Clear();

            // Enumeration of empty collection
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                enumerator.MoveNext().ShouldBeFalse();
                Should.Throw <InvalidOperationException>(() =>
                {
                    object o = ((IEnumerator)enumerator).Current;
                });
                enumerator.Current.ShouldBeNull();
            }

            List <ProjectItemInstance> list = new List <ProjectItemInstance>();

            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Empty(list);

            // Cause an empty list for type 'x' to be added
            ICollection <ProjectItemInstance> itemList = items["x"];

            // Enumerate empty collection, with an empty list in it
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Empty(list);

            // Add and remove some items
            ProjectItemInstance item1 = GetItemInstance("i", "i1");

            Assert.False(items.Remove(item1));
            Assert.Empty(items["j"]);

            items.Add(item1);
            Assert.Single(items["i"]);
            Assert.Equal(item1, items["i"].First());

            ProjectItemInstance item2 = GetItemInstance("i", "i2");

            items.Add(item2);
            ProjectItemInstance item3 = GetItemInstance("j", "j1");

            items.Add(item3);

            // Enumerate to verify contents
            list = new List <ProjectItemInstance>();
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            list.Sort(ProjectItemInstanceComparer);
            Assert.Equal(item1, list[0]);
            Assert.Equal(item2, list[1]);
            Assert.Equal(item3, list[2]);

            // Direct operations on the enumerator
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Null(enumerator.Current);
                Assert.True(enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
                enumerator.Reset();
                Assert.Null(enumerator.Current);
                Assert.True(enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
            }
        }
Пример #21
0
        public void AddsWithDuplicateRemovalWithMetadata()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();

            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();

            // Two items, differ only by metadata
            table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m1") }, project.FullPath));
            table1.Add(new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("m1", "m2") }, project.FullPath));
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            var scope = lookup.EnterScope("test");

            // This one should not get added
            ProjectItemInstance[] newItems = new ProjectItemInstance[]
            {
                new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should get added
                new ProjectItemInstance(project, "i1", "a2", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should get added               
                new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m1" ) }, project.FullPath), // Should not get added               
                new ProjectItemInstance(project, "i1", "a1", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>( "m1", "m3" ) }, project.FullPath), // Should get added               
            };

            // Perform the addition
            lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true);

            var group = lookup.GetItems("i1");

            // We should have the original two duplicates plus one new addition.
            Assert.Equal(5, group.Count);

            // Four of the items will have the a1 include
            Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count());

            // One item will have the a2 include
            Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());

            scope.LeaveScope();

            group = lookup.GetItems("i1");

            // We should have the original two duplicates plus one new addition.
            Assert.Equal(5, group.Count);

            // Four of the items will have the a1 include
            Assert.Equal(4, group.Where(item => item.EvaluatedInclude == "a1").Count());

            // One item will have the a2 include
            Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
        }
Пример #22
0
        public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            // Create some project state with an item with m=m1 and n=n1 
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
            item1.SetMetadata("m", "m1");
            table1.Add(item1);

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            Lookup.Scope enteredScope = lookup.EnterScope("x");

            // Make a modification to the item to be m=m2
            Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false);
            newMetadata.Add("m", "m2");
            List<ProjectItemInstance> group = new List<ProjectItemInstance>();
            group.Add(item1);
            lookup.ModifyItems(item1.ItemType, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType);
            Assert.Equal(1, group2.Count);
            ProjectItemInstance item1b = group2.First();

            // Remove the item
            lookup.RemoveItem(item1b);

            // There's now no items at all
            ICollection<ProjectItemInstance> group3 = lookup.GetItems(item1.ItemType);
            Assert.Equal(0, group3.Count);

            // Leave scope
            enteredScope.LeaveScope();

            // And now none left in the project either
            Assert.Equal(0, table1["i1"].Count);
        }
Пример #23
0
        /// <summary>
        /// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems.
        /// </summary>
        /// <returns></returns>
        private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateItemFunctionExpander()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
            pg.Set(ProjectPropertyInstance.Create("p", "v0"));
            pg.Set(ProjectPropertyInstance.Create("p", "v1"));
            pg.Set(ProjectPropertyInstance.Create("Val", "2"));
            pg.Set(ProjectPropertyInstance.Create("a", "filename"));

            ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>();

            for (int n = 0; n < 10; n++)
            {
                ProjectItemInstance pi = new ProjectItemInstance(project, "i", "i" + n.ToString(), project.FullPath);
                for (int m = 0; m < 5; m++)
                {
                    pi.SetMetadata("Meta" + m.ToString(), @"c:\firstdirectory\seconddirectory\file" + m.ToString() + ".ext");
                }
                pi.SetMetadata("Meta9", @"seconddirectory\file.ext");
                pi.SetMetadata("Meta10", @";someo%3bherplace\foo.txt;secondd%3brectory\file.ext;");
                pi.SetMetadata("MetaBlank", @"");

                if (n % 2 > 0)
                {
                    pi.SetMetadata("Even", "true");
                    pi.SetMetadata("Odd", "false");
                }
                else
                {
                    pi.SetMetadata("Even", "false");
                    pi.SetMetadata("Odd", "true");
                }
                ig.Add(pi);
            }

            Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)";
            itemMetadataTable["Language"] = "english";
            IMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable);

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig, itemMetadata);

            return expander;
        }
Пример #24
0
        public void EvaluateAVarietyOfExpressions()
        {
            string[] files = { "a", "a;b", "a'b", ";", "'" };

            try
            {
                foreach (string file in files)
                {
                    using (StreamWriter sw = File.CreateText(file)) {; }
                }

                Parser p = new Parser();
                GenericExpressionNode tree;

                ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

                // Dummy project instance to own the items.
                ProjectRootElement xml = ProjectRootElement.Create();
                xml.FullPath = @"c:\abc\foo.proj";

                ProjectInstance parentProject = new ProjectInstance(xml);

                itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));

                PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>();

                propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
                propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
                propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
                propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
                propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
                propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
                propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_semi_b", "a;b"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
                propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
                propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));

                Dictionary <string, string> metadataDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                metadataDictionary["Culture"] = "french";
                StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);

                Expander <ProjectPropertyInstance, ProjectItemInstance> expander =
                    new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata);

                string[] trueTests =
                {
                    "true or (SHOULDNOTEVALTHIS)",                                // short circuit
                    "(true and false) or true",
                    "false or true or false",
                    "(true) and (true)",
                    "false or !false",
                    "($(a) or true)",
                    "('$(c)'==1 and (!false))",
                    "@(z -> '%(filename).z', '$')=='xxx.z$yyy.z'",
                    "@(w -> '%(definingprojectname).barproj') == 'foo.barproj'",
                    "false or (false or (false or (false or (false or (true)))))",
                    "!(true and false)",
                    "$(and)=='and'",
                    "0x1==1.0",
                    "0xa==10",
                    "0<0.1",
                    "+4>-4",
                    "'-$(c)'==-1",
                    "$(a)==faLse",
                    "$(a)==oFF",
                    "$(a)==no",
                    "$(a)!=true",
                    "$(b)== True",
                    "$(b)==on",
                    "$(b)==yes",
                    "$(b)!=1",
                    "$(c)==1",
                    "$(d)=='xxx'",
                    "$(d)==$(e)",
                    "$(d)=='$(e)'",
                    "@(y)==$(d)",
                    "'@(z)'=='xxx;yyy'",
                    "$(a)==$(a)",
                    "'1'=='1'",
                    "'1'==1",
                    "1\n==1",
                    "1\t==\t\r\n1",
                    "123=='0123.0'",
                    "123==123",
                    "123==0123",
                    "123==0123.0",
                    "123!=0123.01",
                    "1.2.3<=1.2.3.0",
                    "12.23.34==12.23.34",
                    "0.8.0.0<8.0.0",
                    "1.1.2>1.0.1.2",
                    "8.1>8.0.16.23",
                    "8.0.0>=8",
                    "6<=6.0.0.1",
                    "7>6.8.2",
                    "4<5.9.9135.4",
                    "3!=3.0.0",
                    "1.2.3.4.5.6.7==1.2.3.4.5.6.7",
                    "00==0",
                    "0==0.0",
                    "1\n\t==1",
                    "+4==4",
                    "44==+44.0 and -44==-44.0",
                    "false==no",
                    "true==yes",
                    "true==!false",
                    "yes!=no",
                    "false!=1",
                    "$(c)>0",
                    "!$(a)",
                    "$(b)",
                    "($(d)==$(e))",
                    "!true==false",
                    "a_a==a_a",
                    "a_a=='a_a'",
                    "_a== _a",
                    "@(y -> '%(filename)')=='xxx'",
                    "@(z -> '%(filename)', '!')=='xxx!yyy'",
                    "'xxx!yyy'==@(z -> '%(filename)', '!')",
                    "'$(a)'==(false)",
                    "('$(a)'==(false))",
                    "1>0",
                    "2<=2",
                    "2<=3",
                    "1>=1",
                    "1>=-1",
                    "-1==-1",
                    "-1  <  0",
                    "(1==1)and('a'=='a')",
                    "(true) and ($(a)==off)",
                    "(true) and ($(d)==xxx)",
                    "(false)     or($(d)==xxx)",
                    "!(false)and!(false)",
                    "'and'=='AND'",
                    "$(d)=='XxX'",
                    "true or true or false",
                    "false or true or !true or'1'",
                    "$(a) or $(b)",
                    "$(a) or true",
                    "!!true",
                    "'$(e)1@(y)'=='xxx1xxx'",
                    "0x11==17",
                    "0x01a==26",
                    "0xa==0x0A",
                    "@(x)",
                    "'%77'=='w'",
                    "'%zz'=='%zz'",
                    "true or 1",
                    "true==!false",
                    "(!(true))=='off'",
                    "@(w)>0",
                    "1<=@(w)",
                    "%(culture)=='FRENCH'",
                    "'%(culture) fries' == 'FRENCH FRIES' ",
                    @"'%(HintPath)' == ''",
                    @"%(HintPath) != 'c:\myassemblies\foo.dll'",
                    "exists('a')",
                    "exists(a)",
                    "exists('a%3bb')",                                            /* semicolon */
                    "exists('a%27b')",                                            /* apostrophe */
                    "exists($(a_escapedsemi_b))",
                    "exists('$(a_escapedsemi_b)')",
                    "exists($(a_escapedapos_b))",
                    "exists('$(a_escapedapos_b)')",
                    "exists($(a_apos_b))",
                    "exists('$(a_apos_b)')",
                    "exists(@(v))",
                    "exists('@(v)')",
                    "exists('%3b')",
                    "exists('%27')",
                    "exists('@(v);@(nonexistent)')",
                    @"HASTRAILINGSLASH('foo\')",
                    @"!HasTrailingSlash('foo')",
                    @"HasTrailingSlash('foo/')",
                    @"HasTrailingSlash($(has_trailing_slash))",
                    "'59264.59264' == '59264.59264'",
                    "1" + new String('0',                                            500) + "==" + "1" + new String('0', 500),      /* too big for double, eval as string */
                    "'1" + new String('0',                                         500) + "'=='" + "1" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] falseTests =
                {
                    "false and SHOULDNOTEVALTHIS",                                 // short circuit
                    "$(a)!=no",
                    "$(b)==1.1",
                    "$(c)==$(a)",
                    "$(d)!=$(e)",
                    "!$(b)",
                    "false or false or false",
                    "false and !((true and false))",
                    "on and off",
                    "(true) and (false)",
                    "false or (false or (false or (false or (false or (false)))))",
                    "!$(b)and true",
                    "1==a",
                    "!($(d)==$(e))",
                    "$(a) and true",
                    "true==1",
                    "false==0",
                    "(!(true))=='x'",
                    "oops==false",
                    "oops==!false",
                    "%(culture) == 'english'",
                    "'%(culture) fries' == 'english fries' ",
                    @"'%(HintPath)' == 'c:\myassemblies\foo.dll'",
                    @"%(HintPath) == 'c:\myassemblies\foo.dll'",
                    "exists('')",
                    "exists(' ')",
                    "exists($(nonexistent))",                                      // DDB #141195
                    "exists('$(nonexistent)')",                                    // DDB #141195
                    "exists(@(nonexistent))",                                      // DDB #141195
                    "exists('@(nonexistent)')",                                    // DDB #141195
                    "exists('\t')",
                    "exists('@(u)')",
                    "exists('$(foo_apos_foo)')",
                    "!exists('a')",
                    "!!!exists(a)",
                    "exists('|||||')",
                    @"hastrailingslash('foo')",
                    @"hastrailingslash('')",
                    @"HasTrailingSlash($(nonexistent))",
                    "'59264.59264' == '59264.59265'",
                    "1.2.0==1.2",
                    "$(f)!=$(f)",
                    "1.3.5.8>1.3.6.8",
                    "0.8.0.0>=1.0",
                    "8.0.0<=8.0",
                    "8.1.2<8",
                    "1" + new String('0',                      500) + "==2",            /* too big for double, eval as string */
                    "'1" + new String('0',                  500) + "'=='2'",            /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='01" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] errorTests =
                {
                    "$",
                    "$(",
                    "$()",
                    "@",
                    "@(",
                    "@()",
                    "%",
                    "%(",
                    "%()",
                    "exists",
                    "exists(",
                    "exists()",
                    "exists( )",
                    "exists(,)",
                    "@(x->'",
                    "@(x->''",
                    "@(x-",
                    "@(x->'x','",
                    "@(x->'x',''",
                    "@(x->'x','')",
                    "-1>x",
                    "%00",
                    "\n",
                    "\t",
                    "+-1==1",
                    "1==-+1",
                    "1==+0xa",
                    "!$(c)",
                    "'a'==('a'=='a')",
                    "'a'!=('a'=='a')",
                    "('a'=='a')!=a",
                    "('a'=='a')==a",
                    "!'x'",
                    "!'$(d)'",
                    "ab#==ab#",
                    "#!=#",
                    "$(d)$(e)=='xxxxxx'",
                    "1=1=1",
                    "'a'=='a'=='a'",
                    "1 > 'x'",
                    "x1<=1",
                    "1<=x",
                    "1>x",
                    "x<x",
                    "@(x)<x",
                    "x>x",
                    "x>=x",
                    "x<=x",
                    "x>1",
                    "x>=1",
                    "1>=x",
                    "@(y)<=1",
                    "1<=@(z)",
                    "1>$(d)",
                    "$(c)@(y)>1",
                    "'$(c)@(y)'>1",
                    "$(d)>=1",
                    "1>=$(b)",
                    "1> =0",
                    "or true",
                    "1 and",
                    "and",
                    "or",
                    "not",
                    "not true",
                    "()",
                    "(a)",
                    "!",
                    "or=or",
                    "1==",
                    "1= =1",
                    "=",
                    "'true",
                    "'false''",
                    "'a'=='a",
                    "('a'=='a'",
                    "('a'=='a'))",
                    "'a'=='a')",
                    "!and",
                    "@(a)@(x)!=1",
                    "@(a) @(x)!=1",
                    "$(a==off",
                    "=='x'",
                    "==",
                    "!0",
                    ">",
                    "true!=false==",
                    "true!=false==true",
                    "()",
                    "!1",
                    "1==(2",
                    "$(a)==x>1==2",
                    "'a'>'a'",
                    "0",
                    "$(a)>0",
                    "!$(e)",
                    "1<=1<=1",
                    "true $(and) true",
                    "--1==1",
                    "$(and)==and",
                    "!@#$%^&*",
                    "-($(c))==-1",
                    "a==b or $(d)",
                    "false or $()",
                    "$(d) or true",
                    "%(Culture) or true",
                    "@(nonexistent) and true",
                    "$(nonexistent) and true",
                    "@(nonexistent)",
                    "$(nonexistent)",
                    "@(z) and true",
                    "@() and true",
                    "@()",
                    "$()",
                    "1",
                    "1 or true",
                    "false or 1",
                    "1 and true",
                    "true and 1",
                    "!1",
                    "false or !1",
                    "false or 'aa'",
                    "true blah",
                    "existsX",
                    "!",
                    "nonexistentfunction('xyz')",
                    "exists('a;b')", /* non scalar */
                    "exists(@(z))",
                    "exists('@(z)')",
                    "exists($(a_semi_b))",
                    "exists('$(a_semi_b)')",
                    "exists(@(v)x)",
                    "exists(@(v)$(nonexistent))",
                    "exists('@(v)$(a)')",
                    "exists(|||||)",
                    "HasTrailingSlash(a,'b')",
                    "HasTrailingSlash(,,)",
                    "1.2.3==1,2,3"
                };

                for (int i = 0; i < trueTests.GetLength(0); i++)
                {
                    tree = p.Parse(trueTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                    ConditionEvaluator.IConditionEvaluationState state =
                        new ConditionEvaluator.ConditionEvaluationState <ProjectPropertyInstance, ProjectItemInstance>
                        (
                            trueTests[i],
                            expander,
                            ExpanderOptions.ExpandAll,
                            null,
                            Environment.CurrentDirectory,
                            ElementLocation.EmptyLocation
                        );

                    Assert.IsTrue(tree.Evaluate(state), "expected true from '" + trueTests[i] + "'");
                }

                for (int i = 0; i < falseTests.GetLength(0); i++)
                {
                    tree = p.Parse(falseTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                    ConditionEvaluator.IConditionEvaluationState state =
                        new ConditionEvaluator.ConditionEvaluationState <ProjectPropertyInstance, ProjectItemInstance>
                        (
                            falseTests[i],
                            expander,
                            ExpanderOptions.ExpandAll,
                            null,
                            Environment.CurrentDirectory,
                            ElementLocation.EmptyLocation
                        );

                    Assert.IsFalse(tree.Evaluate(state), "expected false from '" + falseTests[i] + "' and got true");
                }

                for (int i = 0; i < errorTests.GetLength(0); i++)
                {
                    // It seems that if an expression is invalid,
                    //      - Parse may throw, or
                    //      - Evaluate may throw, or
                    //      - Evaluate may return false causing its caller EvaluateCondition to throw
                    bool success         = true;
                    bool caughtException = false;
                    bool value;
                    try
                    {
                        tree = p.Parse(errorTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                        ConditionEvaluator.IConditionEvaluationState state =
                            new ConditionEvaluator.ConditionEvaluationState <ProjectPropertyInstance, ProjectItemInstance>
                            (
                                errorTests[i],
                                expander,
                                ExpanderOptions.ExpandAll,
                                null,
                                Environment.CurrentDirectory,
                                ElementLocation.EmptyLocation
                            );

                        value = tree.Evaluate(state);
                        if (!success)
                        {
                            Console.WriteLine(errorTests[i] + " caused Evaluate to return false");
                        }
                    }
                    catch (InvalidProjectFileException ex)
                    {
                        Console.WriteLine(errorTests[i] + " caused '" + ex.Message + "'");
                        caughtException = true;
                    }
                    Assert.IsTrue((success == false || caughtException == true), "expected '" + errorTests[i] + "' to not parse or not be evaluated");
                }
            }
            finally
            {
                foreach (string file in files)
                {
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                }
            }
        }
Пример #25
0
        public KeyValuePair<string, ItemDictionary<String, String>> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
        {
            var filter = (FilterType)Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var fileDao = GetFileDao())
            using (var folderDao = GetFolderDao())
            {
                var file = fileDao.GetFile(fileId);
                ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound);
                ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile);

                var folder = folderDao.GetFolder(file.FolderID);
                ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound);
                ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem);

                var folderId = file.FolderID;
                var entries = Enumerable.Empty<FileEntry>();
                if (!FileSecurity.CanRead(folder) &&
                    folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
                {
                    folderId = Global.FolderShare;
                    orderBy = new OrderBy(SortedByType.DateAndTime, false);

                    var shared = (IEnumerable<FileEntry>)FileSecurity.GetSharesForMe();
                    shared = EntryManager.FilterEntries(shared, filter, subjectId, searchText)
                                         .Where(f => f is File &&
                                                     f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files
                                                     f.RootFolderType == FolderType.USER); // don't show common files (common files can read)
                    entries = entries.Concat(shared);
                }
                else if (folder.FolderType == FolderType.BUNCH)
                {
                    var path = folderDao.GetBunchObjectID(folder.RootFolderId);

                    var projectID = path.Split('/').Last();

                    if (String.IsNullOrEmpty(projectID))
                    {
                        folderId = Global.FolderMy;
                        entries = entries.Concat(new List<FileEntry> {file});
                    }
                    else
                    {
                        entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
                    }
                }
                else
                {
                    entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
                }

                entries = EntryManager.SortEntries(entries, orderBy);

                var siblingType = FileUtility.GetFileTypeByFileName(file.Title);

                var result = new ItemDictionary<String, String>();
                FileSecurity.FilterRead(entries)
                            .OfType<File>()
                            .Where(f => siblingType.Equals(FileUtility.GetFileTypeByFileName(f.Title)))
                            .ToList()
                            .ForEach(f => result.Add(f.ID.ToString(), f.Version + "&" + f.Title));

                return new KeyValuePair<string, ItemDictionary<string, string>>(folderId.ToString(), result);
            }
        }
Пример #26
0
 public void SetItemDictionary(Item item, int num = 0)
 {
     itemDictionary.Add(item, num);
 }
Пример #27
0
        public ItemDictionary<int, TaskWrapper> GetNearestTask(IEnumerable<int> contactid)
        {
            var sqlResult = DaoFactory.GetTaskDao().GetNearestTask(contactid.ToArray());
            var result = new ItemDictionary<int, TaskWrapper>();

            foreach (var item in sqlResult)
                result.Add(item.Key, ToTaskWrapper(item.Value));

            return result;
        }
Пример #28
0
        public void BasicItemDictionary()
        {
            ItemDictionary <ProjectItemInstance> items = new ItemDictionary <ProjectItemInstance>();

            // Clearing empty collection
            items.Clear();

            // Enumeration of empty collection
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Equal(false, enumerator.MoveNext());
                ObjectModelHelpers.AssertThrows(typeof(InvalidOperationException), delegate { object o = ((IEnumerator)enumerator).Current; });
                Assert.Equal(null, enumerator.Current);
            }

            List <ProjectItemInstance> list = new List <ProjectItemInstance>();

            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Equal(0, list.Count);

            // Cause an empty list for type 'x' to be added
            ICollection <ProjectItemInstance> itemList = items["x"];

            // Enumerate empty collection, with an empty list in it
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            Assert.Equal(0, list.Count);

            // Add and remove some items
            ProjectItemInstance item1 = GetItemInstance("i", "i1");

            Assert.Equal(false, items.Remove(item1));
            Assert.Equal(0, items["j"].Count);

            items.Add(item1);
            Assert.Equal(1, items["i"].Count);
            Assert.Equal(item1, items["i"].First());

            ProjectItemInstance item2 = GetItemInstance("i", "i2");

            items.Add(item2);
            ProjectItemInstance item3 = GetItemInstance("j", "j1");

            items.Add(item3);

            // Enumerate to verify contents
            list = new List <ProjectItemInstance>();
            foreach (ProjectItemInstance item in items)
            {
                list.Add(item);
            }

            list.Sort(ProjectItemInstanceComparer);
            Assert.Equal(item1, list[0]);
            Assert.Equal(item2, list[1]);
            Assert.Equal(item3, list[2]);

            // Direct operations on the enumerator
            using (IEnumerator <ProjectItemInstance> enumerator = items.GetEnumerator())
            {
                Assert.Equal(null, enumerator.Current);
                Assert.Equal(true, enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
                enumerator.Reset();
                Assert.Equal(null, enumerator.Current);
                Assert.Equal(true, enumerator.MoveNext());
                Assert.NotNull(enumerator.Current);
            }
        }
        /// <summary>
        /// Set up expression tests by creating files for existence checks.
        /// </summary>
        public ExpressionTest(ITestOutputHelper output)
        {
            this.output = output;

            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();

            // Dummy project instance to own the items. 
            ProjectRootElement xml = ProjectRootElement.Create();
            xml.FullPath = @"c:\abc\foo.proj";

            ProjectInstance parentProject = new ProjectInstance(xml);

            itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));

            PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
            propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
            propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
            propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_semi_b", "a;b"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
            propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
            propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
            propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));

            Dictionary<string, string> metadataDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            metadataDictionary["Culture"] = "french";
            StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);

            _expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata);

            foreach (string file in FilesWithExistenceChecks)
            {
                using (StreamWriter sw = File.CreateText(file)) {; }
            }
        }
Пример #30
0
        public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            // Create some project state with an item with m=m1 and n=n1 
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
            item1.SetMetadata("m", "m1");
            table1.Add(item1);

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            Lookup.Scope enteredScope = lookup.EnterScope("x");

            // Make a modification to the item to be m=m2
            Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false);
            newMetadata.Add("m", "m2");
            List<ProjectItemInstance> group = new List<ProjectItemInstance>();
            group.Add(item1);
            lookup.ModifyItems(item1.ItemType, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType);
            Assert.Equal(1, group2.Count);
            ProjectItemInstance item1b = group2.First();

            // Modify to m=m3
            Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: false);
            newMetadata2.Add("m", "m3");
            List<ProjectItemInstance> group3 = new List<ProjectItemInstance>();
            group3.Add(item1b);
            lookup.ModifyItems(item1b.ItemType, group3, newMetadata2);

            // Modifications are visible
            ICollection<ProjectItemInstance> group4 = lookup.GetItems(item1b.ItemType);
            Assert.Equal(1, group4.Count);
            Assert.Equal("m3", group4.First().GetMetadataValue("m"));

            // Leave scope
            enteredScope.LeaveScope();

            // Still visible
            ICollection<ProjectItemInstance> group5 = lookup.GetItems(item1b.ItemType);
            Assert.Equal(1, group5.Count);
            Assert.Equal("m3", group5.First().GetMetadataValue("m"));

            // And the one in the project is changed
            Assert.Equal("m3", item1.GetMetadataValue("m"));
        }
Пример #31
0
        public void StringExpansionTests()
        {
            Parser p = new Parser();

            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();
            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("TestQuote", "Contains'Quote'"));
            propertyBag.Set(ProjectPropertyInstance.Create("AnotherTestQuote", "Here's Johnny!"));
            propertyBag.Set(ProjectPropertyInstance.Create("Atsign", "Test the @ replacement"));

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag);

            AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", expander, true);
            AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", expander, true);
            AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", expander, true);
            AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", expander, true);
        }
Пример #32
0
        public void AddsWithDuplicateRemovalItemSpecsOnly()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            // One item in the project
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));

            // Add an existing duplicate
            table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            var scope = lookup.EnterScope("test");

            // This one should not get added
            ProjectItemInstance[] newItems = new ProjectItemInstance[]
            {
                new ProjectItemInstance(project, "i1", "a1", project.FullPath), // Should not get added
                new ProjectItemInstance(project, "i1", "a2", project.FullPath), // Should get added               
            };

            // Perform the addition
            lookup.AddNewItemsOfItemType("i1", newItems, doNotAddDuplicates: true);

            var group = lookup.GetItems("i1");

            // We should have the original two duplicates plus one new addition.
            Assert.Equal(3, group.Count);

            // Only two of the items should have the 'a1' include.
            Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count());
            // And ensure the other item got added.
            Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());

            scope.LeaveScope();

            group = lookup.GetItems("i1");

            // We should have the original two duplicates plus one new addition.
            Assert.Equal(3, group.Count);

            // Only two of the items should have the 'a1' include.
            Assert.Equal(2, group.Where(item => item.EvaluatedInclude == "a1").Count());
            // And ensure the other item got added.
            Assert.Equal(1, group.Where(item => item.EvaluatedInclude == "a2").Count());
        }
Пример #33
0
        public void InvalidItemInConditionEvaluation()
        {
            Parser p = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "a", parentProject.FullPath));

            PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag);

            AssertParseEvaluateThrow(p, "@(Compile) > 0", expander, null);
        }
Пример #34
0
        public void Removes()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            // One item in the project
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a1", project.FullPath);
            table1.Add(item1);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // Start a target
            Lookup.Scope enteredScope = lookup.EnterScope("x");

            // Start a task (eg) and add a new item
            Lookup.Scope enteredScope2 = lookup.EnterScope("x");
            ProjectItemInstance item2 = new ProjectItemInstance(project, "i1", "a2", project.FullPath);
            lookup.AddNewItem(item2);

            // Remove one item
            lookup.RemoveItem(item1);

            // We see one item
            Assert.Equal(1, lookup.GetItems("i1").Count);
            Assert.Equal("a2", lookup.GetItems("i1").First().EvaluatedInclude);

            // Remove the other item
            lookup.RemoveItem(item2);

            // We see no items
            Assert.Equal(0, lookup.GetItems("i1").Count);

            // Finish the task
            enteredScope2.LeaveScope();

            // We still see no items
            Assert.Equal(0, lookup.GetItems("i1").Count);

            // But there's still one item in the project
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal(1, table1["i1"].Count);

            // Finish the target
            enteredScope.LeaveScope();

            // We still see no items
            Assert.Equal(0, lookup.GetItems("i1").Count);

            // And now there are no items in the project either
            Assert.Equal(0, table1["i1"].Count);
        }
Пример #35
0
        public void OldSyntaxTests()
        {
            Parser p = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();

            propertyBag.Set(ProjectPropertyInstance.Create("foo", "true"));
            propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes"));
            propertyBag.Set(ProjectPropertyInstance.Create("one", "1"));
            propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0"));
            propertyBag.Set(ProjectPropertyInstance.Create("two", "2"));
            propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring"));
            propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string"));
            propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one."));
            propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one."));

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag);

            AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", expander, true);
        }
Пример #36
0
        public void AddsAreCombinedWithPopulates()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            // One item in the project
            ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>();
            table1.Add(new ProjectItemInstance(project, "i1", "a1", project.FullPath));
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            // We see the one item
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal(1, lookup.GetItems("i1").Count);

            // One item in the project
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal(1, table1["i1"].Count);

            // Start a target
            Lookup.Scope enteredScope = lookup.EnterScope("x");

            // We see the one item 
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal(1, lookup.GetItems("i1").Count);

            // One item in the project
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal(1, table1["i1"].Count);

            // Start a task (eg) and add a new item
            Lookup.Scope enteredScope2 = lookup.EnterScope("x");
            lookup.AddNewItem(new ProjectItemInstance(project, "i1", "a2", project.FullPath));

            // Now we see two items
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal("a2", lookup.GetItems("i1").ElementAt(1).EvaluatedInclude);
            Assert.Equal(2, lookup.GetItems("i1").Count);

            // But there's still one item in the project
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal(1, table1["i1"].Count);

            // Finish the task
            enteredScope2.LeaveScope();

            // We still see two items
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal("a2", lookup.GetItems("i1").ElementAt(1).EvaluatedInclude);
            Assert.Equal(2, lookup.GetItems("i1").Count);

            // But there's still one item in the project
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal(1, table1["i1"].Count);

            // Finish the target
            enteredScope.LeaveScope();

            // We still see two items
            Assert.Equal("a1", lookup.GetItems("i1").First().EvaluatedInclude);
            Assert.Equal("a2", lookup.GetItems("i1").ElementAt(1).EvaluatedInclude);
            Assert.Equal(2, lookup.GetItems("i1").Count);

            // And now the items have gotten put into the global group
            Assert.Equal("a1", table1["i1"].First().EvaluatedInclude);
            Assert.Equal("a2", table1["i1"].ElementAt(1).EvaluatedInclude);
            Assert.Equal(2, table1["i1"].Count);
        }
Пример #37
0
        public void ConditionedPropertyUpdateTests()
        {
            Parser p = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary<ProjectPropertyInstance>(), itemBag);
            Dictionary<string, List<string>> conditionedProperties = new Dictionary<string, List<string>>();
            ConditionEvaluator.IConditionEvaluationState state =
                               new ConditionEvaluator.ConditionEvaluationState<ProjectPropertyInstance, ProjectItemInstance>
                                   (
                                       String.Empty,
                                       expander,
                                       ExpanderOptions.ExpandAll,
                                       conditionedProperties,
                                       Environment.CurrentDirectory,
                                       ElementLocation.EmptyLocation
                                   );

            List<string> properties = null;

            AssertParseEvaluate(p, "'0' == '1'", expander, false, state);
            Assert.IsTrue(conditionedProperties.Count == 0);

            AssertParseEvaluate(p, "$(foo) == foo", expander, false, state);
            Assert.IsTrue(conditionedProperties.Count == 1);
            properties = conditionedProperties["foo"];
            Assert.IsTrue(properties.Count == 1);

            AssertParseEvaluate(p, "'$(foo)' != 'bar'", expander, true, state);
            Assert.IsTrue(conditionedProperties.Count == 1);
            properties = conditionedProperties["foo"];
            Assert.IsTrue(properties.Count == 2);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab22dev|debug|x86'", expander, false, state);
            Assert.IsTrue(conditionedProperties.Count == 4);
            properties = conditionedProperties["foo"];
            Assert.IsTrue(properties.Count == 2);
            properties = conditionedProperties["branch"];
            Assert.IsTrue(properties.Count == 1);
            properties = conditionedProperties["build"];
            Assert.IsTrue(properties.Count == 1);
            properties = conditionedProperties["platform"];
            Assert.IsTrue(properties.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab21|debug|x86'", expander, false, state);
            Assert.IsTrue(conditionedProperties.Count == 4);
            properties = conditionedProperties["foo"];
            Assert.IsTrue(properties.Count == 2);
            properties = conditionedProperties["branch"];
            Assert.IsTrue(properties.Count == 2);
            properties = conditionedProperties["build"];
            Assert.IsTrue(properties.Count == 1);
            properties = conditionedProperties["platform"];
            Assert.IsTrue(properties.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab23|retail|ia64'", expander, false, state);
            Assert.IsTrue(conditionedProperties.Count == 4);
            properties = conditionedProperties["foo"];
            Assert.IsTrue(properties.Count == 2);
            properties = conditionedProperties["branch"];
            Assert.IsTrue(properties.Count == 3);
            properties = conditionedProperties["build"];
            Assert.IsTrue(properties.Count == 2);
            properties = conditionedProperties["platform"];
            Assert.IsTrue(properties.Count == 2);
            DumpDictionary(conditionedProperties);
        }
Пример #38
0
        public ItemDictionary<String, String> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
        {
            var filter = (FilterType) Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var fileDao = GetFileDao())
            using (var folderDao = GetFolderDao())
            {
                var file = fileDao.GetFile(fileId);
                ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound, true);
                ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile, true);

                var folder = folderDao.GetFolder(file.FolderID);
                ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound, true);
                ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem, true);

                var entries = Enumerable.Empty<FileEntry>();
                if (!FileSecurity.CanRead(folder) &&
                    folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
                {
                    orderBy = new OrderBy(SortedByType.DateAndTime, false);

                    var shared = (IEnumerable<FileEntry>) FileSecurity.GetSharesForMe();
                    shared = FilterEntries(shared, filter, subjectId, searchText)
                        .Where(f => f is File &&
                                    f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files
                                    f.RootFolderType == FolderType.USER); // don't show common files (common files can read)
                    entries = entries.Concat(shared);
                }
                else
                {
                    entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText).Cast<FileEntry>());
                }

                entries = SortEntries(entries, orderBy);

                var result = new ItemDictionary<string, String>();
                FileSecurity.FilterRead(entries)
                    .OfType<File>()
                    .Where(f => FileUtility.ExtsImagePreviewed.Contains(FileUtility.GetFileExtension(f.Title)))
                    .ToList()
                    .ForEach(f => result.Add(f.ID.ToString(), f.Version + "#" + f.Title));

                return result;
            }
        }
Пример #39
0
        /// <summary>
        /// Initialize the host object
        /// </summary>
        /// <param name="throwOnExecute">Should the task throw when executed</param>
        private void InitializeHost(bool throwOnExecute)
        {
            _loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1) as ILoggingService;
            _logger = new MockLogger();
            _loggingService.RegisterLogger(_logger);
            _host = new TaskExecutionHost();
            TargetLoggingContext tlc = new TargetLoggingContext(_loggingService, new BuildEventContext(1, 1, BuildEventContext.InvalidProjectContextId, 1));

            // Set up a temporary project and add some items to it.
            ProjectInstance project = CreateTestProject();

            TypeLoader typeLoader = new TypeLoader(new TypeFilter(IsTaskFactoryClass));
            AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(Assembly.GetAssembly(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory)).FullName, null);
            LoadedType loadedType = new LoadedType(typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory), loadInfo);

            TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory();
            taskFactory.ThrowOnExecute = throwOnExecute;
            string taskName = "TaskBuilderTestTask";
            (_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null);
            _host.InitializeForTask
                (
                this,
                tlc,
                project,
                taskName,
                ElementLocation.Create("none", 1, 1),
                this,
                false,
                null,
                false,
                CancellationToken.None
                );

            ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First();
            TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance);

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();

            ProjectItemInstance item = new ProjectItemInstance(project, "ItemListContainingOneItem", "a.cs", ".");
            item.SetMetadata("Culture", "fr-fr");
            itemsByName.Add(item);
            _oneItem = new ITaskItem[] { new TaskItem(item) };

            item = new ProjectItemInstance(project, "ItemListContainingTwoItems", "b.cs", ".");
            ProjectItemInstance item2 = new ProjectItemInstance(project, "ItemListContainingTwoItems", "c.cs", ".");
            item.SetMetadata("HintPath", "c:\\foo");
            item2.SetMetadata("HintPath", "c:\\bar");
            itemsByName.Add(item);
            itemsByName.Add(item2);
            _twoItems = new ITaskItem[] { new TaskItem(item), new TaskItem(item2) };

            _bucket = new ItemBucket(new string[0], new Dictionary<string, string>(), new Lookup(itemsByName, new PropertyDictionary<ProjectPropertyInstance>(), null), 0);
            _host.FindTask(null);
            _host.InitializeForBatch(talc, _bucket, null);
            _parametersSetOnTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            _outputsReadFromTask = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        }
Пример #40
0
        public ItemDictionary<String, String> MoveOrCopyFilesCheck(ItemList<String> items, String destFolderId)
        {
            var result = new ItemDictionary<string, String>();
            if (items.Count == 0) return result;

            List<object> folders;
            List<object> files;
            ParseArrayItems(items, out folders, out files);

            using (var folderDao = GetFolderDao())
            using (var fileDao = GetFileDao())
            {
                var toFolder = folderDao.GetFolder(destFolderId);
                if (toFolder == null) return result;
                ErrorIf(!FileSecurity.CanCreate(toFolder), FilesCommonResource.ErrorMassage_SecurityException_Create, true);

                foreach (var id in files)
                {
                    var file = fileDao.GetFile(id);
                    if (file != null && fileDao.IsExist(file.Title, toFolder.ID))
                    {
                        result.Add(id.ToString(), file.Title);
                    }
                }

                foreach (var pair in folderDao.CanMoveOrCopy(folders.ToArray(), toFolder.ID))
                {
                    result.Add(pair.Key.ToString(), pair.Value);
                }
            }
            return result;
        }
Пример #41
0
        public void EvaluateAVarietyOfExpressions()
        {
            string[] files = { "a", "a;b", "a'b", ";", "'" };

            try
            {
                foreach (string file in files)
                {
                    using (StreamWriter sw = File.CreateText(file)) {; }
                }

                Parser p = new Parser();
                GenericExpressionNode tree;

                ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();

                // Dummy project instance to own the items. 
                ProjectRootElement xml = ProjectRootElement.Create();
                xml.FullPath = @"c:\abc\foo.proj";

                ProjectInstance parentProject = new ProjectInstance(xml);

                itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath));
                itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath));

                PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>();

                propertyBag.Set(ProjectPropertyInstance.Create("a", "no"));
                propertyBag.Set(ProjectPropertyInstance.Create("b", "true"));
                propertyBag.Set(ProjectPropertyInstance.Create("c", "1"));
                propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx"));
                propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx"));
                propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5"));
                propertyBag.Set(ProjectPropertyInstance.Create("and", "and"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_semi_b", "a;b"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b"));
                propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb"));
                propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b"));
                propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\"));

                Dictionary<string, string> metadataDictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
                metadataDictionary["Culture"] = "french";
                StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary);

                Expander<ProjectPropertyInstance, ProjectItemInstance> expander =
                    new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata);

                string[] trueTests = {
                    "true or (SHOULDNOTEVALTHIS)", // short circuit
                    "(true and false) or true",
                    "false or true or false",
                    "(true) and (true)",
                    "false or !false",
                    "($(a) or true)",
                    "('$(c)'==1 and (!false))",
                    "@(z -> '%(filename).z', '$')=='xxx.z$yyy.z'",
                    "@(w -> '%(definingprojectname).barproj') == 'foo.barproj'",
                    "false or (false or (false or (false or (false or (true)))))",
                    "!(true and false)",
                    "$(and)=='and'",
                    "0x1==1.0",
                    "0xa==10",
                    "0<0.1",
                    "+4>-4",
                    "'-$(c)'==-1",
                    "$(a)==faLse",
                    "$(a)==oFF",
                    "$(a)==no",
                    "$(a)!=true",
                    "$(b)== True",
                    "$(b)==on",
                    "$(b)==yes",
                    "$(b)!=1",
                    "$(c)==1",
                    "$(d)=='xxx'",
                    "$(d)==$(e)",
                    "$(d)=='$(e)'",
                    "@(y)==$(d)",
                    "'@(z)'=='xxx;yyy'",
                    "$(a)==$(a)",
                    "'1'=='1'",
                    "'1'==1",
                    "1\n==1",
                    "1\t==\t\r\n1",
                    "123=='0123.0'",
                    "123==123",
                    "123==0123",
                    "123==0123.0",
                    "123!=0123.01",
                    "1.2.3<=1.2.3.0",
                    "12.23.34==12.23.34",
                    "0.8.0.0<8.0.0",
                    "1.1.2>1.0.1.2",
                    "8.1>8.0.16.23",
                    "8.0.0>=8",
                    "6<=6.0.0.1",
                    "7>6.8.2",
                    "4<5.9.9135.4",
                    "3!=3.0.0",
                    "1.2.3.4.5.6.7==1.2.3.4.5.6.7",
                    "00==0",
                    "0==0.0",
                    "1\n\t==1",
                    "+4==4",
                    "44==+44.0 and -44==-44.0",
                    "false==no",
                    "true==yes",
                    "true==!false",
                    "yes!=no",
                    "false!=1",
                    "$(c)>0",
                    "!$(a)",
                    "$(b)",
                    "($(d)==$(e))",
                    "!true==false",
                    "a_a==a_a",
                    "a_a=='a_a'",
                    "_a== _a",
                    "@(y -> '%(filename)')=='xxx'",
                    "@(z -> '%(filename)', '!')=='xxx!yyy'",
                    "'xxx!yyy'==@(z -> '%(filename)', '!')",
                    "'$(a)'==(false)",
                    "('$(a)'==(false))",
                    "1>0",
                    "2<=2",
                    "2<=3",
                    "1>=1",
                    "1>=-1",
                    "-1==-1",
                    "-1  <  0",
                    "(1==1)and('a'=='a')",
                    "(true) and ($(a)==off)",
                    "(true) and ($(d)==xxx)",
                    "(false)     or($(d)==xxx)",
                    "!(false)and!(false)",
                    "'and'=='AND'",
                    "$(d)=='XxX'",
                    "true or true or false",
                    "false or true or !true or'1'",
                    "$(a) or $(b)",
                    "$(a) or true",
                    "!!true",
                    "'$(e)1@(y)'=='xxx1xxx'",
                    "0x11==17",
                    "0x01a==26",
                    "0xa==0x0A",
                    "@(x)",
                    "'%77'=='w'",
                    "'%zz'=='%zz'",
                    "true or 1",
                    "true==!false",
                    "(!(true))=='off'",
                    "@(w)>0",
                    "1<=@(w)",
                    "%(culture)=='FRENCH'",
                    "'%(culture) fries' == 'FRENCH FRIES' ",
                    @"'%(HintPath)' == ''",
                    @"%(HintPath) != 'c:\myassemblies\foo.dll'",
                    "exists('a')",
                    "exists(a)",
                    "exists('a%3bb')", /* semicolon */
                    "exists('a%27b')", /* apostrophe */
                    "exists($(a_escapedsemi_b))",
                    "exists('$(a_escapedsemi_b)')",
                    "exists($(a_escapedapos_b))",
                    "exists('$(a_escapedapos_b)')",
                    "exists($(a_apos_b))",
                    "exists('$(a_apos_b)')",
                    "exists(@(v))",
                    "exists('@(v)')",
                    "exists('%3b')",
                    "exists('%27')",
                    "exists('@(v);@(nonexistent)')",
                    @"HASTRAILINGSLASH('foo\')",
                    @"!HasTrailingSlash('foo')",
                    @"HasTrailingSlash('foo/')",
                    @"HasTrailingSlash($(has_trailing_slash))",
                    "'59264.59264' == '59264.59264'",
                    "1" + new String('0', 500) + "==" + "1" + new String('0', 500), /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='" + "1" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] falseTests = {
                    "false and SHOULDNOTEVALTHIS", // short circuit
                    "$(a)!=no",
                    "$(b)==1.1",
                    "$(c)==$(a)",
                    "$(d)!=$(e)",
                    "!$(b)",
                    "false or false or false",
                    "false and !((true and false))",
                    "on and off",
                    "(true) and (false)",
                    "false or (false or (false or (false or (false or (false)))))",
                    "!$(b)and true",
                    "1==a",
                    "!($(d)==$(e))",
                    "$(a) and true",
                    "true==1",
                    "false==0",
                    "(!(true))=='x'",
                    "oops==false",
                    "oops==!false",
                    "%(culture) == 'english'",
                    "'%(culture) fries' == 'english fries' ",
                    @"'%(HintPath)' == 'c:\myassemblies\foo.dll'",
                    @"%(HintPath) == 'c:\myassemblies\foo.dll'",
                    "exists('')",
                    "exists(' ')",
                    "exists($(nonexistent))",  // DDB #141195
                    "exists('$(nonexistent)')",  // DDB #141195
                    "exists(@(nonexistent))",  // DDB #141195
                    "exists('@(nonexistent)')",  // DDB #141195
                    "exists('\t')",
                    "exists('@(u)')",
                    "exists('$(foo_apos_foo)')",
                    "!exists('a')",
                    "!!!exists(a)",
                    "exists('|||||')",
                    @"hastrailingslash('foo')",
                    @"hastrailingslash('')",
                    @"HasTrailingSlash($(nonexistent))",
                    "'59264.59264' == '59264.59265'",
                    "1.2.0==1.2",
                    "$(f)!=$(f)",
                    "1.3.5.8>1.3.6.8",
                    "0.8.0.0>=1.0",
                    "8.0.0<=8.0",
                    "8.1.2<8",
                    "1" + new String('0', 500) + "==2", /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='2'", /* too big for double, eval as string */
                    "'1" + new String('0', 500) + "'=='01" + new String('0', 500) + "'" /* too big for double, eval as string */
                };

                string[] errorTests = {
                    "$",
                    "$(",
                    "$()",
                    "@",
                    "@(",
                    "@()",
                    "%",
                    "%(",
                    "%()",
                    "exists",
                    "exists(",
                    "exists()",
                    "exists( )",
                    "exists(,)",
                    "@(x->'",
                    "@(x->''",
                    "@(x-",
                    "@(x->'x','",
                    "@(x->'x',''",
                    "@(x->'x','')",
                    "-1>x",
                    "%00",
                    "\n",
                    "\t",
                    "+-1==1",
                    "1==-+1",
                    "1==+0xa",
                    "!$(c)",
                    "'a'==('a'=='a')",
                    "'a'!=('a'=='a')",
                    "('a'=='a')!=a",
                    "('a'=='a')==a",
                    "!'x'",
                    "!'$(d)'",
                    "ab#==ab#",
                    "#!=#",
                    "$(d)$(e)=='xxxxxx'",
                    "1=1=1",
                    "'a'=='a'=='a'",
                    "1 > 'x'",
                    "x1<=1",
                    "1<=x",
                    "1>x",
                    "x<x",
                    "@(x)<x",
                    "x>x",
                    "x>=x",
                    "x<=x",
                    "x>1",
                    "x>=1",
                    "1>=x",
                    "@(y)<=1",
                    "1<=@(z)",
                    "1>$(d)",
                    "$(c)@(y)>1",
                    "'$(c)@(y)'>1",
                    "$(d)>=1",
                    "1>=$(b)",
                    "1> =0",
                    "or true",
                    "1 and",
                    "and",
                    "or",
                    "not",
                    "not true",
                    "()",
                    "(a)",
                    "!",
                    "or=or",
                    "1==",
                    "1= =1",
                    "=",
                    "'true",
                    "'false''",
                    "'a'=='a",
                    "('a'=='a'",
                    "('a'=='a'))",
                    "'a'=='a')",
                    "!and",
                    "@(a)@(x)!=1",
                    "@(a) @(x)!=1",
                    "$(a==off",
                    "=='x'",
                    "==",
                    "!0",
                    ">",
                    "true!=false==",
                    "true!=false==true",
                    "()",
                    "!1",
                    "1==(2",
                    "$(a)==x>1==2",
                    "'a'>'a'",
                    "0",
                    "$(a)>0",
                    "!$(e)",
                    "1<=1<=1",
                    "true $(and) true",
                    "--1==1",
                    "$(and)==and",
                    "!@#$%^&*",
                    "-($(c))==-1",
                    "a==b or $(d)",
                    "false or $()",
                    "$(d) or true",
                    "%(Culture) or true",
                    "@(nonexistent) and true",
                    "$(nonexistent) and true",
                    "@(nonexistent)",
                    "$(nonexistent)",
                    "@(z) and true",
                    "@() and true",
                    "@()",
                    "$()",
                    "1",
                    "1 or true",
                    "false or 1",
                    "1 and true",
                    "true and 1",
                    "!1",
                    "false or !1",
                    "false or 'aa'",
                    "true blah",
                    "existsX",
                    "!",
                    "nonexistentfunction('xyz')",
                    "exists('a;b')", /* non scalar */
                    "exists(@(z))",
                    "exists('@(z)')",
                    "exists($(a_semi_b))",
                    "exists('$(a_semi_b)')",
                    "exists(@(v)x)",
                    "exists(@(v)$(nonexistent))",
                    "exists('@(v)$(a)')",
                    "exists(|||||)",
                    "HasTrailingSlash(a,'b')",
                    "HasTrailingSlash(,,)",
                    "1.2.3==1,2,3"
                };

                for (int i = 0; i < trueTests.GetLength(0); i++)
                {
                    tree = p.Parse(trueTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                    ConditionEvaluator.IConditionEvaluationState state =
                        new ConditionEvaluator.ConditionEvaluationState<ProjectPropertyInstance, ProjectItemInstance>
                            (
                                trueTests[i],
                                expander,
                                ExpanderOptions.ExpandAll,
                                null,
                                Environment.CurrentDirectory,
                                ElementLocation.EmptyLocation
                            );

                    Assert.IsTrue(tree.Evaluate(state), "expected true from '" + trueTests[i] + "'");
                }

                for (int i = 0; i < falseTests.GetLength(0); i++)
                {
                    tree = p.Parse(falseTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                    ConditionEvaluator.IConditionEvaluationState state =
                        new ConditionEvaluator.ConditionEvaluationState<ProjectPropertyInstance, ProjectItemInstance>
                            (
                                falseTests[i],
                                expander,
                                ExpanderOptions.ExpandAll,
                                null,
                                Environment.CurrentDirectory,
                                ElementLocation.EmptyLocation
                            );

                    Assert.IsFalse(tree.Evaluate(state), "expected false from '" + falseTests[i] + "' and got true");
                }

                for (int i = 0; i < errorTests.GetLength(0); i++)
                {
                    // It seems that if an expression is invalid,
                    //      - Parse may throw, or
                    //      - Evaluate may throw, or
                    //      - Evaluate may return false causing its caller EvaluateCondition to throw
                    bool success = true;
                    bool caughtException = false;
                    bool value;
                    try
                    {
                        tree = p.Parse(errorTests[i], ParserOptions.AllowAll, ElementLocation.EmptyLocation);
                        ConditionEvaluator.IConditionEvaluationState state =
                            new ConditionEvaluator.ConditionEvaluationState<ProjectPropertyInstance, ProjectItemInstance>
                                (
                                    errorTests[i],
                                    expander,
                                    ExpanderOptions.ExpandAll,
                                    null,
                                    Environment.CurrentDirectory,
                                    ElementLocation.EmptyLocation
                                );

                        value = tree.Evaluate(state);
                        if (!success) Console.WriteLine(errorTests[i] + " caused Evaluate to return false");
                    }
                    catch (InvalidProjectFileException ex)
                    {
                        Console.WriteLine(errorTests[i] + " caused '" + ex.Message + "'");
                        caughtException = true;
                    }
                    Assert.IsTrue((success == false || caughtException == true), "expected '" + errorTests[i] + "' to not parse or not be evaluated");
                }
            }
            finally
            {
                foreach (string file in files)
                {
                    if (File.Exists(file)) File.Delete(file);
                }
            }
        }
Пример #42
0
        public void ConditionedPropertyUpdateTests()
        {
            Parser          p             = new Parser();
            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>();

            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));

            Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary <ProjectPropertyInstance>(), itemBag, FileSystems.Default);
            Dictionary <string, List <string> > conditionedProperties        = new Dictionary <string, List <string> >();

            ConditionEvaluator.IConditionEvaluationState state =
                new ConditionEvaluator.ConditionEvaluationState <ProjectPropertyInstance, ProjectItemInstance>
                (
                    String.Empty,
                    expander,
                    ExpanderOptions.ExpandAll,
                    conditionedProperties,
                    Directory.GetCurrentDirectory(),
                    ElementLocation.EmptyLocation,
                    FileSystems.Default
                );

            List <string> properties = null;

            AssertParseEvaluate(p, "'0' == '1'", expander, false, state);
            Assert.Equal(0, conditionedProperties.Count);

            AssertParseEvaluate(p, "$(foo) == foo", expander, false, state);
            Assert.Equal(1, conditionedProperties.Count);
            properties = conditionedProperties["foo"];
            Assert.Equal(1, properties.Count);

            AssertParseEvaluate(p, "'$(foo)' != 'bar'", expander, true, state);
            Assert.Equal(1, conditionedProperties.Count);
            properties = conditionedProperties["foo"];
            Assert.Equal(2, properties.Count);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab22dev|debug|x86'", expander, false, state);
            Assert.Equal(4, conditionedProperties.Count);
            properties = conditionedProperties["foo"];
            Assert.Equal(2, properties.Count);
            properties = conditionedProperties["branch"];
            Assert.Equal(1, properties.Count);
            properties = conditionedProperties["build"];
            Assert.Equal(1, properties.Count);
            properties = conditionedProperties["platform"];
            Assert.Equal(1, properties.Count);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab21|debug|x86'", expander, false, state);
            Assert.Equal(4, conditionedProperties.Count);
            properties = conditionedProperties["foo"];
            Assert.Equal(2, properties.Count);
            properties = conditionedProperties["branch"];
            Assert.Equal(2, properties.Count);
            properties = conditionedProperties["build"];
            Assert.Equal(1, properties.Count);
            properties = conditionedProperties["platform"];
            Assert.Equal(1, properties.Count);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab23|retail|ia64'", expander, false, state);
            Assert.Equal(4, conditionedProperties.Count);
            properties = conditionedProperties["foo"];
            Assert.Equal(2, properties.Count);
            properties = conditionedProperties["branch"];
            Assert.Equal(3, properties.Count);
            properties = conditionedProperties["build"];
            Assert.Equal(2, properties.Count);
            properties = conditionedProperties["platform"];
            Assert.Equal(2, properties.Count);
            DumpDictionary(conditionedProperties);
        }
Пример #43
0
        public void ItemListTests()
        {
            Parser p = new Parser();

            ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create());
            ItemDictionary<ProjectItemInstance> itemBag = new ItemDictionary<ProjectItemInstance>();
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath));
            itemBag.Add(new ProjectItemInstance(parentProject, "Boolean", "true", parentProject.FullPath));

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(new PropertyDictionary<ProjectPropertyInstance>(), itemBag);

            AssertParseEvaluate(p, "@(Compile) == 'foo.cs;bar.cs;baz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile,' ') == 'foo.cs bar.cs baz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile,'') == 'foo.csbar.csbaz.cs'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Filename)') == 'foo;bar;baz'", expander, true);
            AssertParseEvaluate(p, "@(Compile -> 'temp\\%(Filename).xml', ' ') == 'temp\\foo.xml temp\\bar.xml temp\\baz.xml'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'', '') == ''", expander, true);
            AssertParseEvaluate(p, "@(Compile->'') == ';;'", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)', '') == ''", expander, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)') == ';;'", expander, true);
            AssertParseEvaluate(p, "@(Boolean)", expander, true);
            AssertParseEvaluate(p, "@(Boolean) == true", expander, true);
            AssertParseEvaluate(p, "'@(Empty, ';')' == ''", expander, true);
        }
Пример #44
0
        /// <summary>
        /// Creates an expander populated with some ProjectPropertyInstances and ProjectPropertyItems.
        /// </summary>
        /// <returns></returns>
        private Expander<ProjectPropertyInstance, ProjectItemInstance> CreateExpander()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
            pg.Set(ProjectPropertyInstance.Create("p", "v0"));
            pg.Set(ProjectPropertyInstance.Create("p", "v1"));

            ItemDictionary<ProjectItemInstance> ig = new ItemDictionary<ProjectItemInstance>();
            ProjectItemInstance i0 = new ProjectItemInstance(project, "i", "i0", project.FullPath);
            ProjectItemInstance i1 = new ProjectItemInstance(project, "i", "i1", project.FullPath);
            ig.Add(i0);
            ig.Add(i1);

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, ig);

            return expander;
        }
Пример #45
0
    private void InstanceItem(int i, int j)
    {
        int itemId = ItemDictionary.Count;

        ItemDictionary.Add(i * instanceDungeon.size + j, InstantiateObject(itemBoxPrefab[0].name, i, j));
    }