Example #1
0
        public int Main(string[] args)
        {
            string application;
            string[] arguments;

            if (args.Length >= 1)
            {
                application = args[0];
                arguments = args.Skip(1).ToArray();
            }
            else
            {
                application = Directory.GetCurrentDirectory();
                arguments = args;
            }

            try
            {
                var host = new DefaultHost(application);
                using (_container.AddHost(host))
                {
                    return ExecuteMain(host, arguments);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(String.Join(Environment.NewLine, GetExceptions(ex)));
                return -2;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            QueueUtil.PrepareQueue("customer");

            var host = new DefaultHost();
            host.Start<CustomerBootStrapper>();

            Console.WriteLine("Ayende is visiting Starbucks ...");
            Console.WriteLine("Hit enter for buying a hot chocolate ...");

            //Give the other services a bit air to initialize.
            Console.ReadLine();

            var bus = host.Bus as IServiceBus;

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Starbucks Lover",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E12.Client", QueueType.Standard);

            var host = new DefaultHost();
            host.Start<ClientBootStrapper>();

            var bus = host.Bus as IServiceBus;

            Console.WriteLine("Hit enter to send message");
            Console.ReadLine();

            var message = GetMessageWithLargeCollection();

            try
            {
                bus.Send(message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.ReadLine();
        }
Example #4
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB_E9_Customer", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB_E9_Cashier", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB_E9_Barista", QueueType.Standard);

            var customerHost = new DefaultHost();

            customerHost.Start<CustomerBootStrapper>();

            Console.WriteLine("Customer was started");
            Console.WriteLine("Waiting for order");
            Console.ReadLine();

            var bus = customerHost.Bus as IServiceBus;

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
Example #5
0
        private static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
                                                          HandleException((Exception) args.ExceptionObject);

            var host = new DefaultHost();
            host.Start<BootStrapper>();

            var bus = (IServiceBus) host.Bus;

            while (true)
            {
                Console.WriteLine("Write a message.");
                var message = Console.ReadLine();

                for (int i = 0; i < NumberOfMessages; i++)
                {
                    bus.Send(new HelloWorldMessage
                        {
                            Content = message
                        });
                }

                Console.WriteLine("Message '{0}' sent {1} times.", message, NumberOfMessages);
            }
        }
Example #6
0
        public static void Main()
        {
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista");
            PrepareQueues.Prepare("msmq://localhost/starbucks.cashier");
            PrepareQueues.Prepare("msmq://localhost/starbucks.customer");

            var cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            cashier.Start();

            Console.WriteLine("Cashier is started");

            var barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            barista.Start();

            Console.WriteLine("Barista is started");

            var customerHost = new DefaultHost();
            customerHost.Start<CustomerBootStrapper>();

            var bus = customerHost.Container.Resolve<IServiceBus>();

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
		public static void Main()
		{
			PrepareQueues.Prepare("msmq://localhost/TicTakToe.Backend", QueueType.Standard);
			var host = new DefaultHost();
			host.Start<BootStrapper>();

			var forms = new Form1();
			forms.ShowDialog();
		}
Example #8
0
        static void Main(string[] args)
        {
            var host = new DefaultHost();
            host.Start<Client2BootStrapper>();

            Console.WriteLine("Client2: Waiting for message . . . ");

            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E5.Cashier", QueueType.Standard);

            var host = new DefaultHost();
            host.Start<CashierBootStrapper>();

            Console.WriteLine("Cashier: Waiting for message . . . ");

            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            QueueUtil.PrepareQueue("backend");

            Console.WriteLine("Starting to listen for incoming messages ...");

            var host = new DefaultHost();
            host.Start<BackendBootStrapper>();

            Console.ReadLine();
        }
Example #11
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E5.Barista", QueueType.Standard);

            Console.WriteLine("Barista: Ready for drink preparation ...");

            var host = new DefaultHost();
            host.Start<BaristaBootStrapper>();

            Console.ReadLine();
        }
Example #12
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E12.Backend", QueueType.Standard);

            Console.WriteLine("Starting to listen for incoming messages ...");

            var host = new DefaultHost();
            host.Start<BackendBootStrapper>();

            Console.ReadLine(); ;
        }
Example #13
0
        static void Main(string[] args)
        {
            QueueUtil.PrepareQueue("cashier");

            var host = new DefaultHost();
            host.Start<CashierBootStrapper>();

            Console.WriteLine("Cashier: Waiting for message . . . ");

            Console.ReadLine();
        }
        public void Endpoint_queue_is_created_on_start()
        {
            var host = new DefaultHost();
            host.BusConfiguration( config => config.Bus( EndpointUri ) );

            host.Start<AutofacTestBootStrapper>();
            host.Dispose();

            var endpointQueue = MsmqUtil.GetQueuePath( _endpoint );
            Assert.True( endpointQueue.Exists );
        }
        static void Main(string[] args)
        {
            ConfigureQueues.Prepare("msmq://localhost/pruebas.consola.consumidor", QueueType.Standard);

            Console.WriteLine("Esperando los mensajes entrantes...");

            var host = new DefaultHost();

            host.Start<ConsumerBootStrapper>();

            Console.ReadLine();
        }
Example #16
0
        public IntegrationTest()
        {
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista.balancer", QueueType.LoadBalancer);
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista.balancer.acceptingwork", QueueType.Raw);
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.cashier", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.customer", QueueType.Standard);

            baristaLoadBalancer = new RemoteAppDomainHost(typeof (CastleLoadBalancerBootStrapper).Assembly, "BaristaLoadBalancer.config");
            cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            customerHost = new DefaultHost();
        }
Example #17
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            QueueUtil.PrepareQueue("backend");

            Console.WriteLine("Starting to listen for incoming messages ... (enter to quit)");

            var host = new DefaultHost();
            host.Start<BackendBootStrapper>();

            _bus = (IServiceBus) host.Bus;

            Console.ReadLine();
        }
Example #18
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            XmlConfigurator.Configure();

            QueueUtil.PrepareQueue("client");

            var host = new DefaultHost();
            host.Start<ClientBootStrapper>();

            ServiceLocator.Bus = (IServiceBus) host.Bus;
            ServiceLocator.ReadModel = new MongoReadModelFacade();
        }
Example #19
0
        static void Main()
        {
            QueueUtil.PrepareQueue("winclient1");

            var host = new DefaultHost();
            host.BusConfiguration(c => c.Threads(1)
                                        .Retries(5)
                                        .Bus("rhino.queues://localhost:50002/WinClient1","winClient1")
                                        .Receive("Common", "rhino.queues://localhost:50001/RhinoEsbTest"));
            host.Start<ClientBootStrapper>();

            var bus = host.Bus as IServiceBus;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(bus));
        }
Example #20
0
        private static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
                                                          HandleException((Exception) args.ExceptionObject);

            var host = new DefaultHost();
            host.Start<BootStrapper>();

            var bus = (IServiceBus) host.Bus;

            Console.WriteLine("Press enter to place order.");
            Console.ReadLine();

            Guid correlationId = Guid.NewGuid();
            bus.Send(new NewOrder
                {
                    OrderNumber = "1",
                    Customer = "Erik",
                    Articles = new List<string> {"1001", "1002", "1003"},
                    Amount = 1337,
                    CorrelationId = correlationId
                });

            Console.WriteLine("Pay $1337? y/n");
            var input = Console.ReadLine() ?? "";

            if (input.Equals("y"))
            {
                bus.Send(new PaymentCompleted
                    {
                        Reference = "1234567890",
                        CorrelationId = correlationId
                    });

                Console.WriteLine("Order receipt...");
            }
            else
            {
                bus.Send(new PaymentFailed
                    {
                        CorrelationId = correlationId
                    });
            }

            Console.ReadLine();
        }
Example #21
0
        public static void Main()
        {
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista.balancer", QueueType.LoadBalancer);
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista.balancer.acceptingwork", QueueType.LoadBalancer);
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.cashier", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.customer", QueueType.Standard);

            var baristaLoadBalancer = new RemoteAppDomainHost(typeof(SpringBootStrapper).Assembly, "BaristaLoadBalancer.config");
            baristaLoadBalancer.Start();

            Console.WriteLine("Barista load balancer has started");

            var cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            cashier.Start();

            Console.WriteLine("Cashier has started");

            var barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            barista.Start();

            Console.WriteLine("Barista has started");

            var customerHost = new DefaultHost();

            customerHost.BusConfiguration(c => c.Bus("msmq://localhost/starbucks.customer")
                .Receive("Starbucks.Messages.Cashier", "msmq://localhost/starbucks.cashier")
                .Receive("Starbucks.Messages.Barista", "msmq://localhost/starbucks.barista.balancer"));
            customerHost.Start<CustomerBootStrapper>();

            var bus = (IServiceBus)customerHost.Bus;

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
Example #22
0
        public void Can_by_coffee_from_starbucks()
        {
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista.balancer", QueueType.LoadBalancer);
            PrepareQueues.Prepare("msmq://localhost/starbucks.barista", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.cashier", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/starbucks.customer", QueueType.Standard);

            var baristaLoadBalancer = new RemoteAppDomainLoadBalancerHost(typeof (RemoteAppDomainHost).Assembly, "LoadBalancer.config");
            baristaLoadBalancer.Start();

            Console.WriteLine("Barista load balancer has started");

            var cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            cashier.Start();

            Console.WriteLine("Cashier has started");

            var barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            barista.Start();

            Console.WriteLine("Barista has started");

            var customerHost = new DefaultHost();
            customerHost.Start<CustomerBootStrapper>();

            var bus = customerHost.Container.Resolve<IServiceBus>();

            var userInterface = new MockCustomerUserInterface();
            var customer = new CustomerController(bus)
            {
                CustomerUserInterface = userInterface,
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            cashier.Close();
            barista.Close();

            Assert.Equal("Ayende", userInterface.CoffeeRushName);
        }
Example #23
0
        static void Main(string[] args)
        {
            QueueUtil.PrepareQueue("client");

            var host = new DefaultHost();
            host.Start<ClientBootStrapper>();

            Console.WriteLine("Client 1: Hit enter to send message");
            Console.ReadLine();

            var bus = host.Bus as IServiceBus;

            bus.Send(new HelloWorldMessage
            {
                Content = "Hello World!!!"
            });

            Console.ReadLine();
        }
Example #24
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E1.Client", QueueType.Standard);

            var host = new DefaultHost();
            host.Start<ClientBootStrapper>();

            var bus = host.Bus as IServiceBus;

            Console.WriteLine("Hit enter to send message");
            Console.ReadLine();

            bus.Send(new HelloWorldMessage
            {
                Content = "Hello World!!!"
            });

            Console.ReadLine();
        }
Example #25
0
        static void Main(string[] args)
        {
            QueueUtil.PrepareQueue("cashier");
            QueueUtil.PrepareQueue("barista");
            QueueUtil.PrepareQueue("customer");

            var cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            cashier.Start();

            Console.WriteLine("Cashier has started");

            var barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            barista.Start();

            Console.WriteLine("Barista has started");

            var customerHost = new DefaultHost();

            customerHost.BusConfiguration(c =>
            {
                c.Bus("rhino.queues://localhost:53000/LearningRhinoESB_E8_Customer", "customer");
                c.Receive("Messages.Cashier", "rhino.queues://localhost:52000/LearningRhinoESB_E8_Cashier");
                c.Receive("Messages.Barista", "rhino.queues://localhost:51000/LearningRhinoESB_E8_Barista");
                return c;
            });

            customerHost.Start<CustomerBootStrapper>();

            var bus = customerHost.Bus as IServiceBus;

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            ConfigureQueues.Prepare("msmq://localhost/prueba.consola.productor", QueueType.Standard);

            var host = new DefaultHost();
            host.Start<ProductorBootStrapper>();

            var bus = host.Bus as IServiceBus;

            Console.WriteLine("Enter para enviar el mensaje");
            Console.ReadLine();

            bus.Send(new HelloMessage
            {
                Mensaje = "Hola desde el consumidor"
            });

            Console.ReadLine();
            Console.ReadLine();
        }
Example #27
0
        static void Main(string[] args)
        {
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E7.Barista", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E7.Cashier", QueueType.Standard);
            PrepareQueues.Prepare("msmq://localhost/LearningRhinoESB.E7.Customer", QueueType.Standard);

            var cashier = new RemoteAppDomainHost(typeof(CashierBootStrapper))
                .Configuration("Cashier.config");
            cashier.Start();

            Console.WriteLine("Cashier has started");

            var barista = new RemoteAppDomainHost(typeof(BaristaBootStrapper))
                .Configuration("Barista.config");
            barista.Start();

            Console.WriteLine("Barista has started");

            var customerHost = new DefaultHost();
            customerHost.BusConfiguration(c => c.Bus("msmq://localhost/LearningRhinoESB.E7.Customer")
                .Receive("Messages.Cashier", "msmq://localhost/LearningRhinoESB.E7.Cashier")
                .Receive("Messages.Barista", "msmq://localhost/LearningRhinoESB.E7.Barista"));
            customerHost.Start<CustomerBootStrapper>();

            var bus = customerHost.Bus as IServiceBus;

            var customer = new CustomerController(bus)
            {
                Drink = "Hot Chocolate",
                Name = "Ayende",
                Size = DrinkSize.Venti
            };

            customer.BuyDrinkSync();

            Console.ReadLine();
        }
Example #28
0
 public static void Shutdown()
 {
     DefaultHost.ShutdownHost();
     SearchHost.ShutdownHost();
     DevHost.ShutdownHost();
 }
Example #29
0
 public AppLoaderWrapper(DefaultHost host)
 {
     _host = host;
 }
Example #30
0
        public void RunServer(StartOptions options)
        {
            if (options == null)
            {
                return;
            }

            // get existing loader factory services
            string appLoaderFactories;
            if (!options.Settings.TryGetValue(typeof(IAppLoaderFactory).FullName, out appLoaderFactories) ||
                !string.IsNullOrEmpty(appLoaderFactories))
            {
                // use the built-in AppLoaderFactory as the default
                appLoaderFactories = typeof(AppLoaderFactory).AssemblyQualifiedName;
            }

            // prepend with our app loader factory
            options.Settings[typeof(IAppLoaderFactory).FullName] =
                typeof(AppLoaderWrapper).AssemblyQualifiedName + ";" + appLoaderFactories;

            DefaultHost host = null;

            if (options.Settings.ContainsKey("devMode"))
            {
                host = new DefaultHost(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, watchFiles: true);

                host.OnChanged += () =>
                {
                    Environment.Exit(250);
                };
            }
            else
            {
                host = new DefaultHost(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
            }

            using (_hostContainer.AddHost(host))
            {
                WriteLine("Starting with " + GetDisplayUrl(options));

                // Ensure the DefaultHost is available to the AppLoaderWrapper
                IServiceProvider container = ServicesFactory.Create(options.Settings, services =>
                {
                    services.Add(typeof(ITraceOutputFactory), () => new NoopTraceOutputFactory());
                    services.Add(typeof(DefaultHost), () => host);
                });

                IHostingStarter starter = container.GetService<IHostingStarter>();
                using (starter.Start(options))
                {
                    WriteLine("Started successfully");

                    WriteLine("Press Enter to exit");
                    Console.ReadLine();

                    WriteLine("Terminating.");
                }
            }
        }
Example #31
0
        public bool Build()
        {
            Runtime.Project project;
            if (!Runtime.Project.TryGetProject(_buildOptions.ProjectDir, out project))
            {
                WriteError(string.Format("Unable to locate {0}.'", Runtime.Project.ProjectFileName));
                return(false);
            }

            var sw = Stopwatch.StartNew();

            var baseOutputPath = GetBuildOutputDir(_buildOptions);
            var configurations = _buildOptions.Configurations.DefaultIfEmpty("Debug");

            var specifiedFrameworks = _buildOptions.TargetFrameworks
                                      .ToDictionary(f => f, Runtime.Project.ParseFrameworkName);

            var projectFrameworks = new HashSet <FrameworkName>(
                project.GetTargetFrameworks()
                .Select(c => c.FrameworkName));

            IEnumerable <FrameworkName> frameworks = null;

            if (projectFrameworks.Count > 0)
            {
                // Specified target frameworks have to be a subset of
                // the project frameworks
                if (!ValidateFrameworks(projectFrameworks, specifiedFrameworks))
                {
                    return(false);
                }

                frameworks = specifiedFrameworks.Count > 0 ? specifiedFrameworks.Values : (IEnumerable <FrameworkName>)projectFrameworks;
            }
            else
            {
                frameworks = new[] { _applicationEnvironment.RuntimeFramework };
            }

            ScriptExecutor.Execute(project, "prebuild", GetScriptVariable);

            var success = true;

            var allErrors   = new List <string>();
            var allWarnings = new List <string>();

            // Initialize the default host so that we can load custom project export
            // providers from nuget packages/projects
            var host = new DefaultHost(new DefaultHostOptions()
            {
                ApplicationBaseDirectory = project.ProjectDirectory,
                TargetFramework          = _applicationEnvironment.RuntimeFramework,
                Configuration            = _applicationEnvironment.Configuration
            },
                                       _hostServices);

            host.Initialize();

            var cacheContextAccessor = new CacheContextAccessor();
            var cache = new Cache(cacheContextAccessor);

            using (host.AddLoaders(_loaderContainer))
            {
                // Build all specified configurations
                foreach (var configuration in configurations)
                {
                    // Create a new builder per configuration
                    var packageBuilder       = new PackageBuilder();
                    var symbolPackageBuilder = new PackageBuilder();

                    InitializeBuilder(project, packageBuilder);
                    InitializeBuilder(project, symbolPackageBuilder);

                    var configurationSuccess = true;

                    baseOutputPath = Path.Combine(baseOutputPath, configuration);

                    // Build all target frameworks a project supports
                    foreach (var targetFramework in frameworks)
                    {
                        _buildOptions.Reports.Information.WriteLine();
                        _buildOptions.Reports.Information.WriteLine("Building {0} for {1}",
                                                                    project.Name, targetFramework.ToString().Yellow().Bold());

                        var errors   = new List <string>();
                        var warnings = new List <string>();

                        var context = new BuildContext(cache,
                                                       cacheContextAccessor,
                                                       project,
                                                       targetFramework,
                                                       configuration,
                                                       baseOutputPath);
                        context.Initialize(_buildOptions.Reports.Quiet);

                        if (context.Build(warnings, errors))
                        {
                            context.PopulateDependencies(packageBuilder);
                            context.AddLibs(packageBuilder, "*.dll");
                            context.AddLibs(packageBuilder, "*.xml");
                            context.AddLibs(symbolPackageBuilder, "*.*");
                        }
                        else
                        {
                            configurationSuccess = false;
                        }

                        allErrors.AddRange(errors);
                        allWarnings.AddRange(warnings);

                        WriteDiagnostics(warnings, errors);
                    }

                    success = success && configurationSuccess;

                    // Create a package per configuration
                    string nupkg        = GetPackagePath(project, baseOutputPath);
                    string symbolsNupkg = GetPackagePath(project, baseOutputPath, symbols: true);

                    if (configurationSuccess)
                    {
                        foreach (var sharedFile in project.SharedFiles)
                        {
                            var file = new PhysicalPackageFile();
                            file.SourcePath = sharedFile;
                            file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile));
                            packageBuilder.Files.Add(file);
                        }

                        var root = project.ProjectDirectory;

                        foreach (var path in project.SourceFiles)
                        {
                            var srcFile = new PhysicalPackageFile();
                            srcFile.SourcePath = path;
                            srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path));
                            symbolPackageBuilder.Files.Add(srcFile);
                        }

                        using (var fs = File.Create(nupkg))
                        {
                            packageBuilder.Save(fs);
                            _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, nupkg);
                        }

                        if (symbolPackageBuilder.Files.Any())
                        {
                            using (var fs = File.Create(symbolsNupkg))
                            {
                                symbolPackageBuilder.Save(fs);
                            }

                            _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", project.Name, symbolsNupkg);
                        }
                    }
                }
            }

            ScriptExecutor.Execute(project, "postbuild", GetScriptVariable);

            sw.Stop();

            WriteSummary(allWarnings, allErrors);

            _buildOptions.Reports.Information.WriteLine("Time elapsed {0}", sw.Elapsed);
            return(success);
        }
Example #32
0
        public Task <int> Main(string[] args)
        {
            DefaultHostOptions options;

            string[] programArgs;

            var isShowingInformation = ParseArgs(args, out options, out programArgs);

            if (isShowingInformation)
            {
                return(Task.FromResult(0));
            }

            var host = new DefaultHost(options, _serviceProvider);

            if (host.Project == null)
            {
                return(Task.FromResult(-1));
            }

            var    lookupCommand = string.IsNullOrEmpty(options.ApplicationName) ? "run" : options.ApplicationName;
            string replacementCommand;

            if (host.Project.Commands.TryGetValue(lookupCommand, out replacementCommand))
            {
                var replacementArgs = CommandGrammar.Process(
                    replacementCommand,
                    GetVariable).ToArray();
                options.ApplicationName = replacementArgs.First();
                programArgs             = replacementArgs.Skip(1).Concat(programArgs).ToArray();
            }

            if (string.IsNullOrEmpty(options.ApplicationName) ||
                string.Equals(options.ApplicationName, "run", StringComparison.Ordinal))
            {
                if (string.IsNullOrEmpty(host.Project.Name))
                {
                    options.ApplicationName = Path.GetFileName(options.ApplicationBaseDirectory);
                }
                else
                {
                    options.ApplicationName = host.Project.Name;
                }
            }

            IDisposable disposable = null;

            try
            {
                disposable = host.AddLoaders(_container);

                return(ExecuteMain(host, options.ApplicationName, programArgs)
                       .ContinueWith(async(t, state) =>
                {
                    ((IDisposable)state).Dispose();
                    return await t;
                },
                                     disposable).Unwrap());
            }
            catch
            {
                // If there's an error, dispose the host and throw
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                throw;
            }
        }
Example #33
0
        public Task <int> Main(string[] args)
        {
            DefaultHostOptions options;

            string[] programArgs;
            int      exitCode;

            bool shouldExit = ParseArgs(args, out options, out programArgs, out exitCode);

            if (shouldExit)
            {
                return(Task.FromResult(exitCode));
            }

            var host = new DefaultHost(options, _serviceProvider);

            if (host.Project == null)
            {
                return(Task.FromResult(-1));
            }

            var    lookupCommand = string.IsNullOrEmpty(options.ApplicationName) ? "run" : options.ApplicationName;
            string replacementCommand;

            if (host.Project.Commands.TryGetValue(lookupCommand, out replacementCommand))
            {
                // preserveSurroundingQuotes: false to imitate a shell. Shells remove quotation marks before calling
                // Main methods. Here however we are invoking Main() without involving a shell.
                var replacementArgs = CommandGrammar
                                      .Process(replacementCommand, GetVariable, preserveSurroundingQuotes: false)
                                      .ToArray();
                options.ApplicationName = replacementArgs.First();
                programArgs             = replacementArgs.Skip(1).Concat(programArgs).ToArray();
            }

            if (string.IsNullOrEmpty(options.ApplicationName) ||
                string.Equals(options.ApplicationName, "run", StringComparison.Ordinal))
            {
                options.ApplicationName = host.Project.EntryPoint ?? host.Project.Name;
            }

            IDisposable disposable = null;

            try
            {
                disposable = host.AddLoaders(_container);

                return(ExecuteMain(host, options.ApplicationName, programArgs)
                       .ContinueWith(async(t, state) =>
                {
                    ((IDisposable)state).Dispose();
                    return await t;
                },
                                     disposable).Unwrap());
            }
            catch
            {
                // If there's an error, dispose the host and throw
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                throw;
            }
        }
        /// <summary>
        /// Creates a runspace using host of type <see cref="DefaultHost"/>.
        /// </summary>
        /// <returns>
        /// A runspace object.
        /// </returns>
        public static Runspace CreateRunspace()
        {
            PSHost host = new DefaultHost(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);

            return(CreateRunspace(host));
        }
Example #35
0
        private Task<int> ExecuteMain(DefaultHost host, string applicationName, string[] args)
        {
            Assembly assembly = null;

            try
            {
                assembly = host.GetEntryPoint(applicationName);
            }
            catch (FileNotFoundException ex) when (new AssemblyName(ex.FileName).Name == applicationName)
            {
                if (ex.InnerException is ICompilationException)
                {
                    throw ex.InnerException;
                }

                ThrowEntryPointNotfoundException(
                        host,
                        applicationName,
                        ex.InnerException);
            }

            if (assembly == null)
            {
                return Task.FromResult(-1);
            }

            return EntryPointExecutor.Execute(assembly, args, host.ServiceProvider);
        }
Example #36
0
        public Task<int> Main(string[] args)
        {
            RuntimeOptions options;
            string[] programArgs;
            int exitCode;

            bool shouldExit = ParseArgs(args, out options, out programArgs, out exitCode);
            if (shouldExit)
            {
                return Task.FromResult(exitCode);
            }

            IFileWatcher watcher;
            if (options.WatchFiles)
            {
                watcher = new FileWatcher(Runtime.ProjectResolver.ResolveRootDirectory(Path.GetFullPath(options.ApplicationBaseDirectory)));
            }
            else
            {
                watcher = NoopWatcher.Instance;
            }

            var host = new DefaultHost(options, _serviceProvider, _loadContextAccessor, watcher, new CompilationEngineFactory(new CompilationCache()));

            if (host.Project == null)
            {
                return Task.FromResult(-1);
            }

            var lookupCommand = string.IsNullOrEmpty(options.ApplicationName) ? "run" : options.ApplicationName;
            string replacementCommand;
            if (host.Project.Commands.TryGetValue(lookupCommand, out replacementCommand))
            {
                // preserveSurroundingQuotes: false to imitate a shell. Shells remove quotation marks before calling
                // Main methods. Here however we are invoking Main() without involving a shell.
                var replacementArgs = CommandGrammar
                    .Process(replacementCommand, GetVariable, preserveSurroundingQuotes: false)
                    .ToArray();
                options.ApplicationName = replacementArgs.First();
                programArgs = replacementArgs.Skip(1).Concat(programArgs).ToArray();
            }

            if (string.IsNullOrEmpty(options.ApplicationName) ||
                string.Equals(options.ApplicationName, "run", StringComparison.Ordinal))
            {
                options.ApplicationName = host.Project.EntryPoint ?? host.Project.Name;
            }

            IDisposable disposable = null;

            try
            {
                disposable = host.AddLoaders(_container);

                return ExecuteMain(host, options.ApplicationName, programArgs)
                        .ContinueWith(async (t, state) =>
                        {
                            ((IDisposable)state).Dispose();
                            return await t;
                        },
                        disposable).Unwrap();
            }
            catch
            {
                // If there's an error, dispose the host and throw
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                throw;
            }
        }
Example #37
0
        private int ExecuteMain(DefaultHost host, string[] args)
        {
            var assembly = host.GetEntryPoint();

            if (assembly == null)
            {
                return(-1);
            }

            string name = assembly.GetName().Name;

            var program = assembly.GetType("Program");

            if (program == null)
            {
                var programTypeInfo = assembly.DefinedTypes.FirstOrDefault(t => t.Name == "Program");

                if (programTypeInfo == null)
                {
                    Console.WriteLine("'{0}' does not contain a static 'Main' method suitable for an entry point", name);
                    return(-1);
                }

                program = programTypeInfo.AsType();
            }

            var main = program.GetTypeInfo().GetDeclaredMethods("Main").FirstOrDefault();

            if (main == null)
            {
                Console.WriteLine("'{0}' does not contain a 'Main' method suitable for an entry point", name);
                return(-1);
            }

            object instance = null;

            if ((main.Attributes & MethodAttributes.Static) != MethodAttributes.Static)
            {
                var constructors = program.GetTypeInfo().DeclaredConstructors.Where(c => c.IsPublic).ToList();

                switch (constructors.Count)
                {
                case 0:
                    Console.WriteLine("'{0}' does not contain a public constructor.", name);
                    return(-1);

                case 1:
                    var constructor = constructors[0];
                    var services    = constructor.GetParameters().Select(pi => _container);
                    instance = constructor.Invoke(services.ToArray());
                    break;

                default:
                    Console.WriteLine("'{0}' has too many public constructors for an entry point.", name);
                    return(-1);
                }
            }

            object result     = null;
            var    parameters = main.GetParameters();

            if (parameters.Length == 0)
            {
                result = main.Invoke(instance, null);
            }
            else if (parameters.Length == 1)
            {
                result = main.Invoke(instance, new object[] { args });
            }

            if (result is int)
            {
                return((int)result);
            }

            return(0);
        }
Example #38
0
 public static void Main(string[] args)
 {
     DefaultHost.RunHost();
 }