Beispiel #1
0
        /// <summary>
        /// Scans a given <see cref="Type" /> for tasks.
        /// </summary>
        /// <param name="extensionAssembly">The <see cref="ExtensionAssembly" /> containing the <see cref="Type" /> to scan.</param>
        /// <param name="type">The <see cref="Type" /> to scan.</param>
        /// <param name="task">The <see cref="Task" /> which will be used to output messages to the build log.</param>
        /// <returns>
        /// <see langword="true" /> if <paramref name="type" /> represents a
        /// <see cref="Task" />; otherwise, <see langword="false" />.
        /// </returns>
        private static bool ScanTypeForTasks(ExtensionAssembly extensionAssembly, Type type, Task task) {
            try {
                TaskNameAttribute taskNameAttribute = (TaskNameAttribute) 
                    Attribute.GetCustomAttribute(type, typeof(TaskNameAttribute));

                if (type.IsSubclassOf(typeof(Task)) && !type.IsAbstract && taskNameAttribute != null) {
                    task.Log(Level.Debug, string.Format(CultureInfo.InvariantCulture, 
                        ResourceUtils.GetString("String_CreatingTaskBuilder"), 
                        type.Name));

                    TaskBuilder tb = new TaskBuilder(extensionAssembly, type.FullName);
                    if (TaskBuilders[tb.TaskName] == null) {
                        task.Log(Level.Debug, string.Format(CultureInfo.InvariantCulture, 
                            ResourceUtils.GetString("String_AddingTask"), tb.TaskName, 
                            GetAssemblyLocation(tb.Assembly), tb.ClassName));

                        TaskBuilders.Add(tb);
                    }

                    // specified type represents a task
                    return true;
                } else {
                    // specified type does not represent valid task
                    return false;
                }
            } catch {
                task.Log(Level.Error, "Failure scanning \"{0}\" for tasks.", 
                    type.AssemblyQualifiedName);
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Scans a given <see cref="Type" /> for tasks.
        /// </summary>
        /// <param name="type">The <see cref="Type" /> to scan.</param>
        /// <param name="task">The <see cref="Task" /> which will be used to output messages to the build log.</param>
        /// <returns>
        /// <see langword="true" /> if <paramref name="type" /> represents a
        /// <see cref="Task" />; otherwise, <see langword="false" />.
        /// </returns>
        private static bool ScanTypeForTasks(Type type, Task task)
        {
            try {
                TaskNameAttribute taskNameAttribute = (TaskNameAttribute)
                                                      Attribute.GetCustomAttribute(type, typeof(TaskNameAttribute));

                if (type.IsSubclassOf(typeof(Task)) && !type.IsAbstract && taskNameAttribute != null)
                {
                    task.Log(Level.Debug, string.Format(CultureInfo.InvariantCulture,
                                                        ResourceUtils.GetString("String_CreatingTaskBuilder"),
                                                        type.Name));

                    TaskBuilder tb = new TaskBuilder(type.Assembly, type.FullName);
                    if (TaskBuilders[tb.TaskName] == null)
                    {
                        task.Log(Level.Debug, string.Format(CultureInfo.InvariantCulture,
                                                            ResourceUtils.GetString("String_AddingTask"), tb.TaskName,
                                                            GetAssemblyLocation(tb.Assembly), tb.ClassName));

                        TaskBuilders.Add(tb);
                        foreach (WeakReference wr in _projects)
                        {
                            if (!wr.IsAlive)
                            {
                                task.Log(Level.Debug, "WeakReference for project is dead.");
                                continue;
                            }
                            Project p = wr.Target as Project;
                            if (p == null)
                            {
                                task.Log(Level.Debug, "WeakReference is not a"
                                         + " project! This should not be possible.");
                                continue;
                            }
                            UpdateProjectWithBuilder(p, tb);
                        }
                    }

                    // specified type represents a task
                    return(true);
                }
                else
                {
                    // specified type does not represent valid task
                    return(false);
                }
            } catch {
                task.Log(Level.Error, "Failure scanning \"{0}\" for tasks.",
                         type.AssemblyQualifiedName);
                throw;
            }
        }