Exemplo n.º 1
0
        private void AddElement_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.MenuItem mi = e.Source as System.Windows.Controls.MenuItem;

            TypeLoadData tld = builtinTypes[mi.Header.ToString()] as TypeLoadData;

            if (tld != null)
            {
                dynElement newEl = AddDynElement(tld.t, tld.assembly, mi.Header.ToString(), Guid.NewGuid(), 0.0, 0.0);
                if (newEl != null)
                {
                    newEl.CheckInputs();
                    return;
                }
            }

            tld = userTypes[mi.Header.ToString()] as TypeLoadData;
            if (tld != null)
            {
                dynElement newEl = AddDynElement(tld.t, tld.assembly, mi.Header.ToString(), Guid.NewGuid(), 0.0, 0.0);
                if (newEl != null)
                {
                    newEl.CheckInputs();
                    return;
                }
            }
        }
Exemplo n.º 2
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());
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void loadNodesFromAssembly(Assembly assembly)
        {
            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)
                    {
                        string typeName = (attribs[0] as NodeNameAttribute).Name;
                        var data = new TypeLoadData(assembly, t);
                        builtinTypesByNickname.Add(typeName, data);
                        builtinTypesByTypeName.Add(t.FullName, data);
                    }
                }
            }
            catch (Exception e)
            {
                Bench.Log("Could not load types.");
                Bench.Log(e);
                if (e is System.Reflection.ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    var loaderExceptions = typeLoadException.LoaderExceptions;
                    Bench.Log("Dll Load Exception: " + loaderExceptions[0].ToString());
                    Bench.Log(loaderExceptions[0].ToString());
                    Bench.Log("Dll Load Exception: " + loaderExceptions[1].ToString());
                    Bench.Log(loaderExceptions[1].ToString());
                }
            }
        }
Exemplo n.º 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>
        /// <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
                        {
                            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());
                    }
                }
            }

            return AssemblyPathToTypesLoaded[assembly.Location];
        }
Exemplo n.º 5
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());
                    }
                }
            }
        }