Skip to content

Commit

Permalink
almost status
Browse files Browse the repository at this point in the history
Co-authored-by: santosandre123 <[email protected]>
  • Loading branch information
bvalente and santosandre123 committed Nov 8, 2019
1 parent 48a1a63 commit 490145d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
17 changes: 10 additions & 7 deletions msdad/client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ static void Main(string[] args){
TcpChannel channel = new TcpChannel(Int32.Parse(port));
ChannelServices.RegisterChannel(channel, false);

//create client
//create client and puppeteer
Client client = new Client(username, client_url, server_url, script_file);
RemotingServices.Marshal(
client,
service,
typeof(Client));

//create client puppeteer
ClientPuppeteer puppeteer = new ClientPuppeteer(client);

//marshall objects
RemotingServices.Marshal(
puppeteer,
service + "Puppeteer",
typeof(ClientPuppeteer));

RemotingServices.Marshal(
client,
service,
typeof(Client));


//DEBUG
Console.WriteLine("Client " + username +" created");
Console.WriteLine("service " + service);
Console.WriteLine(client.username + " PID: " +
Process.GetCurrentProcess().Id.ToString());

Expand Down
1 change: 1 addition & 0 deletions msdad/lib/msdad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Room(Location location, int capacity, string room_name){
this.location = location;
this.capacity = capacity;
this.room_name = room_name;
this.usedDates = new List<string>();
}
}

Expand Down
7 changes: 4 additions & 3 deletions msdad/puppetMaster/PuppetMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public void addRoom(string location_name, string capacity, string room_name){
if( locationList.ContainsKey(location_name)){
location = locationList[location_name];
} else{
Console.WriteLine("new location: " + location_name);
location = new Location(location_name);
locationList.Add(location_name, location);
}
Expand All @@ -174,13 +173,13 @@ public void addRoom(string location_name, string capacity, string room_name){
pair.Value.url+"Puppeteer");
server.addRoom(location_name, Int32.Parse(capacity), room_name);
}

}

public void status(){
//make all servers and clients print status
//foreach servers
foreach(KeyValuePair<string, ServerInfo> pair in serverList){
Console.WriteLine(pair.Value.url);
IServerPuppeteer server = (IServerPuppeteer) Activator.GetObject(
typeof(IServerPuppeteer),
pair.Value.url+"Puppeteer");
Expand All @@ -192,12 +191,14 @@ public void status(){
}
//foreach clients
foreach(KeyValuePair<string,ClientInfo> pair in clientList){
Console.WriteLine(pair.Value.client_url);
IClientPuppeteer client = (IClientPuppeteer) Activator.GetObject(
typeof(IClientPuppeteer),
pair.Value.client_url+"Puppeteer");
try{
client.statusPuppeteer();
client.statusPuppeteer();
}catch(Exception ex){
Console.WriteLine("aro!");
Console.WriteLine(ex.Message);
}
}
Expand Down
3 changes: 3 additions & 0 deletions msdad/scripts/success1_pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
AddRoom Lisboa 10 room1
AddRoom Lisboa 20 room2
AddRoom Porto 10 room3
Wait 500
Server s1 tcp://localhost:3001/server1 0 100 200
Wait 500
Client c1 tcp://localhost:4001/client1 tcp://localhost:3001/server1 success1_client1
Wait 500
Status
Wait 3000
Freeze s1
Expand Down
44 changes: 38 additions & 6 deletions msdad/server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ public void closeMeeting(string meeting_topic, ClientInfo clientInfo){
if(clientInfo.username != meetingList[meeting_topic].coordinator){
throw new MeetingException("This client can't close the meeting");
}
//ver se tem numero de participantes necessario
if(meeting.participants.Count < meeting.minParticipants){
throw new MeetingException("Not enough participants");
}

//check if there is available room at x date
//ainda nao tem room
//procurar uma room na location certa, ver se tem espaco
Expand All @@ -222,25 +227,52 @@ public void closeMeeting(string meeting_topic, ClientInfo clientInfo){
}
}
//possible slot tem todas as slots possiveis

if(possibleSlots.Count == 0){
throw new MeetingException("Nao ha slot possivel");
}
//depois de encontrar os slots em comum

//temos de encontrar uma sala com espaco
//TODO:
Room room = null;
string date = null;
foreach(Slot slot in possibleSlots){
if( ! locationList.ContainsKey(slot.location)){
throw new MeetingException("location " + slot.location + " does not exist");
}

if(meeting.room.usedDates.Contains(meeting.date)){
throw new MeetingException("This room is already booked");
Location location = locationList[slot.location];
string date2 = slot.date;
//procurar room na location com date disponivel
foreach(Room room2 in location.roomList){
if ( ! room2.usedDates.Contains(date2) &&
room2.capacity >= meeting.participants.Count){
room = room2;
date = date2;
break;
}
}

//se ja encontramos room, sai do loop
if(room != null) break;
}

//ver se existe sala com espaco e data disponivel
if(room == null){
throw new MeetingException("No available rooms");
}

//if everythinh ok, books the meeting
meeting.close(meeting.room, meeting.date);
meeting.close(room, date);
}

private Slot findSlot(List<Participant> participants, Slot slot){
List<Participant> participant_recursive = new List<Participant>(participants);
participant_recursive.RemoveAt(0); //remove first element

if (participants.Count == 0){
return slot;
} else if(participants[0].slotList.Contains(slot)){
List<Participant> participant_recursive = new List<Participant>(participants);
participant_recursive.RemoveAt(0); //remove first element
return findSlot(participant_recursive,slot);
} else {
return null;
Expand Down

0 comments on commit 490145d

Please sign in to comment.