private void GetNextMeetingInfo() { ExchangeService service = new ExchangeService(); service.Credentials = new WebCredentials(Environment.GetEnvironmentVariable("EXCHANGE_PROXY_USERNAME"), Environment.GetEnvironmentVariable("EXCHANGE_PROXY_PASSWORD")); service.Url = new Uri(ConfigurationManager.AppSettings["ExchangeWebServiceURL"]); service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, ConfigurationManager.AppSettings["ExchangeRoomID"]); CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); CalendarView cView = new CalendarView(DateTime.Today, DateTime.Today.AddDays(2)); cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Organizer); FindItemsResults <Appointment> appointments = calendar.FindAppointments(cView); Appointment nextAppointment = null; foreach (Appointment a in appointments) { if ((nextAppointment == null || a.Start < nextAppointment.Start) && a.Start > DateTime.Now.AddMinutes(-30)) { nextAppointment = a; } } nextAppointment.Load(); Data.MeetingTitle = nextAppointment.Subject; Data.NextMeetingStartsAt = "Next meeting at " + nextAppointment.Start.ToString("h:mm tt"); var organizer = service.ResolveName(nextAppointment.Organizer.Address)[0]; Data.OrganizerName = nextAppointment.Organizer.Name; foreach (var attend in nextAppointment.RequiredAttendees) { var attendee = service.ResolveName(attend.Address)[0]; Data.RequiredAttendees.Add(new DataForUI.Attendee() { Name = attend.Name, NetID = attendee.Mailbox.Name, Arrived = false }); } foreach (var attend in nextAppointment.OptionalAttendees) { var attendee = service.ResolveName(attend.Address)[0]; Data.OptionalAttendees.Add(new DataForUI.Attendee() { Name = attend.Name, NetID = attendee.Mailbox.Name, Arrived = false }); } }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("This application must be passed 4 arguments:"); Console.WriteLine(" <username> - The username of the user requesting a calendar. (E.g. abc1d23)."); Console.WriteLine(" <password> - The pass word of the user requesting a calendar."); Console.WriteLine(" <calendar> - The name of the calendar. (E.g. building 32 room 4049 would be b32r4049)."); Console.WriteLine(" <writefile> - The file to write the iCal for the calendar to. (E.g. C:\\Users\\User\\b32r4049.ics or Windows or /home/user/b32r4049.ics on Linux).\n"); Environment.Exit(1); } // Configure filtering options FilterSetting FilterOptions = new FilterSetting(); FilterOptions.SearchStartDate = DateTime.Now.AddDays(-30); FilterOptions.SearchEndDate = DateTime.Now.AddDays(90); // Establish web service session ExchangeService WebService = ExchangeWebServiceWrapper.GetWebServiceInstance(args[0], args[1], "SOTON"); // Retrieve calendar folder Console.WriteLine("Getting calendar..."); Mailbox mailbox = new Mailbox(args[2] + "@soton.ac.uk"); FolderId id = new FolderId(WellKnownFolderName.Calendar, mailbox); CalendarFolder Calendar = CalendarFolder.Bind(WebService, id); if (Calendar == null) { throw new Exception("Could not find calendar folder."); } // Retrieve appointments Console.WriteLine("Getting appointments..."); FindItemsResults <Appointment> Appointments = Calendar.FindAppointments(new CalendarView(FilterOptions.SearchStartDate, FilterOptions.SearchEndDate)); iCalWrapper iCal = new iCalWrapper(); iCal.AddEventsToCalendar(Appointments, FilterOptions); // Write iCal file to disk Console.WriteLine("Writing to file " + args[3] + "..."); iCal.GenerateFile(args[3]); Console.WriteLine("Done"); }
public List <JsonEventsSchedule> GetAppointments(string email, string password) { List <JsonEventsSchedule> eventsItems = new List <JsonEventsSchedule>(); DateTime startDate = DateTime.Now.Date; DateTime endDate = startDate.AddDays(30); try { CalendarFolder calendar = FindNamedCalendarFolder("officehours", email, password); // or //CalendarFolder calendar = FindDefaultCalendarFolder(email, password); CalendarView cView = new CalendarView(startDate, endDate, 50); cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.When, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id); FindItemsResults <Appointment> appointments = calendar.FindAppointments(cView); if (appointments != null && appointments.Any()) { foreach (var appt in appointments) { eventsItems.Add( new JsonEventsSchedule { id = appt.Id.ToString(), title = appt.Subject, start = ConvertToiso8601(appt.Start), end = ConvertToiso8601(appt.End), }); } } return(eventsItems); } catch { throw; } }