-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpServer.cs
88 lines (79 loc) · 2.75 KB
/
HttpServer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Threading;
using System.Collections.Generic;
using ReactiveUI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Http.Headers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.WebUtilities;
using System.Net;
using System.Threading.Tasks;
using api_corelation.Models;
using Microsoft.Extensions.Hosting;
namespace simpleserver.Models
{
public class HttpServerRunner
{
public string port = "8080";
public string folder = "";
public string Status = "Init";
public string Log = "";
public bool IsLaunched = false;
public bool IsSecure = false;
CancellationTokenSource ctSource;
ResponseHeaders Headers;
private IServer ServerInstance;
private static WebHostBuilder ServerBuilder;
public HttpServerRunner()
{
}
public void Start()
{
try
{
//var builder = WebApplication.CreateBuilder();
//// Add services to the container.
//builder.Services.AddRazorPages();
//var app = builder.Build();
//// Configure the HTTP request pipeline.
//if (!app.Environment.IsDevelopment())
//{
// app.UseExceptionHandler("/Error");
//}
//app.UseStaticFiles();
//app.UseRouting();
//app.UseAuthorization();
//app.MapRazorPages();
//app.Run();
ServerInstance = new CustomServer(Int32.Parse(port));
ServerBuilder = new WebHostBuilder();
ServerBuilder.UseServer(ServerInstance).UseUrls("http://*:"+port).UseContentRoot(folder).Configure(app => app.UsePathBase(""));
ServerBuilder.Build().RunAsync();
ctSource = new CancellationTokenSource();
Status = "Running";
//ServerLogger logger = new ServerLogger();
//Log = logger.GetCapturedLogs();
//IsLaunched = true;
//server.RunAsync(ctSource.Token).ConfigureAwait(false);
}
catch (Exception ex)
{
IsLaunched = false;
Status = ex.Message.ToString();
}
}
public void Stop()
{
ctSource.Cancel();
IsLaunched = false;
Status = "Stopped";
}
}
}