Exemplo n.º 1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Get the deferral and save it to local variable so that the app stays alive
            this.backgroundTaskDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += TaskCanceled;

            //  Setup system logging
            logProvider.Add(systemDebugLogger, new NamespaceFilter("MicroServer"));
            LogManager.Provider = logProvider;
            ILogger Logger = LogManager.GetLogger<StartupTask>();

            try
            {
                // Create Http server pipeline  
                ModuleManager ModuleManager = new ModuleManager();

                // Add the router module as the fist module to pipeline
                ModuleManager.Add(new RouterModule());

                // Add the storage service module to pipeline
                //ModuleManager.Add(new FileModule(new StorageService("/", @"WebRoot")));

                // Add the controller module to pipeline
                ModuleManager.Add(new ControllerModule());

                // Add the error module as the last module to pipeline
                ModuleManager.Add(new ErrorModule());

                //  Create the http server
                HttpServer webServer = new HttpServer(ModuleManager);

                IAsyncAction asyncAction = ThreadPool.RunAsync(
                    async (workItem) =>
                    {
                        await webServer.StartAsync("80");
                    });

                Logger.Info("Background task is running...");

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception in Run: {0}", ex.Message);
            }
        }
Exemplo n.º 2
0
        private async void OnMessageReceived(StreamSocket socket)
        {
            _logger.Trace("Pipeline => HttpServer.OnMessageReceived");
            _service = this;

            try
            {
                HttpContextContent socketContext = new HttpContextContent(socket);
                HttpContext context = await socketContext.ReadAsHttpContextAsync();

                context.Application = ApplicationInfo;
                context.Items = new KeyValuePair<string, object>();
                context.Response.Headers.Add("X-Powered-By", _poweredBy);

                _moduleManager.InvokeAsync(context, SendResponseAsync);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpServer" /> class.
        /// </summary>
        public HttpServer(IModuleManager moduleManager)
        {
            _moduleManager = moduleManager;
            _service = this;

            ApplicationInfo = new KeyValuePair<string, object>();

        }