Ejemplo n.º 1
0
 public void addToESet(MeetingSlot meetingS)
 {
     if (this.preferenceSet.Contains(meetingS))
     {
         throw new MSlotException("Slot already in pref set" + (object)meetingS, this);
     }
     this.preferenceSet.Add(meetingS);
 }
Ejemplo n.º 2
0
 public void addToPSet(MeetingSlot meetingS)
 {
     if (this.exclusionSet.Contains(meetingS))
     {
         throw new MSlotException("Slot is in the exclusion set." + (object)meetingS, this);
     }
     this.preferenceSet.Add(meetingS);
 }
Ejemplo n.º 3
0
        public MeetingSlot findTopMS()
        {
            DateTime firstTime      = this.startDate;
            string   location       = this.location;
            int      number_of_slot = 1;
            // generic logic, we'll implement our own, better version
            HashSet <MeetingSlot> first  = new HashSet <MeetingSlot>();
            HashSet <MeetingSlot> source = new HashSet <MeetingSlot>();
            HashSet <MeetingSlot> MS_Set = new HashSet <MeetingSlot>();

            for (; DateTime.Compare(firstTime, this.endDate) <= 0; firstTime = firstTime.AddDays(1.0))
            {// can also change number of slots
                for (; number_of_slot <= 4; ++number_of_slot)
                {
                    MeetingSlot meeting_slot = new MeetingSlot(firstTime.Year, firstTime.Month, firstTime.Day, number_of_slot, location);
                    first.Add(meeting_slot);
                    int number = 0;
                    foreach (Personas persona in this.personaCollection)
                    {
                        bool check_1 = persona.MSInESet(meeting_slot);
                        bool check_2 = persona.MSInPSet(meeting_slot);
                        if (check_1 == true)
                        {
                            MS_Set.Add(meeting_slot);
                        }
                        else if (check_2)
                        {
                            ++number;
                        }
                    }
                    if (this.personaCollection.Count == number)
                    {
                        source.Add(meeting_slot);
                    }
                }
                number_of_slot = 1;
            }
            if (source.Count > 0)
            {
                return(source.ElementAt <MeetingSlot>(0));
            }
            IEnumerable <MeetingSlot> meetingSlots = first.Except <MeetingSlot>((IEnumerable <MeetingSlot>)MS_Set);

            // conflict resolution errors
            if (meetingSlots.Count <MeetingSlot>() > 0)
            {
                throw new WeakConflictError("No available meeting slot in ALL preference sets, but" + (object)meetingSlots.Count <MeetingSlot>() + " slots not within range", meetingSlots);
            }
            throw new StrongConflictError("No available meeting slots found in preference slots, and no available meeting slots found that are not in exclusion sets");
        }
 private void fillPersonaSet(Personas persona, string setType, string setText)//
 {
     foreach (Match match in this.rx.Matches(setText))
     {
         GroupCollection groups = match.Groups;
         // ALSO COMPARE LOCATIONS, EQUIPMENT HERE
         string   location  = "Room 1";
         string   equipment = "Equipment 1";
         DateTime dateTime  = new DateTime(int.Parse(groups[3].Value), int.Parse(groups[2].Value), int.Parse(groups[1].Value));
         // this is comparison city: check to see if we need to throw an exception (location, equipment conflict etc)
         if (string.Compare(location, this.meeting.getLocation()) < 0)
         {
             throw new LocationException(match.ToString() + " ( " + (setType == "preference" ? "pref" : "exc") + ") is a location conflict.", persona);
         }
         if (String.Compare(equipment, this.meeting.getEquipment()) < 0)
         {
             throw new EquipmentException(match.ToString() + " (" + (setType == "preference" ? "pref" : "exc") + ") is an equipment conflict.", persona);
         }
         if (DateTime.Compare(dateTime, this.meeting.getStartDate()) < 0)
         {
             throw new MSlotException(match.ToString() + " (" + (setType == "preference" ? "pref" : "exc") + ") is before the minimum date of the meeting.", persona); // improve, text changes
         }
         if (DateTime.Compare(dateTime, this.meeting.getEndDate()) > 0)
         {
             throw new MSlotException(match.ToString() + " (" + (setType == "preference" ? "pref" : "exc") + ") is after the maximum date of the meeting.", persona);
         }
         MeetingSlot meetingSlot = new MeetingSlot(dateTime, int.Parse(groups[4].Value), location);
         if (setType == "preference")
         {
             persona.addToPSet(meetingSlot);
         }
         else
         {
             persona.addToESet(meetingSlot);
         }
     }
 }
        private void submitMeetingButton_Click(object sender, EventArgs e)
        {
            string[] dateStart = this.dateStart.Text.Split('/');
            string[] dateEnd   = this.dateEnd.Text.Split('/');
            DateTime startDate = new DateTime(int.Parse(dateStart[2]), int.Parse(dateStart[1]), int.Parse(dateStart[0]));
            DateTime endDate   = new DateTime(int.Parse(dateEnd[2]), int.Parse(dateEnd[1]), int.Parse(dateEnd[0]));
            string   equipment = this.equipmentBox.Text;
            string   location  = this.locationRequest.Text;

            this.liamResult.Text    = "Waiting";
            this.rosaliaResult.Text = "Waiting";
            this.heatherResult.Text = "Waiting";
            this.samResult.Text     = "Waiting";
            this.meetingStatus.Text = "Not yet planned";
            this.meetingErrors.Text = "No errors";
            this.meetingDate.Text   = "Not yet planned";
            this.meetingSlotNo.Text = "Not planned";//field population


            // UI components, set values
            try
            {
                this.meeting = new Meeting(new Initiator(this.meetingInitiator.Text.Trim()), startDate, endDate, location, equipment); //location);//meeting constructor
                foreach (Personas persona in this.GetPersonas())                                                                       //
                {
                    this.meeting.addPersona(persona);
                }
                try
                {
                    MeetingSlot topSlot = this.meeting.findTopMS();
                    this.meetingErrors.Text = "No Errors";
                    this.meeting.setStatus("Scheduled");
                    this.meetingDate.Text = topSlot.date.ToShortDateString();
                    // slot no
                    this.meetingSlotNo.Text = "Slot " + topSlot.ID.ToString();
                    //this.location.Text = "Location " + topSlot.location.ToString();
                    int num = (int)MessageBox.Show("Meeting slot has been found: \n" + topSlot.ToString());
                    // explain to users what slots correspond to?
                }
                catch (WeakConflictError er)
                {
                    this.meeting.setStatus("Weak Conflict");
                    this.meetingErrors.Text = "Weak conflict: " + er.Message;
                    int num = (int)MessageBox.Show(er.Message, "Weak Conflict Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); // change this, UI
                }
                catch (StrongConflictError er)
                {
                    this.meeting.setStatus("Strong Conflict");
                    this.meetingErrors.Text = "Strong Conflict: " + er.Message;
                    int num = (int)MessageBox.Show(er.Message, "Strong Conflict Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); // change this, UI
                }
                catch (Exception er)
                {
                    throw er;
                }
            }
            catch (DateRangeError er)
            {
                this.meetingErrors.Text = er.Message;
                int num = (int)MessageBox.Show(er.Message, "Date range error", MessageBoxButtons.OK, MessageBoxIcon.Hand); // change this, UI
                this.meetingStatus.Text = "Error initiating meeting, date";
            }
            // will need an equipment and/or a location version
            catch (LocationException ex)
            {
                this.meetingErrors.Text = ex.Message;
                int num = (int)MessageBox.Show(ex.Message, "Location conflict", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.meetingStatus.Text = "Error initiating meeting, location conflict";
            }
            catch (EquipmentException ex)
            {
                this.meetingErrors.Text = ex.Message;
                int num = (int)MessageBox.Show(ex.Message, "Equipment conflict", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.meetingStatus.Text = "Error initiating meeting, equipment conflict.";
            }
            catch (Exception er)
            {
                this.meeting.setStatus("Participant error");
                this.meetingErrors.Text = er.Message;
                int num = (int)MessageBox.Show(er.Message, "Personas Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            if (this.meeting == null || !(this.meetingStatus.Text != "Error initiating meeting"))
            {
                return;
            }
            this.meetingStatus.Text = this.meeting.getStatus();
        }
Ejemplo n.º 6
0
 public bool MSInESet(MeetingSlot meetingS) => this.exclusionSet.Contains(meetingS);
Ejemplo n.º 7
0
 public bool MSInPSet(MeetingSlot meetingS) => this.preferenceSet.Contains(meetingS);