Пример #1
0
        public int Run(string bounceDirectory, string workingDirectory, string [] rawArguments)
        {
            try {
                Directory.SetCurrentDirectory(workingDirectory);
                var parameters = ParsedArguments(rawArguments);
                Parameters.Main = new Parameters(parameters);

                var dependencyResolver = new AttributedDependencyResolvers();
                var tasks = Tasks(bounceDirectory, dependencyResolver);

                if (rawArguments.Length > 0) {
                    TaskRunner.RunTask(TaskName(rawArguments), parameters, tasks);
                } else {
                    UsageHelp.WriteUsage(Console.Out, tasks);
                }
                return 0;
            } catch (BounceException e) {
                e.Explain(Console.Error);
                return 1;
            } catch (ReflectionTypeLoadException e) {
                foreach (var loaderException in e.LoaderExceptions) {
                    Console.Error.WriteLine(loaderException);
                }
                return 1;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                return 1;
            }
        }
Пример #2
0
        private IEnumerable<ITask> Tasks(string bounceDirectory, AttributedDependencyResolvers dependencyResolvers)
        {
            IEnumerable<Type> allTypes = Directory.GetFiles(bounceDirectory)
                .Where(IsBounceExecutable)
                .SelectMany(file => {
                    try {
                        var assembly = Assembly.LoadFrom(file);
                        return assembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException tl) {
                        Console.Error.WriteLine("Could not load tasks from {0} - typeloader exeptions: {1}", file,
                            string.Join(Environment.NewLine,tl.LoaderExceptions.Select(e => e.ToString())));
                    }
                    catch (BadImageFormatException bi)
                    {
                        Console.Error.WriteLine("Could not load tasks from {0} {1}", file, bi);
                    }
                    return new Type[] {};
                });

            IEnumerable<MethodInfo> resolverMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static));
            IEnumerable<MethodInfo> resolvers = resolverMethods.Where(method => method.GetCustomAttributes(typeof(DependencyResolverAttribute), false).Length > 0);

            foreach (var resolver in resolvers) {
                dependencyResolvers.AddDependencyResolver(resolver);
            }

            IEnumerable<MethodInfo> taskMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance));
            IEnumerable<ITask> tasks = taskMethods.Where(method => method.GetCustomAttributes(typeof(TaskAttribute), false).Length > 0).Select(method => (ITask)new TaskMethod(method, dependencyResolvers));
            return tasks;
        }
Пример #3
0
        public int Run(string bounceDirectory, string [] rawArguments)
        {
            try {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(bounceDirectory));
                var parameters = ParsedArguments(rawArguments);
                Parameters.Main = new Parameters(parameters);

                var dependencyResolver = new AttributedDependencyResolvers();
                var tasks = Tasks(bounceDirectory, dependencyResolver);

                if (rawArguments.Length > 0)
                {
                    TaskRunner.RunTask(TaskName(rawArguments), parameters, tasks);
                }
                else
                {
                    UsageHelp.WriteUsage(Console.Out, tasks);
                }
                return(0);
            } catch (BounceException e) {
                e.Explain(Console.Error);
                return(1);
            } catch (ReflectionTypeLoadException e) {
                foreach (var loaderException in e.LoaderExceptions)
                {
                    Console.Error.WriteLine(loaderException);
                }
                return(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                return(1);
            }
        }
Пример #4
0
        private IEnumerable<ITask> Tasks(string bounceDirectory, AttributedDependencyResolvers dependencyResolvers)
        {
            IEnumerable<Type> allTypes = Directory.GetFiles(bounceDirectory).Where(IsBounceExecutable).SelectMany(file => {
                var assembly = Assembly.LoadFrom(file);
                return assembly.GetTypes();
            });

            IEnumerable<MethodInfo> resolverMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static));
            IEnumerable<MethodInfo> resolvers = resolverMethods.Where(method => method.GetCustomAttributes(typeof(DependencyResolverAttribute), false).Length > 0);

            foreach (var resolver in resolvers) {
                dependencyResolvers.AddDependencyResolver(resolver);
            }

            IEnumerable<MethodInfo> taskMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance));
            IEnumerable<ITask> tasks = taskMethods.Where(method => method.GetCustomAttributes(typeof(TaskAttribute), false).Length > 0).Select(method => (ITask)new TaskMethod(method, dependencyResolvers));
            return tasks;
        }
Пример #5
0
        private IEnumerable <ITask> Tasks(string bounceDirectory, AttributedDependencyResolvers dependencyResolvers)
        {
            IEnumerable <Type> allTypes = Directory.GetFiles(bounceDirectory).Where(IsBounceExecutable).SelectMany(file => {
                var assembly = Assembly.LoadFrom(file);
                return(assembly.GetTypes());
            });

            IEnumerable <MethodInfo> resolverMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static));
            IEnumerable <MethodInfo> resolvers       = resolverMethods.Where(method => method.GetCustomAttributes(typeof(DependencyResolverAttribute), false).Length > 0);

            foreach (var resolver in resolvers)
            {
                dependencyResolvers.AddDependencyResolver(resolver);
            }

            IEnumerable <MethodInfo> taskMethods = allTypes.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance));
            IEnumerable <ITask>      tasks       = taskMethods.Where(method => method.GetCustomAttributes(typeof(TaskAttribute), false).Length > 0).Select(method => (ITask) new TaskMethod(method, dependencyResolvers));

            return(tasks);
        }