Esempio n. 1
0
        internal void InitChain(ExtensionChain chain, ChainedExtension next)
        {
            this.chain  = chain;
            nextInChain = next;

            InitializeChain(next);
        }
Esempio n. 2
0
        void InitializeExtensionChain()
        {
            // Create an initial empty extension chain. This avoid crashes in case a call to SupportsObject ends
            // calling methods from the extension

            var tempExtensions = new List <WorkspaceObjectExtension> ();

            tempExtensions.AddRange(CreateDefaultExtensions().Reverse());
            extensionChain = ExtensionChain.Create(tempExtensions.ToArray());
            foreach (var e in tempExtensions)
            {
                e.Init(this);
            }

            // Collect extensions that support this object

            var extensions = new List <WorkspaceObjectExtension> ();

            foreach (ProjectModelExtensionNode node in GetModelExtensions(extensionContext))
            {
                if (node.CanHandleObject(this))
                {
                    var ext = node.CreateExtension();
                    if (ext.SupportsObject(this))
                    {
                        ext.SourceExtensionNode = node;
                        extensions.Add(ext);
                    }
                }
            }

            foreach (var e in tempExtensions)
            {
                e.Dispose();
            }

            // Now create the final extension chain

            extensions.Reverse();
            var defaultExts = CreateDefaultExtensions().ToList();

            defaultExts.Reverse();
            extensions.AddRange(defaultExts);
            extensionChain = ExtensionChain.Create(extensions.ToArray());
            extensionChain.SetDefaultInsertionPosition(defaultExts.FirstOrDefault());

            foreach (var e in extensions)
            {
                e.Init(this);
            }

            itemExtension = ExtensionChain.GetExtension <WorkspaceObjectExtension> ();

            foreach (var e in extensions)
            {
                e.OnExtensionChainCreated();
            }
        }
Esempio n. 3
0
        protected override void OnExtensionChainInitialized()
        {
            itemExtension = ExtensionChain.GetExtension <SolutionExtension> ();
            base.OnExtensionChainInitialized();

            if (!loadingFromConstructor)
            {
                NotifyItemReady();
            }
        }
Esempio n. 4
0
        public static ExtensionChain Create <T> (T[] extensions) where T : ChainedExtension
        {
            var c = new ExtensionChain();

            for (int n = extensions.Length - 2; n >= 0; n--)
            {
                extensions [n].InitChain(c, extensions [n + 1]);
            }

            c.extensions = extensions;
            return(c);
        }
Esempio n. 5
0
            public void Update(ExtensionChain chain, Type type, int firstChainChangeIndex)
            {
                // We only want to update an extension if we insert somewhere before the extension we found.
                if (extensionIndex < firstChainChangeIndex)
                {
                    return;
                }

                // Maybe it would be useful to skip extensions until min(indices), as they've already been scanned
                // in a previous check
                var impl = ChainedExtension.FindNextImplementation(type, chain.extensions[0], out extensionIndex);

                Extension.InitChain(chain, impl);
            }
Esempio n. 6
0
        public void ExtensionChainQuerying()
        {
            var exts = new BaseTestChainedExtension [] {
                new SquareChainedExtension(),
                new RectangleChainedExtension(),
                new ShapeChainedExtension(),
                new GreenChainedExtension(),
                new ColorChainedExtension(),
                new BaseTestChainedExtension(),
            };

            var initialSquare = exts [0];
            var initialGreen  = exts [3];
            var initialBase   = exts [5];

            var chain = ExtensionChain.Create(exts);

            // Look for shape extensions
            var square    = chain.GetExtension <SquareChainedExtension> ();
            var rectangle = chain.GetExtension <RectangleChainedExtension> ();
            var shape     = chain.GetExtension <ShapeChainedExtension> ();

            Assert.IsNull(square.Next);
            Assert.AreSame(initialSquare, rectangle.Next);
            Assert.AreSame(initialSquare, shape.Next);

            // Look for color extensions
            var green = chain.GetExtension <GreenChainedExtension> ();
            var color = chain.GetExtension <ColorChainedExtension> ();

            Assert.IsNull(green.Next);
            Assert.AreSame(initialGreen, color.Next);

            var chainedExtension = chain.GetExtension <BaseTestChainedExtension> ();

            Assert.IsNull(chainedExtension.Next);

            chain.Dispose();

            // Check that the extensions we queried get disposed
            Assert.IsTrue(square.IsDisposed);
            Assert.IsTrue(rectangle.IsDisposed);
            Assert.IsTrue(shape.IsDisposed);
            Assert.IsTrue(green.IsDisposed);
            Assert.IsTrue(color.IsDisposed);
            Assert.IsTrue(chainedExtension.IsDisposed);
        }
Esempio n. 7
0
 protected override void OnExtensionChainInitialized()
 {
     itemExtension = ExtensionChain.GetExtension <WorkspaceItemExtension> ();
     base.OnExtensionChainInitialized();
 }
Esempio n. 8
0
 public void DetachExtension(WorkspaceObjectExtension ext)
 {
     AssertMainThread();
     ExtensionChain.RemoveExtension(ext);
 }
Esempio n. 9
0
 public void AttachExtension(WorkspaceObjectExtension ext)
 {
     AssertMainThread();
     ExtensionChain.AddExtension(ext);
     ext.Init(this);
 }
Esempio n. 10
0
 protected override void OnExtensionChainInitialized()
 {
     itemExtension = ExtensionChain.GetExtension <WorkspaceItemExtension> ();
     base.OnExtensionChainInitialized();
     fileStatusTracker.TrackFileChanges();
 }
Esempio n. 11
0
 public BatchModifier(ExtensionChain chain)
 {
     this.chain      = chain;
     minChangedIndex = chain.extensions.Length;
 }
Esempio n. 12
0
 static BaseTestChainedExtension [] GetAllExtensions(ExtensionChain chain) => GetAllExtensions <BaseTestChainedExtension> (chain);
Esempio n. 13
0
 static T [] GetAllExtensions <T> (ExtensionChain chain) => chain.GetAllExtensions().Cast <T> ().ToArray();
Esempio n. 14
0
        public void ExtensionChainQueryingCachingBatch()
        {
            var exts = new BaseTestChainedExtension [] {
                new SquareChainedExtension(),
                new RectangleChainedExtension(),
                new ShapeChainedExtension(),
                new GreenChainedExtension(),
                new ColorChainedExtension(),
                new BaseTestChainedExtension(),
            };

            var arrSquare = exts.Single(x => x.GetType() == typeof(SquareChainedExtension));
            var arrRect   = exts.Single(x => x.GetType() == typeof(RectangleChainedExtension));
            var arrShape  = exts.Single(x => x.GetType() == typeof(ShapeChainedExtension));
            var arrGreen  = exts.Single(x => x.GetType() == typeof(GreenChainedExtension));
            var arrColor  = exts.Single(x => x.GetType() == typeof(ColorChainedExtension));
            var arrBase   = exts.Single(x => x.GetType() == typeof(BaseTestChainedExtension));

            var chain = ExtensionChain.Create(exts);

            // Look for shape extensions
            var square           = chain.GetExtension <SquareChainedExtension> ();
            var rectangle        = chain.GetExtension <RectangleChainedExtension> ();
            var shape            = chain.GetExtension <ShapeChainedExtension> ();
            var green            = chain.GetExtension <GreenChainedExtension> ();
            var color            = chain.GetExtension <ColorChainedExtension> ();
            var chainedExtension = chain.GetExtension <BaseTestChainedExtension> ();

            int shapeInitializedCount  = 1;
            int colorInitializedCount  = 1;
            int baseInitializedCount   = 1;
            int noNextInitializedCount = 1;

            AssertInitializedCount();

            BaseTestChainedExtension toAdd = null;

            using (chain.BatchModify()) {
                // Add a BaseTestChainedExtension before the last item
                // This should not trigger any init, as it's not a candidate for anything.
                toAdd = new BaseTestChainedExtension();
                chain.AddExtension(toAdd, insertBefore: arrBase);
                AssertInitializedCount();

                // Remove the same one we added.
                chain.RemoveExtension(toAdd);
                AssertInitializedCount();

                // This won't have any effect, all of the colors go to green which is to the left of the node we insert after
                toAdd = new ColorChainedExtension();
                chain.AddExtension(toAdd, insertAfter: arrColor);
                AssertInitializedCount();
            }

            // Final result is only no next ones being chained.
            noNextInitializedCount++;
            AssertInitializedCount();

            using (chain.BatchModify()) {
                // This won't have any effect, all of the colors go to green, before color
                toAdd = new ColorChainedExtension();
                chain.AddExtension(toAdd, insertBefore: arrColor);
                AssertInitializedCount();

                // Removing green would cause colors and the base extensions to be rechained.
                chain.RemoveExtension(arrGreen);
                AssertInitializedCount();

                // Adding a new square after the first one should rechain everything but shapes
                toAdd = new SquareChainedExtension();
                chain.AddExtension(toAdd, insertAfter: arrSquare);
                AssertInitializedCount();
            }

            // Final result is everything except shapes being rechained
            noNextInitializedCount++;
            baseInitializedCount++;
            colorInitializedCount++;
            AssertInitializedCount();

            using (chain.BatchModify()) {
                // Removing the square rechain everything but shapes
                chain.RemoveExtension(toAdd);
                AssertInitializedCount();

                // Adding a square at the beginning should rechain everything
                chain.AddExtension(toAdd, insertBefore: arrSquare);
                AssertInitializedCount();

                // Then removing it should rechain everything.
                chain.RemoveExtension(toAdd);
                AssertInitializedCount();
            }

            // Final result is everything rechained
            noNextInitializedCount++;
            baseInitializedCount++;
            colorInitializedCount++;
            shapeInitializedCount++;
            AssertInitializedCount();

            void AssertInitializedCount()
            {
                Assert.AreEqual(noNextInitializedCount, square.InitializedCount);
                Assert.AreEqual(shapeInitializedCount, rectangle.InitializedCount);
                Assert.AreEqual(shapeInitializedCount, shape.InitializedCount);
                Assert.AreEqual(noNextInitializedCount, green.InitializedCount);
                Assert.AreEqual(colorInitializedCount, color.InitializedCount);
                Assert.AreEqual(noNextInitializedCount, chainedExtension.InitializedCount);
            }
        }