Exemple #1
0
        public void CanRemoveElementCustomNodeByNameWithSingleCategory()
        {
            var model = new SearchViewModel();
            model.Add("Peter", "Greens", "A description", System.Guid.NewGuid());

            model.SearchAndUpdateResultsSync("Peter");
            Assert.AreEqual(1, model.SearchResults.Count);

            model.Remove("Peter");
            model.SearchAndUpdateResultsSync("Peter");

            Assert.AreEqual(0, model.SearchResults.Count);
        }
Exemple #2
0
        /// <summary>
        ///     Load Custom Nodes from the default directory - the "definitions"
        ///     directory where the executing assembly is located..
        /// </summary>
        /// <param name="bench">The logger is needed in order to tell how long it took.</param>
        public static void LoadCustomNodes(DynamoView bench, CustomNodeLoader customNodeLoader, SearchViewModel searchViewModel)
        {
            // custom node loader
            var sw = new Stopwatch();
            sw.Start();

            customNodeLoader.UpdateSearchPath();
            var nn = customNodeLoader.GetNodeNameCategoryAndGuidList();

            // add nodes to search
            foreach (var pair in nn)
            {
                searchViewModel.Add(pair.Item1, pair.Item2, pair.Item3);
            }

            sw.Stop();
            DynamoCommands.WriteToLogCmd.Execute(string.Format("{0} ellapsed for loading definitions.", sw.Elapsed));

            // update search view
            searchViewModel.SearchAndUpdateResultsSync(searchViewModel.SearchText);
        }
Exemple #3
0
        /// <summary>
        ///     Enumerate the types in an assembly and add them to DynamoController's
        ///     dictionaries and the search view model.  Internally catches exceptions and sends the error 
        ///     to the console.
        /// </summary>
        /// <param name="searchViewModel">The searchViewModel to which the nodes will be added</param>
        /// <param name="controller">The DynamoController, whose dictionaries will be modified</param>
        /// <param name="bench">The bench where logging errors will be sent</param>
        private static void LoadNodesFromAssembly(Assembly assembly, SearchViewModel searchViewModel, DynamoController controller)
        {
            try
            {
                Type[] loadedTypes = assembly.GetTypes();

                foreach (Type t in loadedTypes)
                {
                    try
                    {
                        //only load types that are in the right namespace, are not abstract
                        //and have the elementname attribute
                        object[] attribs = t.GetCustomAttributes(typeof (NodeNameAttribute), false);

                        if (IsNodeSubType(t) && attribs.Length > 0)
                        {
                            //if we are running in revit (or any context other than NONE) use the DoNotLoadOnPlatforms attribute,
                            //if available, to discern whether we should load this type
                            if (!controller.Context.Equals(Context.NONE))
                            {
                                object[] platformExclusionAttribs = t.GetCustomAttributes(typeof(DoNotLoadOnPlatformsAttribute), false);
                                if (platformExclusionAttribs.Length > 0)
                                {
                                    string[] exclusions = (platformExclusionAttribs[0] as DoNotLoadOnPlatformsAttribute).Values;
                                    if (exclusions.Contains(controller.Context))
                                        //if the attribute's values contain the context stored on the controller
                                        //then skip loading this type.
                                        continue;
                                }
                            }

                            searchViewModel.Add(t);
                            string typeName = (attribs[0] as NodeNameAttribute).Name;
                            var data = new TypeLoadData(assembly, t);

                            if (!controller.BuiltInTypesByNickname.ContainsKey(typeName))
                            {
                                controller.BuiltInTypesByNickname.Add(typeName, data);
                            }
                            else
                            {
                                dynSettings.Controller.DynamoViewModel.Log("Duplicate type encountered: " + typeName);
                            }

                            if (!controller.BuiltInTypesByName.ContainsKey(t.FullName))
                            {
                                controller.BuiltInTypesByName.Add(t.FullName, data);
                            }
                            else
                            {
                                dynSettings.Controller.DynamoViewModel.Log("Duplicate type encountered: " + typeName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        dynSettings.Controller.DynamoViewModel.Log("Failed to load type from " + assembly.FullName);
                        dynSettings.Controller.DynamoViewModel.Log("The type was " + t.FullName);
                        dynSettings.Controller.DynamoViewModel.Log(e);
                    }

                }
            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoViewModel.Log("Could not load types.");
                dynSettings.Controller.DynamoViewModel.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions = typeLoadException.LoaderExceptions;
                    dynSettings.Controller.DynamoViewModel.Log("Dll Load Exception: " + loaderExceptions[0]);
                    dynSettings.Controller.DynamoViewModel.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        dynSettings.Controller.DynamoViewModel.Log("Dll Load Exception: " + loaderExceptions[1]);
                        dynSettings.Controller.DynamoViewModel.Log(loaderExceptions[1].ToString());
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///     Enumerate the types in an assembly and add them to DynamoController's
        ///     dictionaries and the search view model.  Internally catches exceptions and sends the error 
        ///     to the console.
        /// </summary>
        /// <param name="searchViewModel">The searchViewModel to which the nodes will be added</param>
        /// <param name="controller">The DynamoController, whose dictionaries will be modified</param>
        /// <param name="bench">The bench where logging errors will be sent</param>
        private static void LoadNodesFromAssembly(Assembly assembly, SearchViewModel searchViewModel, DynamoController controller, dynBench bench )
        {
            try
            {
                Type[] loadedTypes = assembly.GetTypes();

                foreach (Type t in loadedTypes)
                {
                    //only load types that are in the right namespace, are not abstract
                    //and have the elementname attribute
                    object[] attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false);

                    if (IsNodeSubType(t) && attribs.Length > 0)
                    {
                        searchViewModel.Add(t);
                        string typeName = (attribs[0] as NodeNameAttribute).Name;
                        var data = new TypeLoadData(assembly, t);
                        controller.builtinTypesByNickname.Add(typeName, data);
                        controller.builtinTypesByTypeName.Add(t.FullName, data);
                    }
                }
            }
            catch (Exception e)
            {
                bench.Log("Could not load types.");
                bench.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions = typeLoadException.LoaderExceptions;
                    bench.Log("Dll Load Exception: " + loaderExceptions[0]);
                    bench.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        bench.Log("Dll Load Exception: " + loaderExceptions[1]);
                        bench.Log(loaderExceptions[1].ToString());
                    }
                }
            }
        }