Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Browser"/> class.
 /// </summary>
 /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param>
 /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param>
 public Browser(INancyBootstrapper bootstrapper, Action<BrowserContext> defaults = null)
 {
     bootstrapper.Initialise();
     this.engine = bootstrapper.GetEngine();
     this.environment = bootstrapper.GetEnvironment();
     this.defaultBrowserContext = defaults ?? DefaultBrowserContext;
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Browser"/> class.
 /// </summary>
 /// <param name="bootstrapper">A <see cref="INancyBootstrapper"/> instance that determines the Nancy configuration that should be used by the browser.</param>
 /// <param name="defaults">The default <see cref="BrowserContext"/> that should be used in a all requests through this browser object.</param>
 public Browser(INancyBootstrapper bootstrapper, Action <BrowserContext> defaults = null)
 {
     bootstrapper.Initialise();
     this.engine                = bootstrapper.GetEngine();
     this.environment           = bootstrapper.GetEnvironment();
     this.defaultBrowserContext = defaults ?? DefaultBrowserContext;
 }
Example #3
0
        public NancyAdapter(AppFunc next, INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            _next   = next;
            _engine = bootstrapper.GetEngine();
        }
Example #4
0
 public CustomNancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris)
 {
     _bootstrapper  = bootstrapper;
     _configuration = configuration ?? new HostConfiguration();
     _baseUriList   = baseUris;
     bootstrapper.Initialise();
     _engine = bootstrapper.GetEngine();
 }
		public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper)
		{
			_host = host;
			_port = port;
			_bootstrapper = bootstrapper;
			_bootstrapper.Initialise();
			_engine = _bootstrapper.GetEngine();
		}
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using
        /// the provided <paramref name="bootstrapper"/>.
        /// Uses the specified configuration.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper that should be used to handle the request.</param>
        /// <param name="configuration">Configuration to use</param>
        /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param>
        public NancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris)
        {
            this.configuration = configuration ?? new HostConfiguration();
            this.baseUriList   = baseUris;

            bootstrapper.Initialise();
            this.engine = bootstrapper.GetEngine();
        }
Example #7
0
        public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper, int workers)
        {
            _host = host;
            _port = port;
            _workers = workers;

            bootstrapper.Initialise();
            _engine = bootstrapper.GetEngine();
        }
Example #8
0
        public NancyEvent2Host(string host, int port, INancyBootstrapper bootstrapper, int workers)
        {
            _host    = host;
            _port    = port;
            _workers = workers;

            bootstrapper.Initialise();
            _engine = bootstrapper.GetEngine();
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyHost"/> class for the specified <paramref name="baseUris"/>, using
        /// the provided <paramref name="bootstrapper"/>.
        /// Uses the specified configuration.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper that should be used to handle the request.</param>
        /// <param name="configuration">Configuration to use</param>
        /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param>
        public NancyHost(INancyBootstrapper bootstrapper, HostConfiguration configuration, params Uri[] baseUris)
        {
            this.bootstrapper = bootstrapper;
            this.configuration = configuration ?? new HostConfiguration();
            this.baseUriList = baseUris;

            bootstrapper.Initialise();
            this.engine = bootstrapper.GetEngine();
        }
Example #10
0
        public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper)
        {
            this.baseUri = baseUri;
            listener = new HttpListener();
            listener.Prefixes.Add(baseUri.ToString());

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();
        }
Example #11
0
        public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper)
        {
            this.baseUri = baseUri;
            listener     = new HttpListener();
            listener.Prefixes.Add(baseUri.ToString());

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();
        }
        public void Start()
        {
            if (Interlocked.CompareExchange(ref _isInitialized, 1, 0) != 0)
            {
                return;                 // already initialized
            }

            _nancyBootstrapper.Initialise();

            _engine = _engine ?? _nancyBootstrapper.GetEngine();
        }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using
        /// the provided <paramref name="bootstrapper"/>.
        /// </summary>
        /// <param name="bootstrapper">The boostrapper that should be used to handle the request.</param>
        /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param>
        public NancyHost(INancyBootstrapper bootstrapper, params Uri[] baseUris)
        {
            baseUriList = baseUris;
            listener    = new HttpListener();

            foreach (var baseUri in baseUriList)
            {
                listener.Prefixes.Add(baseUri.ToString());
            }

            bootstrapper.Initialise();
            engine = bootstrapper.GetEngine();
        }
Example #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyHost"/> class for the specfied <paramref name="baseUris"/>, using
        /// the provided <paramref name="bootstrapper"/>.
        /// </summary>
        /// <param name="bootstrapper">The boostrapper that should be used to handle the request.</param>
        /// <param name="baseUris">The <see cref="Uri"/>s that the host will listen to.</param>
        public NancyHost(INancyBootstrapper bootstrapper, params Uri[] baseUris)
        {
            baseUriList = baseUris;
            listener = new HttpListener();

            foreach (var baseUri in baseUriList)
            {
                listener.Prefixes.Add(baseUri.ToString().Replace("localhost", "+"));
            }

            bootstrapper.Initialise();
            engine = bootstrapper.GetEngine();
        }
Example #15
0
        public NancyHost(IPAddress address, int port, INancyBootstrapper bootStrapper)
        {
            var filter = new LogFilter();

            filter.AddStandardRules();
            LogFactory.Assign(new ConsoleLogFactory(filter));
            server = new Server();

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();

            // same as previous example.
            AppiaModule module = new AppiaModule(engine);

            server.Add(module);
        }
Example #16
0
        public void Initialise()
        {
            _bootStrapper.Initialise();



            _exludedFolders = new List <string> {
                Path.Combine(_basePath, _configuration.LayoutsPath),
                Path.Combine(_basePath, _configuration.HelpersPath),
                Path.Combine(_basePath, _configuration.ModelsPath),
                Path.Combine(_basePath, _configuration.PagesPath),
                Path.Combine(_basePath, _configuration.PartialsPath),
                Path.Combine(_basePath, _exportPath)
            };

            InitialiseExportPath();
        }
Example #17
0
        public NancyHost(INancyBootstrapper bootStrapper, params Uri[] baseUris)
        {
            baseUriList = baseUris;
            listener = new HttpListener();

            foreach (var baseUri in baseUriList)
            {
                var prefix = baseUri.ToString();

                if (!baseUri.Host.Contains("."))
                {
                    prefix = prefix.Replace("localhost", "+");
                }

                listener.Prefixes.Add(prefix);
            }

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Nancy.Hosting.Owin.NancyOwinHost"/> class.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper that should be used by the host.</param>
        public NancyWindsorOwinHost(INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            engine = bootstrapper.GetEngine();
        }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NancyWcfGenericService"/> class, with the provided <paramref name="bootstrapper"/>.
 /// </summary>
 /// <param name="bootstrapper">An <see cref="INancyBootstrapper"/> instance, that should be used to handle the requests.</param>
 public NancyWcfGenericService(INancyBootstrapper bootstrapper)
 {
     bootstrapper.Initialise();
     this.engine = bootstrapper.GetEngine();
 }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyOwinHost"/> class.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper that should be used by the host.</param>
        public NancyOwinHost(INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            this.engine = bootstrapper.GetEngine();
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyOwinHost"/> class.
        /// </summary>
        /// <param name="bootstrapper">The bootstrapper that should be used by the host.</param>
        public NancyOwinHost(INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            this.engine = bootstrapper.GetEngine();
        }
Example #22
0
 public NancyWcfGenericService(INancyBootstrapper bootstrapper)
 {
     bootstrapper.Initialise();
     engine = bootstrapper.GetEngine();
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NancyWcfGenericService"/> class, with the provided <paramref name="bootstrapper"/>.
 /// </summary>
 /// <param name="bootstrapper">An <see cref="INancyBootstrapper"/> instance, that should be used to handle the requests.</param>
 public NancyWcfGenericService(INancyBootstrapper bootstrapper)
 {
     this.bootstrapper = bootstrapper;
     bootstrapper.Initialise();
     this.engine = bootstrapper.GetEngine();
 }
Example #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NancyOwinHost"/> class.
        /// </summary>
        /// <param name="next">Next middleware to run if necessary</param>
        /// <param name="bootstrapper">The bootstrapper that should be used by the host.</param>
        public NancyOwinHost(Func <IDictionary <string, object>, Task> next, INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();

            this.engine = bootstrapper.GetEngine();
        }
Example #25
0
        public NancyHost(IPAddress address, int port, INancyBootstrapper bootStrapper)
        {
            var filter = new LogFilter();
            filter.AddStandardRules();
            LogFactory.Assign(new ConsoleLogFactory(filter));
            server = new Server();

            bootStrapper.Initialise();
            engine = bootStrapper.GetEngine();

            // same as previous example.
            AppiaModule module = new AppiaModule(engine);
            server.Add(module);
        }
Example #26
0
        public static AppFunc App(INancyBootstrapper bootstrapper)
        {
            bootstrapper.Initialise();
            var engine = bootstrapper.GetEngine();

            return(env =>
            {
                var owinRequestMethod = Get <string>(env, OwinConstants.RequestMethod);
                var owinRequestScheme = Get <string>(env, OwinConstants.RequestScheme);
                var owinRequestHeaders = Get <IDictionary <string, string[]> >(env, OwinConstants.RequestHeaders);
                var owinRequestPathBase = Get <string>(env, OwinConstants.RequestPathBase);
                var owinRequestPath = Get <string>(env, OwinConstants.RequestPath);
                var owinRequestQueryString = Get <string>(env, OwinConstants.RequestQueryString);
                var owinRequestBody = Get <Stream>(env, OwinConstants.RequestBody);
                var serverClientIp = Get <string>(env, OwinConstants.RemoteIpAddress);

                var owinResponseHeaders = Get <IDictionary <string, string[]> >(env, OwinConstants.ResponseHeaders);
                var owinResponseBody = Get <Stream>(env, OwinConstants.ResponseBody);

                var url = new Url
                {
                    Scheme = owinRequestScheme,
                    HostName = GetHeader(owinRequestHeaders, "Host"),
                    Port = null,
                    BasePath = owinRequestPathBase,
                    Path = owinRequestPath,
                    Query = owinRequestQueryString,
                };

                var body = new RequestStream(owinRequestBody, ExpectedLength(owinRequestHeaders), false);

                var nancyRequest = new Request(
                    owinRequestMethod,
                    url,
                    body,
                    owinRequestHeaders.ToDictionary(kv => kv.Key, kv => (IEnumerable <string>)kv.Value, StringComparer.OrdinalIgnoreCase),
                    serverClientIp);

                var tcs = new TaskCompletionSource <object>();
                engine.HandleRequest(
                    nancyRequest,
                    context =>
                {
                    var nancyResponse = context.Response;
                    foreach (var header in nancyResponse.Headers)
                    {
                        owinResponseHeaders.Add(header.Key, new string[] { header.Value });
                    }

                    if (!string.IsNullOrWhiteSpace(nancyResponse.ContentType))
                    {
                        owinResponseHeaders["Content-Type"] = new[] { nancyResponse.ContentType };
                    }
                    if (nancyResponse.Cookies != null && nancyResponse.Cookies.Count != 0)
                    {
                        owinResponseHeaders["Set-Cookie"] = nancyResponse.Cookies.Select(cookie => cookie.ToString()).ToArray();
                    }

                    env[OwinConstants.ResponseStatusCode] = (int)nancyResponse.StatusCode;
                    nancyResponse.Contents(owinResponseBody);
                    context.Dispose();
                    tcs.TrySetResult(null);
                },
                    tcs.SetException);
                return tcs.Task;
            });
        }