Example #1
0
        public void CanRefactorCustomNodeName()
        {
            const string nodeName = "TheNoodle";
            const string catName = "TheCat";
            const string descr = "TheCat";
            const string path = @"C:\turtle\graphics.dyn";
            var guid1 = Guid.NewGuid();
            var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1);

            search.Add(dummySearch1);

            Assert.AreEqual(1, search.NumElements);

            const string newNodeName = "TheTurtle";
            var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path);
            dummySearch1.SyncWithCustomNodeInfo(newInfo);
            search.Update(dummySearch1);

            Assert.AreEqual(1, search.NumElements);

            // search for new name
            var results = search.Search(newNodeName).ToList();

            // results are correct
            Assert.AreEqual(1, results.Count());
            var res1 = results[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res1);
            Assert.AreEqual(guid1, ((CustomNodeSearchElement)res1).ID);

            // search for old name
            var results1 = search.Search(nodeName);

            // results are correct
            Assert.AreEqual(0, results1.Count());
        }
Example #2
0
        private void InitializeCustomNodeManager()
        {
            CustomNodeManager.MessageLogged += LogMessage;

            var customNodeSearchRegistry = new HashSet<Guid>();
            CustomNodeManager.InfoUpdated += info =>
            {
                if (customNodeSearchRegistry.Contains(info.FunctionId)
                        || !info.IsVisibleInDynamoLibrary)
                    return;

                var elements = SearchModel.SearchEntries.OfType<CustomNodeSearchElement>().
                                Where(x =>
                                        {
                                            // Search for common paths and get rid of empty paths.
                                            // It can be empty just in case it's just created node.
                                            return String.Compare(x.Path, info.Path, StringComparison.OrdinalIgnoreCase) == 0 &&
                                                !String.IsNullOrEmpty(x.Path);
                                        }).ToList();

                if (elements.Any())
                {
                    foreach (var element in elements)
                    {
                        element.SyncWithCustomNodeInfo(info);
                        SearchModel.Update(element);
                    }
                    return;
                }

                customNodeSearchRegistry.Add(info.FunctionId);
                var searchElement = new CustomNodeSearchElement(CustomNodeManager, info);
                SearchModel.Add(searchElement);
                Action<CustomNodeInfo> infoUpdatedHandler = null;
                infoUpdatedHandler = newInfo =>
                {
                    if (info.FunctionId == newInfo.FunctionId)
                    {
                        bool isCategoryChanged = searchElement.FullCategoryName != newInfo.Category;
                        searchElement.SyncWithCustomNodeInfo(newInfo);
                        SearchModel.Update(searchElement, isCategoryChanged);
                    }
                };
                CustomNodeManager.InfoUpdated += infoUpdatedHandler;
                CustomNodeManager.CustomNodeRemoved += id =>
                {
                    CustomNodeManager.InfoUpdated -= infoUpdatedHandler;
                    if (info.FunctionId == id)
                    {
                        customNodeSearchRegistry.Remove(info.FunctionId);
                        SearchModel.Remove(searchElement);
                        var workspacesToRemove = _workspaces.FindAll(w => w is CustomNodeWorkspaceModel
                            && (w as CustomNodeWorkspaceModel).CustomNodeId == id);
                        workspacesToRemove.ForEach(w => RemoveWorkspace(w));
                    }
                };
            };
            CustomNodeManager.DefinitionUpdated += UpdateCustomNodeDefinition;
        }
Example #3
0
        public void CanRefactorCustomNodeDescription()
        {
            const string nodeName = "TheNoodle";
            const string catName = "TheCat";
            const string descr = "TheCat";
            const string path = @"C:\turtle\graphics.dyn";
            var guid1 = Guid.NewGuid();
            var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1);

            search.Add(dummySearch1);

            Assert.AreEqual(1, search.NumElements);

            // search for name
            var results = search.Search(nodeName).ToList();

            // results are correct
            Assert.AreEqual(1, results.Count());
            var res1 = results[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res1);
            Assert.AreEqual(guid1, ((CustomNodeSearchElement)res1).ID);

            // refactor description
            const string newDescription = "Tickle me elmo";
            var newInfo = new CustomNodeInfo(guid1, nodeName, catName, newDescription, path);
            dummySearch1.SyncWithCustomNodeInfo(newInfo);
            search.Update(dummySearch1);

            // num elements is unchanged
            Assert.AreEqual(1, search.NumElements);

            // search for name
            var results1 = search.Search(nodeName).ToList();

            // description is updated
            Assert.AreEqual(1, results1.Count());
            var res2 = results1[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res2);
            Assert.AreEqual(guid1, ((CustomNodeSearchElement)res2).ID);
            Assert.AreEqual(newDescription, res2.Description);
        }
Example #4
0
        public void CanRefactorCustomNodeWhilePreservingDuplicates()
        {
            const string nodeName = "TheNoodle";
            const string catName = "TheCat";
            const string descr = "TheCat";
            const string path = @"C:\turtle\graphics.dyn";
            var guid1 = Guid.NewGuid();
            var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1);
            var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo1);

            search.Add(dummySearch1);
            search.Add(dummySearch2);

            Assert.AreEqual(2, search.NumElements);

            // refactor one of the nodes with newNodeName
            const string newNodeName = "TheTurtle";
            var newInfo = new CustomNodeInfo(guid1, newNodeName, catName, descr, path);
            dummySearch1.SyncWithCustomNodeInfo(newInfo);
            search.Update(dummySearch1);

            // num elements is unchanged
            Assert.AreEqual(2, search.NumElements);

            // search for new name
            var results = search.Search(newNodeName).ToList();

            // results are correct - only one result
            Assert.AreEqual(1, results.Count());
            var res1 = results[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res1);
            Assert.AreSame(dummySearch1, res1);

            // search for old name
            results = search.Search(nodeName).ToList();

            // results are correct - the first nodes are returned
            Assert.AreEqual(1, results.Count());
            var res2 = results[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res2);
            Assert.AreSame(dummySearch2, res2);
        }
Example #5
0
        private void InitializeCustomNodeManager()
        {
            CustomNodeManager.MessageLogged += LogMessage;

            var customNodeSearchRegistry = new HashSet<Guid>();
            CustomNodeManager.InfoUpdated += info =>
            {
                if (customNodeSearchRegistry.Contains(info.FunctionId))
                    return;

                var elements = SearchModel.SearchEntries.OfType<CustomNodeSearchElement>().Where(
                                x =>
                                {
                                    return string.Compare(x.Path, info.Path, StringComparison.OrdinalIgnoreCase) == 0;
                                }).ToList();

                if (elements.Any())
                {
                    foreach (var element in elements)
                    {
                        element.SyncWithCustomNodeInfo(info);
                        SearchModel.Update(element);
                    }
                    return;
                }

                customNodeSearchRegistry.Add(info.FunctionId);
                var searchElement = new CustomNodeSearchElement(CustomNodeManager, info);
                SearchModel.Add(searchElement);
                CustomNodeManager.InfoUpdated += newInfo =>
                {
                    if (info.FunctionId == newInfo.FunctionId)
                    {
                        bool isCategoryChanged = searchElement.FullCategoryName != newInfo.Category;
                        searchElement.SyncWithCustomNodeInfo(newInfo);
                        SearchModel.Update(searchElement, isCategoryChanged);
                    }
                };
                CustomNodeManager.CustomNodeRemoved += id =>
                {
                    if (info.FunctionId == id)
                    {
                        customNodeSearchRegistry.Remove(info.FunctionId);
                        SearchModel.Remove(searchElement);
                        var workspacesToRemove = _workspaces.FindAll(w => w is CustomNodeWorkspaceModel
                            && (w as CustomNodeWorkspaceModel).CustomNodeId == id);
                        workspacesToRemove.ForEach(w => RemoveWorkspace(w));
                    }
                };
            };
            CustomNodeManager.DefinitionUpdated += UpdateCustomNodeDefinition;
        }
Example #6
0
        private void InitializeCustomNodeManager()
        {
            CustomNodeManager.MessageLogged += LogMessage;

            var customNodeSearchRegistry = new HashSet<Guid>();
            CustomNodeManager.InfoUpdated += info =>
            {
                if (customNodeSearchRegistry.Contains(info.FunctionId))
                    return;

                customNodeSearchRegistry.Add(info.FunctionId);
                var searchElement = new CustomNodeSearchElement(CustomNodeManager, info);
                SearchModel.Add(searchElement);
                CustomNodeManager.InfoUpdated += newInfo =>
                {
                    if (info.FunctionId == newInfo.FunctionId)
                    {
                        bool isCategoryChanged = searchElement.FullCategoryName != newInfo.Category;
                        searchElement.SyncWithCustomNodeInfo(newInfo);
                        SearchModel.Update(searchElement, isCategoryChanged);
                    }
                };
                CustomNodeManager.CustomNodeRemoved += id =>
                {
                    if (info.FunctionId == id)
                    {
                        customNodeSearchRegistry.Remove(info.FunctionId);
                        SearchModel.Remove(searchElement);
                        var workspacesToRemove = _workspaces.FindAll(w => w is CustomNodeWorkspaceModel
                            && (w as CustomNodeWorkspaceModel).CustomNodeId == id);
                        workspacesToRemove.ForEach(w => RemoveWorkspace(w));
                    }
                };
            };
            CustomNodeManager.DefinitionUpdated += UpdateCustomNodeDefinition;
        }