/// <summary> /// As we rely on search when generating markdown files and matching them with content from the DynamoDictionary /// we need to add all NodeModel nodes to the SearchModel. /// </summary> /// <param name="asm"></param> /// <param name="nodeModelType"></param> /// <param name="searchModel"></param> private static void AddNodeModelsToSearchModel(Assembly asm, NodeSearchModel searchModel) { System.Type[] typesInAsm = null; try { typesInAsm = asm.GetTypes(); } // see https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.gettypes?view=netframework-4.8#remarks catch (ReflectionTypeLoadException ex) { Program.VerboseControlLog(ex.Message); typesInAsm = ex.Types; } var nodeTypes = typesInAsm .Where(x => NodeModelAssemblyLoader.IsNodeSubType(x)) .Select(t => new TypeLoadData(t)) .Where(type => type != null && !type.IsDeprecated && !type.IsHidden) .ToList(); foreach (var type in nodeTypes) { Program.VerboseControlLog($"adding nodeModelSearchElement for {type.Category} {type.Name}"); searchModel.Add(new NodeModelSearchElement(type)); } }
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); }