Пример #1
0
 public MessagingFacility WithJailStrategy(string name, JailStrategy jailStrategy)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (jailStrategy == null)
     {
         throw new ArgumentNullException("jailStrategy");
     }
     m_JailStrategies.Add(name, jailStrategy);
     return(this);
 }
Пример #2
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);
        }