/* * Implements IFacadeService */ public bool Connect() { if (!_isOnline) { _isOnline = true; StartServices(); Log.Show(_username, "Attempting to Register user on central server\n"); _slotManager.Connect(); while (true) { try { Helper.GetRandomServer(_servers).RegisterUser(_username, Helper.GetIPAddress(), _port); Log.Show(_username, "Succesfully Registered\n"); break; } catch (Exception e) { Log.Debug(_username, "\nEXCEPTION: " + e.Message); } } return(true); } return(false); }
private void NotifyPuppetMaster() { try { Log.Show(_username, "Trying to connect to Puppet Master on: " + connectionString); pms.registerClient(_username, Helper.GetIPAddress(), _port); Log.Show(_username, "Sucessfully registered client on Puppet Master."); Log.WriteToFile(_logfile, _username, "Sucessfully registered client on Puppet Master."); } catch (SocketException) { Log.Show(_username, "Unable to connect to Puppet Master."); Log.WriteToFile(_logfile, _username, "Unable to connect to Puppet Master"); } }
/* * SLOT MANAGER METHODS */ public bool StartReservation(ReservationRequest req) { //Updates request with sequence number int resID = RetrieveSequenceNumber(); //Create and populate local reservation Reservation res = CreateReservation(req, resID, _userName, Helper.GetIPAddress(), _port); //Mark slots initial states List <ReservationSlot> reservationSlots = CreateReservationSlots(req, resID); //Update reservation request, removing aborted slots foreach (ReservationSlot slot in new List <ReservationSlot>(reservationSlots)) { if (slot.State == ReservationSlotState.ABORTED) { Log.Show(_userName, "Slot " + slot + " not available on initiator. Removing from reservation."); //removing slot of original request, since it will be passed to participants reservationSlots.Remove(slot); req.Slots.Remove(slot.SlotID); } } res.Slots = reservationSlots; Log.Show(_userName, "Starting reservation " + res.ReservationID + ". With participants " + string.Join(",", res.Participants) + ". Slots: " + string.Join(",", res.Slots)); //If no slots are available, cancel reservation if (res.Slots.Count == 0) { Log.Show(_userName, "No available slots on initiator, aborting reservation."); return(false); } //just the initiator is on the reservation if (req.Users.Count == 1) { foreach (ReservationSlot slot in res.Slots) { Monitor.Enter(_calendar[slot.SlotID]); try { CalendarSlot cSlot = _calendar[slot.SlotID]; if (slot.State != ReservationSlotState.ABORTED && !cSlot.Locked && cSlot.State != CalendarSlotState.ASSIGNED) { AssignCalendarSlot(res, slot, true); return(true); } else if (slot.State != ReservationSlotState.ABORTED) { AbortReservationSlot(slot, true); } } finally { Monitor.Exit(_calendar[slot.SlotID]); } } return(false); } _clientMonitor.MonitorReservation(res); //Add reservation to map of active reservations _activeReservations[res.ReservationID] = res; foreach (string participantID in res.Participants) { if (!participantID.Equals(_userName)) { _msgDispatcher.SendMessage(MessageType.INIT_RESERVATION, resID, participantID, req, _userName, Helper.GetIPAddress(), _port); } } return(true); }