public Routes GetAllRoutes() { Routes routes = new Routes(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT * FROM Routes ")); SelectResponse response = client.Select(request); foreach (Item item in response.SelectResult.Item) { string value = item.Attribute.GetValueByName("Id"); Route route = new Route { Id = Guid.Parse(item.Attribute.GetValueByName("Id")), Distance = item.Attribute.GetDoubleValueByName("Distance"), LastTimeRidden = item.Attribute.GetDateTimeValueByName("LastTimeRidden"), Name = item.Attribute.GetValueByName("Name"), Location = item.Attribute.GetValueByName("Location"), }; routes.Add(route); } } return routes; }
private HashSet <CitySquareDist> NearbyTiles(int nearbyDist) { Dictionary <CitySquare, CitySquareDist> nearbyTiles = new Dictionary <CitySquare, CitySquareDist>(); HashSet <CitySquare> tilesToSearch = new HashSet <CitySquare>(); Routes.Add(this, new Route(this)); foreach (CitySquare tile in this.Neighbors) { nearbyTiles.Add(tile, new CitySquareDist(1, tile, true)); if (tile != this) { tilesToSearch.Add(tile); } Routes.Add(tile, new Route(tile)); } // Do a breadth first search to create routes to squares within nearby dist of the square for (int dist = 2; dist <= nearbyDist && tilesToSearch.Count > 0; dist++) { HashSet <CitySquare> nextTilesToSearch = new HashSet <CitySquare>(); foreach (CitySquare tile in tilesToSearch) { foreach (CitySquare neighborTile in tile.Neighbors) { bool hasRoadAccess = nearbyTiles[tile].roadAccess && tile.HasRoad; if (neighborTile != this) { // Tiles that are very nearby don't need road access to be searched, they can still provide pollution if (!nearbyTiles.ContainsKey(neighborTile) && (dist <= 7 || hasRoadAccess)) { nearbyTiles.Add(neighborTile, new CitySquareDist(dist, neighborTile, hasRoadAccess)); nextTilesToSearch.Add(neighborTile); } else if (hasRoadAccess && !nearbyTiles[neighborTile].roadAccess) { CitySquareDist neighbor = nearbyTiles[neighborTile]; neighbor.roadAccess = true; neighbor.driveDistance = dist; nextTilesToSearch.Add(neighbor.tile); } if (hasRoadAccess && !Routes.ContainsKey(neighborTile)) { addRoute(tile, neighborTile); } } } } tilesToSearch = nextTilesToSearch; } Commutes = new List <Route>(Routes.Values); Commutes.Sort(); return(new HashSet <CitySquareDist>(nearbyTiles.Values)); }
/// <summary> /// Application specific configuration /// This method should initialize any IoC resources utilized by your web service classes. /// </summary> /// <param name="container"></param> public override void Configure(Container container) { //Config examples //this.Plugins.Add(new PostmanFeature()); //Plugins.Add(new CorsFeature()); InitializeAppSettings(); SetConfig(new HostConfig { DebugMode = true, EmbeddedResourceBaseTypes = { typeof(AppHost), typeof(SharedEmbeddedResources) } }); Plugins.Add(new ServerEventsFeature()); SetConfig(new HostConfig { DebugMode = AppSettings.Get("DebugMode", false), DefaultContentType = MimeTypes.Json, AddRedirectParamsToQueryString = true, UseCamelCase = true, }); CustomErrorHttpHandlers.Remove(HttpStatusCode.Forbidden); //Register all Authentication methods you want to enable for this web app. Plugins.Add(new AuthFeature( () => new AuthUserSession(), new IAuthProvider[] { new TwitterAuthProvider(AppSettings) //Sign-in with Twitter })); container.RegisterAutoWiredAs <MemoryChatHistory, IChatHistory>(); var redisHost = AppSettings.GetString("RedisHost"); if (redisHost != null) { container.Register <IRedisClientsManager>(new RedisManagerPool(redisHost)); container.Register <IServerEvents>(c => new RedisServerEvents(c.Resolve <IRedisClientsManager>())); container.Resolve <IServerEvents>().Start(); } // This route is added using Routes.Add and ServiceController.RegisterService due to // using ILMerge limiting our AppHost : base() call to one assembly. // If two assemblies are used, the base() call searchs the same assembly twice due to the ILMerged result. Routes.Add <NativeHostAction>("/nativehost/{Action}"); ServiceController.RegisterService(typeof(NativeHostService)); }
public override void Configure(Container container) { //Signal advanced web browsers what HTTP Methods you accept base.SetConfig(new HostConfig { GlobalResponseHeaders = { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, }, WsdlServiceNamespace = "http://www.servicestack.net/types", LogFactory = new ConsoleLogFactory(), DebugMode = true, }); this.RegisterRequestBinder <CustomRequestBinder>( httpReq => new CustomRequestBinder { IsFromBinder = true }); Routes .Add <Movies>("/custom-movies", "GET") .Add <Movies>("/custom-movies/genres/{Genre}") .Add <Movie>("/custom-movies", "POST,PUT") .Add <Movie>("/custom-movies/{Id}") .Add <GetFactorial>("/fact/{ForNumber}") .Add <MoviesZip>("/all-movies.zip") .Add <GetHttpResult>("/gethttpresult") ; container.Register <IAppSettings>(new AppSettings()); container.Register(c => new ExampleConfig(c.Resolve <IAppSettings>())); //var appConfig = container.Resolve<ExampleConfig>(); container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider)); var resetMovies = container.Resolve <ResetMoviesService>(); resetMovies.Post(null); //var movies = container.Resolve<IDbConnectionFactory>().Exec(x => x.Select<Movie>()); //Console.WriteLine(movies.Dump()); if (ConfigureFilter != null) { ConfigureFilter(container); } Plugins.Add(new RequestInfoFeature()); }
public override void Configure(Funq.Container container) { Routes.Add <Hello>("/hello") .Add <Hello>("/hello/{Name}"); Routes.Add <Files>("/fileupload/{Name}") .Add <Files>("/fileupload"); Routes.Add <CookieInfo>("/cookie") .Add <CookieInfo>("/cookie/{Name}"); Routes.Add <Redirect>("/redirector") .Add <Redirect>("/redirector/redirected"); Routes.Add <SomeData>("/data") .Add <SomeData>("/data/{Id}"); }
public override void Configure(Funq.Container container) { //Set JSON web services to return idiomatic JSON camelCase properties ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; //Register Redis factory in Funq IOC container.Register <IRedisClientsManager>(new BasicRedisClientManager("localhost:6379")); //Register user-defined REST Paths Routes .Add <Todo>("/todos") .Add <Todo>("/todos/{Id}"); }
private void AddRouteForType(Type needsToBeRouted) { var routeName = RouteTokenOfType(needsToBeRouted); var route = ServiceRouteByRouteName(routeName); // dont add if we can already find it in the list of routes (is this possible?) if (route != null) { return; } route = RouteOfType(needsToBeRouted, routeName); Routes.Add(route); }
public override void Configure(Container container) { SetConfig(new HostConfig { RequestRules = { { "CustomAcceptsCsv", httpReq => httpReq.Accept?.IndexOf(MimeTypes.Csv) >= 0 }, }, AdminAuthSecret = "secretz" }); Routes.Add(typeof(MatchesCsv), "/matches/csv", null, null, null, matches: "CustomAcceptsCsv"); }
// Configure the container with the necessary routes for your ServiceStack application. public override void Configure(Container container) { //Configure ServiceStack Json web services to return idiomatic Json camelCase properties. JsConfig.EmitCamelCaseNames = true; //Register Redis factory in Funq IoC. The default port for Redis is 6379. container.Register <IRedisClientsManager>(new BasicRedisClientManager("localhost:6379")); //Register user-defined REST Paths using the fluent configuration API Routes .Add <Todo>("/todos") .Add <Todo>("/todos/{Id}"); }
public ServiceAppHost() : base("Order Management", typeof(ServiceAppHost).Assembly) { Routes .Add <GetProducts>("/products", "GET", "Returns a collection of Products") .Add <GetProduct>("/products/{Id}", "GET", "Returns a single Product") .Add <CreateProduct>("/products", "POST", "Create a product") .Add <UpdateProduct>("/products/{Id}", "PUT", "Update a product") .Add <DeleteProduct>("/products/{Id}", "DELETE", "Deletes a product") .Add <DeleteProduct>("/products", "DELETE", "Deletes all products"); Plugins.Add(new ValidationFeature()); }
public IReverseProxyRouteBuilder MapRoute(string routeTemplate, Func <RouteData, Uri> handler) { var route = new Route( new ReverseProxyRouteHandler(handler), routeTemplate, defaults: null, constraints: null, dataTokens: null, inlineConstraintResolver: GetConstraintResolver(this)); Routes.Add(route); return(this); }
void RegisterRoutes() { Routes.Add("monkeydetails", typeof(MonkeyDetailPage)); Routes.Add("beardetails", typeof(BearDetailPage)); Routes.Add("catdetails", typeof(CatDetailPage)); Routes.Add("dogdetails", typeof(DogDetailPage)); Routes.Add("elephantdetails", typeof(ElephantDetailPage)); foreach (var item in Routes) { Routing.RegisterRoute(item.Key, item.Value); } }
public POTI(EndianBinaryReader er) { Signature = er.ReadString(Encoding.ASCII, 4); if (Signature != "ITOP") { throw new SignatureNotCorrectException(Signature, "ITOP", er.BaseStream.Position - 4); } NrRoutes = er.ReadUInt16(); NrPoints = er.ReadUInt16(); for (int i = 0; i < NrRoutes; i++) { Routes.Add(new POTIRoute(er)); } }
public override void Configure(Container container) { this.RequestFilters.Add((req, res, dto) => { var requestFilter = dto as RequestFilter; if (requestFilter != null) { res.StatusCode = requestFilter.StatusCode; if (!requestFilter.HeaderName.IsNullOrEmpty()) { res.AddHeader(requestFilter.HeaderName, requestFilter.HeaderValue); } res.Close(); } var secureRequests = dto as IRequiresSession; if (secureRequests != null) { res.ReturnAuthRequired(); } }); this.Container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory( "~/App_Data/db.sqlite".MapHostAbsolutePath(), SqliteOrmLiteDialectProvider.Instance)); this.Container.Register <ICacheClient>(new MemoryCacheClient()); var dbFactory = this.Container.Resolve <IDbConnectionFactory>(); dbFactory.Exec(dbCmd => dbCmd.CreateTable <Movie>(true)); Routes .Add <Movies>("/custom-movies", "GET") .Add <Movies>("/custom-movies/genres/{Genre}") .Add <Movie>("/custom-movies", "POST,PUT") .Add <Movie>("/custom-movies/{Id}"); var resetMovies = this.Container.Resolve <ResetMoviesService>(); resetMovies.Post(null); //var onlyEnableFeatures = Feature.All.Remove(Feature.Jsv | Feature.Soap); //SetConfig(new EndpointHostConfig //{ // EnableFeatures = onlyEnableFeatures, // DebugMode = true, //Show StackTraces for easier debugging //}); }
public override void Configure(Container container) { SetConfig(new HostConfig { DebugMode = true, EmbeddedResourceBaseTypes = { typeof(AppHost), typeof(SharedEmbeddedResources) }, UseCamelCase = true, }); Plugins.Add(new SharpPagesFeature()); Routes.Add <NativeHostAction>("/nativehost/{Action}"); ServiceController.RegisterService(typeof(NativeHostService)); }
public override void Configure(Container container) { Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() })); Plugins.Add(new RegistrationFeature()); container.Register <ICacheClient>(new MemoryCacheClient()); var userRep = new BasicAuthImpl(); container.Register <IUserAuthRepository>(userRep); Routes .Add <MessageReceived>("/SmsIncoming"); EndpointConfig.ConfigureNServiceBus(); Container.Register(b => EndpointConfig.Bus); }
/// <summary> /// Application specific configuration /// This method should initialize any IoC resources utilized by your web service classes. /// </summary> /// <param name="container"></param> public override void Configure(Container container) { //Config examples //this.Plugins.Add(new PostmanFeature()); //Plugins.Add(new CorsFeature()); SetConfig(new HostConfig { DebugMode = true, EmbeddedResourceBaseTypes = { typeof(AppHost), typeof(SharedEmbeddedResources) } }); Routes.Add <NativeHostAction>("/nativehost/{Action}"); ServiceController.RegisterService(typeof(NativeHostService)); }
public HeadCommandsConfig() { Port = SampleApiServerPorts.HeadCommandTests; Routes.Add(new DynamicSampleApiServerRoute("HEAD", "", context => { context.Response.Headers.Add("X-HTTPREPL-TESTHEADER", "Header value for root HEAD request."); return(Task.CompletedTask); })); Routes.Add(new DynamicSampleApiServerRoute("HEAD", "this/is/a/test/route", context => { context.Response.Headers.Add("X-HTTPREPL-TESTHEADER", "Header value for HEAD request with route."); return(Task.CompletedTask); })); }
public override void Configure(Container container) { container.Adapter = new AutofacIocAdapter(_container); SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" }); Routes .Add <QualityProfileModel>("/qualityprofiles") .Add <QualityProfileModel>("/qualityprofiles/{Id}") .Add <QualityTypeModel>("/qualitytypes") .Add <QualityTypeModel>("/qualitytypes/{Id}"); Bootstrapper.Initialize(); }
public override void Configure(Funq.Container container) { container.Register(PageManager.Default); Plugins.Add(new MarkdownFormat { MarkdownBaseType = typeof(CustomMarkdownPage) }); Routes .Add <Page>("/pages") .Add <Page>("/pages/{Name}") .Add <Category>("/category/{Name}") .Add <Search>("/search") .Add <Search>("/search/{Query}"); }
public override void Configure(Container container) { container.Adapter = iocAdapter = new IocAdapter(); container.Register(c => new FunqDepCtor()); container.Register(c => new FunqDepProperty()); container.Register(c => new FunqDepDisposableProperty()); container.Register(c => new FunqSingletonScope()).ReusedWithin(ReuseScope.Default); container.Register(c => new FunqRequestScope()).ReusedWithin(ReuseScope.Request); container.Register(c => new FunqNoneScope()).ReusedWithin(ReuseScope.None); container.Register(c => new FunqRequestScopeDepDisposableProperty()).ReusedWithin(ReuseScope.Request); Routes.Add <Ioc>("/ioc"); Routes.Add <IocScope>("/iocscope"); }
protected void ConfigureMessageServiceForReports <T>(Funq.Container container) where T : Reports.Dto.ReportDataRequestDto { Routes.Add <T>("/GetReportData"); container.Resolve <IMessageService>().RegisterHandler <T>(m => { var req = new BasicRequest { Verb = HttpMethods.Post }; req.Headers["X-ss-id"] = m.GetBody().SessionId; var response = ExecuteMessage(m, req); return(response); }); }
public ServerRouteConfig(IAppRouteConfig appRouteConfig) { _routes = new Dictionary <HttpRequestMethod, Dictionary <string, IRoutingContext> >(); var reqMethods = Enum .GetValues(typeof(HttpRequestMethod)) .Cast <HttpRequestMethod>(); foreach (var reqMethod in reqMethods) { Routes.Add(reqMethod, new Dictionary <string, IRoutingContext>()); } _InitializeServerConfig(appRouteConfig); }
public override void Configure(Funq.Container container) { //Set JSON web services to return idiomatic JSON camelCase properties ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; //Configure User Defined REST Paths Routes.Add <ItemRequest>("/Item/{ItemID}"); //Uncomment to change the default ServiceStack configuration //SetConfig(new HostConfig { //}); //Enable Authentication //ConfigureAuth(container); }
public static void RegisterRoutes(Type type) { IEnumerable <MethodInfo> methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(x => x.GetCustomAttributes().Any(a => a.GetType() == typeof(RouteAttribute))); foreach (MethodInfo method in methods) { CustomAttributeData attribute = method.CustomAttributes.First(x => x.AttributeType == typeof(RouteAttribute)); Route route = new Route { Method = method, Url = attribute.ConstructorArguments[1].Value.ToString(), Verb = (HttpVerb)attribute.ConstructorArguments[0].Value, }; Routes.Add(route); } }
public override void Configure(Container container) { SetConfig(new HostConfig { DebugMode = true, EmbeddedResourceBaseTypes = { typeof(AppHost), typeof(SharedEmbeddedResources) }, UseCamelCase = true, }); // This route is added using Routes.Add and ServiceController.RegisterService due to // using ILMerge limiting our AppHost : base() call to one assembly. // If two assemblies are used, the base() call searchs the same assembly twice due to the ILMerged result. Routes.Add <NativeHostAction>("/nativehost/{Action}"); ServiceController.RegisterService(typeof(NativeHostService)); }
void RegisterRoutes() { Routes.Add("pizzadetails", typeof(DishDetailPage)); Routes.Add("drinksdetails", typeof(DishDetailPage)); Routes.Add("snacksdetails", typeof(DishDetailPage)); Routes.Add("otherdetails", typeof(DishDetailPage)); Routes.Add("regdetails", typeof(RegPage)); Routes.Add("authdetails", typeof(AuthPage)); foreach (var item in Routes) { Routing.RegisterRoute(item.Key, item.Value); } }
/// <summary> /// Loads all IController types from the assembly and searches route info in all types. /// </summary> public void CreateRoutes(Assembly assembly = null) { RouteBuilder builder = new RouteBuilder(); Type interfaceType = typeof(IController); List <Assembly> assemblies = new List <Assembly>(); if (assembly == null) { Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly == null) { throw new ArgumentNullException("Entry Assembly could not be found"); } assemblies.Add(entryAssembly); assemblies.AddRange(entryAssembly.GetReferencedAssemblies().Select(Assembly.Load)); } else { assemblies.Add(assembly); } List <Type> types = assemblies .SelectMany(x => x.GetTypes()) .Where(type => interfaceType.IsAssignableFrom(type)) .ToList(); foreach (Type type in types) { if (type.IsInterface) { continue; } if (type.IsAssignableFrom(typeof(TwinoController)) && typeof(TwinoController).IsAssignableFrom(type)) { continue; } IEnumerable <RouteLeaf> routes = builder.BuildRoutes(type); foreach (RouteLeaf route in routes) { Routes.Add(route); } } }
public void MapCorrect() { Routes.Clear(); Routes.Add(new Route( routeTemplate: "/calculator/add/{operand1}/{operand2}", action: typeof(Calculator).GetMethod("Add"))); Routes.Add(new Route( routeTemplate: "/calculator/subtract/{operand1}/{operand2}", action: typeof(Calculator).GetMethod("Subtract"))); Routes.Add(new Route( routeTemplate: "/calculator/divide/{operand1}/{operand2}", action: typeof(Calculator).GetMethod("Divide"))); }
public void LoadRoutes(IEnumerable <Assembly> assemblies) { if (assemblies == null) { throw new ArgumentNullException(nameof(assemblies)); } Routes.Clear(); foreach (var routeAttr in assemblies.SelectMany(a => a.GetCustomAttributes <MvxNavigationAttribute>())) { Routes.Add(new Regex(routeAttr.UriRegex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline), routeAttr.ViewModelOrFacade); } }
/// <summary> /// Base constructor requires a Name and Assembly where web service implementation is located /// </summary> public AppHost() : base("SP_Task1", typeof(BusinessPartnerService).Assembly) { Routes.Add <GetBusinessPartners>("/partners", ApplyTo.Get); Routes.Add <GetBusinessPartner>("/partners/{Id}", ApplyTo.Get); Routes.Add <CreateBusinessPartner>("/partners", ApplyTo.Post); Routes.Add <UpdateBusinessPartner>("/partners/{Id}", ApplyTo.Put); Routes.Add <DeleteBusinessPartner>("/partners/{Id}", ApplyTo.Delete); Routes.Add <GetInvoice>("/invoices/{Id}", ApplyTo.Get); Routes.Add <CreateInvoice>("/invoices", ApplyTo.Post); Routes.Add <PatchInvoice>("/invoices/{Id}", ApplyTo.Patch); Routes.Add <GetPurchaseOrder>("/pos/{Id}", ApplyTo.Get); Routes.Add <CreatePurchaseOrder>("/pos", ApplyTo.Post); }
public Routes GetAllRoutes() { Routes routes = new Routes(); foreach (Route route in stubData) { routes.Add(route); } return routes; }