1
0
Fork 0

Fix build. Set up initial blank embeds.

This commit is contained in:
Starbeamrainbowlabs 2017-01-10 20:36:03 +00:00
parent 879fc98f83
commit 7faac0f6a8
8 changed files with 196 additions and 31 deletions

View File

@ -3,18 +3,16 @@ using IotWeb.Common.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Nibriboard namespace Nibriboard
{ {
public class NibriWebSocketClient : IWebSocketRequestHandler public class NibriWebSocketHandler : IWebSocketRequestHandler
{ {
WebSocket client; public NibriWebSocketHandler()
public NibriWebSocketClient()
{ {
} }
public void Connected(WebSocket socket) public void Connected(WebSocket client)
{ {
client = socket;
client.DataReceived += async (WebSocket clientSocket, string frame) => { /*client.DataReceived += async (WebSocket clientSocket, string frame) => {
try { try {
await onMessage(frame); await onMessage(frame);
} }
@ -24,7 +22,7 @@ namespace Nibriboard
} }
//Task.Run(async () => await onMessage(frame)).Wait(); //Task.Run(async () => await onMessage(frame)).Wait();
}; };*/
} }
/// <summary> /// <summary>
@ -38,10 +36,5 @@ namespace Nibriboard
Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol); Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol);
return true; return true;
} }
private async Task onMessage(string frame)
{
}
} }
} }

View File

@ -57,15 +57,19 @@
<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="NibriWebSocketHandler.cs" />
<Compile Include="Log.cs" /> <Compile Include="Log.cs" />
<Compile Include="NibriWebSocketClient.cs" /> <Compile Include="Utilities\EmbeddedFiles.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Client\" Exclude="node_modules" /> <EmbeddedResource Include="Client\index.html" />
<EmbeddedResource Include="Client\NibriClient.js" />
<EmbeddedResource Include="Client\Nibri.css" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="RippleSpace\" /> <Folder Include="RippleSpace\" />
<Folder Include="Client\" /> <Folder Include="Client\" />
<Folder Include="Utilities\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

View File

@ -28,15 +28,10 @@ namespace Nibriboard
); );
httpServer.AddWebSocketRequestHandler( httpServer.AddWebSocketRequestHandler(
"/RipplespaceConnection", "/RipplespaceConnection",
new NibriWebSocketHandler()
); );
httpServer.Start(); httpServer.Start();
Log.WriteLine("[NibriboardServer] Started on port {0}", Port); Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
} }
private void Test()
{
HttpListener.
}
} }
} }

View File

@ -1,4 +1,6 @@
using System; using System;
using System.Reflection;
using SBRLUtilities;
namespace Nibriboard namespace Nibriboard
{ {
@ -7,6 +9,7 @@ namespace Nibriboard
public static void Main(string[] args) public static void Main(string[] args)
{ {
Console.WriteLine("Hello World!"); Console.WriteLine("Hello World!");
EmbeddedFiles.WriteResourceList();
} }
} }
} }

View File

@ -13,6 +13,11 @@ namespace Nibriboard.RippleSpace
[Serializable] [Serializable]
public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback
{ {
/// <summary>
/// The plane upon which this chunk is located.
/// </summary>
private Plane plane;
/// <summary> /// <summary>
/// The lines that this chunk currently contains. /// The lines that this chunk currently contains.
/// </summary> /// </summary>
@ -70,7 +75,7 @@ namespace Nibriboard.RippleSpace
get { get {
// If the time we were last accessed + the inactive timer is // If the time we were last accessed + the inactive timer is
// still less than the current time, then we're inactive. // still less than the current time, then we're inactive.
if (TimeLastAccessed.AddMilliseconds(Plane.InactiveMillisecs) < DateTime.Now) if (TimeLastAccessed.AddMilliseconds(plane.InactiveMillisecs) < DateTime.Now)
return false; return false;
return true; return true;
@ -96,7 +101,7 @@ namespace Nibriboard.RippleSpace
public Chunk(Plane inPlane, int inSize, ChunkReference inLocation) public Chunk(Plane inPlane, int inSize, ChunkReference inLocation)
{ {
Plane = inPlane; plane = inPlane;
Size = inSize; Size = inSize;
Location = inLocation; Location = inLocation;
} }
@ -168,7 +173,7 @@ namespace Nibriboard.RippleSpace
public static async Task<Chunk> FromStream(Plane plane, Stream chunkSource) public static async Task<Chunk> FromStream(Plane plane, Stream chunkSource)
{ {
Chunk loadedChunk = await Utilities.DeserialiseBinaryObject<Chunk>(chunkSource); Chunk loadedChunk = await Utilities.DeserialiseBinaryObject<Chunk>(chunkSource);
loadedChunk.Plane = plane; loadedChunk.plane = plane;
return loadedChunk; return loadedChunk;
} }

View File

@ -64,8 +64,8 @@ namespace Nibriboard.RippleSpace
source = source.Substring("ChunkReference:".Length); source = source.Substring("ChunkReference:".Length);
source = source.Trim("() \v\t\r\n".ToCharArray()); source = source.Trim("() \v\t\r\n".ToCharArray());
int x = source.Substring(0, source.IndexOf(",")); int x = int.Parse(source.Substring(0, source.IndexOf(",")));
int y = source.Substring(source.IndexOf(",") + 1); int y = int.Parse(source.Substring(source.IndexOf(",") + 1));
return new ChunkReference( return new ChunkReference(
plane, plane,
x, x,

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Configuration; using System.Configuration;
using System.IO;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace
{ {
/// <summary> /// <summary>
@ -50,8 +52,8 @@ namespace Nibriboard.RippleSpace
source = source.Substring("LocationReference:".Length); source = source.Substring("LocationReference:".Length);
source = source.Trim("() \v\t\r\n".ToCharArray()); source = source.Trim("() \v\t\r\n".ToCharArray());
int x = source.Substring(0, source.IndexOf(",")); int x = int.Parse(source.Substring(0, source.IndexOf(",")));
int y = source.Substring(source.IndexOf(",") + 1); int y = int.Parse(source.Substring(source.IndexOf(",") + 1));
return new LocationReference( return new LocationReference(
plane, plane,
x, x,

View File

@ -1,10 +1,173 @@
using System; using System;
namespace Nibriboard.Utilities using System.Reflection;
using System.IO;
using System.Net.Configuration;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace SBRLUtilities
{ {
public class EmbeddedFiles /// <summary>
/// A collection of static methods for manipulating embedded resources.
/// </summary>
/// <description>
/// v0.2, by Starbeamrainbowlabs <feedback@starbeamrainbowlabs.com>
/// Last updated 8th August 2016.
/// Licensed under MPL-2.0.
///
/// Changelog:
/// v0.1 (25th July 2016):
/// - Initial release.
/// v0.2 (8th August 2016):
/// - Changed namespace.
/// </description>
public static class EmbeddedFiles
{ {
public EmbeddedFiles() /// <summary>
/// An array of the filenames of all the resources embedded in the calling assembly.
/// </summary>
/// <value>The resource list.</value>
public static string[] ResourceList {
get {
return Assembly.GetCallingAssembly().GetManifestResourceNames();
}
}
public static string GetResourceListText()
{ {
StringWriter result = new StringWriter();
result.WriteLine("Files embedded in {0}:", Assembly.GetCallingAssembly().GetName().Name);
foreach (string filename in ResourceList)
result.WriteLine(" - {0}", filename);
return result.ToString();
}
/// <summary>
/// Writes a list of embedded resources to the Console's standard output.
/// </summary>
public static void WriteResourceList()
{
Console.WriteLine(GetResourceListText());
}
/// <summary>
/// Gets a StreamReader attached to the specified embedded resource.
/// </summary>
/// <param name="filename">The filename of the embedded resource to a StreamReader for.</param>
/// <returns>A StreamReader attached to the specified embedded resource.</returns>
public static StreamReader GetReader(string filename)
{
return new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename));
}
/// <summary>
/// Gets the specified embedded resource's content as a byte array.
/// </summary>
/// <param name="filename">The filename of the embedded resource to get conteent of.</param>
/// <returns>The specified embedded resource's content as a byte array.</returns>
public static byte[] ReadAllBytes(string filename)
{
// Referencing the Result property will block until the async method completes
return ReadAllBytesAsync(filename).Result;
}
/// <summary>
/// Gets the specified embedded resource's content as a byte array asynchronously.
/// </summary>
/// <param name="filename">The filename of the embedded resource to get conteent of.</param>
/// <returns>The specified embedded resource's content as a byte array.</returns>
public static async Task<byte[]> ReadAllBytesAsync(string filename)
{
using (Stream resourceStream = Assembly.GetCallingAssembly().GetManifestResourceStream(filename))
using (MemoryStream temp = new MemoryStream())
{
await resourceStream.CopyToAsync(temp);
return temp.ToArray();
}
}
/// <summary>
/// Gets all the text stored in the specified embedded resource.
/// </summary>
/// <param name="filename">The filename to fetch the content of.</param>
/// <returns>All the text stored in the specified embedded resource.</returns>
public static string ReadAllText(string filename)
{
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
{
return resourceReader.ReadToEnd();
}
}
/// <summary>
/// Gets all the text stored in the specified embedded resource asynchronously.
/// </summary>
/// <param name="filename">The filename to fetch the content of.</param>
/// <returns>All the text stored in the specified embedded resource.</returns>
public static async Task<string> ReadAllTextAsync(string filename)
{
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
{
return await resourceReader.ReadToEndAsync();
}
}
/// <summary>
/// Enumerates the lines of text in the specified embedded resource.
/// </summary>
/// <param name="filename">The filename of the embedded resource to enumerate.</param>
/// <returns>An IEnumerator that enumerates the specified embedded resource.</returns>
public static IEnumerator<string> EnumerateLines(string filename)
{
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
{
string nextLine;
while ((nextLine = resourceReader.ReadLine()) != null)
{
yield return nextLine;
}
}
}
/// <summary>
/// Enumerates the lines of text in the specified embedded resource asynchronously.
/// Each successive call returns a task that, when complete, returns the next line of text stored
/// in the embedded resource.
/// </summary>
/// <param name="filename">The filename of the embedded resource to enumerate.</param>
/// <returns>An IEnumerator that enumerates the specified embedded resource.</returns>
public static IEnumerable<Task<string>> EnumerateLinesAsync(string filename)
{
using (StreamReader resourceReader = new StreamReader(Assembly.GetCallingAssembly().GetManifestResourceStream(filename)))
{
while (!resourceReader.EndOfStream)
{
yield return resourceReader.ReadLineAsync();
}
}
}
/// <summary>
/// Gets all the lines of text in the specified embedded resource.
/// You might find EnumerateLines(string filename) more useful depending on your situation.
/// </summary>
/// <param name="filename">The filename to obtain the lines of text from.</param>
/// <returns>A list of lines in the specified embedded resource.</returns>
public static List<string> GetAllLines(string filename)
{
// Referencing the Result property will block until the async method completes
return GetAllLinesAsync(filename).Result;
}
/// <summary>
/// Gets all the lines of text in the specified embedded resource asynchronously.
/// </summary>
/// <param name="filename">The filename to obtain the lines of text from.</param>
/// <returns>A list of lines in the specified embedded resource.</returns>
public static async Task<List<string>> GetAllLinesAsync(string filename)
{
List<string> lines = new List<string>();
IEnumerable<Task<string>> lineIterator = EnumerateLinesAsync(filename);
foreach (Task<string> nextLine in lineIterator)
{
lines.Add(await nextLine);
}
return lines;
} }
} }
} }