diff --git a/ConcurrentCSharp/ClientServerConfig.json b/ConcurrentCSharp/ClientServerConfig.json
index 7de1bbfc..329e0b61 100644
--- a/ConcurrentCSharp/ClientServerConfig.json
+++ b/ConcurrentCSharp/ClientServerConfig.json
@@ -3,7 +3,7 @@
"serverIPAddress": "127.0.0.1",
"clientMinStartingTime": 100,
"clientMaxStartingTime": 1000,
- "experimentNumberOfClients": 30,
+ "experimentNumberOfClients": 150,
"delayForTermination": 1000,
"votingList": "ps :open -a preview :open -a whatsapp :ls -all",
"serverListeningQueue": 20,
diff --git a/ConcurrentCSharp/ConcurrentCSharp.sln b/ConcurrentCSharp/ConcurrentCSharp.sln
index 93f2c7d4..c4d517a7 100644
--- a/ConcurrentCSharp/ConcurrentCSharp.sln
+++ b/ConcurrentCSharp/ConcurrentCSharp.sln
@@ -38,6 +38,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Exampl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Asynchronous", "Asynchronous\Asynchronous.csproj", "{CFF4C5D4-01AA-4394-940A-97F1C493D67D}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaseDistribution", "CaseDistribution\CaseDistribution.csproj", "{6604F39B-1D3E-4A18-A4FB-6196AB74B384}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assessment", "Assessment\Assessment.csproj", "{ABE82029-B706-431F-864E-A3952835278A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -108,5 +112,13 @@ Global
{CFF4C5D4-01AA-4394-940A-97F1C493D67D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFF4C5D4-01AA-4394-940A-97F1C493D67D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFF4C5D4-01AA-4394-940A-97F1C493D67D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6604F39B-1D3E-4A18-A4FB-6196AB74B384}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6604F39B-1D3E-4A18-A4FB-6196AB74B384}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6604F39B-1D3E-4A18-A4FB-6196AB74B384}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6604F39B-1D3E-4A18-A4FB-6196AB74B384}.Release|Any CPU.Build.0 = Release|Any CPU
+ {ABE82029-B706-431F-864E-A3952835278A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ABE82029-B706-431F-864E-A3952835278A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ABE82029-B706-431F-864E-A3952835278A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ABE82029-B706-431F-864E-A3952835278A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
diff --git a/ConcurrentCSharp/DiningPhilosophers/Program.cs b/ConcurrentCSharp/DiningPhilosophers/Program.cs
index bcd9f38c..9b5c1a0a 100644
--- a/ConcurrentCSharp/DiningPhilosophers/Program.cs
+++ b/ConcurrentCSharp/DiningPhilosophers/Program.cs
@@ -1,6 +1,6 @@
using System;
-//using Exercise;
-using Solution; // will be provided later
+using Exercise;
+//using Solution; // will be provided later
namespace DiningPhilosophers
{
@@ -12,12 +12,12 @@ static void Main(string[] args)
Table table = new Table(numPhilosphers);
Console.WriteLine("[Dinining Philospher] Dining with one fork is going to start ...");
- //table.startOneForkDining(iteration);
+ table.startOneForkDining(iteration);
//Console.WriteLine("[Dinining Philospher] Dining with two forks is going to start (press enter)...");
//Console.ReadLine();
//table.startTwoForksDining(iteration);
- table.startTwoForksDiningSafe(iteration);
+ //table.startTwoForksDiningSafe(iteration);
}
}
diff --git a/ConcurrentCSharp/SocketClient/Program.cs b/ConcurrentCSharp/SocketClient/Program.cs
index f5417384..8e1866b9 100644
--- a/ConcurrentCSharp/SocketClient/Program.cs
+++ b/ConcurrentCSharp/SocketClient/Program.cs
@@ -1,7 +1,7 @@
using System;
using Sequential;
-using Concurrent;
-//using Solution;
+//using Concurrent;
+using Solution;
namespace Program
{
diff --git a/ConcurrentCSharp/SocketClient/Sequential.cs b/ConcurrentCSharp/SocketClient/Sequential.cs
index a902a6b6..2aa8bc44 100644
--- a/ConcurrentCSharp/SocketClient/Sequential.cs
+++ b/ConcurrentCSharp/SocketClient/Sequential.cs
@@ -166,8 +166,8 @@ public class SequentialClientsSimulator
{
private SimpleClient[] clients;
public Setting settings;
- public string configFile = "../ClientServerConfig.json";
- //public string configFile = "../../../../ClientServerConfig.json"; // for debugging
+ //public string configFile = "../ClientServerConfig.json";
+ public string configFile = "../../../../ClientServerConfig.json"; // for debugging
public SequentialClientsSimulator()
diff --git a/ConcurrentCSharp/SocketServer/Concurrent.cs b/ConcurrentCSharp/SocketServer/Concurrent.cs
index 23646643..6c13a46d 100644
--- a/ConcurrentCSharp/SocketServer/Concurrent.cs
+++ b/ConcurrentCSharp/SocketServer/Concurrent.cs
@@ -1,25 +1,25 @@
-using Sequential;
-using System;
-//todo [Assignment]: add required namespaces
+//using Sequential;
+//using System;
+////todo [Assignment]: add required namespaces
-namespace Concurrent
-{
- public class ConcurrentServer : SequentialServer
- {
- // todo [Assignment]: implement required attributes specific for concurrent server
+//namespace Concurrent
+//{
+// public class ConcurrentServer : SequentialServer
+// {
+// // todo [Assignment]: implement required attributes specific for concurrent server
- public ConcurrentServer(Setting settings) : base(settings)
- {
- // todo [Assignment]: implement required code
- }
- public override void prepareServer()
- {
- // todo [Assignment]: implement required code
- }
- public override string processMessage(String msg)
- {
- // todo [Assignment]: implement required code
- return "";
- }
- }
-}
\ No newline at end of file
+// public ConcurrentServer(Setting settings) : base(settings)
+// {
+// // todo [Assignment]: implement required code
+// }
+// public override void prepareServer()
+// {
+// // todo [Assignment]: implement required code
+// }
+// public override string processMessage(String msg)
+// {
+// // todo [Assignment]: implement required code
+// return "";
+// }
+// }
+//}
\ No newline at end of file
diff --git a/ConcurrentCSharp/SocketServer/Program.cs b/ConcurrentCSharp/SocketServer/Program.cs
index b697cd11..74e5e27b 100644
--- a/ConcurrentCSharp/SocketServer/Program.cs
+++ b/ConcurrentCSharp/SocketServer/Program.cs
@@ -13,7 +13,9 @@ namespace Program
public class ServerSimulator
{
public Setting settings;
- public string configFile = "../ClientServerConfig.json";
+ //public string configFile = "../ClientServerConfig.json";
+ public string configFile = "../../../../ClientServerConfig.json"; // for debugging
+
public ServerSimulator()
{
@@ -84,8 +86,7 @@ static void Main(string[] args)
Console.WriteLine("\n Invalid input ... ");
break;
}
- }
-
+ }
}
}
}
diff --git a/Networking/DistLibrary/ClientServerConfig.json b/Networking/DistLibrary/ClientServerConfig.json
index 0c378d98..e52856b1 100644
--- a/Networking/DistLibrary/ClientServerConfig.json
+++ b/Networking/DistLibrary/ClientServerConfig.json
@@ -1,9 +1,9 @@
{
- "serverPortNumber": 11111,
- "bookHelperPortNumber": 11112,
- "userHelperPortNumber": 11113,
- "serverIPAddress": "127.0.0.1",
- "bookHelperIPAddress": "127.0.0.1",
- "userHelperIPAddress": "127.0.0.1",
- "serverListeningQueue": 5
+ "ServerPortNumber": 11111,
+ "BookHelperPortNumber": 11112,
+ "UserHelperPortNumber": 11113,
+ "ServerIPAddress": "127.0.0.1",
+ "BookHelperIPAddress": "127.0.0.1",
+ "UserHelperIPAddress": "127.0.0.1",
+ "ServerListeningQueue": 5
}
\ No newline at end of file
diff --git a/Networking/DistLibrary/LibBookHelper/BookHelper.cs b/Networking/DistLibrary/LibBookHelper/BookHelper.cs
index fe3c8f71..d65c2688 100644
--- a/Networking/DistLibrary/LibBookHelper/BookHelper.cs
+++ b/Networking/DistLibrary/LibBookHelper/BookHelper.cs
@@ -1,5 +1,4 @@
using System;
-using System.Threading;
using System.Text.Json;
using System.Net;
using System.Net.Sockets;
@@ -12,15 +11,16 @@ namespace BookHelper
// Note: Do not change this class.
public class Setting
{
- public int serverPortNumber { get; set; }
- public int bookHelperPortNumber { get; set; }
- public int userHelperPortNumber { get; set; }
- public string serverIPAddress { get; set; }
- public string bookHelperIPAddress { get; set; }
- public string userHelperIPAddress { get; set; }
- public int serverListeningQueue { get; set; }
+ public int ServerPortNumber { get; set; }
+ public int BookHelperPortNumber { get; set; }
+ public int UserHelperPortNumber { get; set; }
+ public string ServerIPAddress { get; set; }
+ public string BookHelperIPAddress { get; set; }
+ public string UserHelperIPAddress { get; set; }
+ public int ServerListeningQueue { get; set; }
}
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
public class SequentialHelper
{
public SequentialHelper()
diff --git a/Networking/DistLibrary/LibBookHelper/Data.cs b/Networking/DistLibrary/LibBookHelper/Data.cs
index a78e7102..aeaa70d6 100644
--- a/Networking/DistLibrary/LibBookHelper/Data.cs
+++ b/Networking/DistLibrary/LibBookHelper/Data.cs
@@ -2,35 +2,36 @@
namespace LibData
{
+
public class Message
{
- public string type { get; set; }
- public string content { get; set; }
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
}
- public class MessageType
+ public enum MessageType
{
- public const string hello = "Hello";
- public const string welcome = "Welcome";
- public const string bookInquiry = "BookInquiry";
- public const string userInquiry = "UserInquiry";
- public const string bookInqReply = "BookInquiryReply";
- public const string userInqReply = "UserInquiryReply";
- public const string endComm = "EndCommunication";
- public const string error = "Error";
- public const string notFound = "NotFound";
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
}
public class BookData
{
// the name of the book
- public string title { get; set; }
+ public string Title { get; set; }
// the author of the book
- public string author { get; set; }
+ public string Author { get; set; }
// the availability of the book: can be either Available or Borrowed
- public string status { get; set; }
+ public string Status { get; set; }
//the user id of the person who borrowed the book, otherwise null if the book is available.
- public string borrowedBy { get; set; }
+ public string BorrowedBy { get; set; }
// return date of a book if it is borrowed, otherwise null.
public string ReturnDate { get; set; }
}
@@ -38,10 +39,10 @@ public class BookData
public class UserData
{
// user id: has the format User-[a number]
- public string user_id { get; set; }
+ public string User_id { get; set; }
// full name
- public string name { get; set; }
- public string email { get; set; }
- public string phone { get; set; }
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
}
}
diff --git a/Networking/DistLibrary/LibBookHelper/Program.cs b/Networking/DistLibrary/LibBookHelper/Program.cs
index 4882a9e5..2dbce1e0 100644
--- a/Networking/DistLibrary/LibBookHelper/Program.cs
+++ b/Networking/DistLibrary/LibBookHelper/Program.cs
@@ -1,6 +1,9 @@
-using System;
-using BookHelper;
-//using BookHelperSolution;
+
+using System;
+// using BookHelper;
+using BookHelperSolution;
+using System.Text;
+using System.Diagnostics.Tracing;
// NOTE: THIS FILE MUST NOT CHANGE
@@ -26,9 +29,54 @@ class Program
///
static void Main(string[] args)
{
+ using var listener = new SocketEventListener();
Console.Clear();
HelperSimulator hs = new HelperSimulator();
hs.sequentialRun();
}
+
+ internal sealed class SocketEventListener : EventListener
+ {
+ // Constant necessary for attaching ActivityId to the events.
+ public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // List of event source names provided by networking in .NET 5.
+ if (eventSource.Name == "System.Net.Sockets" ||
+ eventSource.Name == "System.Net.Security"||
+ eventSource.Name == "System.Net.NameResolution")
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways);
+ }
+ // Turn on ActivityId.
+ else if (eventSource.Name == "System.Threading.Tasks.TplEventSource")
+ {
+ // Attach ActivityId to the events.
+ EnableEvents(eventSource, EventLevel.LogAlways, TasksFlowActivityIds);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ Console.ResetColor();
+
+ var sb = new StringBuilder().Append($"{eventData.TimeStamp:HH:mm:ss.ff} {eventData.ActivityId}.{eventData.RelatedActivityId} {eventData.EventSource.Name}.{eventData.EventName}(");
+ for (int i = 0; i < eventData.Payload?.Count; i++)
+ {
+ sb.Append(eventData.PayloadNames?[i]).Append(": ").Append(eventData.Payload[i]);
+ if (i < eventData.Payload?.Count - 1)
+ {
+ sb.Append(", ");
+ }
+ }
+
+ sb.Append(")");
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(sb.ToString());
+ Console.ResetColor();
+ }
+ }
}
}
+
diff --git a/Networking/DistLibrary/LibClient/Client.cs b/Networking/DistLibrary/LibClient/Client.cs
index e8e51670..ac5d8b0b 100644
--- a/Networking/DistLibrary/LibClient/Client.cs
+++ b/Networking/DistLibrary/LibClient/Client.cs
@@ -3,32 +3,34 @@
using System.Net.Sockets;
using System.Net;
using System.Text.Json;
-using System.Threading;
using LibData;
namespace LibClient
{
+ // Note: Do not change this class
public class Setting
{
- public int serverPortNumber { get; set; }
- public int bookHelperPortNumber { get; set; }
- public int userHelperPortNumber { get; set; }
- public string serverIPAddress { get; set; }
- public string bookHelperIPAddress { get; set; }
- public string userHelperIPAddress { get; set; }
- public int serverListeningQueue { get; set; }
+ public int ServerPortNumber { get; set; }
+ public int BookHelperPortNumber { get; set; }
+ public int UserHelperPortNumber { get; set; }
+ public string ServerIPAddress { get; set; }
+ public string BookHelperIPAddress { get; set; }
+ public string UserHelperIPAddress { get; set; }
+ public int ServerListeningQueue { get; set; }
}
+ // Note: Do not change this class
public class Output
{
- public string client_id { get; set; } // the id of the client that requests the book
- public string bookName { get; set; } // the name of the book to be reqyested
- public string status { get; set; } // final status received from the server
- public string borrowerName { get; set; } // the name of the borrower in case the status is borrowed, otherwise null
- public string borrowerEmail { get; set; } // the email of the borrower in case the status is borrowed, otherwise null
+ public string Client_id { get; set; } // the id of the client that requests the book
+ public string BookName { get; set; } // the name of the book to be reqyested
+ public string Status { get; set; } // final status received from the server
+ public string BorrowerName { get; set; } // the name of the borrower in case the status is borrowed, otherwise null
+ public string BorrowerEmail { get; set; } // the email of the borrower in case the status is borrowed, otherwise null
}
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
public class SimpleClient
{
// some of the fields are defined.
@@ -56,14 +58,14 @@ public SimpleClient(int id, string bookName)
this.bookName = bookName;
this.client_id = "Client " + id.ToString();
this.result = new Output();
- result.bookName = bookName;
- result.client_id = this.client_id;
+ result.BookName = bookName;
+ result.Client_id = this.client_id;
// read JSON directly from a file
try
{
string configContent = File.ReadAllText(configFile);
this.settings = JsonSerializer.Deserialize(configContent);
- this.ipAddress = IPAddress.Parse(settings.serverIPAddress);
+ this.ipAddress = IPAddress.Parse(settings.ServerIPAddress);
}
catch (Exception e)
{
@@ -78,7 +80,7 @@ public SimpleClient(int id, string bookName)
/// The result of the request
public Output start()
{
-
+
// todo: implement the body to communicate with the server and requests the book. Return the result as an Output object.
// Adding extra methods to the class is permitted. The signature of this method must not change.
diff --git a/Networking/DistLibrary/LibClient/Data.cs b/Networking/DistLibrary/LibClient/Data.cs
index a78e7102..aeaa70d6 100644
--- a/Networking/DistLibrary/LibClient/Data.cs
+++ b/Networking/DistLibrary/LibClient/Data.cs
@@ -2,35 +2,36 @@
namespace LibData
{
+
public class Message
{
- public string type { get; set; }
- public string content { get; set; }
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
}
- public class MessageType
+ public enum MessageType
{
- public const string hello = "Hello";
- public const string welcome = "Welcome";
- public const string bookInquiry = "BookInquiry";
- public const string userInquiry = "UserInquiry";
- public const string bookInqReply = "BookInquiryReply";
- public const string userInqReply = "UserInquiryReply";
- public const string endComm = "EndCommunication";
- public const string error = "Error";
- public const string notFound = "NotFound";
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
}
public class BookData
{
// the name of the book
- public string title { get; set; }
+ public string Title { get; set; }
// the author of the book
- public string author { get; set; }
+ public string Author { get; set; }
// the availability of the book: can be either Available or Borrowed
- public string status { get; set; }
+ public string Status { get; set; }
//the user id of the person who borrowed the book, otherwise null if the book is available.
- public string borrowedBy { get; set; }
+ public string BorrowedBy { get; set; }
// return date of a book if it is borrowed, otherwise null.
public string ReturnDate { get; set; }
}
@@ -38,10 +39,10 @@ public class BookData
public class UserData
{
// user id: has the format User-[a number]
- public string user_id { get; set; }
+ public string User_id { get; set; }
// full name
- public string name { get; set; }
- public string email { get; set; }
- public string phone { get; set; }
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
}
}
diff --git a/Networking/DistLibrary/LibClient/LibOutput.json b/Networking/DistLibrary/LibClient/LibOutput.json
index 2460e43c..4211a7e7 100644
--- a/Networking/DistLibrary/LibClient/LibOutput.json
+++ b/Networking/DistLibrary/LibClient/LibOutput.json
@@ -1 +1 @@
-[{"client_id":"Client 0","bookName":"War and Peace","status":"Borrowed","borrowerName":"Abdul Barker","borrowerEmail":"in@Pellentesqueultricies.co.uk"},{"client_id":"Client 1","bookName":"Harry Potter","status":"Available","borrowerName":null,"borrowerEmail":null},{"client_id":"Client 2","bookName":"Lord of the Rings","status":"Available","borrowerName":null,"borrowerEmail":null},{"client_id":"Client 3","bookName":"An Unknown Book","status":"NotFound","borrowerName":null,"borrowerEmail":null}]
\ No newline at end of file
+[{"Client_id":"Client 0","BookName":"War and Peace","Status":"NotFound","BorrowerName":null,"BorrowerEmail":null},{"Client_id":"Client 1","BookName":"Harry Potter","Status":"NotFound","BorrowerName":null,"BorrowerEmail":null},{"Client_id":"Client 2","BookName":"Lord of the Rings","Status":"NotFound","BorrowerName":null,"BorrowerEmail":null},{"Client_id":"Client 3","BookName":"An Unknown Book","Status":"NotFound","BorrowerName":null,"BorrowerEmail":null}]
\ No newline at end of file
diff --git a/Networking/DistLibrary/LibClient/Program.cs b/Networking/DistLibrary/LibClient/Program.cs
index 5b2c7865..99a93d6f 100644
--- a/Networking/DistLibrary/LibClient/Program.cs
+++ b/Networking/DistLibrary/LibClient/Program.cs
@@ -1,9 +1,12 @@
-using System;
+using System.Text;
+using System.Diagnostics.Tracing;
+using System.Drawing;
+using System;
using System.Text.Json;
using System.IO;
using System.Collections.Generic;
-using LibClient;
-//using LibClientSolution;
+// using LibClient;
+using LibClientSolution;
// NOTE: DO NOT CHANGE THIS FILE
@@ -42,10 +45,11 @@ public ClientsSimulator()
// each client is initialized by a client id and a book name (from the input file) to request
foreach (InputData d in this.inputDataList)
{
- clients[id] = new SimpleClient(id,d.BookName);
+ clients[id] = new SimpleClient(id, d.BookName);
id++;
}
- }catch (Exception e) { Console.Out.WriteLine("[ClientSimulator] Exception: {0}", e.Message); }
+ }
+ catch (Exception e) { Console.Out.WriteLine("[ClientSimulator] Exception: {0}", e.Message); }
}
///
/// Starts the book requesting process for each client and collects the result for each request
@@ -59,7 +63,7 @@ public void startSimulation()
results[i] = clients[i].start();
}
//this is the ending client
- new SimpleClient(-1,"").start();
+ new SimpleClient(-1, "").start();
}
///
@@ -70,14 +74,14 @@ public void printOutput()
Console.Out.WriteLine("\n *************** Final Output *********** \n");
for (int i = 0; i < results.Length; i++)
Console.WriteLine("{0} {1} {2} {3}",
- results[i].client_id,
- results[i].bookName,
- results[i].borrowerName,
- results[i].borrowerEmail);
+ results[i].Client_id,
+ results[i].BookName,
+ results[i].BorrowerName,
+ results[i].BorrowerEmail);
string outputContent = JsonSerializer.Serialize
///
+
static void Main(string[] args)
{
+
+ using var listener = new SocketEventListener();
Console.Clear();
ClientsSimulator simulator = new ClientsSimulator();
simulator.startSimulation();
+
simulator.printOutput();
}
+
+ internal sealed class SocketEventListener : EventListener
+ {
+ // Constant necessary for attaching ActivityId to the events.
+ public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // List of event source names provided by networking in .NET 5.
+ if (eventSource.Name == "System.Net.Sockets" ||
+ eventSource.Name == "System.Net.Security" ||
+ eventSource.Name == "System.Net.NameResolution")
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways);
+ }
+ // Turn on ActivityId.
+ else if (eventSource.Name == "System.Threading.Tasks.TplEventSource")
+ {
+ // Attach ActivityId to the events.
+ EnableEvents(eventSource, EventLevel.LogAlways, TasksFlowActivityIds);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ Console.ResetColor();
+
+ var sb = new StringBuilder().Append($"{eventData.TimeStamp:HH:mm:ss.ff} {eventData.ActivityId}.{eventData.RelatedActivityId} {eventData.EventSource.Name}.{eventData.EventName}(");
+ for (int i = 0; i < eventData.Payload?.Count; i++)
+ {
+ sb.Append(eventData.PayloadNames?[i]).Append(": ").Append(eventData.Payload[i]);
+ if (i < eventData.Payload?.Count - 1)
+ {
+ sb.Append(", ");
+ }
+ }
+
+ sb.Append(")");
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(sb.ToString());
+ Console.ResetColor();
+ }
+ }
}
+
}
diff --git a/Networking/DistLibrary/LibServer/Data.cs b/Networking/DistLibrary/LibServer/Data.cs
index a78e7102..2106c130 100644
--- a/Networking/DistLibrary/LibServer/Data.cs
+++ b/Networking/DistLibrary/LibServer/Data.cs
@@ -2,46 +2,47 @@
namespace LibData
{
- public class Message
+
+ public class Message
{
- public string type { get; set; }
- public string content { get; set; }
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
}
- public class MessageType
+ public enum MessageType
{
- public const string hello = "Hello";
- public const string welcome = "Welcome";
- public const string bookInquiry = "BookInquiry";
- public const string userInquiry = "UserInquiry";
- public const string bookInqReply = "BookInquiryReply";
- public const string userInqReply = "UserInquiryReply";
- public const string endComm = "EndCommunication";
- public const string error = "Error";
- public const string notFound = "NotFound";
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
}
- public class BookData
+ public class BookData
{
// the name of the book
- public string title { get; set; }
+ public string Title { get; set; }
// the author of the book
- public string author { get; set; }
+ public string Author { get; set; }
// the availability of the book: can be either Available or Borrowed
- public string status { get; set; }
+ public string Status { get; set; }
//the user id of the person who borrowed the book, otherwise null if the book is available.
- public string borrowedBy { get; set; }
+ public string BorrowedBy { get; set; }
// return date of a book if it is borrowed, otherwise null.
public string ReturnDate { get; set; }
}
- public class UserData
+ public class UserData
{
// user id: has the format User-[a number]
- public string user_id { get; set; }
+ public string User_id { get; set; }
// full name
- public string name { get; set; }
- public string email { get; set; }
- public string phone { get; set; }
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
}
}
diff --git a/Networking/DistLibrary/LibServer/LibServer.cs b/Networking/DistLibrary/LibServer/LibServer.cs
index 2ab57668..724c6b86 100644
--- a/Networking/DistLibrary/LibServer/LibServer.cs
+++ b/Networking/DistLibrary/LibServer/LibServer.cs
@@ -4,7 +4,7 @@
using System.Net.Sockets;
using System.IO;
using LibData;
-using System.Threading;
+
namespace LibServer
{
@@ -20,8 +20,10 @@ public class Setting
public int serverListeningQueue { get; set; }
}
+
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
public class SequentialServer
- {
+ {
public SequentialServer()
{
//todo: implement the body. Add extra fields and methods to the class if it is needed
@@ -33,4 +35,8 @@ public void start()
}
}
+
}
+
+
+
diff --git a/Networking/DistLibrary/LibServer/Program.cs b/Networking/DistLibrary/LibServer/Program.cs
index 3334e7ec..ffdc42bb 100644
--- a/Networking/DistLibrary/LibServer/Program.cs
+++ b/Networking/DistLibrary/LibServer/Program.cs
@@ -1,6 +1,8 @@
using System;
-using LibServer;
-//using LibServerSolution;
+// using LibServer;
+using LibServerSolution;
+using System.Text;
+using System.Diagnostics.Tracing;
// NOTE: THIS FILE MUST NOT CHANGE
@@ -11,7 +13,7 @@ public class ServerSimulator
public Setting settings;
public ServerSimulator()
- { }
+ { }
///
/// initiates the server
@@ -31,9 +33,54 @@ public class Program
///
static void Main(string[] args)
{
+ using var listener = new SocketEventListener();
Console.Clear();
new ServerSimulator().sequentialRun();
}
+
+ internal sealed class SocketEventListener : EventListener
+ {
+ // Constant necessary for attaching ActivityId to the events.
+ public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // List of event source names provided by networking in .NET 5.
+ if (eventSource.Name == "System.Net.Sockets" ||
+ eventSource.Name == "System.Net.Security" ||
+ eventSource.Name == "System.Net.NameResolution")
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways);
+ }
+ // Turn on ActivityId.
+ else if (eventSource.Name == "System.Threading.Tasks.TplEventSource")
+ {
+ // Attach ActivityId to the events.
+ EnableEvents(eventSource, EventLevel.LogAlways, TasksFlowActivityIds);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ Console.ResetColor();
+
+ var sb = new StringBuilder().Append($"{eventData.TimeStamp:HH:mm:ss.ff} {eventData.ActivityId}.{eventData.RelatedActivityId} {eventData.EventSource.Name}.{eventData.EventName} {eventData.Task}.{eventData.Message}(");
+ for (int i = 0; i < eventData.Payload?.Count; i++)
+ {
+ sb.Append(eventData.PayloadNames?[i]).Append(": ").Append(eventData.Payload[i]);
+ if (i < eventData.Payload?.Count - 1)
+ {
+ sb.Append(", ");
+ }
+ }
+
+ sb.Append(")");
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(sb.ToString());
+ Console.ResetColor();
+ }
+ }
}
}
+
diff --git a/Networking/DistLibrary/LibUserHelper/Data.cs b/Networking/DistLibrary/LibUserHelper/Data.cs
index a78e7102..aeaa70d6 100644
--- a/Networking/DistLibrary/LibUserHelper/Data.cs
+++ b/Networking/DistLibrary/LibUserHelper/Data.cs
@@ -2,35 +2,36 @@
namespace LibData
{
+
public class Message
{
- public string type { get; set; }
- public string content { get; set; }
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
}
- public class MessageType
+ public enum MessageType
{
- public const string hello = "Hello";
- public const string welcome = "Welcome";
- public const string bookInquiry = "BookInquiry";
- public const string userInquiry = "UserInquiry";
- public const string bookInqReply = "BookInquiryReply";
- public const string userInqReply = "UserInquiryReply";
- public const string endComm = "EndCommunication";
- public const string error = "Error";
- public const string notFound = "NotFound";
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
}
public class BookData
{
// the name of the book
- public string title { get; set; }
+ public string Title { get; set; }
// the author of the book
- public string author { get; set; }
+ public string Author { get; set; }
// the availability of the book: can be either Available or Borrowed
- public string status { get; set; }
+ public string Status { get; set; }
//the user id of the person who borrowed the book, otherwise null if the book is available.
- public string borrowedBy { get; set; }
+ public string BorrowedBy { get; set; }
// return date of a book if it is borrowed, otherwise null.
public string ReturnDate { get; set; }
}
@@ -38,10 +39,10 @@ public class BookData
public class UserData
{
// user id: has the format User-[a number]
- public string user_id { get; set; }
+ public string User_id { get; set; }
// full name
- public string name { get; set; }
- public string email { get; set; }
- public string phone { get; set; }
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
}
}
diff --git a/Networking/DistLibrary/LibUserHelper/Program.cs b/Networking/DistLibrary/LibUserHelper/Program.cs
index 4a22624d..885a7fa1 100644
--- a/Networking/DistLibrary/LibUserHelper/Program.cs
+++ b/Networking/DistLibrary/LibUserHelper/Program.cs
@@ -1,6 +1,9 @@
-using System;
-using UserHelper;
-//using UserHelperSolution;
+using System.Drawing;
+using System;
+// using UserHelper;
+using UserHelperSolution;
+using System.Text;
+using System.Diagnostics.Tracing;
// NOTE: THIS FILE MUST NOT CHANGE
@@ -26,9 +29,56 @@ class Program
///
static void Main(string[] args)
{
+ using var listener = new SocketEventListener();
Console.Clear();
HelperSimulator hs = new HelperSimulator();
hs.sequentialRun();
}
+
+ internal sealed class SocketEventListener : EventListener
+ {
+ // Constant necessary for attaching ActivityId to the events.
+ public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // List of event source names provided by networking in .NET 5.
+ if (eventSource.Name == "System.Net.Sockets" ||
+ eventSource.Name == "System.Net.Security"||
+ eventSource.Name == "System.Net.NameResolution")
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways);
+ }
+ // Turn on ActivityId.
+ else if (eventSource.Name == "System.Threading.Tasks.TplEventSource")
+ {
+ // Attach ActivityId to the events.
+ EnableEvents(eventSource, EventLevel.LogAlways, TasksFlowActivityIds);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ Console.ResetColor();
+
+ var sb = new StringBuilder().Append($"{eventData.TimeStamp:HH:mm:ss.ff} {eventData.ActivityId}.{eventData.RelatedActivityId} {eventData.EventSource.Name}.{eventData.EventName}(");
+ for (int i = 0; i < eventData.Payload?.Count; i++)
+ {
+
+ sb.Append(eventData.PayloadNames?[i]).Append(": ").Append(eventData.Payload[i]);
+ if (i < eventData.Payload?.Count - 1)
+ {
+ sb.Append(", ");
+ }
+ }
+
+ sb.Append(")");
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(sb.ToString());
+ Console.ResetColor();
+ }
+ }
}
+
+
}
diff --git a/Networking/DistLibrary/LibUserHelper/UserHelper.cs b/Networking/DistLibrary/LibUserHelper/UserHelper.cs
index 122aada6..75dd26bf 100644
--- a/Networking/DistLibrary/LibUserHelper/UserHelper.cs
+++ b/Networking/DistLibrary/LibUserHelper/UserHelper.cs
@@ -1,5 +1,4 @@
using System;
-using System.Threading;
using System.Text.Json;
using System.Net;
using System.Net.Sockets;
@@ -12,15 +11,16 @@ namespace UserHelper
// Note: Do not change this class.
public class Setting
{
- public int serverPortNumber { get; set; }
- public int bookHelperPortNumber { get; set; }
- public int userHelperPortNumber { get; set; }
- public string serverIPAddress { get; set; }
- public string bookHelperIPAddress { get; set; }
- public string userHelperIPAddress { get; set; }
- public int serverListeningQueue { get; set; }
+ public int ServerPortNumber { get; set; }
+ public int BookHelperPortNumber { get; set; }
+ public int UserHelperPortNumber { get; set; }
+ public string ServerIPAddress { get; set; }
+ public string BookHelperIPAddress { get; set; }
+ public string UserHelperIPAddress { get; set; }
+ public int ServerListeningQueue { get; set; }
}
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
public class SequentialHelper
{
public SequentialHelper()
diff --git a/Networking/SimpleClientServer/Client/Client.csproj b/Networking/SimpleClientServer/Client/Client.csproj
new file mode 100644
index 00000000..1d2d39a9
--- /dev/null
+++ b/Networking/SimpleClientServer/Client/Client.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net5.0
+
+
+
diff --git a/Networking/SimpleClientServer/Client/Program.cs b/Networking/SimpleClientServer/Client/Program.cs
new file mode 100644
index 00000000..5b441b25
--- /dev/null
+++ b/Networking/SimpleClientServer/Client/Program.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+
+namespace socket_prog
+{
+ class Client
+ {
+ static void Main(string[] args)
+ {
+ byte[] buffer = new byte[1000];
+ byte[] msg = new byte[1000];
+ string data = null;
+
+
+ IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
+
+ IPEndPoint serverEndpoint = new IPEndPoint(ipAddress, 32000);
+
+ ConsoleKeyInfo key;
+
+
+ Socket sock = new Socket(AddressFamily.InterNetwork,
+ SocketType.Stream, ProtocolType.Tcp);
+ sock.Connect(serverEndpoint);
+
+ while (true)
+ {
+ Console.WriteLine("\nEnter a message to send to the server");
+ data = Console.ReadLine();
+ if (data.Length != 0)
+ {
+
+ msg = Encoding.ASCII.GetBytes(data);
+ sock.Send(msg);
+ int b = sock.Receive(buffer);
+ data = Encoding.ASCII.GetString(buffer, 0, b);
+
+ Console.WriteLine("" + data);
+ data = null;
+ }
+
+ Console.WriteLine("\n<< Continue 'y' , Exit 'e'>>\n");
+ key = Console.ReadKey();
+ if (key.KeyChar == 'e')
+ {
+ sock.Send(Encoding.ASCII.GetBytes("Closed"));
+ Console.WriteLine("\nExiting.. Press any key to continue");
+ key = Console.ReadKey();
+ sock.Close();
+ break;
+ }
+
+ }
+ }
+ }
+
+}
diff --git a/Networking/SimpleClientServer/Server/Program.cs b/Networking/SimpleClientServer/Server/Program.cs
new file mode 100644
index 00000000..8f082ac2
--- /dev/null
+++ b/Networking/SimpleClientServer/Server/Program.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+
+namespace socket_prog
+{
+ class Server
+ {
+ static void Main(string[] args)
+ {
+ // define required variables
+ const string ipAdd = "127.0.0.1";
+ const int portNum = 32000;
+ const int maxBuffSize = 1000;
+ byte[] buffer = new byte[maxBuffSize];
+ byte[] msg = Encoding.ASCII.GetBytes("From server: Your message delivered\n");
+ string data = null;
+
+ // define parameters equired to set up the network
+ IPAddress ipAddress = IPAddress.Parse(ipAdd);
+ IPEndPoint localEndpoint = new IPEndPoint(ipAddress, portNum);
+
+ // establish a listening socket
+ Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
+
+ //bind to the socket
+ sock.Bind(localEndpoint);
+ // listen with max number of pending incoming requests
+ sock.Listen(5);
+ Console.WriteLine("\n Waiting for clients..");
+ // wait to accept incoming requests
+ Socket newSock = sock.Accept();
+
+ // a loop to receive / process / reply
+ while (true)
+ {
+ int b = newSock.Receive(buffer); // receive
+ data = Encoding.ASCII.GetString(buffer, 0, b);
+ // process
+ if (data == "Closed")
+ {
+ newSock.Close();
+ Console.WriteLine("Closing the socket..");
+ break;
+ }
+ else
+ {
+ Console.WriteLine("" + data);
+ data = null;
+ newSock.Send(msg); // reply
+ }
+
+ }
+ // close the socket
+ sock.Close();
+
+ }
+ }
+
+}
diff --git a/Networking/SimpleClientServer/Server/Server.csproj b/Networking/SimpleClientServer/Server/Server.csproj
new file mode 100644
index 00000000..1d2d39a9
--- /dev/null
+++ b/Networking/SimpleClientServer/Server/Server.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net5.0
+
+
+
diff --git a/Networking/SimpleClientServer/SimpleClientServer.sln b/Networking/SimpleClientServer/SimpleClientServer.sln
new file mode 100644
index 00000000..4a1e7ed9
--- /dev/null
+++ b/Networking/SimpleClientServer/SimpleClientServer.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.810.9
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{1D7EAE9B-A9C2-488E-99F4-7C33D9EFFE5C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{FDF5BA6E-8C4E-48CD-961B-0509175977E3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {1D7EAE9B-A9C2-488E-99F4-7C33D9EFFE5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1D7EAE9B-A9C2-488E-99F4-7C33D9EFFE5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1D7EAE9B-A9C2-488E-99F4-7C33D9EFFE5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1D7EAE9B-A9C2-488E-99F4-7C33D9EFFE5C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FDF5BA6E-8C4E-48CD-961B-0509175977E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FDF5BA6E-8C4E-48CD-961B-0509175977E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FDF5BA6E-8C4E-48CD-961B-0509175977E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FDF5BA6E-8C4E-48CD-961B-0509175977E3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {C0D849A0-6F44-4884-A47B-FFF3ED38E3D4}
+ EndGlobalSection
+EndGlobal
diff --git a/basecamp/readme.md b/basecamp/readme.md
index b2cd98a1..d1e6ba46 100644
--- a/basecamp/readme.md
+++ b/basecamp/readme.md
@@ -10,4 +10,3 @@ The learning activities are designed based on these following references:
- **Ref-B01**: Book, Bill Lubanovic; "Introducing Python: Modern Computing in Simple Packages"; [Available here](https://www.oreilly.com/library/view/introducing-python-2nd/9781492051374/)
- **Ref-O02**: Online Tutorial; Charles Severance; "Python for Everybody"; [Available here](https://books.trinket.io/pfe/index.html)
--
diff --git a/basecamp/week02/inf-bc-w02-program.md b/basecamp/week02/inf-bc-w02-program.md
index a2d0d656..a128722a 100644
--- a/basecamp/week02/inf-bc-w02-program.md
+++ b/basecamp/week02/inf-bc-w02-program.md
@@ -2,9 +2,9 @@
**Introduction**: This document presents learning activities for week 02. In Week 02, you will learn basics of Python structures to add decision points to your linear programs. A branching program is a flow of sequential instructions with branching statements. By the end this week, you will be able to implement a program where a user can enter simple input, the program can make choices based on some conditions and after calculation results can be printed as output.
-## Day-01: What is a ???
+## Day-01: How to check conditions?
-1. Using **Ref-B01: Chapter 03** answer and experiment the following questions:
+1. Using **Ref-O02: Chapter 03** answer and experiment the following questions:
1. What is a
2. Using **RefB-01: Appendix B** perform the following tasks:
1. Install Pyt
diff --git a/models/Closing.png b/models/Closing.png
new file mode 100644
index 00000000..a67c2756
Binary files /dev/null and b/models/Closing.png differ
diff --git a/models/Closing.png.bak b/models/Closing.png.bak
new file mode 100644
index 00000000..38baece1
Binary files /dev/null and b/models/Closing.png.bak differ
diff --git a/models/bookAvailable.png b/models/bookAvailable.png
new file mode 100644
index 00000000..8a6e41f4
Binary files /dev/null and b/models/bookAvailable.png differ
diff --git a/models/bookAvailable.png.bak b/models/bookAvailable.png.bak
new file mode 100644
index 00000000..273198e1
Binary files /dev/null and b/models/bookAvailable.png.bak differ
diff --git a/models/bookBorrowed.png b/models/bookBorrowed.png
new file mode 100644
index 00000000..8fe37d69
Binary files /dev/null and b/models/bookBorrowed.png differ
diff --git a/models/bookBorrowed.png.bak b/models/bookBorrowed.png.bak
new file mode 100644
index 00000000..7c4e656a
Binary files /dev/null and b/models/bookBorrowed.png.bak differ
diff --git a/models/bookNotFound.png b/models/bookNotFound.png
new file mode 100644
index 00000000..5985f0ad
Binary files /dev/null and b/models/bookNotFound.png differ
diff --git a/models/bookNotFound.png.bak b/models/bookNotFound.png.bak
new file mode 100644
index 00000000..fdf1912a
Binary files /dev/null and b/models/bookNotFound.png.bak differ
diff --git a/models/networking-SD.asta b/models/networking-SD.asta
new file mode 100644
index 00000000..7f62ac83
Binary files /dev/null and b/models/networking-SD.asta differ
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/ClientServerConfig.json b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/ClientServerConfig.json
new file mode 100644
index 00000000..e52856b1
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/ClientServerConfig.json
@@ -0,0 +1,9 @@
+{
+ "ServerPortNumber": 11111,
+ "BookHelperPortNumber": 11112,
+ "UserHelperPortNumber": 11113,
+ "ServerIPAddress": "127.0.0.1",
+ "BookHelperIPAddress": "127.0.0.1",
+ "UserHelperIPAddress": "127.0.0.1",
+ "ServerListeningQueue": 5
+}
\ No newline at end of file
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/DistLibrary.sln b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/DistLibrary.sln
new file mode 100644
index 00000000..470ea7b0
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/DistLibrary.sln
@@ -0,0 +1,48 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.810.9
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibClient", "LibClient\LibClient.csproj", "{D01312F2-3D27-4A7E-A0AB-B8E0D208C7C1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserHelper", "LibUserHelper\UserHelper.csproj", "{50A9474A-A777-41A8-A028-D6428516773F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookHelper", "LibBookHelper\BookHelper.csproj", "{5E3DF90F-B75D-4C89-85EE-BA49D4446F46}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibServer", "LibServer\LibServer.csproj", "{4C716E6E-165B-44EB-90CE-07A864B371A8}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E8D2FBCB-D24D-4A3C-BB87-54C4344272F9}"
+ ProjectSection(SolutionItems) = preProject
+ ClientServerConfig.json = ClientServerConfig.json
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D01312F2-3D27-4A7E-A0AB-B8E0D208C7C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D01312F2-3D27-4A7E-A0AB-B8E0D208C7C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D01312F2-3D27-4A7E-A0AB-B8E0D208C7C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D01312F2-3D27-4A7E-A0AB-B8E0D208C7C1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {50A9474A-A777-41A8-A028-D6428516773F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {50A9474A-A777-41A8-A028-D6428516773F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {50A9474A-A777-41A8-A028-D6428516773F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {50A9474A-A777-41A8-A028-D6428516773F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5E3DF90F-B75D-4C89-85EE-BA49D4446F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5E3DF90F-B75D-4C89-85EE-BA49D4446F46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5E3DF90F-B75D-4C89-85EE-BA49D4446F46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5E3DF90F-B75D-4C89-85EE-BA49D4446F46}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4C716E6E-165B-44EB-90CE-07A864B371A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4C716E6E-165B-44EB-90CE-07A864B371A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4C716E6E-165B-44EB-90CE-07A864B371A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4C716E6E-165B-44EB-90CE-07A864B371A8}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {8DA0EFBE-C809-4848-BE1F-ACEF770B2252}
+ EndGlobalSection
+EndGlobal
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.cs
new file mode 100644
index 00000000..d65c2688
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Text.Json;
+using System.Net;
+using System.Net.Sockets;
+using System.IO;
+using System.Collections.Generic;
+using LibData;
+
+namespace BookHelper
+{
+ // Note: Do not change this class.
+ public class Setting
+ {
+ public int ServerPortNumber { get; set; }
+ public int BookHelperPortNumber { get; set; }
+ public int UserHelperPortNumber { get; set; }
+ public string ServerIPAddress { get; set; }
+ public string BookHelperIPAddress { get; set; }
+ public string UserHelperIPAddress { get; set; }
+ public int ServerListeningQueue { get; set; }
+ }
+
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
+ public class SequentialHelper
+ {
+ public SequentialHelper()
+ {
+ //todo: implement the body. Add extra fields and methods to the class if needed
+ }
+
+ public void start()
+ {
+ //todo: implement the body. Add extra fields and methods to the class if needed
+ }
+ }
+}
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.csproj b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.csproj
new file mode 100644
index 00000000..1d2d39a9
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/BookHelper.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net5.0
+
+
+
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Books.json b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Books.json
new file mode 100644
index 00000000..5f90765d
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Books.json
@@ -0,0 +1 @@
+[{"Title":"War and Peace","Author":"Tolstoy, Leo","Status":"Borrowed","BorrowedBy":"user-2","ReturnDate":"20-09-2021"},{"Title":"Anna Karenina","Author":"Tolstoy, Leo","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Mrs. Dalloway","Author":"Woolf, Virginia","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"The Hours","Author":"Cunnningham, Michael","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Huckleberry Finn","Author":"Twain, Mark","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Bleak House","Author":"Dickens, Charles","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Tom Sawyer","Author":"Twain, Mark","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"A Room of One\u0027s Own","Author":"Woolf, Virginia","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Harry Potter","Author":"Rowling, J.K.","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"One Hundred Years of Solitude","Author":"Marquez","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Hamlet, Prince of Denmark","Author":"Shakespeare","Status":"Available","BorrowedBy":null,"ReturnDate":null},{"Title":"Lord of the Rings","Author":"Tolkien, J.R.","Status":"Available","BorrowedBy":null,"ReturnDate":null}]
\ No newline at end of file
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Data.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Data.cs
new file mode 100644
index 00000000..aeaa70d6
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Data.cs
@@ -0,0 +1,48 @@
+// NOTE: THIS FILE MUST NOT CHANGE
+
+namespace LibData
+{
+
+ public class Message
+ {
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
+ }
+
+ public enum MessageType
+ {
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
+ }
+
+ public class BookData
+ {
+ // the name of the book
+ public string Title { get; set; }
+ // the author of the book
+ public string Author { get; set; }
+ // the availability of the book: can be either Available or Borrowed
+ public string Status { get; set; }
+ //the user id of the person who borrowed the book, otherwise null if the book is available.
+ public string BorrowedBy { get; set; }
+ // return date of a book if it is borrowed, otherwise null.
+ public string ReturnDate { get; set; }
+ }
+
+ public class UserData
+ {
+ // user id: has the format User-[a number]
+ public string User_id { get; set; }
+ // full name
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
+ }
+}
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Program.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Program.cs
new file mode 100644
index 00000000..2dbce1e0
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibBookHelper/Program.cs
@@ -0,0 +1,82 @@
+
+using System;
+// using BookHelper;
+using BookHelperSolution;
+using System.Text;
+using System.Diagnostics.Tracing;
+
+// NOTE: THIS FILE MUST NOT CHANGE
+
+namespace LibHelper
+{
+ public class HelperSimulator
+ {
+ ///
+ /// initiates the helper
+ ///
+ public void sequentialRun()
+ {
+ SequentialHelper server = new SequentialHelper();
+ server.start();
+ }
+ }
+
+ class Program
+ {
+ ///
+ /// Starts the simulation for a set of clients and produces the output results.
+ ///
+ ///
+ static void Main(string[] args)
+ {
+ using var listener = new SocketEventListener();
+ Console.Clear();
+ HelperSimulator hs = new HelperSimulator();
+ hs.sequentialRun();
+ }
+
+ internal sealed class SocketEventListener : EventListener
+ {
+ // Constant necessary for attaching ActivityId to the events.
+ public const EventKeywords TasksFlowActivityIds = (EventKeywords)0x80;
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // List of event source names provided by networking in .NET 5.
+ if (eventSource.Name == "System.Net.Sockets" ||
+ eventSource.Name == "System.Net.Security"||
+ eventSource.Name == "System.Net.NameResolution")
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways);
+ }
+ // Turn on ActivityId.
+ else if (eventSource.Name == "System.Threading.Tasks.TplEventSource")
+ {
+ // Attach ActivityId to the events.
+ EnableEvents(eventSource, EventLevel.LogAlways, TasksFlowActivityIds);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ Console.ResetColor();
+
+ var sb = new StringBuilder().Append($"{eventData.TimeStamp:HH:mm:ss.ff} {eventData.ActivityId}.{eventData.RelatedActivityId} {eventData.EventSource.Name}.{eventData.EventName}(");
+ for (int i = 0; i < eventData.Payload?.Count; i++)
+ {
+ sb.Append(eventData.PayloadNames?[i]).Append(": ").Append(eventData.Payload[i]);
+ if (i < eventData.Payload?.Count - 1)
+ {
+ sb.Append(", ");
+ }
+ }
+
+ sb.Append(")");
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine(sb.ToString());
+ Console.ResetColor();
+ }
+ }
+ }
+}
+
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Client.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Client.cs
new file mode 100644
index 00000000..ac5d8b0b
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Client.cs
@@ -0,0 +1,91 @@
+using System;
+using System.IO;
+using System.Net.Sockets;
+using System.Net;
+using System.Text.Json;
+using LibData;
+
+
+namespace LibClient
+{
+ // Note: Do not change this class
+ public class Setting
+ {
+ public int ServerPortNumber { get; set; }
+ public int BookHelperPortNumber { get; set; }
+ public int UserHelperPortNumber { get; set; }
+ public string ServerIPAddress { get; set; }
+ public string BookHelperIPAddress { get; set; }
+ public string UserHelperIPAddress { get; set; }
+ public int ServerListeningQueue { get; set; }
+ }
+
+ // Note: Do not change this class
+ public class Output
+ {
+ public string Client_id { get; set; } // the id of the client that requests the book
+ public string BookName { get; set; } // the name of the book to be reqyested
+ public string Status { get; set; } // final status received from the server
+ public string BorrowerName { get; set; } // the name of the borrower in case the status is borrowed, otherwise null
+ public string BorrowerEmail { get; set; } // the email of the borrower in case the status is borrowed, otherwise null
+ }
+
+ // Note: Complete the implementation of this class. You can adjust the structure of this class.
+ public class SimpleClient
+ {
+ // some of the fields are defined.
+ public Output result;
+ public Socket clientSocket;
+ public IPEndPoint serverEndPoint;
+ public IPAddress ipAddress;
+ public Setting settings;
+ public string client_id;
+ private string bookName;
+ // all the required settings are provided in this file
+ public string configFile = @"../ClientServerConfig.json";
+ //public string configFile = @"../../../../ClientServerConfig.json"; // for debugging
+
+ // todo: add extra fields here in case needed
+
+ ///
+ /// Initializes the client based on the given parameters and seeting file.
+ ///
+ /// id of the clients provided by the simulator
+ /// name of the book to be requested from the server, provided by the simulator
+ public SimpleClient(int id, string bookName)
+ {
+ //todo: extend the body if needed.
+ this.bookName = bookName;
+ this.client_id = "Client " + id.ToString();
+ this.result = new Output();
+ result.BookName = bookName;
+ result.Client_id = this.client_id;
+ // read JSON directly from a file
+ try
+ {
+ string configContent = File.ReadAllText(configFile);
+ this.settings = JsonSerializer.Deserialize(configContent);
+ this.ipAddress = IPAddress.Parse(settings.ServerIPAddress);
+ }
+ catch (Exception e)
+ {
+ Console.Out.WriteLine("[Client Exception] {0}", e.Message);
+ }
+ }
+
+ ///
+ /// Establishes the connection with the server and requests the book according to the specified protocol.
+ /// Note: The signature of this method must not change.
+ ///
+ /// The result of the request
+ public Output start()
+ {
+
+ // todo: implement the body to communicate with the server and requests the book. Return the result as an Output object.
+ // Adding extra methods to the class is permitted. The signature of this method must not change.
+
+ return result;
+ }
+
+ }
+}
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Data.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Data.cs
new file mode 100644
index 00000000..aeaa70d6
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Data.cs
@@ -0,0 +1,48 @@
+// NOTE: THIS FILE MUST NOT CHANGE
+
+namespace LibData
+{
+
+ public class Message
+ {
+ public MessageType Type { get; set; }
+ public string Content { get; set; }
+ }
+
+ public enum MessageType
+ {
+ Hello,
+ Welcome,
+ BookInquiry,
+ UserInquiry,
+ BookInquiryReply,
+ UserInquiryReply,
+ EndCommunication,
+ Error,
+ NotFound,
+ }
+
+ public class BookData
+ {
+ // the name of the book
+ public string Title { get; set; }
+ // the author of the book
+ public string Author { get; set; }
+ // the availability of the book: can be either Available or Borrowed
+ public string Status { get; set; }
+ //the user id of the person who borrowed the book, otherwise null if the book is available.
+ public string BorrowedBy { get; set; }
+ // return date of a book if it is borrowed, otherwise null.
+ public string ReturnDate { get; set; }
+ }
+
+ public class UserData
+ {
+ // user id: has the format User-[a number]
+ public string User_id { get; set; }
+ // full name
+ public string Name { get; set; }
+ public string Email { get; set; }
+ public string Phone { get; set; }
+ }
+}
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibClient.csproj b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibClient.csproj
new file mode 100644
index 00000000..c5cb60fa
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibClient.csproj
@@ -0,0 +1,7 @@
+
+
+
+ Exe
+ net5.0
+
+
\ No newline at end of file
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibInput.json b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibInput.json
new file mode 100644
index 00000000..069b87b8
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibInput.json
@@ -0,0 +1,14 @@
+[
+ {
+ "BookName": "War and Peace"
+ },
+ {
+ "BookName": "Harry Potter"
+ },
+ {
+ "BookName": "Lord of the Rings"
+ },
+ {
+ "BookName": "An Unknown Book"
+ }
+]
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibOutput.json b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibOutput.json
new file mode 100644
index 00000000..4bbc625c
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/LibOutput.json
@@ -0,0 +1 @@
+[{"Client_id":"Client 0","BookName":"War and Peace","Status":"Borrowed","BorrowerName":"Abdul Barker","BorrowerEmail":"in@Pellentesqueultricies.co.uk"},{"Client_id":"Client 1","BookName":"Harry Potter","Status":"Available","BorrowerName":null,"BorrowerEmail":null},{"Client_id":"Client 2","BookName":"Lord of the Rings","Status":"Available","BorrowerName":null,"BorrowerEmail":null},{"Client_id":"Client 3","BookName":"An Unknown Book","Status":"NotFound","BorrowerName":null,"BorrowerEmail":null}]
\ No newline at end of file
diff --git a/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Program.cs b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Program.cs
new file mode 100644
index 00000000..99a93d6f
--- /dev/null
+++ b/temp/DistLibraryFinalTeachers/DistLibraryFinalTeachers/LibClient/Program.cs
@@ -0,0 +1,150 @@
+using System.Text;
+using System.Diagnostics.Tracing;
+using System.Drawing;
+using System;
+using System.Text.Json;
+using System.IO;
+using System.Collections.Generic;
+// using LibClient;
+using LibClientSolution;
+
+
+// NOTE: DO NOT CHANGE THIS FILE
+namespace LibClientSimulator
+{
+ public class InputData
+ {
+ public string BookName { get; set; }
+ }
+ public class ClientsSimulator
+ {
+ private SimpleClient client;
+ private List inputDataList;
+ private SimpleClient[] clients;
+ private Output[] results;
+ private string inputFile = @"LibInput.json";
+ private string outputFile = @"LibOutput.json";
+
+ // paths for debugging
+ //private string inputFile = @"../../../LibInput.json";
+ //private string outputFile = @"../../../LibOutput.json";
+
+ ///
+ /// Reads the input file and creats the clients and output objects accordingly
+ ///
+ public ClientsSimulator()
+ {
+ int id = 0;
+ try
+ {
+ string inputContent = File.ReadAllText(inputFile);
+ this.inputDataList = JsonSerializer.Deserialize>(inputContent);
+ clients = new SimpleClient[this.inputDataList.Count];
+ results = new Output[this.inputDataList.Count];
+
+ // each client is initialized by a client id and a book name (from the input file) to request
+ foreach (InputData d in this.inputDataList)
+ {
+ clients[id] = new SimpleClient(id, d.BookName);
+ id++;
+ }
+ }
+ catch (Exception e) { Console.Out.WriteLine("[ClientSimulator] Exception: {0}", e.Message); }
+ }
+ ///
+ /// Starts the book requesting process for each client and collects the result for each request
+ ///
+ public void startSimulation()
+ {
+ int numCases = clients.Length;
+ for (int i = 0; i < numCases; i++)
+ {
+ Console.Out.WriteLine("\n *********** \n");
+ results[i] = clients[i].start();
+ }
+ //this is the ending client
+ new SimpleClient(-1, "").start();
+ }
+
+ ///
+ /// Prints all the results in console and produces the output file
+ ///
+ public void printOutput()
+ {
+ Console.Out.WriteLine("\n *************** Final Output *********** \n");
+ for (int i = 0; i < results.Length; i++)
+ Console.WriteLine("{0} {1} {2} {3}",
+ results[i].Client_id,
+ results[i].BookName,
+ results[i].BorrowerName,
+ results[i].BorrowerEmail);
+ string outputContent = JsonSerializer.Serialize