コード例 #1
0
        internal static CacheEntry CreateFromStream(BinaryReader reader)
        {
            CacheEntryTypes entryType = (CacheEntryTypes)reader.ReadByte();
            CacheEntry      entry     = null;

            switch (entryType)
            {
            case CacheEntryTypes.BuildItem:
                entry = new BuildItemCacheEntry();
                break;

            case CacheEntryTypes.BuildResult:
                entry = new BuildResultCacheEntry();
                break;

            case CacheEntryTypes.Property:
                entry = new PropertyCacheEntry();
                break;

            default:
                ErrorUtilities.VerifyThrow(false, "Should not get to the default of CacheEntryCustomSerializer CreateFromStream");
                break;
            }

            entry.CreateFromStream(reader);
            return(entry);
        }
コード例 #2
0
ファイル: CacheEntry_Tests.cs プロジェクト: nikson/msbuild
        public void CacheEntryGettersDefaultConstructors()
        {
            BuildItem[] buildItems = new BuildItem[2] { null, null };

            BuildItemCacheEntry tice = new BuildItemCacheEntry();
            Assertion.AssertEquals(null, tice.Name);
            Assertion.AssertEquals(null, tice.BuildItems);
            
            tice.Name = "tice";
            tice.BuildItems = buildItems;
            Assertion.AssertEquals("tice", tice.Name);
            Assertion.AssertEquals(buildItems, tice.BuildItems);

            PropertyCacheEntry pce = new PropertyCacheEntry();
            Assertion.AssertEquals(null, pce.Name);
            Assertion.AssertEquals(null, pce.Value);

            pce.Name = "pce";
            pce.Value = "propertyValue";
            Assertion.AssertEquals("pce", pce.Name);
            Assertion.AssertEquals("propertyValue", pce.Value);

            BuildResultCacheEntry brce = new BuildResultCacheEntry();
            Assertion.AssertEquals(null, brce.Name);
            Assertion.AssertEquals(null, brce.BuildItems);
            Assertion.AssertEquals(default(bool), brce.BuildResult);

            brce.Name = "brce";
            brce.BuildItems = buildItems;
            brce.BuildResult = false;
            Assertion.AssertEquals("brce", brce.Name);
            Assertion.AssertEquals(buildItems, brce.BuildItems);
            Assertion.AssertEquals(false, brce.BuildResult);
        }
コード例 #3
0
        /// <summary>
        /// Returns true if the given cache entry contains equivalent contents
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        internal override bool IsEquivalent(CacheEntry other)
        {
            if ((other == null) || (other.GetType() != this.GetType()))
            {
                return(false);
            }

            BuildItemCacheEntry otherEntry = (BuildItemCacheEntry)other;

            if (this.Name != otherEntry.Name)
            {
                return(false);
            }

            if ((this.BuildItems == null && otherEntry.BuildItems != null) ||
                (this.BuildItems != null && otherEntry.BuildItems == null))
            {
                return(false);
            }

            if ((this.BuildItems == null) && (otherEntry.BuildItems == null))
            {
                return(true);
            }

            if (this.BuildItems.Length != otherEntry.BuildItems.Length)
            {
                return(false);
            }

            for (int i = 0; i < this.BuildItems.Length; i++)
            {
                if ((this.BuildItems[i] == null && otherEntry.BuildItems[i] != null) ||
                    (this.BuildItems[i] != null && otherEntry.BuildItems[i] == null))
                {
                    return(false);
                }

                if ((this.BuildItems[i].FinalItemSpecEscaped != otherEntry.BuildItems[i].FinalItemSpecEscaped) ||
                    (this.BuildItems[i].GetCustomMetadataCount() != otherEntry.BuildItems[i].GetCustomMetadataCount()))
                {
                    return(false);
                }

                HashSet <string> otherEntryMetadataNames = new HashSet <string>(otherEntry.BuildItems[i].GetAllCustomMetadataNames(), StringComparer.Ordinal);

                foreach (string metadataName in this.BuildItems[i].GetAllCustomMetadataNames())
                {
                    if ((!otherEntryMetadataNames.Contains(metadataName)) ||
                        (this.BuildItems[i].GetEvaluatedMetadataEscaped(metadataName) != otherEntry.BuildItems[i].GetEvaluatedMetadataEscaped(metadataName)))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #4
0
ファイル: CacheEntry_Tests.cs プロジェクト: nikson/msbuild
        public void CacheEntryGetters()
        {
            BuildItem[] buildItems = new BuildItem[2] { null, null };

            BuildItemCacheEntry tice = new BuildItemCacheEntry("tice", buildItems);
            Assertion.AssertEquals("tice", tice.Name);
            Assertion.AssertEquals(buildItems, tice.BuildItems);

            PropertyCacheEntry pce = new PropertyCacheEntry("pce", "propertyValue");
            Assertion.AssertEquals("pce", pce.Name);
            Assertion.AssertEquals("propertyValue", pce.Value);

            BuildResultCacheEntry brce = new BuildResultCacheEntry("brce", buildItems, true);
            Assertion.AssertEquals("brce", brce.Name);
            Assertion.AssertEquals(buildItems, brce.BuildItems);
            Assertion.AssertEquals(true, brce.BuildResult);
        }
コード例 #5
0
        internal static CacheEntry CreateFromStream(BinaryReader reader)
        {
            CacheEntryTypes entryType = (CacheEntryTypes) reader.ReadByte();
            CacheEntry entry = null;

            switch (entryType)
            {
                case CacheEntryTypes.BuildItem:
                    entry = new BuildItemCacheEntry();
                    break;
                case CacheEntryTypes.BuildResult:
                    entry = new BuildResultCacheEntry();
                    break;
                case CacheEntryTypes.Property:
                    entry = new PropertyCacheEntry();
                    break;
                default:
                    ErrorUtilities.VerifyThrow(false, "Should not get to the default of CacheEntryCustomSerializer CreateFromStream");
                    break;
            }

            entry.CreateFromStream(reader);
            return entry;
        }
コード例 #6
0
ファイル: CacheEntry_Tests.cs プロジェクト: nikson/msbuild
        public void IsEquivalentTaskItem()
        {
            BuildItem bi = new BuildItem("itemname", "itemspec");
            bi.SetMetadata("mn", "mv");

            BuildItemCacheEntry e = new BuildItemCacheEntry("name", new BuildItem[] { bi });

            Assert.IsFalse(e.IsEquivalent(null));
            Assert.IsFalse(e.IsEquivalent(new PropertyCacheEntry()));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry()));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("naame", new BuildItem[] { bi })));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", null)));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { null })));
            Assert.IsFalse(new BuildItemCacheEntry("name", new BuildItem[] { null }).IsEquivalent(e));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { new BuildItem("itemname", "itemspec") })));
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { bi, bi })));

            BuildItem bi2 = new BuildItem("itemname", "itemspec");
            bi2.SetMetadata("n", "v");
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { bi2 })));
            bi2.SetMetadata("mn", "mv");
            Assert.IsFalse(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { bi2 })));

            BuildItem bi3 = new BuildItem("itemname", "itemspec");
            bi3.SetMetadata("mn", "mv");
            Assert.IsTrue(e.IsEquivalent(new BuildItemCacheEntry("name", new BuildItem[] { bi3 })));
        }
コード例 #7
0
ファイル: CacheEntry_Tests.cs プロジェクト: nikson/msbuild
        public void TestCacheEntryCustomSerialization()
        {
            // Stream, writer and reader where the events will be serialized and deserialized from
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);
            BinaryReader reader = new BinaryReader(stream);
            try
            {
                BuildItem buildItem1 = new BuildItem("BuildItem1", "Item1");
                BuildItem buildItem2 = new BuildItem("BuildItem2", "Item2");
                buildItem1.Include = "TestInclude1";
                buildItem2.Include = "TestInclude2";
                BuildItem[] buildItems = new BuildItem[2];
                buildItems[0] = buildItem1;
                buildItems[1] = buildItem2;

                BuildItemCacheEntry buildItemEntry = new BuildItemCacheEntry("Badger", buildItems);
                BuildResultCacheEntry buildResultEntry = new BuildResultCacheEntry("Koi", buildItems, true);
                PropertyCacheEntry propertyEntry = new PropertyCacheEntry("Seagull", "bread");
                
                stream.Position = 0;
                // Serialize
                buildItemEntry.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                long streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position = 0;
                BuildItemCacheEntry newCacheEntry = new BuildItemCacheEntry();
                newCacheEntry.CreateFromStream(reader);
                long streamReadEndPosition = stream.Position;
                Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
                Assert.IsTrue(string.Compare(newCacheEntry.Name, buildItemEntry.Name, StringComparison.OrdinalIgnoreCase) == 0);
                BuildItem[] buildItemArray = newCacheEntry.BuildItems;
                Assert.IsTrue(buildItemArray.Length == 2);
                Assert.IsTrue(string.Compare(buildItemArray[0].Include, buildItem1.Include, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(buildItemArray[1].Include, buildItem2.Include, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(buildItemArray[1].Name, buildItem2.Name, StringComparison.OrdinalIgnoreCase) == 0);


                stream.Position = 0;
                // Serialize
                buildResultEntry.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position = 0;
                BuildResultCacheEntry newCacheEntryBuildResult = new BuildResultCacheEntry();
                newCacheEntryBuildResult.CreateFromStream(reader);
                streamReadEndPosition = stream.Position;
                Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
                Assert.IsTrue(string.Compare(newCacheEntryBuildResult.Name, buildResultEntry.Name, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(buildResultEntry.BuildResult == newCacheEntryBuildResult.BuildResult);
                buildItemArray = newCacheEntryBuildResult.BuildItems;
                Assert.IsTrue(buildItemArray.Length == 2);
                Assert.IsTrue(string.Compare(buildItemArray[0].Include, buildItem1.Include, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(buildItemArray[1].Include, buildItem2.Include, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(buildItemArray[1].Name, buildItem2.Name, StringComparison.OrdinalIgnoreCase) == 0);


                stream.Position = 0;
                // Serialize
                propertyEntry.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position = 0;
                PropertyCacheEntry newPropertyCacheEntry = new PropertyCacheEntry();
                newPropertyCacheEntry.CreateFromStream(reader);
                streamReadEndPosition = stream.Position;
                Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
                Assert.IsTrue(string.Compare(newPropertyCacheEntry.Name, propertyEntry.Name, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(newPropertyCacheEntry.Value, propertyEntry.Value, StringComparison.OrdinalIgnoreCase) == 0);
            }
            finally
            {
                // Close will close the writer/reader and the underlying stream
                writer.Close();
                reader.Close();
                reader = null;
                stream = null;
                writer = null;
            }
        }
コード例 #8
0
ファイル: SharedMemory_Test.cs プロジェクト: nikson/msbuild
        private static CacheEntry[] CreateCacheEntries()
        {
            CacheEntry[] entries = new CacheEntry[3];

            BuildItem buildItem1 = new BuildItem("BuildItem1", "Item1");
            BuildItem buildItem2 = new BuildItem("BuildItem2", "Item2");
            buildItem1.Include = "TestInclude1";
            buildItem2.Include = "TestInclude2";
            BuildItem[] buildItems = new BuildItem[2];
            buildItems[0] = buildItem1;
            buildItems[1] = buildItem2;

            entries[0] = new BuildItemCacheEntry("Badger", buildItems);
            entries[1] = new BuildResultCacheEntry("Koi", buildItems, true);
            entries[2] = new PropertyCacheEntry("Seagull", "bread");
            return entries;
        }