private void Initialize() { outlookApp = new Outlook.Application(); outlookNS = outlookApp.GetNamespace("MAPI"); inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox); items = (Outlook.Items)inboxFolder.Items; items.ItemAddEvent += new Outlook.Items_ItemAddEventHandler(items_ItemAdd); }
private void CreateAppointment(WorkShift workShift) { if (!workShift.IsValidForCalendar) { Console.WriteLine("Des erreurs ont été trouvé lors du parsing des shifts. Impossible de créer un rendez-vous pour #" + workShift.ShiftPosition); return; } Outlook.MAPIFolder primaryCalendar = (Outlook.MAPIFolder) thisOutlookApp.ActiveExplorer().Session.GetDefaultFolder (OlDefaultFolders.olFolderCalendar); Outlook.MAPIFolder familialCalendar = null; foreach (Outlook.MAPIFolder personalCalendar in primaryCalendar.Folders) { if (personalCalendar.Name == "familial") { familialCalendar = personalCalendar; break; } } if (familialCalendar == null) { Console.WriteLine("Impossible de créer un rendez-vous pour le shift #" + workShift.ShiftPosition + " : Calendrier Familial non trouvé."); return; } Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)familialCalendar.Items.Add(OlItemType.olAppointmentItem); newAppointment.Start = workShift.StartingShiftDate; newAppointment.End = workShift.FinishingShiftDate; newAppointment.Location = workShift.Location; newAppointment.Body = string.Empty; foreach (var type in workShift.typeOfShift) { newAppointment.Body += "Shift de " + type.ShiftTitle + " : " + type.ShiftDescription + "\n"; } newAppointment.AllDayEvent = false; newAppointment.Subject = "Travail McDonald's " + EmpName; Outlook.Items calendarItems = (Outlook.Items)familialCalendar.Items; newAppointment.Save(); Console.WriteLine("Shift " + workShift.ShiftPosition + " enregistré avec succès!"); }