mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Set up core basic framework that calls the main code
This commit is contained in:
parent
cf8fb234b4
commit
33f3c44d6e
10 changed files with 191 additions and 87 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
"use strict";
|
||||||
|
|
15
Nibriboard/Env.cs
Normal file
15
Nibriboard/Env.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
namespace Nibriboard
|
||||||
|
{
|
||||||
|
public static class Env
|
||||||
|
{
|
||||||
|
public static readonly DateTime ServerStartTime = DateTime.Now;
|
||||||
|
|
||||||
|
public static double SecondsSinceStart {
|
||||||
|
get {
|
||||||
|
TimeSpan timeSinceStart = DateTime.Now - ServerStartTime;
|
||||||
|
return timeSinceStart.TotalSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,10 @@ namespace Nibriboard
|
||||||
{
|
{
|
||||||
public static class Log
|
public static class Log
|
||||||
{
|
{
|
||||||
|
|
||||||
public static int WriteLine(string text, params object[] args)
|
public static int WriteLine(string text, params object[] args)
|
||||||
{
|
{
|
||||||
string outputText = $"[{DateTime.Now}] " + string.Format(text, args);
|
string outputText = $"[{Env.SecondsSinceStart}] " + string.Format(text, args);
|
||||||
Console.WriteLine(outputText);
|
Console.WriteLine(outputText);
|
||||||
return outputText.Length;
|
return outputText.Length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace Nibriboard
|
||||||
|
|
||||||
//Task.Run(async () => await onMessage(frame)).Wait();
|
//Task.Run(async () => await onMessage(frame)).Wait();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task onMessage(string frame)
|
private async Task onMessage(string frame)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
@ -57,10 +56,12 @@
|
||||||
<Compile Include="RippleSpace\Reference.cs" />
|
<Compile Include="RippleSpace\Reference.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
<Compile Include="NibriboardServer.cs" />
|
<Compile Include="NibriboardServer.cs" />
|
||||||
|
<Compile Include="NibriClient.cs" />
|
||||||
<Compile Include="NibriClientManager.cs" />
|
<Compile Include="NibriClientManager.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
<Compile Include="Utilities\EmbeddedFiles.cs" />
|
<Compile Include="Utilities\EmbeddedFiles.cs" />
|
||||||
<Compile Include="NibriClient.cs" />
|
<Compile Include="Env.cs" />
|
||||||
|
<Compile Include="RippleSpace\RippleSpaceManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Client\index.html" />
|
<EmbeddedResource Include="Client\index.html" />
|
||||||
|
@ -74,6 +75,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
<None Include="Client\index.js" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
|
@ -1,22 +1,26 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using IotWeb.Server;
|
using IotWeb.Server;
|
||||||
using IotWeb.Common.Http;
|
using IotWeb.Common.Http;
|
||||||
using System.Net;
|
|
||||||
|
using Nibriboard.RippleSpace;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
{
|
{
|
||||||
public class NibriboardServer
|
public class NibriboardServer
|
||||||
{
|
{
|
||||||
private HttpServer httpServer;
|
private HttpServer httpServer;
|
||||||
|
|
||||||
|
private RippleSpaceManager planeManager = new RippleSpaceManager();
|
||||||
|
|
||||||
public readonly int Port = 31586;
|
public readonly int Port = 31586;
|
||||||
|
|
||||||
public NibriboardServer()
|
public NibriboardServer(int inPort = 31586)
|
||||||
{
|
{
|
||||||
}
|
Port = inPort;
|
||||||
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
httpServer = new HttpServer(Port);
|
httpServer = new HttpServer(Port);
|
||||||
httpServer.AddHttpRequestHandler(
|
httpServer.AddHttpRequestHandler(
|
||||||
"/",
|
"/",
|
||||||
|
@ -30,8 +34,14 @@ namespace Nibriboard
|
||||||
"/RipplespaceConnection",
|
"/RipplespaceConnection",
|
||||||
new NibriClientManager()
|
new NibriClientManager()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Start()
|
||||||
|
{
|
||||||
httpServer.Start();
|
httpServer.Start();
|
||||||
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
|
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
|
||||||
|
|
||||||
|
await planeManager.StartMaintenanceMonkey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using SBRLUtilities;
|
using SBRLUtilities;
|
||||||
|
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
|
@ -8,8 +9,15 @@ namespace Nibriboard
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello World!");
|
Log.WriteLine("[core] Starting Nibriboard.");
|
||||||
|
|
||||||
|
Log.WriteLine("[core] Detected embedded files: ");
|
||||||
EmbeddedFiles.WriteResourceList();
|
EmbeddedFiles.WriteResourceList();
|
||||||
|
|
||||||
|
NibriboardServer server = new NibriboardServer();
|
||||||
|
Task.WaitAll(
|
||||||
|
server.Start()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,5 +82,10 @@ namespace Nibriboard.RippleSpace
|
||||||
containingChunk.Add(newLineSegment);
|
containingChunk.Add(newLineSegment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task PerformMaintenance()
|
||||||
|
{
|
||||||
|
// TODO: Perform maintenance here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
59
Nibriboard/RippleSpace/RippleSpaceManager.cs
Normal file
59
Nibriboard/RippleSpace/RippleSpaceManager.cs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Nibriboard.RippleSpace
|
||||||
|
{
|
||||||
|
public class RippleSpaceManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The master list of planes that this PlaneManager is in charge of.
|
||||||
|
/// </summary>
|
||||||
|
public List<Plane> Planes = new List<Plane>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of milliseconds between each maintenance run.
|
||||||
|
/// </summary>
|
||||||
|
public readonly int MaintenanceInternal = 5000;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of milliseconds the last maintenance run took.
|
||||||
|
/// </summary>
|
||||||
|
public long LastMaintenanceDuration = 0;
|
||||||
|
|
||||||
|
public RippleSpaceManager()
|
||||||
|
{
|
||||||
|
Log.WriteLine("[RippleSpace] New blank ripplespace initialised.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plane GetById(string targetName)
|
||||||
|
{
|
||||||
|
foreach (Plane plane in Planes)
|
||||||
|
{
|
||||||
|
if (plane.Name == targetName)
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartMaintenanceMonkey()
|
||||||
|
{
|
||||||
|
Log.WriteLine("[RippleSpace/Maintenance] Automated maintenance monkey created.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Stopwatch maintenanceStopwatch = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
foreach (Plane plane in Planes)
|
||||||
|
await plane.PerformMaintenance();
|
||||||
|
|
||||||
|
LastMaintenanceDuration = maintenanceStopwatch.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
await Task.Delay(MaintenanceInternal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue