예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PomonaResponseProcessorBase"/> class.
        /// </summary>
        /// <param name="routeCacheProvider">The route cache provider.</param>
        /// <exception cref="System.ArgumentNullException">routeCacheProvider</exception>
        protected PomonaResponseProcessorBase(IRouteCacheProvider routeCacheProvider)
        {
            if (routeCacheProvider == null)
                throw new ArgumentNullException(nameof(routeCacheProvider));

            this.routeCacheProvider = routeCacheProvider;
        }
예제 #2
0
 public SystemModule(IAppFolderInfo appFolderInfo,
                     IRuntimeInfo runtimeInfo,
                     IPlatformInfo platformInfo,
                     IOsInfo osInfo,
                     IRouteCacheProvider routeCacheProvider,
                     IConfigFileProvider configFileProvider,
                     IMainDatabase database,
                     ILifecycleService lifecycleService,
                     IDeploymentInfoProvider deploymentInfoProvider)
     : base("system")
 {
     _appFolderInfo          = appFolderInfo;
     _runtimeInfo            = runtimeInfo;
     _platformInfo           = platformInfo;
     _osInfo                 = osInfo;
     _routeCacheProvider     = routeCacheProvider;
     _configFileProvider     = configFileProvider;
     _database               = database;
     _lifecycleService       = lifecycleService;
     _deploymentInfoProvider = deploymentInfoProvider;
     Get("/status", x => GetStatus());
     Get("/routes", x => GetRoutes());
     Post("/shutdown", x => Shutdown());
     Post("/restart", x => Restart());
 }
예제 #3
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/css/{file}"] = x => {
                return Response.AsCss("css/" + (string)x.file);
            };

            Get["/js/{file}"] = x =>
            {
                return Response.AsJs("js/" + (string)x.file);
            };

            Get["/lib/{file}"] = x =>
            {
                return Response.AsFile("lib/" + (string)x.file);
            };

            Get["/"] = x => {
                return View["index"];
            };

            Get["/{path}", (ctx) => ctx.Request.Uri != "/"] = x =>
            {
                return ViewOrFallback((string)x.path, () =>
                {
                    dynamic result = IsAllowedFile((string)x.path) ? Response.AsFile((string)x.path) : 403;

                    return result;
                });
            };
        }
예제 #4
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            _routeCacheProvider = routeCacheProvider;

            Get["/"]    = ListRoutes;
            Delete["/"] = Exit;
        }
예제 #5
0
        public RhinoGetModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/sdk"] = _ =>
            {
                var result = new StringBuilder("<!DOCTYPE html><html><body>");
                var cache  = routeCacheProvider.GetCache();
                result.AppendLine($" <a href=\"/sdk/csharp\">C# SDK</a><BR>");
                result.AppendLine("<p>API<br>");

                int route_index = 0;
                foreach (var module in cache)
                {
                    foreach (var route in module.Value)
                    {
                        var method = route.Item2.Method;
                        var path   = route.Item2.Path;
                        if (method == "GET")
                        {
                            route_index += 1;
                            result.AppendLine($"{route_index} <a href='{path}'>{path}</a><BR>");
                        }
                    }
                }

                result.AppendLine("</p></body></html>");
                return(result.ToString());
            };

            foreach (var endpoint in GeometryEndPoint.AllEndPoints)
            {
                string key = endpoint.PathURL;
                Get[key] = _ => endpoint.Get(Context);
            }
        }
 public DocsModule(IRouteCacheProvider routeCacheProvider)
     : base(routeCacheProvider, "/api/docs/swagger.json", "Sample API documentation", "v1.0", "localhost:53053", "/api", "http")
 {
     Get["/", true] = async(_, __) =>
                      await Task.Run(() => Response.AsRedirect("/Content/index.html"))
                      .ConfigureAwait(false);
 }
예제 #7
0
        // add dependency to IRouteCacheProvider
        public HomeModule(IRouteCacheProvider rc) : base("/")
        {
            routeCache = rc;
            Get("/", p => View["index", GetIndex()], null, "Shows available routes.");


            //Stop Lighthouse
            Get("/stop", args =>
            {
                LighthouseActorService.StopAsync().Wait();
                return("Stopping Lighthouse at " + DateTime.Now);
            }, null, "Stops Lighthouse.");

            //Restart Lighthouse
            Get("/restart", args =>
            {
                LighthouseActorService.StopAsync().Wait();

                LighthouseActorService = new LighthouseService();

                LighthouseActorService.Start();

                return("Restarting Lighthouse at " + DateTime.Now);
            }, null, "Restarts Lighthouse.");
        }
예제 #8
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/css/{file}"] = x => {
                return(Response.AsCss("css/" + (string)x.file));
            };

            Get["/js/{file}"] = x =>
            {
                return(Response.AsJs("js/" + (string)x.file));
            };

            Get["/lib/{file}"] = x =>
            {
                return(Response.AsFile("lib/" + (string)x.file));
            };

            Get["/"] = x => {
                return(View["index"]);
            };

            Get["/{path}", (ctx) => ctx.Request.Uri != "/"] = x =>
            {
                return(ViewOrFallback((string)x.path, () =>
                {
                    dynamic result = IsAllowedFile((string)x.path) ? Response.AsFile((string)x.path) : 403;

                    return result;
                }));
            };
        }
 public DefaultSwaggerMetadataProvider(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog = modelCatalog;
 }
 public V2SwaggerMetadataProvider(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog       = modelCatalog;
 }
예제 #11
0
 public DefaultSwaggerMetadataConverter(
     IRouteCacheProvider routeCacheProvider,
     ISwaggerModelCatalog modelCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _modelCatalog       = modelCatalog;
 }
예제 #12
0
 public FakeDocsModule(IRouteCacheProvider routeCacheProvider) :
     base(routeCacheProvider,
          DocsLocation,
          Title,
          ApiVersion,
          host: Server)
 {
 }
예제 #13
0
 public DocsModule(IRouteCacheProvider routeCacheProvider)
     : base(routeCacheProvider,
            "Ezbob API v.1 Documentation", // title
            "v1.0",                        // api version
            "localhost:12345",             // host
            "/api/v1",                     // api base url (ie /dev, /api)
            "http")                        // schemes
 {
 }
예제 #14
0
 public DocumentationModule(IRouteCacheProvider routeCacheProvider) : base("/documentation")
 {
     Get["/"] = parameters =>
     {
         var model = new DocumentationViewModel(routeCacheProvider.GetCache().SelectMany(p => p.Value)
                                                .SelectMany(p => p.Item2.Metadata.Raw.Select(g => (DocumentationObject)g.Value).ToList()).Where(p => p != null).ToList());
         return(Response.AsJson(model));
     };
 }
예제 #15
0
 public DocsModule(IRouteCacheProvider routeCacheProvider) :
     base(routeCacheProvider,
          "/api/docs/openapi.json",
          "Sample API documentation",
          "v1.0",
          host: Server)
 {
     Get["/"] = _ => Response.AsRedirect("/Content/index.html");
 }
예제 #16
0
        public TrashModule(IRepository <Order> orderRepository, ResourceLinker linker)
            : base(path)
        {
            this.orderRepository    = orderRepository;
            this.linker             = linker;
            this.routeCacheProvider = routeCacheProvider;

            Get["ReadCancelledOrder", GetCancelledPath] = parameters => GetCanceled((int)parameters.orderId);
        }
예제 #17
0
        public TrashModule(IRepository<Order> orderRepository, ResourceLinker linker)
            : base(path)
        {
            this.orderRepository = orderRepository;
              this.linker = linker;
              this.routeCacheProvider = routeCacheProvider;

              Get["ReadCancelledOrder", GetCancelledPath] = parameters => GetCanceled((int) parameters.orderId);
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PomonaResponseProcessorBase"/> class.
        /// </summary>
        /// <param name="routeCacheProvider">The route cache provider.</param>
        /// <exception cref="System.ArgumentNullException">routeCacheProvider</exception>
        protected PomonaResponseProcessorBase(IRouteCacheProvider routeCacheProvider)
        {
            if (routeCacheProvider == null)
            {
                throw new ArgumentNullException(nameof(routeCacheProvider));
            }

            this.routeCacheProvider = routeCacheProvider;
        }
예제 #19
0
 public FakeDocsModule(IRouteCacheProvider routeCacheProvider, string TermsOfService) :
     base(routeCacheProvider,
          DocsLocation,
          Title,
          ApiVersion,
          termsOfService: TermsOfService,
          host: Server)
 {
 }
예제 #20
0
 public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider, IConfigFileProvider configFileProvider)
     : base("system")
 {
     _appFolderInfo      = appFolderInfo;
     _runtimeInfo        = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     Get["/status"]      = x => GetStatus();
     Get["/routes"]      = x => GetRoutes();
 }
예제 #21
0
        public DefaultService(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x =>
            {
                ViewModel model = new ViewModel();
                model.ServicePort = System.Configuration.ConfigurationManager.AppSettings["service_port"];

                return(View["default", model]);
            };
        }
예제 #22
0
 public SystemModule(IAppFolderInfo appFolderInfo, IRuntimeInfo runtimeInfo, IRouteCacheProvider routeCacheProvider, IConfigFileProvider configFileProvider)
     : base("system")
 {
     _appFolderInfo = appFolderInfo;
     _runtimeInfo = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     Get["/status"] = x => GetStatus();
     Get["/routes"] = x => GetRoutes();
 }
예제 #23
0
 public FakeModule(IRouteCacheProvider routeCacheProvider) :
     base(routeCacheProvider,
          DocsLocation,
          Title,
          ApiVersion,
          termsOfService: TermsOfService,
          host: Server,
          apiBaseUrl: ApiBaseUrl,
          tags: Tags)
 {
 }
예제 #24
0
        /// <summary>
        /// Returns the information about the services
        /// </summary>
        /// <param name="cacheProvider">The cache provider</param>
        /// <returns>The response</returns>
        private object ShowInfo(IRouteCacheProvider cacheProvider)
        {
            var metaData = cacheProvider.GetCache().RetrieveMetadata <CustomMetadata>().Where(w => w != null).ToList();

            var data = new
            {
                BaseData = GetBaseData(),
                Metadata = metaData
            };

            return(View["info.html", data]);
        }
예제 #25
0
 public RhinoPostModule(IRouteCacheProvider routeCacheProvider)
 {
     foreach (var endpoint in GeometryEndPoint.AllEndPoints)
     {
         string key = endpoint.PathURL;
         Post[key] = _ =>
         {
             var r = endpoint.Post(Context);
             r.ContentType = "application/json";
             return(r);
         };
     }
 }
예제 #26
0
 public DocsModule(IRouteCacheProvider routeCacheProvider, AppSettings appSettings)
     : base(routeCacheProvider,
            appSettings.Metadata.DocsPath,                       // where module should be located
            appSettings.Metadata.Title,                          // title
            appSettings.Metadata.Version,                        // api version
            host: new Server()                                   // host
 {
     Description = appSettings.Metadata.Host.Description,
     Url         = appSettings.Metadata.Host.Url
 }
            )
 {
     Get("/", async(_, __) => await Task.FromResult(Response.AsRedirect("/index.html")).ConfigureAwait(false));
 }
예제 #27
0
        public MainModule(IRouteCacheProvider cacheProvider)
        {
            Get("/", _ => ProcessGetRequest(), name: "main");

            Post("/service/", _ => AddService(), name: "postService");

            Post("/task/{name}", x => AddTask(x.Name), name: "postTask");

            Delete("/service/{name}", x => DeleteService(x.Name), name: "deleteService");

            Delete("/task/{name}", x => DeleteTask(x.Name), name: "deleteTask");

            Get("/docs", _ => ShowInfo(cacheProvider), name: "docRoute");
        }
예제 #28
0
        public IndexModule(IRouteCacheProvider routeCache) : base("/api/")
        {
            this.EnableCors();
            m_routeCache = routeCache;
            Get["/"]     = parameters =>
            {
                var responseObject = new IndexModel();
                var cache          = m_routeCache.GetCache();

                responseObject.Routes = cache.Values.SelectMany(t => t.Select(t1 => t1.Item2));

                return(Response.AsJson(responseObject.Routes.Select(p => new KeyValuePair <string, string>(p.Path, p.Method))));
            };
        }
        /// <summary>
        /// Constructor with minimal amount of values required values.
        /// </summary>
        /// <param name="routeCacheProvider"></param>
        /// <param name="docsLocation"></param>
        /// <param name="title"></param>
        /// <param name="apiVersion"></param>
        public OpenApiDocsModuleBase(IRouteCacheProvider routeCacheProvider,
                                     string docsLocation,
                                     string title,
                                     string apiVersion) : this(routeCacheProvider,
                                                               docsLocation,
                                                               title,
                                                               apiVersion,
                                                               null,
                                                               new Server {
            Url = HOST, Description = HOST_DESCRIPTION
        },
                                                               null)

        {
        }
예제 #30
0
파일: MainModule.cs 프로젝트: tt/Nancy
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => {
                return View.Razor("~/views/routes.cshtml", routeCacheProvider.GetCache());
            };

            // TODO - implement filtering at the RouteDictionary GetRoute level
            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/static"] = x => {
                return View.Static("~/views/static.htm");
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View.Razor("~/views/razor.cshtml", model);
            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View.Django("~/views/ndjango.django", model);
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View.Spark("~/views/spark.spark", model);
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };
        }
 /// <summary>
 /// Constructor established for use with Open Api version as a basic version
 /// </summary>
 /// <param name="routeCacheProvider"></param>
 /// <param name="docsLocation"></param>
 /// <param name="title"></param>
 /// <param name="apiVersion"></param>
 /// <param name="termsOfService"></param>
 /// <param name="host"></param>
 /// <param name="contact"></param>
 /// <param name="license"></param>
 /// <param name="tags"></param>
 protected OpenApiDocsModuleBase(IRouteCacheProvider routeCacheProvider,
                                 string docsLocation,
                                 string title,
                                 string apiVersion,
                                 string termsOfService = null,
                                 Server host           = null,
                                 Tag[] tags            = null) : this(
         routeCacheProvider,
         docsLocation,
         title,
         apiVersion,
         termsOfService,
         new Server[] { host },
         tags)
 {
 }
예제 #32
0
        public DocMudule(IRouteCacheProvider routeCacheProvider) : base("/docs")
        {
            this._routeCacheProvider = routeCacheProvider;

            Get["/"] = _ =>
            {
                var routeDescriptionList = _routeCacheProvider
                                           .GetCache()
                                           .SelectMany(x => x.Value)
                                           .Select(x => x.Item2)
                                           .Where(x => !string.IsNullOrWhiteSpace(x.Name))
                                           .ToList();

                return(Response.AsJson(routeDescriptionList));
            };
        }
예제 #33
0
        public RhinoModule(IRouteCacheProvider routeCacheProvider)
        {
            Get[""]             = _ => FixedEndpoints.HomePage(Context);
            Get["/healthcheck"] = _ => "healthy";
            Get["version"]      = _ => FixedEndpoints.GetVersion(Context);
            Get["sdk/csharp"]   = _ => FixedEndpoints.CSharpSdk(Context);
            Post["hammertime"]  = _ => FixedEndpoints.HammerTime(Context);

            Get["/sdk"] = _ =>
            {
                var result = new StringBuilder("<!DOCTYPE html><html><body>");
                var cache  = routeCacheProvider.GetCache();
                result.AppendLine($" <a href=\"/sdk/csharp\">C# SDK</a><BR>");
                result.AppendLine("<p>API<br>");

                int route_index = 0;
                foreach (var module in cache)
                {
                    foreach (var route in module.Value)
                    {
                        var method = route.Item2.Method;
                        var path   = route.Item2.Path;
                        if (method == "GET")
                        {
                            route_index += 1;
                            result.AppendLine($"{route_index} <a href='{path}'>{path}</a><BR>");
                        }
                    }
                }

                result.AppendLine("</p></body></html>");
                return(result.ToString());
            };

            foreach (string nameSpace in new List <string>()
            {
                "Rhino.Geometry", "Rhino.Geometry.Intersect"
            })
            {
                foreach (var endpoint in CreateEndpoints(typeof(Rhino.RhinoApp).Assembly, nameSpace))
                {
                    string key = endpoint.Path.ToLowerInvariant();
                    Get[key]  = _ => endpoint.Get(Context);
                    Post[key] = _ => endpoint.Post(Context);
                }
            }
        }
예제 #34
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => "Hello World it's " + DateTime.Now.ToLongTimeString();

            Get["/filtered", r => true] = x => "This is a route with a filter that always returns true.";

            Get["/filtered", r => false] = x => "This is also a route, but filtered out so should never be hit.";

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);

            Get["/test"] = x => "Test";

            Get["/error"] = x =>
            {
                throw new NotSupportedException("This is an exception thrown in a route.");
            };
        }
예제 #35
0
        protected SwaggerDocsModuleBase(IRouteCacheProvider routeCacheProvider,
                                        string title      = "API documentation",
                                        string apiVersion = "1.0",
                                        string host       = "localhost:5000",
                                        string apiBaseUrl = "/",
                                        params string[] schemes)
            : base()
        {
            this.routeCacheProvider = routeCacheProvider;
            this.title      = title;
            this.apiVersion = apiVersion;
            this.host       = host;
            this.apiBaseUrl = apiBaseUrl;
            this.schemes    = schemes;

            Get[apiBaseUrl] = r => GetDocumentation();
        }
예제 #36
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => "Hello World it's " + DateTime.Now.ToLongTimeString();

            Get["/filtered", r => true] = x => "This is a route with a filter that always returns true.";

            Get["/filtered", r => false] = x => "This is also a route, but filtered out so should never be hit.";

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);

            Get["/test"] = x => "Test";

            Get["/error"] = x =>
                {
                    throw new NotSupportedException("This is an exception thrown in a route.");
                };
        }
        protected SwaggerDocsModuleBase(IRouteCacheProvider routeCacheProvider, 
            string docsLocation = "/api/docs", 
            string title = "API documentation",
            string apiVersion = "1.0", 
            string host = "localhost:5000",
            string apiBaseUrl = "/", 
            params string[] schemes)
            : base(docsLocation)
        {
            this.routeCacheProvider = routeCacheProvider;
            this.title = title;
            this.apiVersion = apiVersion;
            this.host = host;
            this.apiBaseUrl = apiBaseUrl;
            this.schemes = schemes;

            Get["/"] = r => GetDocumentation();
        }
예제 #38
0
        public DocModule(IRouteCacheProvider cacheProvider) : base("/docs")
        {
            Get("/", _ =>
            {
                var metadata = cacheProvider.GetCache().RetrieveMetadata <CustomMetadata>().Where(w => w != null)
                               .ToList();

                return(Response.AsJson(metadata));
            });

            Get("/page", _ =>
            {
                var metaData = cacheProvider.GetCache().RetrieveMetadata <CustomMetadata>().Where(w => w != null)
                               .ToList();

                return(View["RouteInfo.html", metaData]);
            });
        }
예제 #39
0
 public SystemModule(IAppFolderInfo appFolderInfo,
                     IRuntimeInfo runtimeInfo,
                     IRouteCacheProvider routeCacheProvider,
                     IConfigFileProvider configFileProvider,
                     IMainDatabase database,
                     ILifecycleService lifecycleService)
     : base("system")
 {
     _appFolderInfo = appFolderInfo;
     _runtimeInfo = runtimeInfo;
     _routeCacheProvider = routeCacheProvider;
     _configFileProvider = configFileProvider;
     _database = database;
     _lifecycleService = lifecycleService;
     Get["/status"] = x => GetStatus();
     Get["/routes"] = x => GetRoutes();
     Post["/shutdown"] = x => Shutdown();
     Post["/restart"] = x => Restart();
 }
예제 #40
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => {
                return View["routes.cshtml", routeCacheProvider.GetCache()];
            };

            Get["/style/{file}"] = x => {
                return Response.AsCss("Content/" + (string)x.file);
            };

            Get["/scripts/{file}"] = x => {
                return Response.AsJs("Content/" + (string)x.file);
            };

            Get["/images/{file}"] = x =>
            {
                return Response.AsImage("Content/" + (string)x.file);
            };

            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => {
                return string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/dotliquid"] = parameters => {
                return View["dot", new { name = "dot" }];
            };

            Get["/javascript"] = x => {
                return View["javascript.html"];
            };

            Get["/static"] = x => {
                return View["static.htm"];
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor.cshtml", model];
            };

            Get["/razor-simple"] = x =>
            {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor-simple.cshtml", model];
            };

            Get["/razor-dynamic"] = x =>
            {
                return View["razor.cshtml", new { FirstName = "Frank" }];
            };

            Get["/ssve"] = x =>
            {
                var model = new RatPack { FirstName = "You" };
                return View["ssve.sshtml", model];
            };

            Get["/viewmodelconvention"] = x => {
                return View[new SomeViewModel()];
            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View["ndjango.django", model];
            };

            Get["/ndjango-extends"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View["with-master.django", model];
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View["spark.spark", model];
            };

            Get["/spark-anon"] = x =>
            {
                var model = new { FirstName = "Anonymous" };
                return View["anon.spark", model];
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };

            Get["/session"] = x => {
                var value = Session["moo"] ?? "";

                var output = "Current session value is: " + value;

                if (String.IsNullOrEmpty(value.ToString()))
                {
                    Session["moo"] = "I've created a session!";
                }

                return output;
            };

            Get["/sessionObject"] = x => {
                var value = Session["baa"] ?? "null";

                var output = "Current session value is: " + value;

                if (value.ToString() == "null")
                {
                    Session["baa"] = new Payload(27, true, "some random string value");
                }

                return output;
            };

            Get["/error"] = x =>
                {
                    throw new NotSupportedException("This is an exception thrown in a route.");
                };
        }
예제 #41
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            //Compiles but does not execute as expected under Mono 2.8
            //            Get["/"] = x => {
            //                return View.Razor("~/views/routes.cshtml", routeCacheProvider.GetCache());
            //            };

            Get["/"] = x => {
                var model = routeCacheProvider.GetCache().ToList();
                return View.Spark("~/views/routes.spark", model);
            };

            // TODO - implement filtering at the RouteDictionary GetRoute level
            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get["/redirect"] = x => {
                return Response.AsRedirect("http://www.google.com");
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/static"] = x => {
                return View.Static("~/views/static.htm");
            };

            //Compiles but does not execute as expected under Mono 2.8
            //            Get["/razor"] = x => {
            //                var model = new RatPack { FirstName = "Frank" };
            //                return View.Razor("~/views/razor.cshtml", model);
            //            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View.Django("~/views/ndjango.django", model);
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View.Spark("~/views/spark.spark", model);
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };

            //Call the following url to test
            //http://127.0.0.1:8080/access?oauth_token=11111111111111&oauth_verifier=2222222222222222
            //Dynamic cast is for Mono 2.8 only - Fixed in Mono 2.10 Preview
            Get["/access"] = x => {
                try{
                    return "Success: " + ((dynamic)Request.Query).oauth_token + "; " + ((dynamic)Request.Query).oauth_verifier;
                }
                catch {
                    return "Call as: /access?oauth_token=11111111111111&oauth_verifier=2222222222222222";
                }
            };
        }
 public ApiMetaDataGenerator(IRouteCacheProvider routeCacheProvider, IRouteMetadataProvider routeMetadataProvider, INancyModuleCatalog nancyModuleCatalog)
 {
     _routeCacheProvider = routeCacheProvider;
     _routeMetadataProvider = routeMetadataProvider;
     _nancyModuleCatalog = nancyModuleCatalog;
 }
예제 #43
0
 public ResourceLinker(IRouteCacheProvider routesProvider, IRouteSegmentExtractor extractor, IUriFilter queryFilter)
 {
   this.routesProvider = routesProvider;
   this.segmentExtractor = extractor;
   this.uriFilter = queryFilter;
 }
예제 #44
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => {
                return View.Razor("~/views/routes.cshtml", routeCacheProvider.GetCache());
            };

            Get["/style/{file}"] = x => {
                return Response.AsCss("~/Content/" + (string)x.file);
            };

            Get["/scripts/{file}"] = x => {
                return Response.AsJs("~/Content/" + (string)x.file);
            };

            // TODO - implement filtering at the RouteDictionary GetRoute level
            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => {
                return string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/javascript"] = x => {
                return View.Static("~/views/javascript.html");
            };

            Get["/static"] = x => {
                return View.Static("~/views/static.htm");
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View.Razor("~/views/razor.cshtml", model);
            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return SmartView("~/views/ndjango.django", model);
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View.Spark("~/views/spark.spark", model);
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };
        }
예제 #45
0
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x =>{
                return View["routes.cshtml", routeCacheProvider.GetCache()];
            };

            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => {
                return string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/dotliquid"] = parameters => {
                return View["dot", new { name = "dot" }];
            };

            Get["/javascript"] = x => {
                return View["javascript.html"];
            };

            Get["/static"] = x => {
                return View["static"];
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor.cshtml", model];
            };

            Get["/razor-simple"] = x =>
            {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor-simple.cshtml", model];
            };

            Get["/razor-dynamic"] = x =>
            {
                return View["razor.cshtml", new { FirstName = "Frank" }];
            };

            Get["/ssve"] = x =>
            {
                var model = new RatPack { FirstName = "You" };
                return View["ssve.sshtml", model];
            };

            Get["/viewmodelconvention"] = x => {
                return View[new SomeViewModel()];
            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View["ndjango.django", model];
            };

            Get["/ndjango-extends"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View["with-master.django", model];
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View["spark.spark", model];
            };

            Get["/spark-anon"] = x =>
            {
                var model = new { FirstName = "Anonymous" };
                return View["anon.spark", model];
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };

            Get["/session"] = x => {
                var value = Session["moo"] ?? "";

                var output = "Current session value is: " + value;

                if (String.IsNullOrEmpty(value.ToString()))
                {
                    Session["moo"] = "I've created a session!";
                }

                return output;
            };

            Get["/sessionObject"] = x => {
                var value = Session["baa"] ?? "null";

                var output = "Current session value is: " + value;

                if (value.ToString() == "null")
                {
                    Session["baa"] = new Payload(27, true, "some random string value");
                }

                return output;
            };

            Get["/error"] = x =>
                {
                    throw new NotSupportedException("This is an exception thrown in a route.");
                };

            Get["/customErrorHandler"] = _ => HttpStatusCode.ImATeapot;

            Get["/csrf"] = x => this.View["csrf", new { Blurb = "CSRF without an expiry using the 'session' token" }];

            Post["/csrf"] = x =>
            {
                this.ValidateCsrfToken();

                return string.Format("Hello {0}!", Request.Form.Name);
            };

            Get["/csrfWithExpiry"] = x =>
                {
                    // Create a new one because we have an expiry to check
                    this.CreateNewCsrfToken();

                    return this.View["csrf", new { Blurb = "You have 20 seconds to submit the page.. TICK TOCK :-)" }];
                };

            Post["/csrfWithExpiry"] = x =>
                {
                    this.ValidateCsrfToken(TimeSpan.FromSeconds(20));

                    return string.Format("Hello {0}!", Request.Form.Name);
                };
        }
예제 #46
0
파일: MainModule.cs 프로젝트: ToJans/Nancy
        public MainModule(IRouteCacheProvider routeCacheProvider)
        {
            Get["/"] = x => {
                return View["routes.cshtml", routeCacheProvider.GetCache()];
            };

            Get["/style/{file}"] = x => {
                return Response.AsCss("Content/" + (string)x.file);
            };

            Get["/scripts/{file}"] = x => {
                return Response.AsJs("Content/" + (string)x.file);
            };

            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => {
                return string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/javascript"] = x => {
                return View["~/views/javascript.html"];
            };

            Get["/static"] = x => {
                return View["~/views/static.htm"];
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View["~/views/razor.cshtml", model];
            };

            Get["/embedded"] = x => {
                var model = new RatPack { FirstName = "Embedded" };
                return View["embedded", model];
            };

            Get["/embedded2"] = x => {
                var model = new RatPack { FirstName = "Embedded2" };
                return View["embedded.django", model];
            };

            Get["/viewmodelconvention"] = x => {
                return View[new SomeViewModel()];
            };

            Get["/ndjango"] = x => {
                var model = new RatPack { FirstName = "Michael" };
                return View["~/views/ndjango.django", model];
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View["~/views/spark.spark", model];
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return Response.AsXml(model);
            };

            Get["session"] = x =>
                {
                    var value = Session["moo"] ?? "";

                    var output = "Current session value is: " + value;

                    if (String.IsNullOrEmpty(value.ToString()))
                    {
                        Session["moo"] = "I've created a session!";
                    }

                    return output;
                };

            Get["sessionObject"] = x =>
            {
                var value = Session["baa"] ?? "null";

                var output = "Current session value is: " + value;

                if (value.ToString() == "null")
                {
                    Session["baa"] = new Payload(27, true, "some random string value");
                }

                return output;
            };
        }
예제 #47
0
        public MainModule(IRouteCacheProvider routeCacheProvider, INancyEnvironment environment)
        {
            Get["/"] = x => {
                return View["routes", routeCacheProvider.GetCache()];
            };

            Get["/texts"] = parameters => {
                return (string)this.Context.Text.Menu.Home;
            };

            Get["/env"] = _ =>
            {
                return "From nancy environment: " + environment.GetValue<MyConfig>().Value;
            };

            Get["/meta"] = parameters =>
            {
                return Negotiate
                    .WithModel(routeCacheProvider.GetCache().RetrieveMetadata<MyRouteMetadata>())
                    .WithView("meta");
            };

            Get["/uber-meta"] = parameters =>
            {
                return Negotiate
                    .WithModel(routeCacheProvider.GetCache().RetrieveMetadata<MyUberRouteMetadata>().OfType<MyUberRouteMetadata>())
                    .WithView("uber-meta");
            };

            Get["/text"] = x =>
            {
                var value = (string)this.Context.Text.Menu.Home;
                return string.Concat("Value of 'Home' resource key in the Menu resource file: ", value);
            };

            Get["/negotiated"] = parameters => {
                return Negotiate
                    .WithModel(new RatPack {FirstName = "Nancy "})
                    .WithMediaRangeModel("text/html", new RatPack {FirstName = "Nancy fancy pants"})
                    .WithView("negotiatedview")
                    .WithHeader("X-Custom", "SomeValue");
            };

            Get["/user/{name}"] = parameters =>
            {
                return (string)parameters.name;
            };

            Get["/filtered", r => true] = x => {
                return "This is a route with a filter that always returns true.";
            };

            Get["/filtered", r => false] = x => {
                return "This is also a route, but filtered out so should never be hit.";
            };

            Get[@"/(?<foo>\d{2,4})/{bar}"] = x => {
                return string.Format("foo: {0}<br/>bar: {1}", x.foo, x.bar);
            };

            Get["/test"] = x => {
                return "Test";
            };

            Get["/nustache"] = parameters => {
                return View["nustache", new { name = "Nancy", value = 1000000 }];
            };

            Get["/dotliquid"] = parameters => {
                return View["dot", new { name = "dot" }];
            };

            Get["/javascript"] = x => {
                return View["javascript.html"];
            };

            Get["/static"] = x => {
                return View["static"];
            };

            Get["/razor"] = x => {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor.cshtml", model];
            };

            Get["/razor-divzero"] = x =>
            {
                var model = new { FirstName = "Frank", Number = 22 };
                return View["razor-divzero.cshtml", model];
            };

            Get["/razorError"] = x =>
            {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor-error.cshtml", model];
            };

            Get["/razor-simple"] = x =>
            {
                var model = new RatPack { FirstName = "Frank" };
                return View["razor-simple.cshtml", model];
            };

            Get["/razor-dynamic"] = x =>
            {
                return View["razor.cshtml", new { FirstName = "Frank" }];
            };

            Get["/razor-cs-strong"] = x =>
            {
                return View["razor-strong.cshtml", new RatPack { FirstName = "Frank" }];
            };

            Get["/razor-vb-strong"] = x =>
            {
                return View["razor-strong.vbhtml", new RatPack { FirstName = "Frank" }];
            };

            Get["/razor2"] = _ => new Razor2();

            Get["/ssve"] = x =>
            {
                var model = new RatPack { FirstName = "You" };
                return View["ssve.sshtml", model];
            };

            Get["/viewmodelconvention"] = x => {
                return View[new SomeViewModel()];
            };

            Get["/spark"] = x => {
                var model = new RatPack { FirstName = "Bright" };
                return View["spark.spark", model];
            };

            Get["/spark-anon"] = x =>
            {
                var model = new { FirstName = "Anonymous" };
                return View["anon.spark", model];
            };

            Get["/json"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return this.Response.AsJson(model);
            };

            Get["/xml"] = x => {
                var model = new RatPack { FirstName = "Andy" };
                return this.Response.AsXml(model);
            };

            Get["/session"] = x => {
                var value = Session["moo"] ?? "";

                var output = "Current session value is: " + value;

                if (String.IsNullOrEmpty(value.ToString()))
                {
                    Session["moo"] = "I've created a session!";
                }

                return output;
            };

            Get["/sessionObject"] = x => {
                var value = Session["baa"] ?? "null";

                var output = "Current session value is: " + value;

                if (value.ToString() == "null")
                {
                    Session["baa"] = new Payload(27, true, "some random string value");
                }

                return output;
            };

            Get["/error"] = x =>
                {
                    throw new NotSupportedException("This is an exception thrown in a route.");
                };

            Get["/customErrorHandler"] = _ => HttpStatusCode.ImATeapot;

            Get["/csrf"] = x => this.View["csrf", new { Blurb = "CSRF without an expiry using the 'session' token" }];

            Post["/csrf"] = x =>
            {
                this.ValidateCsrfToken();

                return string.Format("Hello {0}!", this.Request.Form.Name);
            };

            Get["/csrfWithExpiry"] = x =>
                {
                    // Create a new one because we have an expiry to check
                    this.CreateNewCsrfToken();

                    return this.View["csrf", new { Blurb = "You have 20 seconds to submit the page.. TICK TOCK :-)" }];
                };

            Post["/csrfWithExpiry"] = x =>
                {
                    this.ValidateCsrfToken(TimeSpan.FromSeconds(20));

                    return string.Format("Hello {0}!", this.Request.Form.Name);
                };

            Get["/viewNotFound"] = _ => View["I-do-not-exist"];

            Get["/fileupload"] = x =>
            {
                return View["FileUpload", new { Posted = "Nothing" }];
            };

            Post["/fileupload"] = x =>
            {
                var file = this.Request.Files.FirstOrDefault();

                string fileDetails = "Nothing";

                if (file != null)
                {
                    fileDetails = string.Format("{3} - {0} ({1}) {2}bytes", file.Name, file.ContentType, file.Value.Length, file.Key);
                }

                return View["FileUpload", new { Posted = fileDetails }];
            };

            Get["NamedRoute", "/namedRoute"] = _ => "I am a named route!";
        }
예제 #48
0
 public PomonaJsonResponseProcessor(IRouteCacheProvider routeCacheProvider)
     : base(routeCacheProvider)
 {
 }
 public FakeNancyModuleWithRouteCacheProviderDependency(IRouteCacheProvider routeCacheProvider)
 {
     RouteCacheProvider = routeCacheProvider;
 }
예제 #50
0
 public ResourceLinker(IRouteCacheProvider routesProvider)
 {
     this.routesProvider = routesProvider;
 }
 public DefaultSwaggerMetadataProvider(IRouteCacheProvider routeCacheProvider, ISwaggerModelCatalog modelCatalog, ISwaggerTagCatalog tagCatalog)
 {
     this.routeCacheProvider = routeCacheProvider;
     this.modelCatalog = modelCatalog;
     this.tagCatalog = tagCatalog;
 }