Пример #1
0
#pragma warning disable 28
        public static int Main(IDictionary<string, object> env)
        {
            bool requireFirstRunOnProjectUpgrade = false;
            bool inSystem = true;
            var serviceRegistry = new ServiceRegistry();
            serviceRegistry = serviceRegistry.Override<IEnvironment>(() =>
            {
                var cdenv = new CurrentDirectoryEnvironment(LocalFileSystem.Instance.GetDirectory(env.CurrentDirectory()))
                {
                    BeforeProjectRepositoryInitialized = (dir, options) =>
                    {
                        requireFirstRunOnProjectUpgrade = dir.GetFile("packages").Exists == false;
                        inSystem = false;
                    }
                };
                if (env.SysPath() != null)
                    cdenv.SystemRepositoryDirectory = LocalFileSystem.Instance.GetDirectory(new Path(env.SysPath()).Combine("wraps"));

                return cdenv;
            });

            if (env.ShellArgs().ContainsNoCase("UseSystem"))
            {
                
                serviceRegistry
                    .Override(() => new RuntimeAssemblyResolver
                    {
                        IgnoreProjectAssemblies = true
                    })
                    .Override<ICommandRepository>(() => new CommandRepository(
                                                            ServiceLocator.GetService<IPackageManager>().CommandExports(
                                                                ServiceLocator.GetService<IEnvironment>(), true)
                                                                .SelectMany(x => x)
                                                                .Select(x => x.Descriptor)));
            }
            var formatterType = env.Formatter();
            if (formatterType != null)
            {
                serviceRegistry.Override(() => (ICommandOutputFormatter)Activator.CreateInstance(Type.GetType(formatterType)));
            }
            serviceRegistry.Initialize();

            //if (requireFirstRunOnProjectUpgrade)
            //{
            //    ServiceLocator.GetService<ICommandOutputFormatter>().Render(
            //        new Warning("This is the first time you run a version of OpenWrap that supports post-install hooks on this project. Please wait while we run the hooks for the current packages."));

            //    serviceRegistry.Initialize();
            //}

            return new ConsoleCommandExecutor(ServiceLocator.GetService<IEnumerable<ICommandLocator>>(), ServiceLocator.GetService<IEventHub>(), ServiceLocator.GetService<ICommandOutputFormatter>())
                .Execute(env.CommandLine(), env.ShellArgs());
        }
Пример #2
0
#pragma warning disable 28
        public static int Main(IDictionary<string, object> env)
        {
            bool requireFirstRunOnProjectUpgrade = false;

            var serviceRegistry = new ServiceRegistry();
            serviceRegistry = serviceRegistry.Override<IEnvironment>(() =>
            {
                var cdenv = new CurrentDirectoryEnvironment(LocalFileSystem.Instance.GetDirectory(env.CurrentDirectory()))
                {
                    BeforeProjectRepositoryInitialized = (dir, options) =>
                    {
                        requireFirstRunOnProjectUpgrade = dir.GetFile("packages").Exists == false;
                    }
                };
                var systemRepositoryPath = env.SystemRepositoryPath();
                var systemRootPath = env.SystemRootPath();
                if (systemRootPath != null)
                    cdenv.SystemRepositoryDirectory = LocalFileSystem.Instance.GetDirectory(new Path(systemRepositoryPath).Combine("wraps"));
                if (systemRepositoryPath != null)
                    cdenv.SystemRepositoryDirectory = LocalFileSystem.Instance.GetDirectory(new Path(systemRepositoryPath));

                return cdenv;
            });

            if (env.ShellArgs().ContainsNoCase("UseSystem"))
            {
                
                serviceRegistry
                    .Override(() => new RuntimeAssemblyResolver
                    {
                        IgnoreProjectAssemblies = true
                    })
                    .Override<ICommandRepository>(() => new CommandRepository(
                                                            ServiceLocator.GetService<IPackageManager>().CommandExports(
                                                                ServiceLocator.GetService<IEnvironment>(), true)
                                                                .SelectMany(x => x)
                                                                .Select(x => x.Descriptor)));
            }
            var formatterType = env.Formatter();
            if (formatterType != null)
            {
                serviceRegistry.Override(() => (ICommandOutputFormatter)Activator.CreateInstance(Type.GetType(formatterType)));
            }
            serviceRegistry.Initialize();

            return new ConsoleCommandExecutor(ServiceLocator.GetService<IEnumerable<ICommandLocator>>(), ServiceLocator.GetService<IEventHub>(), ServiceLocator.GetService<ICommandOutputFormatter>())
                .Execute(env.CommandLine(), env.ShellArgs());
        }
Пример #3
0
        IEnumerable<ICommandOutput> SetEnvironmentToFromInput()
        {
            if (From != null)
            {
                var directory = _fileSystem.GetDirectory(From);
                if (directory.Exists == false)
                {
                    yield return new DirectoryNotFound(directory);
                    yield break;
                }
                var newEnv = new CurrentDirectoryEnvironment(directory);
                newEnv.Initialize();

                _environment = newEnv;
            }
        }
Пример #4
0
 ICommandOutput FromEnvironmentNotFound()
 {
     if (From != null)
     {
         var directory = _fileSystem.GetDirectory(From);
         if (directory.Exists == false)
             return new Error("Directory '{0}' not found.", From);
         var newEnv = new CurrentDirectoryEnvironment(directory);
         newEnv.Initialize();
         if (newEnv.ScopedDescriptors.Any() == false)
             return new Error("No descriptor found in directory '{0}'.", From);
         _environment = newEnv;
         //return new Info("Building package at '{0}'.", From);
     }
     return null;
 }
 private static IEnvironment GetEnvironment()
 {
     var environment = new CurrentDirectoryEnvironment();
     environment.Initialize();
     return environment;
 }
Пример #6
0
        public static int Main(IDictionary<string, object> env)
        {
            Services.ServiceLocator.TryRegisterService<IFileSystem>(() => LocalFileSystem.Instance);
            Services.ServiceLocator.TryRegisterService<IConfigurationManager>(
                    () => new DefaultConfigurationManager(Services.ServiceLocator.GetService<IFileSystem>().GetDirectory(DefaultInstallationPaths.ConfigurationDirectory)));
            Services.ServiceLocator.TryRegisterService<IEnvironment>(() =>
            {
                var cdenv = new CurrentDirectoryEnvironment(LocalFileSystem.Instance.GetDirectory(env.CurrentDirectory()));
                if (env.SysPath() != null)
                    cdenv.SystemRepositoryDirectory = LocalFileSystem.Instance.GetDirectory(new Path(env.SysPath()).Combine("wraps"));
                return cdenv;
            });
            Services.ServiceLocator.TryRegisterService<IPackageResolver>(() => new ExhaustiveResolver());
            Services.ServiceLocator.TryRegisterService<IPackageExporter>(() => new DefaultPackageExporter(new List<IExportProvider>()
            {
                    new DefaultAssemblyExporter(),
                    new CecilCommandExporter()
            }));
            Services.ServiceLocator.TryRegisterService<IPackageDeployer>(() => new DefaultPackageDeployer());
            Services.ServiceLocator.TryRegisterService<IPackageManager>(() => new DefaultPackageManager(
                                                                                Services.ServiceLocator.GetService<IPackageDeployer>(),
                                                                                Services.ServiceLocator.GetService<IPackageResolver>(),
                                                                                Services.ServiceLocator.GetService<IPackageExporter>()
                                                                                ));

            Services.ServiceLocator.RegisterService<ITaskManager>(new TaskManager());
            ServiceLocator.TryRegisterService<IAssemblyResolver>(() => new CecilStaticAssemblyResolver(ServiceLocator.GetService<IPackageManager>(), ServiceLocator.GetService<IEnvironment>()));

            var commands = Services.ServiceLocator.GetService<IPackageManager>().CommandExports(ServiceLocator.GetService<IEnvironment>());

            var commandRepository = new CommandRepository(commands.SelectMany(x=>x).Select(x=>x.Descriptor));
            Services.ServiceLocator.TryRegisterService<ICommandRepository>(() => commandRepository);

            Services.ServiceLocator.RegisterService(new RuntimeAssemblyResolver());
            return new ConsoleCommandExecutor(ServiceLocator.GetService<ICommandRepository>(),
                                       new List<ICommandLocator>
                                       {
                                               new NounVerbCommandLocator(commandRepository),
                                               new VerbNounCommandLocator(commandRepository),
                                               new DefaultVerbCommandLocator(commandRepository)
                                       }).Execute(env.CommandLine(), env.ShellArgs());
        }