7 Commits
5 changed files with 291 additions and 262 deletions
+3
View File
@@ -0,0 +1,3 @@
/.vs
/Bot-Utils/obj
/Bot-Utils/bin
+49 -43
View File
@@ -1,43 +1,49 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.28307.136 VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot-Utils", "Bot-Utils\Bot-Utils.csproj", "{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bot-Utils", "Bot-Utils\Bot-Utils.csproj", "{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils-IoT\Utils-IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
EndProject EndProject
Global Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Posix", "..\..\Librarys\Mono.Posix\Mono.Posix\Mono.Posix.csproj", "{E2CA132E-E85C-40AD-BE94-B138AA68772B}"
GlobalSection(SolutionConfigurationPlatforms) = preSolution EndProject
Debug|Any CPU = Debug|Any CPU Global
Release|Any CPU = Release|Any CPU GlobalSection(SolutionConfigurationPlatforms) = preSolution
EndGlobalSection Debug|Any CPU = Debug|Any CPU
GlobalSection(ProjectConfigurationPlatforms) = postSolution Release|Any CPU = Release|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU EndGlobalSection
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.Build.0 = Debug|Any CPU GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.Build.0 = Release|Any CPU {BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}.Release|Any CPU.Build.0 = Release|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU
GlobalSection(SolutionProperties) = preSolution {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
HideSolutionNode = FALSE {E2CA132E-E85C-40AD-BE94-B138AA68772B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
EndGlobalSection {E2CA132E-E85C-40AD-BE94-B138AA68772B}.Debug|Any CPU.Build.0 = Debug|Any CPU
GlobalSection(ExtensibilityGlobals) = postSolution {E2CA132E-E85C-40AD-BE94-B138AA68772B}.Release|Any CPU.ActiveCfg = Release|Any CPU
SolutionGuid = {99DB6F34-BD41-4AFF-82B7-E4B3EFDF56DC} {E2CA132E-E85C-40AD-BE94-B138AA68772B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {99DB6F34-BD41-4AFF-82B7-E4B3EFDF56DC}
EndGlobalSection
EndGlobal
+82 -81
View File
@@ -1,82 +1,83 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}</ProjectGuid> <ProjectGuid>{BB7BFCB5-3DB0-49E1-802A-3CE3EECC59F9}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BlubbFish.Utils.IoT.Bots</RootNamespace> <RootNamespace>BlubbFish.Utils.IoT.Bots</RootNamespace>
<AssemblyName>Bot-Utils</AssemblyName> <AssemblyName>Bot-Utils</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Posix"> <Reference Include="System" />
<HintPath>..\..\Zway-Bot\packages\Mono.Posix.dll</HintPath> <Reference Include="System.Core" />
</Reference> <Reference Include="System.Xml.Linq" />
<Reference Include="System" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Core" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Net.Http" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="System.Xml" />
<Reference Include="System.Data" /> </ItemGroup>
<Reference Include="System.Net.Http" /> <ItemGroup>
<Reference Include="System.Xml" /> <Compile Include="Bot.cs" />
</ItemGroup> <Compile Include="Events\CronEvent.cs" />
<ItemGroup> <Compile Include="Events\ModulEventArgs.cs" />
<Compile Include="Bot.cs" /> <Compile Include="Events\SenmlEvent.cs" />
<Compile Include="Events\CronEvent.cs" /> <Compile Include="Events\MqttEvent.cs" />
<Compile Include="Events\ModulEventArgs.cs" /> <Compile Include="Events\OvertakerEvent.cs" />
<Compile Include="Events\SenmlEvent.cs" /> <Compile Include="Events\StatusPollingEvent.cs" />
<Compile Include="Events\MqttEvent.cs" /> <Compile Include="Interfaces\IForceLoad.cs" />
<Compile Include="Events\OvertakerEvent.cs" /> <Compile Include="Moduls\AModul.cs" />
<Compile Include="Events\StatusPollingEvent.cs" /> <Compile Include="Moduls\CronJob.cs" />
<Compile Include="Interfaces\IForceLoad.cs" /> <Compile Include="Moduls\Mqtt.cs" />
<Compile Include="Moduls\AModul.cs" /> <Compile Include="Moduls\Overtaker.cs" />
<Compile Include="Moduls\CronJob.cs" /> <Compile Include="Moduls\Statuspolling.cs" />
<Compile Include="Moduls\Mqtt.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Moduls\Overtaker.cs" /> <Compile Include="Webserver.cs" />
<Compile Include="Moduls\Statuspolling.cs" /> </ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <ItemGroup>
<Compile Include="Webserver.cs" /> <ProjectReference Include="..\..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj">
</ItemGroup> <Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project>
<ItemGroup> <Name>litjson_4.7.1</Name>
<ProjectReference Include="..\..\..\Librarys\litjson\litjson\litjson_4.7.1.csproj"> </ProjectReference>
<Project>{91a14cd2-2940-4500-8193-56d37edddbaa}</Project> <ProjectReference Include="..\..\..\Librarys\Mono.Posix\Mono.Posix\Mono.Posix.csproj">
<Name>litjson_4.7.1</Name> <Project>{e2ca132e-e85c-40ad-be94-b138aa68772b}</Project>
</ProjectReference> <Name>Mono.Posix</Name>
<ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT.csproj"> </ProjectReference>
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project> <ProjectReference Include="..\..\Utils-IoT\Utils-IoT\Utils-IoT.csproj">
<Name>Utils-IoT</Name> <Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
</ProjectReference> <Name>Utils-IoT</Name>
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj"> </ProjectReference>
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project> <ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
<Name>Utils</Name> <Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
</ProjectReference> <Name>Utils</Name>
</ItemGroup> </ProjectReference>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
+45 -40
View File
@@ -1,40 +1,45 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Bot-Utils")] [assembly: AssemblyTitle("Bot-Utils")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("Bot-Utils are helpers for programming a bot")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("BlubbFish")]
[assembly: AssemblyProduct("Bot-Utils")] [assembly: AssemblyProduct("Bot-Utils")]
[assembly: AssemblyCopyright("Copyright © 2018 - 02.10.2018")] [assembly: AssemblyCopyright("Copyright © 2018 - 12.03.2019")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("© BlubbFish")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly // Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("bb7bfcb5-3db0-49e1-802a-3ce3eecc59f9")] [assembly: Guid("bb7bfcb5-3db0-49e1-802a-3ce3eecc59f9")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
// //
// Hauptversion // Hauptversion
// Nebenversion // Nebenversion
// Buildnummer // Buildnummer
// Revision // Revision
// //
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0")] [assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.0")] [assembly: AssemblyFileVersion("1.1.5")]
/* /*
* 1.1.0 Remove Helper from Bot-Utils * 1.1.0 Remove Helper from Bot-Utils
*/ * 1.1.1 Update to local librarys
* 1.1.2 Fixing bug for Contenttype
* 1.1.3 Variables parsing now as a String
* 1.1.4 add Woff as Binary type
* 1.1.5 add a function to send an object as json directly
*/
+112 -98
View File
@@ -1,98 +1,112 @@
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events; using BlubbFish.Utils.IoT.Events;
using System; using LitJson;
using System.Collections.Generic; using System;
using System.IO; using System.Collections.Generic;
using System.Linq; using System.IO;
using System.Net; using System.Linq;
using System.Text; using System.Net;
using System.Threading; using System.Text;
using System.Threading.Tasks; using System.Threading;
using System.Threading.Tasks;
namespace BlubbFish.Utils.IoT.Bots
{ namespace BlubbFish.Utils.IoT.Bots
public abstract class Webserver {
{ public abstract class Webserver
protected Dictionary<String, String> config; {
protected InIReader requests; protected Dictionary<String, String> config;
protected HttpListener httplistener; protected InIReader requests;
protected HttpListener httplistener;
public Webserver(ABackend backend, Dictionary<String, String> settings, InIReader requests) {
this.config = settings; public Webserver(ABackend backend, Dictionary<String, String> settings, InIReader requests) {
this.requests = requests; this.config = settings;
backend.MessageIncomming += this.Backend_MessageIncomming; this.requests = requests;
this.httplistener = new HttpListener(); backend.MessageIncomming += this.Backend_MessageIncomming;
this.httplistener.Prefixes.Add(this.config["prefix"]); this.httplistener = new HttpListener();
this.httplistener.Start(); this.httplistener.Prefixes.Add(this.config["prefix"]);
ThreadPool.QueueUserWorkItem((o) => { this.httplistener.Start();
Console.WriteLine("Webserver is Running..."); ThreadPool.QueueUserWorkItem((o) => {
try { Console.WriteLine("Webserver is Running...");
while (this.httplistener.IsListening) { try {
ThreadPool.QueueUserWorkItem((state) => { while (this.httplistener.IsListening) {
HttpListenerContext httplistenercontext = state as HttpListenerContext; ThreadPool.QueueUserWorkItem((state) => {
try { HttpListenerContext httplistenercontext = state as HttpListenerContext;
this.SendResponse(httplistenercontext); try {
} catch { } finally { this.SendResponse(httplistenercontext);
httplistenercontext.Response.OutputStream.Close(); } catch { } finally {
} httplistenercontext.Response.OutputStream.Close();
}, this.httplistener.GetContext()); }
} }, this.httplistener.GetContext());
} catch { }; }
}); } catch { };
} });
}
protected virtual void SendResponse(HttpListenerContext cont) {
String restr = cont.Request.Url.PathAndQuery; protected virtual void SendResponse(HttpListenerContext cont) {
if (restr.StartsWith("/")) { String restr = cont.Request.Url.PathAndQuery;
if(restr.IndexOf("?") != -1) { if (restr.StartsWith("/")) {
restr = restr.Substring(1, restr.IndexOf("?")-1); if(restr.IndexOf("?") != -1) {
} else { restr = restr.Substring(1, restr.IndexOf("?")-1);
restr = restr.Substring(1); } else {
} restr = restr.Substring(1);
if(restr == "") { }
restr = "index.html"; if(restr == "") {
} restr = "index.html";
String end = restr.IndexOf('.') != -1 ? restr.Substring(restr.IndexOf('.')+1) : ""; }
if (File.Exists("resources/"+ restr)) { String end = restr.IndexOf('.') != -1 ? restr.Substring(restr.IndexOf('.')+1) : "";
try { if (File.Exists("resources/"+ restr)) {
if (end == "png" || end == ".jpg" || end == ".jpeg" || end == ".ico") { try {
Byte[] output = File.ReadAllBytes("resources/" + restr); if (end == "png" || end == "jpg" || end == "jpeg" || end == "ico" || end == "woff") {
cont.Response.OutputStream.Write(output, 0, output.Length); Byte[] output = File.ReadAllBytes("resources/" + restr);
cont.Response.ContentType = "image/"+end; switch(end) {
return; case "ico": cont.Response.ContentType = "image/x-ico"; break;
} else { case "woff": cont.Response.ContentType = "font/woff"; break;
String file = File.ReadAllText("resources/" + restr); }
if (this.requests.GetSections(false).Contains(restr)) { cont.Response.OutputStream.Write(output, 0, output.Length);
Dictionary<String, String> vars = this.requests.GetSection(restr); return;
foreach (KeyValuePair<String, String> item in vars) { } else {
file = file.Replace("{%" + item.Key.ToUpper() + "%}", item.Value); String file = File.ReadAllText("resources/" + restr);
} if (this.requests.GetSections(false).Contains(restr)) {
} Dictionary<String, String> vars = this.requests.GetSection(restr);
file = file.Replace("{%REQUEST_URL_HOST%}", cont.Request.Url.Host); foreach (KeyValuePair<String, String> item in vars) {
Byte[] buf = Encoding.UTF8.GetBytes(file); file = file.Replace("\"{%" + item.Key.ToUpper() + "%}\"", item.Value);
cont.Response.ContentLength64 = buf.Length; }
cont.Response.OutputStream.Write(buf, 0, buf.Length); }
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery); file = file.Replace("{%REQUEST_URL_HOST%}", cont.Request.Url.Host);
return; Byte[] buf = Encoding.UTF8.GetBytes(file);
} cont.Response.ContentLength64 = buf.Length;
} catch(Exception e) { switch(end) {
Helper.WriteError("500 - " + e.Message); case "css": cont.Response.ContentType = "text/css"; break;
cont.Response.StatusCode = 500; }
return; cont.Response.OutputStream.Write(buf, 0, buf.Length);
} Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
} return;
Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!"); }
cont.Response.StatusCode = 404; } catch(Exception e) {
return; Helper.WriteError("500 - " + e.Message);
} cont.Response.StatusCode = 500;
return; return;
} }
}
public void Dispose() { Helper.WriteError("404 - " + cont.Request.Url.PathAndQuery + " not found!");
this.httplistener.Stop(); cont.Response.StatusCode = 404;
this.httplistener.Close(); return;
} }
return;
protected abstract void Backend_MessageIncomming(Object sender, BackendEvent e); }
}
} protected void SendJsonResponse(Object data, HttpListenerContext cont) {
Byte[] buf = Encoding.UTF8.GetBytes(JsonMapper.ToJson(data));
cont.Response.ContentLength64 = buf.Length;
cont.Response.OutputStream.Write(buf, 0, buf.Length);
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
}
public void Dispose() {
this.httplistener.Stop();
this.httplistener.Close();
}
protected abstract void Backend_MessageIncomming(Object sender, BackendEvent e);
}
}