Example #1
0
        /// <summary>
        /// Retrieves a list of calendar events for a given conference room.
        /// </summary>
        /// <param name="RoomName">The name of the conference room.</param>
        /// <param name="Start">The begining of the DateTime filter.</param>
        /// <param name="End">The end of the DateTime filter.</param>
        /// <returns>A <see cref="Task(IQueryable{CalendarEvent}"/> for the the specified conference room/timestpan arguments.</returns>
        public async Task <IQueryable <CalendarEvent> > GetEvents(string RoomName, DateTime?Start = null, DateTime?End = null)
        {
            // Convert to UTC for the request. We assume all incoming requests are in EST for now.
            DateTime start = DateTime.Parse(DateTime.Now.ToShortDateString()).ToUniversalTime();
            DateTime end   = DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).ToUniversalTime();

            if (Start != null && End != null)
            {
                start = Start.Value.ToUniversalTime();
                end   = End.Value.ToUniversalTime();
            }

            List <CalendarEvent> events = await _graphClient.GetConferenceRoomCalendarEvents(RoomName, start, end, 30);

            return(events.OrderBy(x => x.Start).AsQueryable());
        }
Example #2
0
        /// <summary>
        /// Gets the availability of a given room on any given day of the week.
        /// </summary>
        /// <param name="RoomName">The name of the room to query.</param>
        /// <param name="ReplyURI">The unique time-limited URL with which to post the calendar response to Slack.</param>
        /// <param name="DayOfWeek">The name of the day of the week to query for. NOTE: This is the next instance of this day if not today.</param>
        private void GetRoom(string RoomName, string ReplyURI, string DayOfWeek = "")
        {
            List <string> rooms = ConfigurationManager.AppSettings["Rooms"].Split(',').ToList();
            DateTime      start = DateTime.Now;
            DateTime      end   = DateTime.Now;
            string        day   = string.Empty;

            Models.Slack.Message message = new Models.Slack.Message();
            message.mrkdwn = true;

            if (DayOfWeek == string.Empty)
            {
                day = DateTime.Today.DayOfWeek.ToString();
            }
            else
            {
                day = DayOfWeek;
            }

            string[] days     = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
            string   notFound = string.Empty;

            if (!days.Contains(day.ToLower()) || !rooms.Contains(RoomName.ToLower()))
            {
                message.text = string.Format("Could not find a schedule for *{0}* on *{1}*", RoomName, day);
                SendReply(message, ReplyURI);
                return;
            }

            if (day.ToLower() == DateTime.Now.DayOfWeek.ToString().ToLower())
            {
                message.text = string.Format("Here's *{0}'s* schedule for the rest of today:", RoomName);
                notFound     = string.Format("There's nothing on *{0}'s* schedule today.", RoomName);
            }
            else
            {
                while (start.DayOfWeek.ToString().ToLower() != day.ToLower())
                {
                    start = start.AddDays(1);
                }
                start        = DateTime.Parse(start.ToShortDateString());
                message.text = string.Format("Here's *{0}'s* schedule for this coming *{1} ({2})*:", RoomName, start.DayOfWeek.ToString(), start.ToString("M/d"));
                notFound     = string.Format("There's nothing on *{0}'s* schedule for this coming *{1} ({2})*:", RoomName, start.DayOfWeek.ToString(), start.ToString("M/d"));
            }

            end = DateTime.Parse(start.AddDays(1).ToShortDateString());

            List <CalendarEvent> events = _graphClient.GetConferenceRoomCalendarEvents(RoomName, start.ToUniversalTime(), end.ToUniversalTime(), 10).Result;

            if (events != null && events.Count > 0)
            {
                message.attachments = new List <Models.Slack.Attachment>();

                foreach (var evnt in events.OrderBy(x => x.Start))
                {
                    var attachment = new Models.Slack.Attachment();
                    attachment.fields = new List <Models.Slack.Field>();
                    attachment.color  = "#007fe0";

                    var timeField = new Models.Slack.Field();
                    timeField.@short = true;
                    timeField.title  = "Reserved";
                    timeField.value  = evnt.Start.ToString("h:mm tt") + " - " + evnt.End.ToString("h:mm tt");

                    attachment.fields.Add(timeField);

                    var reservedBy = new Models.Slack.Field();
                    reservedBy.@short = true;
                    reservedBy.title  = "Organizer";
                    reservedBy.value  = evnt.OrganizerName;

                    attachment.fields.Add(reservedBy);
                    message.attachments.Add(attachment);
                }
            }
            else
            {
                message.text = notFound;
            }

            SendReply(message, ReplyURI);
        }