public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); // Start the API server var restRouteHandler = new RestRouteHandler(); try { restRouteHandler.RegisterController <RoasterController>(); restRouteHandler.RegisterController <ProfileController>(); restRouteHandler.RegisterController <LogController>(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } var configuration = new HttpServerConfiguration() .ListenOnPort(9900) .RegisterRoute("api", restRouteHandler) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public void GivenMultipleRouteHandlersAreBeingAddedWithTheSamePrefix_ThenAnExceptionShouldBeThrown() { var configuration = new HttpServerConfiguration() .RegisterRoute("api", new EchoRouteHandler()); Assert.ThrowsException <Exception>(() => configuration.RegisterRoute("api", new EchoRouteHandler())); }
public async void Run(IBackgroundTaskInstance taskInstance) { _Deferral = taskInstance.GetDeferral(); var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <RestControllers.Query>(); restRouteHandler.RegisterController <RestControllers.Relays>(); restRouteHandler.RegisterController <RestControllers.Timers>(); restRouteHandler.RegisterController <RestControllers.Lights>(); var configuration = new HttpServerConfiguration() .ListenOnPort(81) .RegisterRoute(new StaticFileRouteHandler(@"web")) .RegisterRoute("api", restRouteHandler) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); // Initialize the database Database.Active = new Database(); GpioControlCenter.Active = new GpioControlCenter(); RelayControlCenter.Active = new RelayControlCenter(); LoadLastStates(); // Start the lights control center LightsControlCenter.Active = new LightsControlCenter(); // Start the timer controler TimersControlCenter.Active = new TimersControlCenter(); }
/// <summary> /// Creates a rest api endpoint for direct TCP communication. /// </summary> /// <param name="tcpPort">The tcp port to listen on.</param> async void InitializeRestApi(int tcpPort) { Debug.WriteLine("Initializing Rest Api"); try { var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <DiscoveryController>(this); var configuration = new HttpServerConfiguration() .ListenOnPort(tcpPort) .RegisterRoute("discovery", restRouteHandler) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); } catch (Exception ex) { Debug.WriteLine(ex); } Debug.WriteLine($"Initializing Rest Api Completed"); Debug.WriteLine($"http://{IpAddress}:{tcpPort}/discovery"); }
private async Task startWebServer() { var restRouteHandler = new RestRouteHandler(); try { restRouteHandler.RegisterController <DoorDetectorDashBoardController>(service); } catch (Exception ex) { throw new Exception("failed to register controller", ex); } var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Web")) .EnableCors(); this.httpServer = new HttpServer(configuration); Debug.WriteLine("BeforeStartServerAsync"); try { await httpServer.StartServerAsync(); } catch (Exception ex) { throw new Exception("failed to start WebServer", ex); } }
/// <remarks> /// If you start any asynchronous methods here, prevent the task /// from closing prematurely by using BackgroundTaskDeferral as /// described in http://aka.ms/backgroundtaskdeferral /// </remarks> public async void Run(IBackgroundTaskInstance taskInstance) { // This deferral should have an instance reference, if it doesn't... the GC will // come some day, see that this method is not active anymore and the local variable // should be removed. Which results in the application being closed. _deferral = taskInstance.GetDeferral(); var authProvider = new BasicAuthorizationProvider("Please login", new DemoCredentialValidator()); var restRouteHandler = new RestRouteHandler(authProvider); restRouteHandler.RegisterController <AsyncControllerSample>(); restRouteHandler.RegisterController <FromContentControllerSample>(); restRouteHandler.RegisterController <AuthenticatedPerCallControllerSample>(); restRouteHandler.RegisterController <PerCallControllerSample>(); restRouteHandler.RegisterController <SimpleParameterControllerSample>(); restRouteHandler.RegisterController <SingletonControllerSample>(); restRouteHandler.RegisterController <ThrowExceptionControllerSample>(); restRouteHandler.RegisterController <WithResponseContentControllerSample>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web", authProvider)) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); // Dont release deferral, otherwise app will stop }
private void OnTest() { var webSocketRouteHandler = new WebSocketRouteHandler <WebSocketConnection>(); var webSocketRouteHandler2 = new WebSocketRouteHandler <WebSocketConnection>(); var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <ParameterController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute("ws", webSocketRouteHandler) .RegisterRoute("ws2", webSocketRouteHandler2) .EnableCors(); var httpServer = new HttpServer(configuration); var task = httpServer.StartServerAsync(); Task.Run(async() => { var dp = new DataPush(); while (true) { dp.dt = DateTime.Now.ToString(); var j = Newtonsoft.Json.JsonConvert.SerializeObject(dp); await webSocketRouteHandler.SendAsync(j); await Task.Delay(20); } }); }
public FluentHttpServerTests() { _configuration = new HttpServerConfiguration(); _httpServer = new HttpServer(_configuration); _responses = new List <HttpServerResponse>(); _routeHandlers = new Dictionary <string, EchoRouteHandler>(); }
private async Task InitializeWebServer() { var authProvider = new BasicAuthorizationProvider("Please login", new DemoCredentialValidator()); var restRouteHandler = new RestRouteHandler(authProvider); restRouteHandler.RegisterController <AsyncControllerSample>(); restRouteHandler.RegisterController <FromContentControllerSample>(); restRouteHandler.RegisterController <PerCallControllerSample>(); restRouteHandler.RegisterController <AuthenticatedPerCallControllerSample>(); restRouteHandler.RegisterController <SimpleParameterControllerSample>(); restRouteHandler.RegisterController <SingletonControllerSample>(); restRouteHandler.RegisterController <ThrowExceptionControllerSample>(); restRouteHandler.RegisterController <WithResponseContentControllerSample>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web", authProvider)) .EnableCors(); // allow cors requests on all origins //.EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); // Don't release deferral, otherwise app will stop }
public WebApiInstaller(Assembly[] scanAssemblies, Type[] addControllers, Type[] removeControllers, HttpServerConfiguration httpServerConfiguration) { if (scanAssemblies == null) { throw new ArgumentNullException(nameof(scanAssemblies)); } if (addControllers == null) { throw new ArgumentNullException(nameof(addControllers)); } if (removeControllers == null) { throw new ArgumentNullException(nameof(removeControllers)); } if (httpServerConfiguration == null) { throw new ArgumentNullException(nameof(httpServerConfiguration)); } _scanAssemblies = scanAssemblies; _addControllers = addControllers; _removeControllers = removeControllers; _httpServerConfiguration = httpServerConfiguration; }
public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); HttpServerConfiguration.Configure(config); app.UseWebApi(config); }
public void GivenMultipleRouteHandlersAreBeingAddedOnTheCatchAllRoute_ThenAnExceptionShouldBeThrown() { var configuration = new HttpServerConfiguration(); configuration.RegisterRoute(new EchoRouteHandler()); Assert.ThrowsException <Exception>(() => configuration.RegisterRoute(new EchoRouteHandler())); }
internal void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); HttpServerConfiguration.Configure(config); Container = (config.DependencyResolver as MyDependencyResolver).GetContainer() as SimpleIocContainer; app.UseWebApi(config); }
async Task InitServer() { var configuration = new HttpServerConfiguration() .ListenOnPort(4200) .RegisterRoute(new StaticFileRouteHandler("Web")) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public SelfHostedServer() { var config = new HttpSelfHostConfiguration(BaseAddress); HttpServerConfiguration.Configure(config); // ReSharper disable once PossibleNullReferenceException Container = (config.DependencyResolver as MyDependencyResolver).GetContainer() as SimpleIocContainer; server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); }
public InMemoryServer() { var config = new HttpConfiguration(); HttpServerConfiguration.Configure(config); // ReSharper disable once PossibleNullReferenceException Container = (config.DependencyResolver as MyDependencyResolver).GetContainer() as SimpleIocContainer; var server = new HttpServer(config); messageInvoker = new HttpMessageInvoker(new InMemoryHttpContentSerializationHandler(server)); }
public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); // Start the HTTP server var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute(new StaticFileRouteHandler(@"Web")) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public async Task ListenAsync(int port, string routePrefix) { RestRouteHandler restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <BoardsController>(); restRouteHandler.RegisterController <BulbsController>(); HttpServerConfiguration configuration = new HttpServerConfiguration() .ListenOnPort(port) .RegisterRoute(routePrefix, restRouteHandler) .EnableCors(); HttpServer httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public async Task Run() { var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <HomeController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(5000) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"myfoodapp.WebServer\Web")) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public async void Run(IBackgroundTaskInstance taskInstance) { // // TODO: Insert code to perform background work // // If you start any asynchronous methods here, prevent the task // from closing prematurely by using BackgroundTaskDeferral as // described in http://aka.ms/backgroundtaskdeferral // var restRouteHandler = new RestRouteHandler(); try { _deferral = taskInstance.GetDeferral(); // initialize sqlite context await Context.Initialize(); restRouteHandler.RegisterController <SensorTemperatureValueControler>(); restRouteHandler.RegisterController <SensorHumidityValueController>(); restRouteHandler.RegisterController <SensorPressureValueController>(); restRouteHandler.RegisterController <SensorsController>(); restRouteHandler.RegisterController <SensorValuesController>(); restRouteHandler.RegisterController <SensorOnOffValueController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) // .RegisterRoute(new StaticFileRouteHandler(@"wola.ha\wola.ha.view.web\Web")) .RegisterRoute(new StaticFileRouteHandler(@"wola.ha.view.web\Web")) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; // LogManager.SetLogFactory(new DebugLogFactory()); await httpServer.StartServerAsync(); } catch (Exception ex) { throw ex; } }
/// <remarks> /// If you start any asynchronous methods here, prevent the task /// from closing prematurely by using BackgroundTaskDeferral as /// described in http://aka.ms/backgroundtaskdeferral /// </remarks> public async void Run(IBackgroundTaskInstance taskInstance) { try { //We need to create database tables to run application //SQLiteDBHelper.CreateDatabase(); //DBLogger.Log(LogType.Information, "Application started"); // This deferral should have an instance reference, if it doesn't... the GC will // come some day, see that this method is not active anymore and the local variable // should be removed. Which results in the application being closed. //Get raspeberryPi mac address FileLogger.Log(LogType.Information, "Application Started..."); _myRaspberryMacAddress = Utility.GetMacAddress();//await GetMAC(); _deferral = taskInstance.GetDeferral(); var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <ParameterController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) // .RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web")) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); //DBLogger.Log(LogType.Information, "ServerStarted"); //var startTimeSpan = TimeSpan.Zero; //var periodTimeSpan = TimeSpan.FromMinutes(1); //var stateTimer = new Timer(UpdateIpAsync, null, TimeSpan.Zero, TimeSpan.FromMinutes(1)); startTriggerIpUpdate(); // Dont release deferral, otherwise app will stop } catch (Exception ex) { FileLogger.Log(LogType.Error, ex.Message); } }
public async void Run(IBackgroundTaskInstance taskInstance) { _deferral = taskInstance.GetDeferral(); //register controller var module = new ModuleController().RegisterModule(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", module) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); }
public async void start(int port, string root, bool localOnly, bool keepAlive) { this.port = port; this.www_root = root.Replace('/', '\\'); this.localhost_only = localOnly; this.keep_alive = keepAlive; var configuration = new HttpServerConfiguration() .ListenOnPort(port) .RegisterRoute(new StaticFileRouteHandler(www_root)) .EnableCors(); LogManager.SetLogFactory(new DebugLogFactory()); server = new HttpServer(configuration); await server.StartServerAsync(); }
private static void EnsureConfig(HttpServerConfiguration config) { if (config == null) { throw new UriFormatException("missing config"); } if (string.IsNullOrEmpty(config.AbsolutePath) || string.IsNullOrWhiteSpace(config.AbsolutePath)) { throw new UriFormatException("missing absolute path"); } if (!config.AbsolutePath.StartsWith("/")) { throw new UriFormatException("absolute path must start with forward slash"); } }
public HttpServer(HttpServerConfiguration config) { EnsureConfig(config); _listener = new HttpListener(); ApplyConfiguration(config); var schema = _sslEnabled ? "https://" : "http://"; var host = _dnsEndPoint.Host; var port = _dnsEndPoint.Port != 80 ? ":" + _dnsEndPoint.Port : string.Empty; _listenerUrl = new Uri($"{schema}{host}{port}{config.AbsolutePath}").AbsoluteUri; _listenerUrl += _listenerUrl[_listenerUrl.Length - 1] != '/' ? "/" : string.Empty; _listener.Prefixes.Add(_listenerUrl); }
internal WebApiConfiguration(ApplicationConfiguration application) { if (application == null) { throw new ArgumentNullException(nameof(application)); } Application = application.Hosts(hosts => hosts.Host <WebApiHost>()); _scan = new List <Assembly>(); _add = new List <Type>(); _remove = new List <Type>(); _httpServerConfiguration = new HttpServerConfiguration(); // scan own assembly AddFromAssemblyOfThis <WebApiConfiguration>(); }
private async Task StartWebserverAsync() { // start local webserver var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <HueController>(_device.HttpServerIpAddress, _device.HttpServerPort, _device.HttpServerOptionalSubFolder, _device.HueUuid, _device.HueSerialNumber); var configuration = new HttpServerConfiguration() .ListenOnPort(80) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Web")) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await _httpServer.StartServerAsync(); }
public async Task Run() { var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <ConfigController>(); restRouteHandler.RegisterController <OverViewDataController>(); restRouteHandler.RegisterController <MeasuredDataController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8888) .RegisterRoute("api", restRouteHandler) .EnableCors(); var httpServer = new HttpServer(configuration); await httpServer.StartServerAsync(); Log.Info("started"); // now make sure the app won't stop after this (eg use a BackgroundTaskDeferral) }
public async Task StartWebserverAsync() { // start local webserver var authProvider = new BasicAuthorizationProvider("Login", new FixedCredentialsValidator()); var restRouteHandler = new RestRouteHandler(authProvider); restRouteHandler.RegisterController <QueueController>(_loggerFactory); var configuration = new HttpServerConfiguration() .ListenOnPort(80) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Web")) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await _httpServer.StartServerAsync(); }
private async Task InitializeWebServer() { var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController <HomeAlarmController>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) //.RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web")) .EnableCors(); // allow cors requests on all origins //.EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); // Don't release deferral, otherwise app will stop }
public HttpServerConfigurator() { Configuration = new HttpServerConfiguration(); }