Added new classes and fixed bugs
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
namespace ErgometerLibrary
|
||||||
|
{
|
||||||
|
public class ChatMessage
|
||||||
|
{
|
||||||
|
public string Message { get; }
|
||||||
|
public string Name { get; }
|
||||||
|
public double TimeStamp { get; set;}
|
||||||
|
|
||||||
|
public ChatMessage(string name, string message)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Message = message;
|
||||||
|
TimeStamp = Helper.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"[{Name}] <{TimeStamp}> - {Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@@ -40,12 +44,18 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ChatMessage.cs" />
|
||||||
|
<Compile Include="Helper.cs" />
|
||||||
<Compile Include="NetCommand.cs" />
|
<Compile Include="NetCommand.cs" />
|
||||||
<Compile Include="ComPort.cs" />
|
<Compile Include="ComPort.cs" />
|
||||||
<Compile Include="FileHandler.cs" />
|
<Compile Include="FileHandler.cs" />
|
||||||
<Compile Include="Meting.cs" />
|
<Compile Include="Meting.cs" />
|
||||||
|
<Compile Include="NetHelper.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ErgometerLibrary
|
namespace ErgometerLibrary
|
||||||
{
|
{
|
||||||
@@ -42,17 +40,26 @@ namespace ErgometerLibrary
|
|||||||
File.Create(Path.Combine(GetSessionFolder(session), "metingen.ergo"));
|
File.Create(Path.Combine(GetSessionFolder(session), "metingen.ergo"));
|
||||||
File.Create(Path.Combine(GetSessionFolder(session), "chat.log"));
|
File.Create(Path.Combine(GetSessionFolder(session), "chat.log"));
|
||||||
|
|
||||||
File.WriteAllText(GetSessionFile(session), naam);
|
File.WriteAllText(GetSessionFile(session), naam + "\n" + Helper.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddMeting(int session, params Meting[] metingen)
|
public static void WriteMetingen(int session, List<Meting> metingen)
|
||||||
{
|
{
|
||||||
|
string json = Newtonsoft.Json.JsonConvert.SerializeObject(metingen);
|
||||||
|
File.WriteAllText(GetSessionMetingen(session), json);
|
||||||
|
Console.WriteLine("Writing metingen: " + GetSessionMetingen(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddChat(int session, string name, string chatmessage)
|
public static void WriteChat(int session, List<ChatMessage> chat)
|
||||||
{
|
{
|
||||||
|
string write = "";
|
||||||
|
foreach(ChatMessage c in chat)
|
||||||
|
{
|
||||||
|
write += c.ToString() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(GetSessionChat(session), write);
|
||||||
|
Console.WriteLine("Writing chat: " + GetSessionChat(session));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetSessionFolder(int session)
|
private static string GetSessionFolder(int session)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ErgometerLibrary
|
||||||
|
{
|
||||||
|
class Helper
|
||||||
|
{
|
||||||
|
public static double Now { get { return (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ namespace ErgometerLibrary
|
|||||||
if (status.Length == 9)
|
if (status.Length == 9)
|
||||||
timestamp = double.Parse(status[8]);
|
timestamp = double.Parse(status[8]);
|
||||||
else
|
else
|
||||||
timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
timestamp = Helper.Now;
|
||||||
|
|
||||||
string[] temp = status[6].Split(':');
|
string[] temp = status[6].Split(':');
|
||||||
int seconds = (int.Parse(temp[0]) * 60) + (int.Parse(temp[1]));
|
int seconds = (int.Parse(temp[0]) * 60) + (int.Parse(temp[1]));
|
||||||
|
|||||||
@@ -24,21 +24,21 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
Type = CommandType.SESSION;
|
Type = CommandType.SESSION;
|
||||||
Session = session;
|
Session = session;
|
||||||
Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
Timestamp = Helper.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetCommand(CommandType commandtype, int session)
|
public NetCommand(CommandType commandtype, int session)
|
||||||
{
|
{
|
||||||
Type = commandtype;
|
Type = commandtype;
|
||||||
Session = session;
|
Session = session;
|
||||||
Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
Timestamp = Helper.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetCommand(Meting m, int session)
|
public NetCommand(Meting m, int session)
|
||||||
{
|
{
|
||||||
Type = CommandType.DATA;
|
Type = CommandType.DATA;
|
||||||
Session = session;
|
Session = session;
|
||||||
Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
Timestamp = Helper.Now;
|
||||||
|
|
||||||
Meting = m;
|
Meting = m;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
Type = CommandType.CHAT;
|
Type = CommandType.CHAT;
|
||||||
Session = session;
|
Session = session;
|
||||||
Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
Timestamp = Helper.Now;
|
||||||
|
|
||||||
ChatMessage = chat;
|
ChatMessage = chat;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
Type = CommandType.LOGIN;
|
Type = CommandType.LOGIN;
|
||||||
Session = session;
|
Session = session;
|
||||||
Timestamp = (DateTime.Now - DateTime.Parse("1/1/1870 0:0:0")).TotalMilliseconds;
|
Timestamp = Helper.Now;
|
||||||
|
|
||||||
DisplayName = name;
|
DisplayName = name;
|
||||||
IsDoctor = doctor;
|
IsDoctor = doctor;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ErgometerLibrary
|
||||||
|
{
|
||||||
|
class NetHelper
|
||||||
|
{
|
||||||
|
public static void SendNetCommand(TcpClient client, NetCommand command)
|
||||||
|
{
|
||||||
|
byte[] b = Encoding.ASCII.GetBytes(command.ToString());
|
||||||
|
client.GetStream().Write(b, 0, b.Length);
|
||||||
|
client.GetStream().Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetCommand ReadNetCommand(TcpClient client)
|
||||||
|
{
|
||||||
|
byte[] bytesFrom = new byte[(int) client.ReceiveBufferSize];
|
||||||
|
client.GetStream().Read(bytesFrom, 0, (int)client.ReceiveBufferSize);
|
||||||
|
String response = Encoding.ASCII.GetString(bytesFrom);
|
||||||
|
NetCommand net = NetCommand.Parse(response);
|
||||||
|
return net;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IPAddress GetIP(string ipstring)
|
||||||
|
{
|
||||||
|
IPAddress ip;
|
||||||
|
|
||||||
|
bool ipIsOk = IPAddress.TryParse(ipstring, out ip);
|
||||||
|
if (!ipIsOk) { return null; }
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.1.0")]
|
[assembly: AssemblyVersion("1.0.2.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
[assembly: AssemblyFileVersion("1.0.2.0")]
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
||||||
|
</packages>
|
||||||
Reference in New Issue
Block a user