Skip to content

Commit

Permalink
version rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickduhaime committed Apr 29, 2018
1 parent 6eebc9a commit ffb9abf
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 137 deletions.
Binary file modified .vs/INF1009/v15/.suo
Binary file not shown.
Binary file modified .vs/INF1009/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/INF1009/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/INF1009/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
Binary file modified .vs/INF1009/v15/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/INF1009/v15/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified .vs/INF1009/v15/sqlite3/storage.ide-wal
Binary file not shown.
16 changes: 15 additions & 1 deletion INF1009/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 40 additions & 12 deletions INF1009/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.IO;

namespace INF1009
{
public partial class Form1 : Form
{
public static Form1 _UI;
private int nbclk = 0;
private int nbTest = 1;
private static Queue N2TQ = new Queue();
private static Queue N2TQS = Queue.Synchronized(N2TQ);
Expand All @@ -22,6 +22,8 @@ public partial class Form1 : Form
private Network network = new Network(ref T2NQS, ref N2TQS, ref PP2NQS, ref N2PPQS);
private Transport transport = new Transport(ref T2NQS, ref N2TQS);
private Thread networkWriteThread, transportWriteThread, transportReadThread, networkReadThread, processingThread;
private const string S_lec = "s_lec.txt";
private string d_msg;
delegate void UIDisplayText(string text);

public Form1()
Expand Down Expand Up @@ -61,9 +63,7 @@ private void openThreads()

private void buttonStart_Click(object sender, EventArgs e)
{
nbclk++;
if (nbclk > 6)
buttonStart.Enabled = false;

try
{
reset();
Expand Down Expand Up @@ -96,15 +96,14 @@ public void reset()

private void buttonReset_Click(object sender, EventArgs e)
{
buttonStart.Enabled = true;
nbclk = 0;
transport.Stop();
rtbL_ecr.Clear();
rtbL_lec.Clear();
rtbS_ecr.Clear();
rtbS_lec.Clear();
transport.Restart();
reset();
network.resetFiles();
transport.resetFiles();
}

private void buttonQuit_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -134,18 +133,47 @@ private void buttonGenerate_Click(object sender, EventArgs e)
int intDest = Int32.Parse(dest);
string source = transport.setSourceAddress(intDest);

richTextBoxGen.AppendText("N_CONNECT " + dest + " " + source + "\n");
richTextBoxGen.AppendText("N_DATA test no.: " + nbTest + "\n");
richTextBoxGen.AppendText("N_DISCONNECT " + dest + " " + source + "\n");
d_msg = "N_CONNECT " + dest + " " + source + "\n" +
"N_DATA test no.: " + nbTest + "\n" +
"N_DISCONNECT " + dest + " " + source + "\n";

richTextBoxGen.AppendText(d_msg);

}

private void buttonSend2File_Click(object sender, EventArgs e)
{
transport.Stop();
File.AppendAllText(S_lec, d_msg + Environment.NewLine);

richTextBoxGen.Clear();
nbTest++;
transport.Restart();
}

richTextBoxGen.SaveFile("t_lec.txt");
transport.networkTest();
private void buttonTest_Click(object sender, EventArgs e)
{
d_msg = "N_CONNECT 1 11\n" +
"N_DATA Start testing INF1009\n" +
"N_DISCONNECT 1 11\n" +
"N_CONNECT 47 15\n" +
"N_DATA negative Acknoledgment\n" +
"N_DISCONNECT 47 15\n" +
"N_CONNECT 200 27\n" +
"N_DATA declined by Network\n" +
"N_DISCONNECT 200 27\n" +
"N_CONNECT 200 500\n" +
"N_DATA declined by Network - no route\n" +
"N_DISCONNECT 200 500\n" +
"N_CONNECT 9 19\n" +
"N_DATA multiple of 19 - no awnser\n" +
"N_DISCONNECT 9 19\n" +
"N_CONNECT 12 13\n" +
"N_DATA multiple of 13 - connection declined by destination\n" +
"N_DISCONNECT 12 13\n" +
"N_CONNECT 58 217\n" +
"N_DATA This is the last test, this program was written for the recognition of the achievements of Patrick Duhaime for the course INF1009 ...\n" +
"N_DISCONNECT 58 217\n";
}

public void write2L_lec(string text)
Expand Down
2 changes: 1 addition & 1 deletion INF1009/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static PACKET decapBytes(byte[] received)
currentPacket.destAddr = received[3];
currentPacket.target = received[4];
}
else if (received.Length == 0) ;
else if (received.Length == 0);
else
{
currentPacket.connectionNumber = received[0];
Expand Down
100 changes: 35 additions & 65 deletions INF1009/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading;
using System.Collections;
using System;
using System.Security.AccessControl;

namespace INF1009
{
Expand All @@ -27,18 +28,16 @@ public struct Npdu
class Transport
{
private const string S_lec = "s_lec.txt";
private const string T_lec = "t_lec.txt";
private const string S_ecr = "s_ecr.txt";
private StreamReader reader;
private StreamReader T_reader;
private StreamWriter writer;
private FileStream inputFile;
private FileStream T_inputFile;
private FileStream outputFile;
private Queue transport2Network;
private Queue network2Transport;
string msg;
bool disconnect;
bool end;
ArrayList connected;

/**
Expand All @@ -59,6 +58,7 @@ public Transport(ref Queue transport2Network, ref Queue network2Transport)
Start();
}


/**
* Methode Start appelé au demarrage
*/
Expand All @@ -69,12 +69,41 @@ public void Start()
msg = "";
}

/**
* Methode Stop appelé au changement du fichier source
*/
public void Stop()
{
end = true;
inputFile.Close();
outputFile.Close();
reader.Close();
System.IO.File.WriteAllText(S_lec, string.Empty);
}

/**
* Methode Restart appelé au changement du fichier source
*/
public void Restart()
{
end = false;

inputFile = new FileStream(S_lec, FileMode.OpenOrCreate, FileAccess.Read);
reader = new StreamReader(inputFile);
outputFile = new FileStream(S_ecr, FileMode.OpenOrCreate, FileAccess.Write);
writer = new StreamWriter(outputFile);

resetFiles();
Start();
}

/**
* Methode resetFiles qui remets différents paramètres a leurs
* valeurs initiales pour la lecture et l'écriture des fichiers.
*/
public void resetFiles()
{

inputFile.Position = 0;
outputFile.Position = 0;
connected.Clear();
Expand Down Expand Up @@ -184,7 +213,8 @@ public void networkWrite()
string lineRead;
Npdu networkNNpdu;
string[] settings;
bool valid, end = false;
bool valid;
end = false;

while (!end && !disconnect)
{
Expand Down Expand Up @@ -234,66 +264,6 @@ public void networkWrite()
}
}

public void networkTest()
{

T_inputFile = new FileStream(T_lec, FileMode.OpenOrCreate, FileAccess.Read);
T_reader = new StreamReader(T_inputFile);

string lineRead;
Npdu networkNNpdu;
string[] settings;
bool valid, end = false;

while (!end && !disconnect)
{
if ((lineRead = T_reader.ReadLine()) != null)
{
networkNNpdu = new Npdu();
try
{
valid = false;
settings = lineRead.Split(' ');
Form1._UI.write2S_lec(lineRead);

if (settings[0] == "N_CONNECT")
{
networkNNpdu.type = "N_CONNECT.req";
networkNNpdu.destAddr = settings[1];
networkNNpdu.sourceAddr = settings[2];
networkNNpdu.routeAddr = setRouteAddress(settings[1], settings[2]);
valid = true;
}
else if (settings[0] == "N_DATA")
{
networkNNpdu.type = "N_DATA.req";
for (int i = 1; i < settings.Length; i++)
networkNNpdu.data += settings[i] + " ";
valid = true;
}
else if (settings[0] == "N_DISCONNECT")
{
networkNNpdu.type = "N_DISCONNECT.req";
networkNNpdu.routeAddr = settings[1];
valid = true;
disconnect = true;
}
if (valid)
transport2Network.Enqueue(networkNNpdu);
}
catch (ThreadAbortException)
{

}
}
else
{
end = true;
}
}
T_reader.Close();
T_inputFile.Close();
}

/**
* Methode networkRead (lire_de_reseau) qui verifie si la file network2Transport
Expand All @@ -302,7 +272,7 @@ public void networkTest()
*/
public void networkRead()
{
while (true)
while (!end)
{
try
{
Expand Down
Binary file modified INF1009/bin/Debug/INF1009.exe
Binary file not shown.
Binary file modified INF1009/bin/Debug/INF1009.pdb
Binary file not shown.
15 changes: 5 additions & 10 deletions INF1009/bin/Debug/l_ecr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ N_CONNECT 47 15 route: 47
N_DATA negative Acknoledgment
N_CONNECT 200 27 route: 254
N_CONNECT 200 500 route: -1
54
N_CONNECT 200 500 route: -1
N_CONNECT 9 19 route: 9
N_DATA multiple of 19 - no awnser
N_DISCONNECT 9
N_CONNECT 12 13 route: 12
n declined by destination

destination
N_DISCONNECT 12
tination
N_DISCONNECT 12
ition of the achievements of Patrick Duhaime for the course INF1009 ...
N_CONNECT 58 217 route: 251
N_DATA This is the last test, this program was written for the recognition of the achievements of Patrick Duhaime for the course INF1009 ...
N_DISCONNECT 58
e INF1009 ...
N_DISCONNECT 58
... Sed quid est quod in hac causa maxime homines admirentur et reprehendant meum consilium, cum ego idem antea multa decreverim, que magis ad hominis dignitatem quam ad rei publicae necessitatem pertinerent? Supplicationem quindecim dierum decrevi sententia mea
d quid est quod in hac causa maxime homines admirentur et reprehendant meum consilium, cum ego idem antea multa decreverim, que magis ad hominis dignitatem quam ad rei publicae necessitatem pertinerent? Supplicationem quindecim dierum decrevi sententia mea
N_DISCONNECT 58
15 changes: 6 additions & 9 deletions INF1009/bin/Debug/l_lec.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
N_CONNECT dest Address :1 source Address: 11
N_DATA transferring network data
N_CONNECT dest Address :47 source Address: 15
Closed by Client
N_CONNECT dest Address :47 source Address: 15
N_DISCONNECT Closed by Client
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
N_DISCONNECT Closed by Client

N_CONNECT dest Address :58 source Address: 217
N_DATA transferring network data

ress :12 source Address: 11
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
N_DATA transferring network data
N_DISCONNECT Closed by Client
ng network data
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
TA transferring network data
N_DATA transferring network data
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
ATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
ta
Expand Down
Loading

0 comments on commit ffb9abf

Please sign in to comment.