Пример #1
0
        public void Start()
        {
            var opts = new NancyOptions();
            var app  = Owin.OwinAppModule.OfMidFunc("/", NancyMiddleware.UseNancy(opts));

            Web.startWebServer(Web.defaultConfig, app);
        }
Пример #2
0
        public void Configuration(IAppBuilder app)
        {
            // token generation
            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions {
                // for demo purposes
#if DEBUG
                AllowInsecureHttp = true,
#endif
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(8),
                Provider = AuthorizationProvider
            });

            // token consumption
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

            //configures nancy to use specific bootstrapper
            NancyOptions options = new NancyOptions {
                Bootstrapper = NancyBootstrapper
            };

            app.UseNancy(options);
//#if DEBUG
//            app.UseErrorPage();
//#endif
//            app.UseWelcomePage("/");
        }
Пример #3
0
        public static App Initialize(AppConfig config)
        {
            config.ThrowIfInvalid();
            var poller       = new LeaderInfoPoller(config.StorageAccount);
            var startOptions = new StartOptions();

            startOptions.Urls.Add(config.InternalUri);
            startOptions.Urls.Add(config.PublicUri);

            var auth = LoadAuth.LoadFromStorageAccount(config.StorageAccount);

            AddSystemAccess(auth, config.StorageAccount.GetSysPassword());
            var api          = ApiImplementation.Create(config.StorageAccount, poller, auth);
            var nancyOptions = new NancyOptions
            {
                Bootstrapper = new NancyBootstrapper(api, new UserValidator(auth))
            };
            var nodeInfo = new LeaderInfo(config.InternalUri);

            var selector = new LeaderLock(config.StorageAccount, nodeInfo, api);

            var cts = new CancellationTokenSource();
            // fire up leader and scheduler first
            var tasks = new List <Task> {
                selector.KeepTryingToAcquireLock(cts.Token),
                poller.KeepPollingForLeaderInfo(cts.Token),
            };


            // bind the API
            var webApp = WebApp.Start(startOptions, x => x.UseNancy(nancyOptions));

            return(new App(webApp, cts, tasks));
        }
Пример #4
0
        /// <summary>
        /// Adds Nancy to the OWIN pipeline.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="configuration">A configuration builder action.</param>
        /// <returns>IAppBuilder.</returns>
        public static IAppBuilder UseNancy(this IAppBuilder builder, Action <NancyOptions> configuration)
        {
            var options = new NancyOptions();

            configuration(options);
            return(UseNancy(builder, options));
        }
Пример #5
0
 public void Start()
 {
     _Log.Info("WebServer is starting...");
     try
     {
         // TODO Build optional SSL support with certificates
         SuaveHttp.Protocol protocol = SuaveHttp.Protocol.HTTP;
         FSharpList <SuaveHttp.HttpBinding> bindings = ListModule.OfSeq(_ListenAddresses.Select(ep => new SuaveHttp.HttpBinding(protocol, new Suave.Sockets.SocketBinding(ep.Address, (ushort)ep.Port))));
         var suaveConfig = SuaveWeb.defaultConfig.withCancellationToken(_CancellationTokenSource.Token).withBindings(bindings);
         GlobalHost.DependencyResolver.Register(typeof(RemoteHub), () => new RemoteHub(_RemoteControlService, this));
         AppBootstrapper bootstrapper = new AppBootstrapper(_RemoteControlService);
         NancyOptions    nancyOptions = new NancyOptions();
         nancyOptions.Bootstrapper = bootstrapper;
         AppBuilder appBuilder = new AppBuilder();
         appBuilder.MapSignalR();
         appBuilder.UseNancy(nancyOptions);
         var owin        = appBuilder.Build();
         var app         = Suave.Owin.OwinAppModule.OfAppFunc("", owin);
         var startAction = SuaveWeb.startWebServerAsync(suaveConfig, app);
         FSharpAsync.Start(startAction.Item2, FSharpOption <CancellationToken> .Some(_CancellationTokenSource.Token));
         FSharpAsync.StartAsTask(startAction.Item1, FSharpOption <TaskCreationOptions> .Some(TaskCreationOptions.None), FSharpOption <CancellationToken> .None).ContinueWith((started) =>
         {
             _Log.Info("WebServer is running.");
             Status = ServerStatus.Ready;
         });
     }
     catch (Exception ex)
     {
         _Log.Error(string.Format("Failed to start web server: {0}", ex.Message), ex);
         Status = ServerStatus.Stopped;
         Error  = ex;
     }
 }
        public void Configuration(IAppBuilder app)
        {
            var serviceBusScaleoutConfiguration = new ServiceBusScaleoutConfiguration(ConfigurationManager.ConnectionStrings["servicebus"].ConnectionString, "nancysignals")
            {
                BackoffTime = TimeSpan.FromSeconds(5)
            };

            var ioc              = new TinyIoCContainer();
            var bootstrapper     = new Bootstrapper(ioc);
            var hubConfiguration = new HubConfiguration
            {
                Resolver = bootstrapper.DependencyResolver
            };

            hubConfiguration.Resolver.UseServiceBus(serviceBusScaleoutConfiguration);
            var nancyOptions = new NancyOptions
            {
                Bootstrapper = bootstrapper
            };

            GlobalHost.DependencyResolver = bootstrapper.DependencyResolver;

            app.MapSignalR(hubConfiguration);
            app.UseNancy(nancyOptions);
        }
 public void When_response_status_code_match_then_should_perform_pass_through()
 {
     var options = new NancyOptions();
     options.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound);
     var nancyContext = new NancyContext { Response = new Response {StatusCode = HttpStatusCode.NotFound} };
     options.PerformPassThrough(nancyContext).ShouldBeTrue();
 }
Пример #8
0
        public void Configuration(IAppBuilder app)
        {
            var options = new NancyOptions();

            options.Bootstrapper = new Bootstrapper();
            app.UseNancy();
        }
        /// <summary>
        /// Adds Nancy to the OWIN pipeline.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="options">The Nancy options.</param>
        /// <returns>IAppBuilder.</returns>
        public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null)
        {
            var nancyOptions = options ?? new NancyOptions();

            HookDisposal(builder, nancyOptions);

            return(builder.Use(NancyMiddleware.UseNancy(nancyOptions)));
        }
Пример #10
0
        public static int Main(string[] args)
        {
            var opts = new NancyOptions();
            var app  = Owin.OwinAppModule.OfMidFunc("/", NancyMiddleware.UseNancy(opts));

            Web.startWebServer(Web.defaultConfig, app);
            return(0);
        }
Пример #11
0
        /// <summary>
        /// Adds Nancy to the OWIN pipeline.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="options">The Nancy options.</param>
        /// <returns>IAppBuilder.</returns>
        public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null)
        {
            var nancyOptions = options ?? new NancyOptions();

            HookDisposal(builder, nancyOptions);

            return(builder.Use(typeof(NancyOwinHost), nancyOptions));
        }
Пример #12
0
        /// <summary>
        /// Adds Nancy to the AspNetCore pipeline.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="action">A configuration builder action.</param>
        /// <returns>The application builder.</returns>
        public static IApplicationBuilder UseNancy(this IApplicationBuilder builder, Action <NancyOptions> action)
        {
            var options = new NancyOptions();

            action(options);

            return(builder.UseNancy(options));
        }
Пример #13
0
        /// <summary>
        /// Adds Nancy to the AspNetCore pipeline.
        /// </summary>
        /// <param name="builder">The application builder.</param>
        /// <param name="options">The Nancy options.</param>
        /// <returns>The application builder.</returns>
        public static IApplicationBuilder UseNancy(this IApplicationBuilder builder, NancyOptions options = null)
        {
            var nancyOptions = options ?? new NancyOptions();

            builder.UseMiddleware <NancyMiddleware>(nancyOptions);

            return(builder);
        }
Пример #14
0
        public void Attach(IAppBuilder appBuilder)
        {
            var options = new NancyOptions
            {
                Bootstrapper       = _nancyBootstrapper,
                PerformPassThrough = context => context.Request.Path.StartsWith("/signalr")
            };

            appBuilder.UseNancy(options);
        }
Пример #15
0
        public static void Main()
        {
            var opts = new NancyOptions
            {
                Bootstrapper = new Bootstrap()
            };
            var app = Suave.Owin.OwinAppModule.OfMidFunc("/", NancyMiddleware.UseNancy(opts));

            Web.startWebServer(Web.defaultConfig, app);
        }
Пример #16
0
        private static Task OnComponent(IDictionary <string, object> env, Func <IDictionary <string, object>, Task> next)
        {
            var nancyOptions = new NancyOptions {
                Bootstrapper = new DefaultNancyBootstrapper()
            };

            var nancyHost = new NancyOwinHost(next, nancyOptions);

            return(nancyHost.Invoke(env));
        }
Пример #17
0
        public void Attach(IAppBuilder appBuilder)
        {
            appBuilder.UseCors(CorsOptions.AllowAll);
            var options = new NancyOptions
            {
                Bootstrapper = _nancyBootstrapper,
            };

            appBuilder.UseNancy(options);
        }
Пример #18
0
        public void Configure(IApplicationBuilder app)
        {
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMiddleware <AuthorizeMiddleware>();

            var nancyOptions = new NancyOptions();

            nancyOptions.Bootstrapper = new Bootstrapper(app);
            app.UseOwin(x => x.UseNancy(nancyOptions));
        }
 public void Configure(IApplicationBuilder app)
 {
     app.UseOwin(pipeline =>
     {
         NancyOptions options = new NancyOptions
         {
             Bootstrapper = new Bootstrapper()
         };
         pipeline.UseNancy(options);
     });
 }
Пример #20
0
        public void Configuration(IAppBuilder app)
        {
            IKernel container = new StandardKernel(new NinjectModuleConfig());

            var nancyConfig = new NancyOptions()
            {
                Bootstrapper = new NinjectNancyAppBootstrapper(container)
            };

            //app.UseNancy();
            app.UseNancy(nancyConfig);
        }
Пример #21
0
        public static void Configure(IAppBuilder app, IWindsorContainer container)
        {
            app.UseWindowsAuthentication();
            app.ServeEmbeddedFiles();
            app.MapSignalR();

            var options = new NancyOptions {
                Bootstrapper = new NancyBootstrapper(container)
            };

            app.UseNancy(options);
        }
Пример #22
0
        public void When_response_status_code_match_then_should_perform_pass_through()
        {
            var options = new NancyOptions();

            options.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound);
            var nancyContext = new NancyContext {
                Response = new Response {
                    StatusCode = HttpStatusCode.NotFound
                }
            };

            options.PerformPassThrough(nancyContext).ShouldBeTrue();
        }
        // OWIN Configuration goes here
        public static void Configuration(IAppBuilder app)
        {
            var cookieOptions = new CookieAuthenticationOptions()
            {
                AuthenticationMode = AuthenticationMode.Active
            };
            var nancyCfg = new NancyOptions();

            nancyCfg.Bootstrapper = new NBootstrapper();
            app.UseStaticFiles();
            app.UseCookieAuthentication(cookieOptions);
            app.UseNancy(nancyCfg);
        }
Пример #24
0
        private static void HookDisposal(IAppBuilder builder, NancyOptions nancyOptions)
        {
            if (!builder.Properties.ContainsKey(AppDisposingKey))
            {
                return;
            }

            var appDisposing = builder.Properties[AppDisposingKey] as CancellationToken?;

            if (appDisposing.HasValue)
            {
                appDisposing.Value.Register(nancyOptions.Bootstrapper.Dispose);
            }
        }
Пример #25
0
        private static void HookDisposal(IAppBuilder builder, NancyOptions nancyOptions)
        {
            object value;

            if (!builder.Properties.TryGetValue(AppDisposingKey, out value))
            {
                return;
            }

            var appDisposing = value as CancellationToken?;

            if (appDisposing.HasValue)
            {
                appDisposing.Value.Register(nancyOptions.Bootstrapper.Dispose);
            }
        }
Пример #26
0
        public void Configuration(IAppBuilder app)
        {
            // Map the hubs first, otherwise Nancy grabs them and you get a 404.
            var configuration = new HubConfiguration {
                EnableDetailedErrors = true
            };

            app.MapSignalR(configuration);

            var options = new NancyOptions
            {
                Bootstrapper = new NancyBootstrapper()
            };

            app.UseNancy(options);
        }
Пример #27
0
        /// <summary>The configuration.</summary>
        /// <param name="app">The app.</param>
        public void Configuration(IAppBuilder app)
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(this.container));

            app.UseAutofacMiddleware(this.container);
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();

            var options = new NancyOptions {
                Bootstrapper = new Bootstrapper(this.container)
            };

            app.UseNancy(options);
        }
Пример #28
0
        public static IApplicationBuilder UseNancy(this IApplicationBuilder app, Action <NancyOptions> configure = null)
        {
            var options = new NancyOptions
            {
                // We try to pull it from the application container in order for it to get the ILifetimeScope injected.
                Bootstrapper = app.ApplicationServices.GetService <INancyBootstrapper>()
            };

            configure?.Invoke(options);

            // Because synchronous IO is disabled by default in ASP.NET Core 3.0 and
            // some paths in Nancy still requires synchronous IO, we have to enable it.
            app.UseSynchronousIO();

            // Because there's still no proper ASP.NET Core middleware
            // for Nancy, we have to wrap it in the OWIN adapter.
            return(app.UseOwin(owin => owin.UseNancy(options)));
        }
Пример #29
0
        public static IAppBuilder UsePingOwin(this IAppBuilder appBuilder, PingOwinOptions options = null)
        {
            options = options ?? new PingOwinOptions();

            var connectionString = $"Data Source={options.PathToDb}pingowin.db;Version=3;Pooling=True;Max Pool Size=100;";

            var databaseSettings = new DbSettings(connectionString);
            var migrator         = new Migrator(databaseSettings);

            migrator.Migrate();

            var conf = new NancyOptions
            {
                Bootstrapper = new PingOwinWebBootstrapper(databaseSettings)
            };

            appBuilder.UseNancy(conf);

            var pingConfiguration = new PingConfiguration
            {
                RequestTimeOut = new TimeSpan(0, 0, 0, 0, options.RequestTimeOut),
                WarnThreshold  = options.WarnThreshold
            };

            var notifierType = NotifierType.Konsole;
            var slackConfig  = new SlackConfig();

            var notifierFactory    = new NotifierFactory(notifierType, slackConfig);
            var transformerFactory = new TransformerFactory(notifierType, Level.OK);

            var processor = IoCFactory.CreateProcessor(pingConfiguration, databaseSettings, notifierFactory, transformerFactory);


            var serviceRunner = new ServiceRunner(new ServiceRunnerOptions
            {
                PingIntervalInMillis = options.PingIntervalInMillis,
                RunBackgroundThread  = options.StartService
            }, processor);

            serviceRunner.StartBackgroundThread();

            return(appBuilder);
        }
Пример #30
0
        static void Main()
        {
            var nancyOptions = new NancyOptions {
                Bootstrapper = new DefaultNancyBootstrapper()
            };

            var app = new Fixer()
                      .Use((env, next) => new NancyOwinHost(next, nancyOptions).Invoke(env))
                      .Build();

            // Set up the Nowin server
            var builder = ServerBuilder.New()
                          .SetPort(8888)
                          .SetOwinApp(app);

            // Run
            using (builder.Start())
            {
                Console.WriteLine("Listening on port 1337. Enter to exit.");
                Console.ReadLine();
            }
        }
Пример #31
0
        public void Configuration(IAppBuilder app)
        {
            //Enable CORS
            app.UseCors(CorsOptions.AllowAll);

            //Enable SignalR
            app.MapSignalR();

            // Configure Web API for self-host and use it.
            var config = new HttpConfiguration();

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

            // File Server
            var fileOptions = new FileServerOptions
            {
                EnableDirectoryBrowsing = true,
                FileSystem        = new PhysicalFileSystem("Jobs"),
                StaticFileOptions = { ContentTypeProvider = new ContentTypeProvider() },
                RequestPath       = new Microsoft.Owin.PathString("/Directory")
            };

            app.UseFileServer(fileOptions);

            // Nancy
            var nancyOptions = new NancyOptions
            {
                Bootstrapper = new IDPJobManagerBootstrapper(JobPoolManager.Scheduler)
            };

            app.UseNancy(nancyOptions);
        }
Пример #32
0
 public NancyOptionsFixture()
 {
     this.nancyOptions = new NancyOptions();
 }