Skip to content

Commit

Permalink
distlib is updated with new message type format
Browse files Browse the repository at this point in the history
  • Loading branch information
afshinamighi committed Sep 28, 2021
1 parent 0543b97 commit a60bca6
Show file tree
Hide file tree
Showing 59 changed files with 1,477 additions and 185 deletions.
2 changes: 1 addition & 1 deletion ConcurrentCSharp/ClientServerConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions ConcurrentCSharp/ConcurrentCSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions ConcurrentCSharp/DiningPhilosophers/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
//using Exercise;
using Solution; // will be provided later
using Exercise;
//using Solution; // will be provided later

namespace DiningPhilosophers
{
Expand All @@ -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);

}
}
Expand Down
4 changes: 2 additions & 2 deletions ConcurrentCSharp/SocketClient/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Sequential;
using Concurrent;
//using Solution;
//using Concurrent;
using Solution;

namespace Program
{
Expand Down
4 changes: 2 additions & 2 deletions ConcurrentCSharp/SocketClient/Sequential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
46 changes: 23 additions & 23 deletions ConcurrentCSharp/SocketServer/Concurrent.cs
Original file line number Diff line number Diff line change
@@ -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 "";
}
}
}
// 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 "";
// }
// }
//}
7 changes: 4 additions & 3 deletions ConcurrentCSharp/SocketServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -84,8 +86,7 @@ static void Main(string[] args)
Console.WriteLine("\n Invalid input ... ");
break;
}
}

}
}
}
}
14 changes: 7 additions & 7 deletions Networking/DistLibrary/ClientServerConfig.json
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 8 additions & 8 deletions Networking/DistLibrary/LibBookHelper/BookHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading;
using System.Text.Json;
using System.Net;
using System.Net.Sockets;
Expand All @@ -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()
Expand Down
41 changes: 21 additions & 20 deletions Networking/DistLibrary/LibBookHelper/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@

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; }
}

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; }
}
}
54 changes: 51 additions & 3 deletions Networking/DistLibrary/LibBookHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -26,9 +29,54 @@ class Program
/// <param name="args"></param>
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();
}
}
}
}

Loading

0 comments on commit a60bca6

Please sign in to comment.