Example #1
0
 private static IDisposable createHost(AppServerSetup setup = null)
 {
     return(Bootstrapper.Start(setup));
 }
Example #2
0
        public static void Main(params string[] args)
        {
            var setup = new AppServerSetup
            {
                SendHb      = true,
                Environment = ConfigurationManager.AppSettings["Environment"],
                ConfSvcUrl  = ConfigurationManager.AppSettings["confSvcUrl"]
            };

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].ToLower())
                {
                case "-appstostart":
                    i++;
                    if (i < args.Length)
                    {
                        setup.AppsToStart = args[i].Split(',');
                    }
                    break;

                case "-repository":
                    i++;
                    if (i < args.Length)
                    {
                        setup.Repository = args[i];
                    }
                    break;

                case "-debug-wrap":
                    i++;
                    if (i < args.Length)
                    {
                        var wraps = args[i].Split(',').Select(w => w.Trim());
                        foreach (var wrap in wraps)
                        {
                            if (Path.GetExtension(wrap).ToLower() != ".wrap")
                            {
                                Console.WriteLine("-debug-wrap should be followed with comma separated list pf .wrap files");
                                Environment.Exit(1);
                            }
                            if (!File.Exists(wrap))
                            {
                                Console.WriteLine(wrap + " could not be found");
                                Environment.Exit(1);
                            }
                        }
                        setup.DebugWraps = wraps.Select(Path.GetFullPath).ToArray();
                    }
                    break;

                default:
                    Console.WriteLine("Unknown arg: " + args[i]);
                    return;
                }
            }
            if (!Environment.UserInteractive)
            {
                const string source = "InternetBank";
                const string log    = "Application";

                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, log);
                }
                var eLog = new EventLog {
                    Source = source
                };
                eLog.WriteEntry(@"Starting the service in " + AppDomain.CurrentDomain.BaseDirectory,
                                EventLogEntryType.Information);

                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                var servicesToRun = new ServiceBase[] { new ServiceHostSvc(() => createHost(setup)) };
                ServiceBase.Run(servicesToRun);
                return;
            }

            using (createHost(setup))
            {
                Console.ReadLine();
            }
        }
Example #3
0
        internal static IDisposable Start(AppServerSetup setup)
        {
            AppDomainRenderer.Register();
            string            machineName = Environment.MachineName;
            IWindsorContainer container;

            ILogger logger;
            var     nlogConf = Path.Combine(Path.GetDirectoryName(typeof(Bootstrapper).Assembly.Location), "nlog.config");

            using (var logFactory = new LogFactory(new XmlLoggingConfiguration(nlogConf)))
            {
                var log = logFactory.GetLogger(typeof(Bootstrapper).Name);
                log.Info("Initializing...");
                log.Info("Creating container");
                try
                {
                    container = new WindsorContainer()
                                .AddFacility <StartableFacility>()
                                //.AddFacility<LoggingFacility>(f => f.LogUsing(LoggerImplementation.NLog).WithConfig(nlogConf));
                                .AddFacility <LoggingFacility>(f => f.LogUsing <GenericsAwareNLoggerFactory>().WithConfig(nlogConf));

                    container.Kernel.Resolver.AddSubResolver(new ConventionBasedResolver(container.Kernel));

                    logger = container.Resolve <ILoggerFactory>().Create(typeof(Bootstrapper));
                }catch (Exception e)
                {
                    log.FatalException("Failed to start\r\n", e);
                    throw;
                }
                log.Info("Registering components");
            }

            try
            {
                container.Register(
                    Component.For <IConfigurationProvider, IManageableConfigurationProvider>().ImplementedBy <LocalStorageConfigurationProvider>().Named("localStorageConfigurationProvider")
                    .DependsOn(new { configFolder = Path.Combine(Environment.CurrentDirectory, Path.Combine("Configuration")) }));

                //If remote configuration source is provided in app.config use it by default
                if (setup.ConfSvcUrl != null)
                {
                    container.Register(Component.For <IConfigurationProvider>().ImplementedBy <LegacyRemoteConfigurationProvider>()
                                       .DependsOn(new { serviceUrl = setup.ConfSvcUrl, path = "." })
                                       .IsDefault());
                }

                //Configuration local/remote
                container
                .AddFacility <ConfigurationFacility>(f => f.Configuration("AppServer")
                                                     .Params(new { environment = setup.Environment, machineName })
                                                     .ConfigureTransports(new Dictionary <string, JailStrategy> {
                    { "Environment", JailStrategy.Custom(() => setup.Environment) }
                },
                                                                          "server.transports", "{environment}", "{machineName}"))
                //messaging
                .AddFacility <MessagingFacility>(f => { })
                .Register(
                    Component.For <IHost>().ImplementedBy <Host>().DependsOn(new { name = setup.Environment }),
                    //Applications to be started
                    setup.AppsToStart == null
                            ? Component.For <Bootstrapper>().DependsOnBundle("server.host", "", "{environment}", "{machineName}")
                            : Component.For <Bootstrapper>().DependsOn(new { appsToStart = setup.AppsToStart }),
                    Component.For <IServerCore>().ImplementedBy <ServerCore>(),
                    Component.For <ManagementConsole>().DependsOn(new { container }).DependsOnBundle("server.host", "ManagementConsole", "{environment}", "{machineName}"),
                    Component.For <IApplicationBrowser>().ImplementedBy <OpenWrapApplicationBrowser>().DependsOn(
                        new
                {
                    repository = setup.Repository ?? "Repository",
                    debugWraps = setup.DebugWraps ?? new string[0]
                })
                    );

                //HearBeats
                if (setup.SendHb)
                {
                    container.Register(Component.For <HbSender>().DependsOn(new { environment = setup.Environment, hbInterval = setup.HbInterval }));
                }
            }
            catch (Exception e)
            {
                logger.FatalFormat(e, "Failed to start");
                throw;
            }


            logger.Info("Starting application host");
            var sw = Stopwatch.StartNew();

            container.Resolve <Bootstrapper>().start();
            logger.InfoFormat("Initialization complete in {0}ms", sw.ElapsedMilliseconds);
            return(container);
        }