Exemplo n.º 1
0
        private static NodeSearchElement CreateCustomNode(string name, string category,
            string description = "", string path = "")
        {
            var element = new CustomNodeSearchElement(null,
                new CustomNodeInfo(Guid.NewGuid(), name, category, description, path));

            return element;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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;
        }
 public CustomNodeSearchElementViewModel(CustomNodeSearchElement element, SearchViewModel svm)
     : base(element, svm)
 {
     Path = Model.Path;
 }
Exemplo n.º 6
0
        private void ExecuteElement(CustomNodeSearchElement element)
        {
            string name = element.Guid.ToString();

            // create node
            var guid = Guid.NewGuid();
            dynamoViewModel.ExecuteCommand(
                new DynamoViewModel.CreateNodeCommand(guid, name, 0, 0, true, true));

            // select node
            var placedNode = dynamoViewModel.Model.Nodes.Find((node) => node.GUID == guid);
            if (placedNode != null)
            {
                DynamoSelection.Instance.ClearSelection();
                DynamoSelection.Instance.Selection.Add(placedNode);
            }
        }
Exemplo n.º 7
0
        public void CanRemoveElementCustomNodeByNameWithSingleCategory()
        {
            var element = new CustomNodeSearchElement(
                   null,
                   new CustomNodeInfo(Guid.NewGuid(), "Peter", "Greens", "des", ""));
            search.Add(element);

            var results = search.Search("Peter");
            Assert.AreEqual(1, results.Count());

            search.Remove(element);

            results = search.Search("Peter");
            Assert.AreEqual(0, results.Count());
        }
Exemplo n.º 8
0
        public void CanRemoveSingleCustomNodeByIdWhereThereAreDuplicatesWithDifferentIds()
        {
            const string nodeName = "TheNoodle";
            const string catName = "TheCat";
            const string descr = "TheCat";
            const string path = @"C:\turtle\graphics.dyn";
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();
            var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1);
            var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path);
            var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo2);

            search.Add(dummySearch1);
            search.Add(dummySearch2);
            Assert.AreEqual(2, search.NumElements);

            search.Remove(dummySearch2);
            Assert.AreEqual(1, search.NumElements);

            var results = search.Search(nodeName).ToList();
            Assert.AreEqual(1, results.Count());

            var res1 = results[0];
            Assert.IsInstanceOf<CustomNodeSearchElement>(res1);
            var node1 = (CustomNodeSearchElement)res1;
            Assert.AreEqual(node1.ID, guid1);
        }
Exemplo n.º 9
0
        public void CanAddDuplicateCustomNodeWithDifferentGuidsAndGetBothInResults()
        {
            const string nodeName = "TheNoodle";
            const string catName = "TheCat";
            const string descr = "TheCat";
            const string path = @"C:\turtle\graphics.dyn";
            var guid1 = Guid.NewGuid();
            var guid2 = Guid.NewGuid();
            var dummyInfo1 = new CustomNodeInfo(guid1, nodeName, catName, descr, path);
            var dummySearch1 = new CustomNodeSearchElement(null, dummyInfo1);
            var dummyInfo2 = new CustomNodeInfo(guid2, nodeName, catName, descr, path);
            var dummySearch2 = new CustomNodeSearchElement(null, dummyInfo2);

            search.Add(dummySearch1);
            search.Add(dummySearch2);
            Assert.AreEqual(2, search.NumElements);

            var results = search.Search(nodeName).ToList();
            Assert.AreEqual(2, results.Count());

            var resultIds = results.Cast<CustomNodeSearchElement>().Select(x => x.ID).ToList();
            Assert.IsTrue(resultIds.Contains(guid1));
            Assert.IsTrue(resultIds.Contains(guid2));

        }
Exemplo n.º 10
0
        public void CanRemoveNodeAndCategoryByFunctionId()
        {
            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);

            // add custom node
            search.Add(dummySearch1);
            // confirm it's in the dictionary
            Assert.AreEqual(1, search.NumElements);

            // remove custom node
            search.Remove(dummySearch1);
            // it's gone
            Assert.AreEqual(0, search.NumElements);

            var results = search.Search(nodeName);
            Assert.AreEqual(0, results.Count());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Helper method for custom node adding and removing
        /// </summary>
        public static void AssertAddAndRemoveCustomNode(
            NodeSearchModel searchModel, string nodeName, string catName, string descr = "Bla",
            string path = "Bla")
        {
            var dummyInfo = new CustomNodeInfo(Guid.NewGuid(), nodeName, catName, descr, path);
            var dummySearch = new CustomNodeSearchElement(null, dummyInfo);
            searchModel.Add(dummySearch);

            var res = searchModel.Search(nodeName).ToList();
            Assert.AreNotEqual(0, res.Count());
            Assert.AreEqual(res[0].Name, nodeName);

            searchModel.Remove(dummySearch);
            res = searchModel.Search(nodeName).ToList();
            Assert.AreEqual(0, res.Count());
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        public bool Add(CustomNodeInfo nodeInfo)
        {
            var nodeEle = new CustomNodeSearchElement(nodeInfo);

            if (SearchDictionary.Contains(nodeEle))
            {
                return this.Refactor(nodeInfo);
            }

            SearchDictionary.Add(nodeEle, nodeEle.Name);
            SearchDictionary.Add(nodeEle, nodeInfo.Category + "." + nodeEle.Name);

            TryAddCategoryAndItem(nodeInfo.Category, nodeEle);

            return true;
        }
Exemplo n.º 16
0
 public CustomNodeSearchElementViewModel(CustomNodeSearchElement element, SearchViewModel svm)
     : base(element, svm)
 {
     Model.PropertyChanged += ModelOnPropertyChanged;
     Path = Model.Path;
 }