add ir daemon test server code - irdaemon_server.linq
add code to send start notifications at race start.
This commit is contained in:
parent
6d48a36ed8
commit
54907cb57d
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Interfaces;
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
@ -10,9 +11,13 @@ namespace RaceLapTimer.ApiControllers
|
||||
public class RaceSessionApiModule : NancyModule
|
||||
{
|
||||
private readonly IDbProvider _provider;
|
||||
public RaceSessionApiModule(IDbProvider provider) : base("/api/racesession")
|
||||
private readonly INotifierManager _notifier;
|
||||
|
||||
public RaceSessionApiModule(IDbProvider provider, INotifierManager notifierManager) : base("/api/racesession")
|
||||
{
|
||||
_provider = provider;
|
||||
_notifier = notifierManager;
|
||||
|
||||
Get[""] = args => GetRaceSessions();
|
||||
Post["/create"] = args => CreateRaceSession(args);
|
||||
Get["/historic"] = args => GetHistoricRaceSessions();
|
||||
@ -34,6 +39,10 @@ namespace RaceLapTimer.ApiControllers
|
||||
{
|
||||
var session = this.Bind<RaceSession>();
|
||||
var res = _provider.CreateRaceSession(session);
|
||||
if (res)
|
||||
{
|
||||
_notifier.NotifyRaceStarted(new NotificationEventArgs {RaceStartTime = DateTime.UtcNow, MaxLaps = session.MaxLaps});
|
||||
}
|
||||
return Context.GetRedirect("/racedirector");
|
||||
}
|
||||
}
|
||||
|
||||
37
TestScripts/irdaemon_server.linq
Normal file
37
TestScripts/irdaemon_server.linq
Normal file
@ -0,0 +1,37 @@
|
||||
<Query Kind="Program">
|
||||
<Namespace>System.Net</Namespace>
|
||||
<Namespace>System.Net.Sockets</Namespace>
|
||||
</Query>
|
||||
|
||||
const int PORT_NO = 3006;
|
||||
const string SERVER_IP = "127.0.0.1";
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//---listen at the specified IP and port no.---
|
||||
IPAddress localAdd = IPAddress.Parse(SERVER_IP);
|
||||
TcpListener listener = new TcpListener(localAdd, PORT_NO);
|
||||
Console.WriteLine("Listening...");
|
||||
listener.Start();
|
||||
|
||||
//---incoming client connected---
|
||||
TcpClient client = listener.AcceptTcpClient();
|
||||
|
||||
//---get the incoming data through a network stream---
|
||||
NetworkStream nwStream = client.GetStream();
|
||||
byte[] buffer = new byte[client.ReceiveBufferSize];
|
||||
|
||||
//---read incoming stream---
|
||||
int bytesRead = nwStream.Read(buffer, 0, client.ReceiveBufferSize);
|
||||
|
||||
//---convert the data received into a string---
|
||||
string dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead);
|
||||
Console.WriteLine("Received : " + dataReceived);
|
||||
|
||||
//---write back the text to the client---
|
||||
Console.WriteLine("Sending back : " + dataReceived);
|
||||
nwStream.Write(buffer, 0, bytesRead);
|
||||
client.Close();
|
||||
listener.Stop();
|
||||
Console.ReadLine();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user