protected NodeModelSearchElementBase(TypeLoadData typeLoadData)
 {
     Name = typeLoadData.Name;
     foreach (var aka in typeLoadData.AlsoKnownAs.Concat(typeLoadData.SearchKeys))
         SearchKeywords.Add(aka);
     FullCategoryName = typeLoadData.Category;
     Description = typeLoadData.Description;
     Assembly = typeLoadData.Assembly.Location;
     inputParameters = new List<System.Tuple<string, string>>();
     outputParameters = new List<string>();
     iconName = typeLoadData.Type.FullName;
     ElementType = ElementTypes.ZeroTouch;
     if(typeLoadData.IsPackageMember)
         ElementType |= ElementTypes.Packaged;
 }
 protected NodeModelSearchElementBase(TypeLoadData typeLoadData)
 {
     Name = typeLoadData.Name;
     foreach (var aka in typeLoadData.AlsoKnownAs.Concat(typeLoadData.SearchKeys))
     {
         SearchKeywords.Add(aka);
         // By default search tag has weight = 0.5
         keywordWeights.Add(0.5);
     }
     FullCategoryName = typeLoadData.Category;
     Description = typeLoadData.Description;
     Assembly = typeLoadData.Assembly.Location;
     inputParameters = typeLoadData.InputParameters.ToList();
     outputParameters = typeLoadData.OutputParameters.ToList();
     iconName = typeLoadData.Type.FullName;
     ElementType = ElementTypes.ZeroTouch;
     if(typeLoadData.IsPackageMember)
         ElementType |= ElementTypes.Packaged;
 }
Пример #3
0
        private void InitializeIncludedNodes()
        {
            NodeFactory.AddLoader(new CustomNodeLoader(CustomNodeManager, IsTestMode));

            var dsFuncData = new TypeLoadData(typeof(DSFunction));
            var dsVarArgFuncData = new TypeLoadData(typeof(DSVarArgFunction));
            var cbnData = new TypeLoadData(typeof(CodeBlockNodeModel));
            var dummyData = new TypeLoadData(typeof(DummyNode));
            var symbolData = new TypeLoadData(typeof(Symbol));
            var outputData = new TypeLoadData(typeof(Output));

            var ztLoader = new ZeroTouchNodeLoader(LibraryServices);
            NodeFactory.AddLoader(dsFuncData.Type, ztLoader);
            NodeFactory.AddAlsoKnownAs(dsFuncData.Type, dsFuncData.AlsoKnownAs);
            NodeFactory.AddLoader(dsVarArgFuncData.Type, ztLoader);
            NodeFactory.AddAlsoKnownAs(dsVarArgFuncData.Type, dsVarArgFuncData.AlsoKnownAs);

            var cbnLoader = new CodeBlockNodeLoader(LibraryServices);
            NodeFactory.AddLoader(cbnData.Type, cbnLoader);
            NodeFactory.AddFactory(cbnData.Type, cbnLoader);
            NodeFactory.AddAlsoKnownAs(cbnData.Type, cbnData.AlsoKnownAs);

            NodeFactory.AddTypeFactoryAndLoader(dummyData.Type);
            NodeFactory.AddAlsoKnownAs(dummyData.Type, dummyData.AlsoKnownAs);

            var inputLoader = new InputNodeLoader();
            NodeFactory.AddLoader(symbolData.Type, inputLoader);
            NodeFactory.AddFactory(symbolData.Type, inputLoader);
            NodeFactory.AddAlsoKnownAs(symbolData.Type, symbolData.AlsoKnownAs);

            NodeFactory.AddTypeFactoryAndLoader(outputData.Type);
            NodeFactory.AddAlsoKnownAs(outputData.Type, outputData.AlsoKnownAs);

            SearchModel.Add(new CodeBlockNodeSearchElement(cbnData, LibraryServices));

            var symbolSearchElement = new NodeModelSearchElement(symbolData)
            {
                IsVisibleInSearch = CurrentWorkspace is CustomNodeWorkspaceModel
            };
            var outputSearchElement = new NodeModelSearchElement(outputData)
            {
                IsVisibleInSearch = CurrentWorkspace is CustomNodeWorkspaceModel
            };

            WorkspaceHidden += _ =>
            {
                var isVisible = CurrentWorkspace is CustomNodeWorkspaceModel;
                symbolSearchElement.IsVisibleInSearch = isVisible;
                outputSearchElement.IsVisibleInSearch = isVisible;
            };

            SearchModel.Add(symbolSearchElement);
            SearchModel.Add(outputSearchElement);
        }
Пример #4
0
        private void AddNodeTypeToSearch(TypeLoadData typeLoadData)
        {
            if (!typeLoadData.IsDSCompatible || typeLoadData.IsDeprecated || typeLoadData.IsHidden
                || typeLoadData.IsMetaNode)
            {
                return;
            }

            SearchModel.Add(new NodeModelSearchElement(typeLoadData));
        }
Пример #5
0
 public CodeBlockNodeSearchElement(TypeLoadData data, LibraryServices manager)
     : base(data)
 {
     libraryServices = manager;
 }
        private List<Type> LoadNodesFromAssembly(Assembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            var searchViewModel = DynamoViewModel.Model.SearchModel;

            var types = new List<Type>();

            try
            {
                var loadedTypes = assembly.GetTypes();

                foreach (var t in loadedTypes)
                {
                    //only load types that are in the right namespace, are not abstract
                    //and have the elementname attribute
                    var attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false);
                    var isDeprecated = t.GetCustomAttributes(typeof(NodeDeprecatedAttribute), true).Any();
                    var isMetaNode = t.GetCustomAttributes(typeof(IsMetaNodeAttribute), false).Any();
                    var isDSCompatible = t.GetCustomAttributes(typeof(IsDesignScriptCompatibleAttribute), true).Any();

                    bool isHidden = false;
                    var attrs = t.GetCustomAttributes(typeof(IsVisibleInDynamoLibraryAttribute), true);
                    if (null != attrs && attrs.Any())
                    {
                        var isVisibleAttr = attrs[0] as IsVisibleInDynamoLibraryAttribute;
                        if (null != isVisibleAttr && isVisibleAttr.Visible == false)
                        {
                            isHidden = true;
                        }
                    }

                    if (!DynamoViewModel.Model.Loader.IsNodeSubType(t) && 
                        t.Namespace != "Dynamo.Nodes") /*&& attribs.Length > 0*/
                        continue;

                    //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 (!DynamoViewModel.Model.Context.Equals(Context.NONE))
                    {

                        object[] platformExclusionAttribs = 
                            t.GetCustomAttributes(typeof(DoNotLoadOnPlatformsAttribute), false);
                        if (platformExclusionAttribs.Length > 0)
                        {
                            string[] exclusions = 
                                (platformExclusionAttribs[0] as DoNotLoadOnPlatformsAttribute).Values;

                            //if the attribute's values contain the context stored on the controller
                            //then skip loading this type.

                            if (exclusions.Reverse().Any(e => e.Contains(DynamoViewModel.Model.Context)))
                                continue;

                            //utility was late for Vasari release, 
                            //but could be available with after-post RevitAPI.dll
                            if (t.Name.Equals("dynSkinCurveLoops"))
                            {
                                MethodInfo[] specialTypeStaticMethods = 
                                    t.GetMethods(BindingFlags.Static | BindingFlags.Public);
                                const string nameOfMethodCreate = "noSkinSolidMethod";
                                bool exclude = true;
                                foreach (MethodInfo m in specialTypeStaticMethods)
                                {
                                    if (m.Name == nameOfMethodCreate)
                                    {
                                        var argsM = new object[0];
                                        exclude = (bool)m.Invoke(null, argsM);
                                        break;
                                    }
                                }
                                if (exclude)
                                    continue;
                            }
                        }
                    }

                    string typeName;

                    if (attribs.Length > 0 && !isDeprecated && 
                        !isMetaNode && isDSCompatible && !isHidden)
                    {
                        searchViewModel.Add(t);
                        typeName = (attribs[0] as NodeNameAttribute).Name;
                    }
                    else
                        typeName = t.Name;

                    types.Add(t);

                    var data = new TypeLoadData(assembly, t);


                }
            }
            catch (Exception e)
            {
                DynamoViewModel.Model.Logger.Log("Could not load types.");
                DynamoViewModel.Model.Logger.Log(e);
            }

            return types;
        }
Пример #7
0
        private NodeModel GetNodeModelInstanceByNickName(string name)
        {
            TypeLoadData tld = dynamoModel.BuiltInTypesByNickname[name];

            return(this.GetNodeModelInstanceByType(tld.Type));
        }
Пример #8
0
 /// <summary>
 ///     Adds a new type containing Migration methods into this manager.
 /// </summary>
 /// <param name="t"></param>
 public void AddMigrationType(TypeLoadData t)
 {
     nodeMigrationLookup[t.Type.FullName] = t.Type;
     foreach (var aka in t.AlsoKnownAs)
     {
         if (nodeMigrationLookup.ContainsKey(aka))
             Log(string.Format(Properties.Resources.DuplicateMigrationTypeRegistered, aka), WarningLevel.Moderate);
         nodeMigrationLookup[aka] = t.Type;
     }
 }
Пример #9
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>
        /// <Returns>The list of node types loaded from this assembly</Returns>
        public static List<Type> LoadNodesFromAssembly(Assembly assembly)
        {
            if (assembly == null) 
                throw new ArgumentNullException("assembly");
            
            var controller = dynSettings.Controller;
            var searchViewModel = dynSettings.Controller.SearchViewModel;

            AssemblyPathToTypesLoaded.Add(assembly.Location, new List<Type>());

            try
            {
                var loadedTypes = assembly.GetTypes();
 
                foreach (var t in loadedTypes)
                {
                    try
                    {
                        //only load types that are in the right namespace, are not abstract
                        //and have the elementname attribute
                        var attribs = t.GetCustomAttributes(typeof (NodeNameAttribute), false);
                        var isDeprecated = t.GetCustomAttributes(typeof (NodeDeprecatedAttribute), true).Any();
                        var isMetaNode = t.GetCustomAttributes(typeof(IsMetaNodeAttribute), false).Any();
                        var isDSCompatible = t.GetCustomAttributes(typeof(IsDesignScriptCompatibleAttribute), true).Any();

                        bool isHidden = false;
                        var attrs = t.GetCustomAttributes(typeof(IsVisibleInDynamoLibraryAttribute), true);
                        if (null != attrs && attrs.Any())
                        {
                            var isVisibleAttr = attrs[0] as IsVisibleInDynamoLibraryAttribute;
                            if (null != isVisibleAttr && isVisibleAttr.Visible == false)
                            {
                                isHidden = true;
                            }
                        }

                        if (!IsNodeSubType(t) && t.Namespace != "Dynamo.Nodes") /*&& attribs.Length > 0*/
                            continue;

                        //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 the attribute's values contain the context stored on the controller
                                //then skip loading this type.

                                if (exclusions.Reverse().Any(e => e.Contains(controller.Context)))
                                    continue;

                                //utility was late for Vasari release, but could be available with after-post RevitAPI.dll
                                if (t.Name.Equals("dynSkinCurveLoops"))
                                {
                                    MethodInfo[] specialTypeStaticMethods = t.GetMethods(BindingFlags.Static | BindingFlags.Public);
                                    const string nameOfMethodCreate = "noSkinSolidMethod";
                                    bool exclude = true;
                                    foreach (MethodInfo m in specialTypeStaticMethods)
                                    {
                                        if (m.Name == nameOfMethodCreate)
                                        {
                                            var argsM = new object[0];
                                            exclude = (bool)m.Invoke(null, argsM);
                                            break;
                                        }
                                    }
                                    if (exclude)
                                        continue;
                                }
                            }
                        }

                        string typeName;

                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && isDSCompatible && !isHidden)
                        {
                            searchViewModel.Add(t);
                            typeName = (attribs[0] as NodeNameAttribute).Name;
                        }
                        else
                            typeName = t.Name;

                        AssemblyPathToTypesLoaded[assembly.Location].Add(t);

                        var data = new TypeLoadData(assembly, t);

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

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

                }
            }
            catch (Exception e)
            {
                dynSettings.DynamoLogger.Log("Could not load types.");
                dynSettings.DynamoLogger.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions = typeLoadException.LoaderExceptions;
                    dynSettings.DynamoLogger.Log("Dll Load Exception: " + loaderExceptions[0]);
                    dynSettings.DynamoLogger.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        dynSettings.DynamoLogger.Log("Dll Load Exception: " + loaderExceptions[1]);
                        dynSettings.DynamoLogger.Log(loaderExceptions[1].ToString());
                    }
                }
            }

            return AssemblyPathToTypesLoaded[assembly.Location];
        }
Пример #10
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>
        /// <Returns>The list of node types loaded from this assembly</Returns>
        public List<Type> LoadNodesFromAssembly(Assembly assembly)
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            var searchViewModel = dynamoModel.SearchModel;

            AssemblyPathToTypesLoaded.Add(assembly.Location, new List<Type>());

            try
            {
                var loadedTypes = assembly.GetTypes();

                foreach (var t in loadedTypes)
                {
                    try
                    {
                        //only load types that are in the right namespace, are not abstract
                        //and have the elementname attribute
                        var attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false);
                        var isDeprecated = t.GetCustomAttributes(typeof(NodeDeprecatedAttribute), true).Any();
                        var isMetaNode = t.GetCustomAttributes(typeof(IsMetaNodeAttribute), false).Any();
                        var isDSCompatible = t.GetCustomAttributes(typeof(IsDesignScriptCompatibleAttribute), true).Any();

                        bool isHidden = false;
                        var attrs = t.GetCustomAttributes(typeof(IsVisibleInDynamoLibraryAttribute), true);
                        if (null != attrs && attrs.Any())
                        {
                            var isVisibleAttr = attrs[0] as IsVisibleInDynamoLibraryAttribute;
                            if (null != isVisibleAttr && isVisibleAttr.Visible == false)
                            {
                                isHidden = true;
                            }
                        }

                        if (!IsNodeSubType(t) && t.Namespace != "Dynamo.Nodes") /*&& attribs.Length > 0*/
                            continue;

                        //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 (!dynamoModel.Context.Equals(Context.NONE))
                        {

                            object[] platformExclusionAttribs = t.GetCustomAttributes(typeof(DoNotLoadOnPlatformsAttribute), false);
                            if (platformExclusionAttribs.Length > 0)
                            {
                                string[] exclusions = (platformExclusionAttribs[0] as DoNotLoadOnPlatformsAttribute).Values;

                                //if the attribute's values contain the context stored on the Model
                                //then skip loading this type.
                                if (exclusions.Reverse().Any(e => e.Contains(dynamoModel.Context)))
                                    continue;
                            }
                        }

                        string typeName;

                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && isDSCompatible && !isHidden)
                        {
                            searchViewModel.Add(t);
                            typeName = (attribs[0] as NodeNameAttribute).Name;
                        }
                        else
                            typeName = t.Name;

                        AssemblyPathToTypesLoaded[assembly.Location].Add(t);

                        var data = new TypeLoadData(assembly, t);

                        if (!dynamoModel.BuiltInTypesByNickname.ContainsKey(typeName))
                            dynamoModel.BuiltInTypesByNickname.Add(typeName, data);
                        else
                            dynamoModel.Logger.Log("Duplicate type encountered: " + typeName);

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

                }
            }
            catch (Exception e)
            {
                dynamoModel.Logger.Log("Could not load types.");
                dynamoModel.Logger.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions = typeLoadException.LoaderExceptions;
                    dynamoModel.Logger.Log("Dll Load Exception: " + loaderExceptions[0]);
                    dynamoModel.Logger.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        dynamoModel.Logger.Log("Dll Load Exception: " + loaderExceptions[1]);
                        dynamoModel.Logger.Log(loaderExceptions[1].ToString());
                    }
                }
            }

            return AssemblyPathToTypesLoaded[assembly.Location];
        }
Пример #11
0
        public void TestNodeCanLoadOutputPortsFromAttributes()
        {
            var node = new DummyNodeModel();
            Assert.AreEqual(2, node.InPorts.Count);

            Assert.AreEqual("output1", node.OutPorts[0].PortName);
            Assert.AreEqual("output2", node.OutPorts[1].PortName);

            Assert.AreEqual("some description", node.OutPorts[0].ToolTipContent);
            Assert.AreEqual("", node.OutPorts[1].ToolTipContent);

            var typeLoadData = new TypeLoadData(node.GetType());
            Assert.AreEqual(2, typeLoadData.OutputParameters.Count());

            Assert.AreEqual("foo", typeLoadData.OutputParameters.ElementAt(0));
            Assert.AreEqual("bla", typeLoadData.OutputParameters.ElementAt(1));
        }
Пример #12
0
        public void TestNodeCanLoadInputPortsFromAttributes()
        {
            var node = new DummyNodeModel();
            Assert.AreEqual(2, node.InPorts.Count);

            Assert.AreEqual("input1", node.InPorts[0].PortName);
            Assert.AreEqual("input2", node.InPorts[1].PortName);

            Assert.AreEqual("This is input1", node.InPorts[0].ToolTipContent);
            Assert.AreEqual("This is input2", node.InPorts[1].ToolTipContent);

            var typeLoadData = new TypeLoadData(node.GetType());
            Assert.AreEqual(2, typeLoadData.InputParameters.Count());

            Assert.AreEqual(Tuple.Create("input1", "int"), typeLoadData.InputParameters.ElementAt(0));
            Assert.AreEqual(Tuple.Create("input2", "double"), typeLoadData.InputParameters.ElementAt(1));
        }
Пример #13
0
 public NodeModelSearchElement(TypeLoadData typeLoadData) : base(typeLoadData)
 {
     constructor = typeLoadData.Type.GetDefaultConstructor<NodeModel>();
 }