1
0
Fork 0
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:
Starbeamrainbowlabs 2017-01-19 13:13:35 +00:00
parent cf8fb234b4
commit 33f3c44d6e
10 changed files with 191 additions and 87 deletions

View file

@ -0,0 +1,2 @@
"use strict";

15
Nibriboard/Env.cs Normal file
View 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;
}
}
}
}

View file

@ -3,9 +3,10 @@ namespace Nibriboard
{
public static class Log
{
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);
return outputText.Length;
}

View file

@ -26,6 +26,8 @@ namespace Nibriboard
//Task.Run(async () => await onMessage(frame)).Wait();
};
}
private async Task onMessage(string frame)

View file

@ -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>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
@ -57,15 +56,17 @@
<Compile Include="RippleSpace\Reference.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="NibriboardServer.cs" />
<Compile Include="NibriClient.cs" />
<Compile Include="NibriClientManager.cs" />
<Compile Include="Log.cs" />
<Compile Include="Utilities\EmbeddedFiles.cs" />
<Compile Include="NibriClient.cs" />
<Compile Include="Env.cs" />
<Compile Include="RippleSpace\RippleSpaceManager.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Client\index.html" />
<EmbeddedResource Include="Client\NibriClient.js" />
<EmbeddedResource Include="Client\Nibri.css" />
<EmbeddedResource Include="Client\index.html" />
<EmbeddedResource Include="Client\NibriClient.js" />
<EmbeddedResource Include="Client\Nibri.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="RippleSpace\" />
@ -74,6 +75,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Client\index.js" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,22 +1,26 @@
using System;
using System.Reflection;
using IotWeb.Server;
using IotWeb.Common.Http;
using System.Net;
using Nibriboard.RippleSpace;
using System.Threading.Tasks;
namespace Nibriboard
{
public class NibriboardServer
{
private HttpServer httpServer;
private RippleSpaceManager planeManager = new RippleSpaceManager();
public readonly int Port = 31586;
public NibriboardServer()
public NibriboardServer(int inPort = 31586)
{
}
Port = inPort;
public void Setup()
{
httpServer = new HttpServer(Port);
httpServer.AddHttpRequestHandler(
"/",
@ -30,8 +34,14 @@ namespace Nibriboard
"/RipplespaceConnection",
new NibriClientManager()
);
}
public async Task Start()
{
httpServer.Start();
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
await planeManager.StartMaintenanceMonkey();
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using SBRLUtilities;
namespace Nibriboard
@ -8,8 +9,15 @@ namespace Nibriboard
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Log.WriteLine("[core] Starting Nibriboard.");
Log.WriteLine("[core] Detected embedded files: ");
EmbeddedFiles.WriteResourceList();
NibriboardServer server = new NibriboardServer();
Task.WaitAll(
server.Start()
);
}
}
}

View file

@ -82,5 +82,10 @@ namespace Nibriboard.RippleSpace
containingChunk.Add(newLineSegment);
}
}
public async Task PerformMaintenance()
{
// TODO: Perform maintenance here
}
}
}

View 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);
}
}
}
}