Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bvalente committed Nov 8, 2019
1 parent 490145d commit 589ceda
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 48 deletions.
2 changes: 0 additions & 2 deletions chat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ run_client:
run_client_ui:
#dotnet run -p ClientUI
mono ClientUI/bin/Debug/net472/ClientUI.exe

#TODO add for loop to create multiple clients
56 changes: 31 additions & 25 deletions msdad/client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void sendMeeting(MeetingProposal meeting){
meetingList.Add(meeting.topic,meeting);
}

//execute script file
void executeScript(string fileName){

//load file and get commands
Expand All @@ -65,6 +66,7 @@ void executeScript(string fileName){
}
}

//execute one command
public void executeCommand(string command){
//receives a command and executes respective function
string[] cmds = command.Split(' ');
Expand Down Expand Up @@ -98,7 +100,6 @@ public void executeCommand(string command){
}
}


//Lists all available meetings
void list(){
//print meetings
Expand All @@ -109,18 +110,8 @@ void list(){
IServer server = (IServer) Activator.GetObject(
typeof(IServer),
server_url);
ListDelegate del = new ListDelegate(server.getMeetings); //TODO replace ping
del.BeginInvoke(listCallback,null);
}
//delegate
delegate Dictionary<string,MeetingProposal> ListDelegate();
//callback
void listCallback(IAsyncResult ar){
//will be called when delegate is over
ListDelegate del = (ListDelegate)((AsyncResult)ar).AsyncDelegate;
meetingList.Clear();
meetingList = del.EndInvoke(ar);
//TODO
ListDelegate del = new ListDelegate(server.getMeetings);
del.BeginInvoke(updateCallback,null);
}

//Creates a new meeting
Expand Down Expand Up @@ -148,11 +139,6 @@ void create(string[] args){
MeetingProposal meeting = new MeetingProposal(this.username,
meeting_topic, min_attendees, slotList, invitees);

//what to do with the meeting?

//guardar meeting


//get server
IServer server = (IServer) Activator.GetObject(
typeof(IServer),
Expand All @@ -161,53 +147,61 @@ void create(string[] args){
//try to create meeting
try{
server.createMeeting(meeting);
} catch(Exception ex){

//TODO nossas excepcoes
} catch(MeetingException ex){
Console.WriteLine(ex.Message);
return;
}catch(Exception ex){
Console.WriteLine("connection with server failed");
Console.WriteLine(ex.Message);
return;
}

//pedir mais meetings?
meetingList.Add(meeting.topic, meeting);



}

//Joins an existing meeting
void join(string[] args){
string meeting_topic = args[1];
int number_of_slots = Int32.Parse(args[2]);
//parse slots
List<Slot> slotList = new List<Slot>();
for(int i = 3; i < number_of_slots + 3;i++){
string[] str = args[i].Split(',');
Slot slot = new Slot(str[0],str[1]);
slotList.Add(slot);
}

//get server
IServer server = (IServer) Activator.GetObject(
typeof(IServer),
server_url);
//TODO try catch

//try to join meeting
try{
server.joinClient(this.GetInfo(), meeting_topic, slotList);
}catch(MeetingException ex){
Console.WriteLine(ex.Message);
}
}


}

//Closes a meeting
void close(string meeting_topic){
IServer server = (IServer) Activator.GetObject(
typeof(IServer),
server_url);
//try to close meeting
try{
server.closeMeeting(meeting_topic, this.GetInfo());
} catch(MeetingException ex){
Console.WriteLine(ex.Message);
}
//get meetings
ListDelegate del = new ListDelegate(server.getMeetings);
del.BeginInvoke(updateCallback,null);

}

Expand All @@ -229,6 +223,17 @@ public void status(){
Console.WriteLine(key.Value);
}
}

//update meetings async
//delegate
delegate Dictionary<string,MeetingProposal> ListDelegate();
//callback
void updateCallback(IAsyncResult ar){
//will be called when delegate is over
ListDelegate del = (ListDelegate)((AsyncResult)ar).AsyncDelegate;
meetingList.Clear();
meetingList = del.EndInvoke(ar);
}
}

//interface for the Puppet Master
Expand All @@ -253,6 +258,7 @@ public void wait(int x){
return;
}

//print client status
public void statusPuppeteer(){
client.status();
}
Expand Down
8 changes: 7 additions & 1 deletion msdad/lib/IClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;


namespace lib{

Expand Down Expand Up @@ -54,5 +56,9 @@ public ClientException(string message)
public ClientException(string message, Exception inner)
: base(message, inner){
}

public ClientException(SerializationInfo info, StreamingContext context)
: base(info, context){
}
}
}
5 changes: 5 additions & 0 deletions msdad/lib/IPCS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;

namespace lib{

Expand Down Expand Up @@ -26,5 +27,9 @@ public PCSException(string message)
public PCSException(string message, Exception inner)
:base(message, inner){
}

public PCSException(SerializationInfo info, StreamingContext context)
: base(info, context){
}
}
}
5 changes: 5 additions & 0 deletions msdad/lib/IServer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace lib{

Expand Down Expand Up @@ -79,5 +80,9 @@ public ServerException(string message)
public ServerException(string message, Exception inner)
: base(message, inner){
}

public ServerException(SerializationInfo info, StreamingContext context)
: base(info, context){
}
}
}
18 changes: 14 additions & 4 deletions msdad/lib/msdad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ public MeetingProposal(string coordinator, string topic, int minParticipants,
public override string ToString(){

string text = "";
text += "Coordinator: " + coordinator + "\n";
text += "Topic: " + topic + "\n";
text += "Coordinator: " + coordinator + "\n";
text += "Minimum Participants: " + minParticipants.ToString() + "\n";

text += "Slots:\n";
foreach(Slot slot in slotList){
text += slot.location + ':' + slot.date + "\n";
text += "\t" + slot.location + ':' + slot.date + "\n";
}
text += "Invited clients:\n";
foreach(string invitee in invitees){
text += invitee + "\n";
text += "\t" + invitee + "\n";
}
text += "Participants\n";
foreach(Participant participant in participants){
text += "\t" + participant.client.username + "\n";
}
if (open){
text += "This meeting is open";
} else{
text += "This meeting is closed";
}

return text;
Expand Down Expand Up @@ -134,7 +145,6 @@ public MeetingException(string message, Exception inner)

public MeetingException(SerializationInfo info, StreamingContext context)
: base(info, context){

}
}
}
1 change: 1 addition & 0 deletions msdad/pcs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public ClientInfo createClient(string username, string client_url, string server
public ServerInfo createServer(string server_id, string url,
string max_faults, string min_delay, string max_delay){

//create server process
string cPath = AppDomain.CurrentDomain.BaseDirectory;
string filePath = Path.Combine(cPath,
"../../../../server/bin/Debug/net472/server.exe");
Expand Down
17 changes: 13 additions & 4 deletions msdad/puppetMaster/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ private void InitializeComponent(){
AvaloniaXamlLoader.Load(this);
}

//Buttons here! only 499$ each
//Buttons here!

//load script and run it
//load script file and run it
public void executeScript(object sender, RoutedEventArgs e){

//load file and get commands
Expand All @@ -143,6 +143,7 @@ public void executeScript(object sender, RoutedEventArgs e){
}
}

//create server
public void createServer(object sender, RoutedEventArgs e){

string server_id = createServerID.Text;
Expand All @@ -155,6 +156,7 @@ public void createServer(object sender, RoutedEventArgs e){

}

//create client
public void createClient(object sender, RoutedEventArgs e){

string username = createClient_username.Text;
Expand All @@ -165,6 +167,7 @@ public void createClient(object sender, RoutedEventArgs e){
puppetMaster.createClient(username, url, server_url, script_file);
}

//add room
public void addRoom(object sender, RoutedEventArgs e){

string location = room_location.Text;
Expand All @@ -174,51 +177,57 @@ public void addRoom(object sender, RoutedEventArgs e){
puppetMaster.addRoom(location, capacity, name);
}


//print clients and servers status
public void status(object sender, RoutedEventArgs e){

puppetMaster.status();
}

//crash server
public void crash(object sender, RoutedEventArgs e){
string server_id = crashServerID.Text;
puppetMaster.crashServer(server_id);

}

//freeze server
public void freezeServer(object sender, RoutedEventArgs e){

string server_id = freezeServerID.Text;
puppetMaster.freezeServer(server_id);
}

//unfreeze server
public void unfreezeServer(object sender, RoutedEventArgs e){

string server_id = unfreezeServerID.Text;
puppetMaster.unfreezeServer(server_id);
}

//freeze puppetmaster
public void waitTime(object sender, RoutedEventArgs e){

string time = waitTimeBox.Text;
puppetMaster.wait(time);
}

//update ui
//update client list
public void addClient(ClientInfo client){
TextBlock block = new TextBlock();
block.Name = client.username;
block.Text = client.username;
clientPanel.Children.Add(block);
}

//update server list
public void addServer(ServerInfo server){
TextBlock block = new TextBlock();
block.Text = server.server_id;
block.Name = server.server_id;
serverPanel.Children.Add(block);
}

//update server list
public void removeServer(ServerInfo server){
TextBlock block = this.Find<TextBlock>(server.server_id);
serverPanel.Children.Remove(block);
Expand Down
Loading

0 comments on commit 589ceda

Please sign in to comment.