Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        public void TestCodeBlockNodeSearchNewNodeModel()
        {
            //Arrange
            var cbnData         = new TypeLoadData(typeof(CodeBlockNodeModel));
            var codeBlockSearch = new CodeBlockNodeSearchElement(cbnData, CurrentDynamoModel.LibraryServices);
            int initialCount    = CurrentDynamoModel.SearchModel.NumElements;

            CurrentDynamoModel.SearchModel.Add(codeBlockSearch);

            //Act
            //This will call the method CodeBlockNodeSearchElement.ConstructNewNodeModel()
            codeBlockSearch.ProduceNode();

            //Assert
            //Just validate that the new CodeBlockNodeSearchElement was added correctly
            Assert.AreEqual(initialCount + 1, CurrentDynamoModel.SearchModel.NumElements);
        }
Ejemplo n.º 4
0
        public void TestNodeModelSearchElement()
        {
            //Arrange
            var symbolData = new TypeLoadData(typeof(Symbol));

            //Act
            var symbolSearchElement = new NodeModelSearchElementDerived(symbolData)
            {
                IsVisibleInSearch = CurrentDynamoModel.CurrentWorkspace is CustomNodeWorkspaceModel
            };

            //Internally this will execute the ConstructNewNodeModel() through the NodeModelSearchElementDerived class
            var model = symbolSearchElement.NewModel();

            //Assert
            //We just check that the model was successfully created
            Assert.IsNotNull(model);
        }
 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;
 }
Ejemplo n.º 6
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].ToolTip);
            Assert.AreEqual("This is input2", node.InPorts[1].ToolTip);

            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));
        }
Ejemplo n.º 7
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].ToolTip);
            Assert.AreEqual("", node.OutPorts[1].ToolTip);

            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));
        }
 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  = new List <System.Tuple <string, string> >();
     outputParameters = new List <string>();
     iconName         = typeLoadData.Type.FullName;
     ElementType      = ElementTypes.ZeroTouch;
     if (typeLoadData.IsPackageMember)
     {
         ElementType |= ElementTypes.Packaged;
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     Adds a new type containing Migration methods into this manager.
 /// </summary>
 /// <param name="t">Type data to add</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;
     }
 }
Ejemplo n.º 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>
        /// <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>
        /// <Returns>The list of node types loaded from this assembly</Returns>
        public static List <Type> LoadNodesFromAssembly(Assembly assembly)
        {
            var controller      = dynSettings.Controller;
            var searchViewModel = dynSettings.Controller.SearchViewModel;

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

            try
            {
                Type[] 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
                        object[] attribs = t.GetCustomAttributes(typeof(NodeNameAttribute), false);

                        if (!IsNodeSubType(t)) /*&& 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;
                                int      iExclusion = exclusions.Length - 1;
                                for (; iExclusion > -1; iExclusion--)
                                {
                                    if (exclusions[iExclusion].Contains(controller.Context))
                                    {
                                        //if the attribute's values contain the context stored on the controller
                                        //then skip loading this type.
                                        break;
                                    }
                                }
                                if (iExclusion > -1)
                                {
                                    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(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                                    String       nameOfMethodCreate       = "noSkinSolidMethod";
                                    bool         exclude = true;
                                    foreach (MethodInfo m in specialTypeStaticMethods)
                                    {
                                        if (m.Name == nameOfMethodCreate)
                                        {
                                            object[] argsM = new object[0];
                                            exclude = (bool)m.Invoke(null, argsM);
                                            break;
                                        }
                                    }
                                    if (exclude)
                                    {
                                        continue;
                                    }
                                }
                            }
                        }

                        string typeName;

                        if (attribs.Length > 0)
                        {
                            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
                        {
                            DynamoLogger.Instance.Log("Duplicate type encountered: " + typeName);
                        }

                        if (!controller.BuiltInTypesByName.ContainsKey(t.FullName))
                        {
                            controller.BuiltInTypesByName.Add(t.FullName, data);
                        }
                        else
                        {
                            DynamoLogger.Instance.Log("Duplicate type encountered: " + typeName);
                        }
                    }
                    catch (Exception e)
                    {
                        DynamoLogger.Instance.Log("Failed to load type from " + assembly.FullName);
                        DynamoLogger.Instance.Log("The type was " + t.FullName);
                        DynamoLogger.Instance.Log(e);
                    }
                }
            }
            catch (Exception e)
            {
                DynamoLogger.Instance.Log("Could not load types.");
                DynamoLogger.Instance.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var         typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions  = typeLoadException.LoaderExceptions;
                    DynamoLogger.Instance.Log("Dll Load Exception: " + loaderExceptions[0]);
                    DynamoLogger.Instance.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        DynamoLogger.Instance.Log("Dll Load Exception: " + loaderExceptions[1]);
                        DynamoLogger.Instance.Log(loaderExceptions[1].ToString());
                    }
                }
            }

            return(AssemblyPathToTypesLoaded[assembly.Location]);
        }
        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].ToolTip);
            Assert.AreEqual("", node.OutPorts[1].ToolTip);

            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));
        }
        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].ToolTip);
            Assert.AreEqual("This is input2", node.InPorts[1].ToolTip);

            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));
        }
Ejemplo n.º 13
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]);
        }
Ejemplo n.º 14
0
        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 (!NodeModelAssemblyLoader.IsNodeSubType(t) &&
                        t.Namespace != "Dynamo.Graph.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(t);
                }
            }
            catch (Exception e)
            {
                DynamoViewModel.Model.Logger.Log("Could not load types.");
                DynamoViewModel.Model.Logger.Log(e);
            }

            return(types);
        }
Ejemplo n.º 15
0
 internal NodeModelSearchElementDerived(TypeLoadData typeLoadData) : base(typeLoadData)
 {
 }
Ejemplo n.º 16
0
        private void InitializeIncludedNodes()
        {
            var customNodeData = new TypeLoadData(typeof(Function));
            NodeFactory.AddLoader(new CustomNodeLoader(CustomNodeManager, IsTestMode));
            NodeFactory.AddAlsoKnownAs(customNodeData.Type, customNodeData.AlsoKnownAs);

            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);
        }
Ejemplo n.º 17
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 USE_DSENGINE
                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && isDSCompatible && !isHidden)
#else
                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && !isHidden)
#endif
                        {
                            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.Controller.DynamoLogger.Log("Duplicate type encountered: " + typeName);
                        }

                        if (!controller.BuiltInTypesByName.ContainsKey(t.FullName))
                        {
                            controller.BuiltInTypesByName.Add(t.FullName, data);
                        }
                        else
                        {
                            dynSettings.Controller.DynamoLogger.Log("Duplicate type encountered: " + typeName);
                        }
                    }
                    catch (Exception e)
                    {
                        dynSettings.Controller.DynamoLogger.Log("Failed to load type from " + assembly.FullName);
                        dynSettings.Controller.DynamoLogger.Log("The type was " + t.FullName);
                        dynSettings.Controller.DynamoLogger.Log(e);
                    }
                }
            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoLogger.Log("Could not load types.");
                dynSettings.Controller.DynamoLogger.Log(e);
                if (e is ReflectionTypeLoadException)
                {
                    var         typeLoadException = e as ReflectionTypeLoadException;
                    Exception[] loaderExceptions  = typeLoadException.LoaderExceptions;
                    dynSettings.Controller.DynamoLogger.Log("Dll Load Exception: " + loaderExceptions[0]);
                    dynSettings.Controller.DynamoLogger.Log(loaderExceptions[0].ToString());
                    if (loaderExceptions.Count() > 1)
                    {
                        dynSettings.Controller.DynamoLogger.Log("Dll Load Exception: " + loaderExceptions[1]);
                        dynSettings.Controller.DynamoLogger.Log(loaderExceptions[1].ToString());
                    }
                }
            }

            return(AssemblyPathToTypesLoaded[assembly.Location]);
        }
Ejemplo n.º 18
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 (!NodeModelAssemblyLoader.IsNodeSubType(t) && 
                        t.Namespace != "Dynamo.Graph.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(t);


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

            return types;
        }
 public CodeBlockNodeSearchElement(TypeLoadData data, LibraryServices manager)
     : base(data)
 {
     libraryServices = manager;
 }
Ejemplo n.º 21
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>
        /// <Returns>The list of node types loaded from this assembly</Returns>
        public static List<Type> LoadNodesFromAssembly(Assembly 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.Count() > 0)
                        {
                            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;
                                int iExclusion = exclusions.Length - 1;
                                for (; iExclusion > -1; iExclusion--)
                                {
                                    if (exclusions[iExclusion].Contains(controller.Context))
                                        //if the attribute's values contain the context stored on the controller
                                        //then skip loading this type.
                                        break;
                                }
                                if (iExclusion > -1)
                                    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(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                                    String nameOfMethodCreate = "noSkinSolidMethod";
                                    bool exclude = true;
                                    foreach (MethodInfo m in specialTypeStaticMethods)
                                    {
                                        if (m.Name == nameOfMethodCreate)
                                        {
                                            object[] argsM = new object[0];
                                            exclude = (bool)m.Invoke(null, argsM);
                                            break;
                                        }
                                    }
                                    if (exclude)
                                        continue;
                                }
                            }
                        }

                        string typeName;

            #if USE_DSENGINE
                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && isDSCompatible && !isHidden)
            #else
                        if (attribs.Length > 0 && !isDeprecated && !isMetaNode && !isHidden)
            #endif
                        {
                            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
                        {
                            DynamoLogger.Instance.Log("Duplicate type encountered: " + typeName);
                        }

                        if (!controller.BuiltInTypesByName.ContainsKey(t.FullName))
                        {
                            controller.BuiltInTypesByName.Add(t.FullName, data);
                        }
                        else
                        {
                            DynamoLogger.Instance.Log("Duplicate type encountered: " + typeName);
                        }

                    }
                    catch (Exception e)
                    {
                        DynamoLogger.Instance.Log("Failed to load type from " + assembly.FullName);
                        DynamoLogger.Instance.Log("The type was " + t.FullName);
                        DynamoLogger.Instance.Log(e);
                    }

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

            return AssemblyPathToTypesLoaded[assembly.Location];
        }
Ejemplo n.º 22
0
        private void AddNodeTypeToSearch(TypeLoadData typeLoadData)
        {
            if (!typeLoadData.IsDSCompatible || typeLoadData.IsDeprecated || typeLoadData.IsHidden
                || typeLoadData.IsMetaNode)
            {
                return;
            }

            SearchModel.Add(new NodeModelSearchElement(typeLoadData));
        }
Ejemplo n.º 23
0
 internal NodeModelSearchElement(TypeLoadData typeLoadData) : base(typeLoadData)
 {
     constructor = typeLoadData.Type.GetDefaultConstructor <NodeModel>();
 }
 internal NodeModelSearchElement(TypeLoadData typeLoadData) : base(typeLoadData)
 {
     constructor = typeLoadData.Type.GetDefaultConstructor<NodeModel>();
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NodeModelSearchElement"/> class.
 /// </summary>
 /// <param name="typeLoadData">Data to load.</param>
 internal NodeModelSearchElement(TypeLoadData typeLoadData) : base(typeLoadData)
 {
     constructor  = typeLoadData.Type.GetDefaultConstructor <NodeModel>();
     creationName = typeLoadData.Type.ToString();
 }