Example #1
0
        /*
         * AUX METHODS
         */

        private void BookNextSlot(Reservation res)
        {
            bool booked = false;

            //LOCK HERE

            foreach (ReservationSlot slot in res.Slots)
            {
                Monitor.Enter(_calendar[slot.SlotID]);
                CalendarSlot cSlot = _calendar[slot.SlotID];
                if (slot.State != ReservationSlotState.ABORTED && !cSlot.Locked && (cSlot.State == CalendarSlotState.ACKNOWLEDGED || (cSlot.State == CalendarSlotState.BOOKED && res.ReservationID < cSlot.ReservationID)))
                {
                    booked = true;

                    BookCalendarSlot(res, slot);

                    Monitor.Exit(_calendar[slot.SlotID]);

                    Log.Show(_userName, "Starting book process of slot " + slot.SlotID + " from reservation " + res.ReservationID);

                    foreach (string participantID in res.Participants)
                    {
                        if (!participantID.Equals(_userName))
                        {
                            _msgDispatcher.SendMessage(MessageType.BOOK_SLOT, res.ReservationID, participantID, slot.SlotID);
                        }
                    }

                    break;
                }
                else
                {
                    Monitor.Exit(_calendar[slot.SlotID]);
                }
            }

            if (!booked)
            {
                Log.Show(_userName, "No available slots. Aborting reservation " + res.ReservationID);

                foreach (IBookingService client in res.ClientStubs.Values)
                {
                    try
                    {
                        Log.Show(_userName, "Sending abort to client...");
                        AbortDelegate bookSlot = new AbortDelegate(client.AbortReservation);
                        IAsyncResult  RemAr    = bookSlot.BeginInvoke(res.ReservationID, null, null);
                    }
                    catch (SocketException e)
                    {
                        Log.Show(_userName, "ERROR: Could not connect to client. Exception: " + e);
                    }
                }

                AbortReservation(res.ReservationID);
            }
        }
Example #2
0
        /*
         * AUX METHODS
         */
        private void BookNextSlot(Reservation res)
        {
            bool booked = false;

            //LOCK HERE

            foreach (ReservationSlot slot in res.Slots)
            {
                Monitor.Enter(_calendar[slot.SlotID]);
                CalendarSlot cSlot = _calendar[slot.SlotID];
                if (slot.State != ReservationSlotState.ABORTED && !cSlot.Locked && (cSlot.State == CalendarSlotState.ACKNOWLEDGED || (cSlot.State == CalendarSlotState.BOOKED && res.ReservationID < cSlot.ReservationID)))
                {
                    booked = true;

                    BookCalendarSlot(res, slot);

                    Monitor.Exit(_calendar[slot.SlotID]);

                    Log.Show(_userName, "Starting book process of slot " + slot.SlotID + " from reservation " + res.ReservationID);

                    foreach (string participantID in res.Participants)
                    {
                        if (!participantID.Equals(_userName))
                        {
                            _msgDispatcher.SendMessage(MessageType.BOOK_SLOT, res.ReservationID, participantID, slot.SlotID);
                        }
                    }

                    break;
                }
                else
                {
                    Monitor.Exit(_calendar[slot.SlotID]);
                }
            }

            if (!booked)
            {
                Log.Show(_userName, "No available slots. Aborting reservation " + res.ReservationID);

                foreach (IBookingService client in res.ClientStubs.Values)
                {
                    try
                    {
                        Log.Show(_userName, "Sending abort to client...");
                        AbortDelegate bookSlot = new AbortDelegate(client.AbortReservation);
                        IAsyncResult RemAr = bookSlot.BeginInvoke(res.ReservationID, null, null);
                    }
                    catch (SocketException e)
                    {
                        Log.Show(_userName, "ERROR: Could not connect to client. Exception: " + e);
                    }
                }

                AbortReservation(res.ReservationID);
            }
        }