-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoluiNetService.cs
More file actions
76 lines (68 loc) · 2.72 KB
/
SoluiNetService.cs
File metadata and controls
76 lines (68 loc) · 2.72 KB
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
// <copyright file="SoluiNetService.cs" company="SoluiNet">
// Copyright (c) SoluiNet. All rights reserved.
// </copyright>
namespace SoluiNet.DevTools.Web
{
using System;
using System.Globalization;
using System.Net.Http;
using System.ServiceProcess;
using System.Text;
using SoluiNet.DevTools.Core.Tools.Object;
using SoluiNet.DevTools.Core.Web.Renderer;
/// <summary>
/// The SoluiNet service.
/// </summary>
public partial class SoluiNetService : ServiceBase
{
private SoluiNetWebServer webServer;
/// <summary>
/// Initializes a new instance of the <see cref="SoluiNetService"/> class.
/// </summary>
public SoluiNetService()
{
this.InitializeComponent();
}
/// <summary>
/// The start event handler.
/// </summary>
/// <param name="args">The arguments.</param>
protected override void OnStart(string[] args)
{
this.webServer = new SoluiNetWebServer();
this.webServer.HandleRequest += (webRequest, webArgs) =>
{
if (webRequest.Method == HttpMethod.Get)
{
if (webRequest.Route.StartsWith("/favicon.ico", StringComparison.InvariantCulture))
{
return new Core.Web.Communication.WebResponse(
this.GetEmbeddedResourceContentStream("favicon.ico", string.Empty),
"image/x-icon",
Encoding.UTF8,
true);
}
else if (webRequest.Route.StartsWith("/Status", StringComparison.InvariantCulture))
{
return new Core.Web.Communication.WebResponse(
WebRenderer.RenderPage(string.Format(CultureInfo.InvariantCulture, "Status: {0}\r\nVersion: {1}", "OK", this.GetType().Assembly.GetName().Version.ToString())),
Encoding.UTF8);
}
else
{
return new Core.Web.Communication.WebResponse(WebRenderer.RenderPage("not found"), Encoding.UTF8) { StatusCode = System.Net.HttpStatusCode.NotFound };
}
}
return new Core.Web.Communication.WebResponse(WebRenderer.RenderPage("no supported method"), Encoding.UTF8) { StatusCode = System.Net.HttpStatusCode.MethodNotAllowed };
};
this.webServer.Start();
}
/// <summary>
/// The stop event handler.
/// </summary>
protected override void OnStop()
{
this.webServer?.Stop();
}
}
}