Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            XmlConfigurator.ConfigureAndWatch(new FileInfo(configurationFile));

            SetConsoleCtrlHandler(ConsoleCtrlCheck,
                                  true);

            var managerName = ConfigurationManager.AppSettings["ManagerName"];
            var baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

            var managerAddress = baseAddress.Scheme + "://+:" +
                                 baseAddress.Port + "/";

            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;


            WhoAmI =
                "[MANAGER CONSOLE HOST ( " + managerName + ", " + managerAddress + " )," + Environment.MachineName.ToUpper() + "]";

            Logger.InfoWithLineNumber(WhoAmI + " : started.");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var managerConfiguration = new ManagerConfiguration(
                ConfigurationManager.ConnectionStrings["ManagerConnectionString"].ConnectionString,
                ConfigurationManager.AppSettings["route"],
                int.Parse(ConfigurationManager.AppSettings["AllowedNodeDownTimeSeconds"]),
                int.Parse(ConfigurationManager.AppSettings["CheckNewJobIntervalSeconds"]),
                int.Parse(ConfigurationManager.AppSettings["purgeJobsBatchSize"]),
                int.Parse(ConfigurationManager.AppSettings["purgeJobsIntervalHours"]),
                int.Parse(ConfigurationManager.AppSettings["PurgeJobsOlderThanHours"]),
                int.Parse(ConfigurationManager.AppSettings["PurgeNodesIntervalHours"]));

            var container = new ContainerBuilder().Build();
            var config    = new HttpConfiguration();

            using (WebApp.Start(managerAddress,
                                appBuilder =>
            {
                string owinListenerName = "Microsoft.Owin.Host.HttpListener.OwinHttpListener";
                OwinHttpListener owinListener = (OwinHttpListener)appBuilder.Properties[owinListenerName];

                int maxAccepts;
                int maxRequests;
                owinListener.GetRequestProcessingLimits(out maxAccepts, out maxRequests);

                owinListener.SetRequestQueueLimit(int.MaxValue);
                owinListener.SetRequestProcessingLimits(int.MaxValue, int.MaxValue);

                appBuilder.UseAutofacMiddleware(container);

                // Configure Web API for self-host.
                appBuilder.UseStardustManager(managerConfiguration,
                                              container);

                appBuilder.UseAutofacWebApi(config);
                appBuilder.UseWebApi(config);
            }))
            {
                Logger.InfoWithLineNumber(WhoAmI + ": Started listening on port : ( " + baseAddress + " )");

                QuitEvent.WaitOne();
            }
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            if (app.Properties.ContainsKey("Microsoft.Owin.Host.HttpListener.OwinHttpListener"))
            {
                Logger.Info("configuring server environment");

                OwinHttpListener listener =
                    (OwinHttpListener)app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"];

                int maxAccepts, maxRequests;
                listener.GetRequestProcessingLimits(out maxAccepts, out maxRequests);


                listener.SetRequestQueueLimit(int.Parse(ConfigurationManager.AppSettings["Owin.RequestQueueLimit"]));

                listener.SetRequestProcessingLimits(int.Parse(ConfigurationManager.AppSettings["Owin.MaxAccepts"]),
                                                    int.Parse(ConfigurationManager.AppSettings["Owin.MaxRequests"]));


                app.Properties["Microsoft.Owin.Host.HttpListener.OwinHttpListener"] = listener;
            }
            else
            {
                Logger.Warn("key {0} not found. Will revert to default values.", "Microsoft.Owin.Host.HttpListener.OwinHttpListener");
            }



            app.AttachAuthenticationModules();


            var config = new HttpConfiguration();

            config.AttachDelegatingHandlers();
            config.AttachMediaFormatters();

            config.Services.Replace(typeof(IAssembliesResolver), new SidekickHttpAssemblyResolver());

            config.AttachSwagger();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Formatters.XmlFormatter.UseXmlSerializer = true;

            config.MapHttpAttributeRoutes();

            config.EnsureInitialized();

            app.UseCors(CorsOptions.AllowAll);

            SidekickEventsManager.Start();

            app.MapSignalR();

            EventhandlerModules = new List <IEventhandlerModule>();

            LoadEventHandlers();


            app.UseWebApi(config);
        }