This commit is contained in:
Jannick van Ballegooijen
2015-10-11 19:35:14 +02:00
5 changed files with 336 additions and 0 deletions
@@ -33,6 +33,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ErgometerLibrary">
<HintPath>..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -61,6 +64,13 @@
<Compile Include="ConSessionLibrary.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="LoginWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="LoginWindow.Designer.cs">
<DependentUpon>LoginWindow.cs</DependentUpon>
</Compile>
<Compile Include="MainClient.cs" />
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
@@ -69,6 +79,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="LoginWindow.resx">
<DependentUpon>LoginWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainWindow.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
+71
View File
@@ -0,0 +1,71 @@
namespace ErgometerDoctorApplication
{
partial class LoginWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LoginButton = new System.Windows.Forms.Button();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// LoginButton
//
this.LoginButton.Location = new System.Drawing.Point(197, 12);
this.LoginButton.Name = "LoginButton";
this.LoginButton.Size = new System.Drawing.Size(75, 23);
this.LoginButton.TabIndex = 0;
this.LoginButton.Text = "Login";
this.LoginButton.UseVisualStyleBackColor = true;
this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
//
// PasswordTextBox
//
this.PasswordTextBox.Location = new System.Drawing.Point(13, 13);
this.PasswordTextBox.Name = "PasswordTextBox";
this.PasswordTextBox.Size = new System.Drawing.Size(178, 20);
this.PasswordTextBox.TabIndex = 1;
//
// LoginWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 53);
this.Controls.Add(this.PasswordTextBox);
this.Controls.Add(this.LoginButton);
this.Name = "LoginWindow";
this.Text = "LoginWindow";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button LoginButton;
private System.Windows.Forms.TextBox PasswordTextBox;
}
}
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ErgometerDoctorApplication
{
public partial class LoginWindow : Form
{
public LoginWindow()
{
InitializeComponent();
}
private void LoginButton_Click(object sender, EventArgs e)
{
if(MainClient.Connect(PasswordTextBox.Text))
{
PasswordTextBox.BackColor = System.Drawing.SystemColors.Window;
Close();
}
else
{
PasswordTextBox.BackColor = Color.Red;
}
}
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+99
View File
@@ -0,0 +1,99 @@
using ErgometerLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ErgometerDoctorApplication
{
class MainClient
{
public static TcpClient Server { get; }
public static bool Loggedin;
private static Thread t;
private static bool running;
private static int Session;
public static string HOST = "127.0.0.1";
public static int PORT = 8888;
static MainClient()
{
Server = new TcpClient();
t = new Thread(run);
Loggedin = false;
}
public static bool Connect(string password)
{
if (!Server.Connected)
{
Server.Connect(HOST, PORT);
NetCommand net = NetHelper.ReadNetCommand(Server);
if (net.Type == NetCommand.CommandType.SESSION)
Session = net.Session;
else
throw new Exception("Session not assigned");
running = true;
t.Start();
}
if (!Loggedin)
{
NetCommand command = new NetCommand("Doctor0tVfW", true, password, Session);
NetHelper.SendNetCommand(Server, command);
NetCommand response = NetHelper.ReadNetCommand(Server);
if (response.Type == NetCommand.CommandType.RESPONSE && response.Response == NetCommand.ResponseType.LOGINWRONG)
{
Loggedin = false;
return false;
}
Loggedin = true;
}
return true;
}
public static void Disconnect()
{
if (Server.Connected)
{
NetHelper.SendNetCommand(Server, new NetCommand(NetCommand.CommandType.LOGOUT, Session));
Loggedin = false;
Server.Close();
running = false;
}
}
public static void run()
{
while (running)
{
if (Server.Connected && Server.Available > 0)
{
NetCommand command = NetHelper.ReadNetCommand(Server);
HandToClient(command);
}
}
}
private static void HandToClient(NetCommand command)
{
throw new NotImplementedException();
}
}
}