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!"); }
/// <summary> /// Inside the thread /// </summary> public void Start() { weekShifts = new List <WorkShift>(); InitializeOutlookCalendar(); var work = FindWorkingShift(EntireMailBody); for (int i = 0; i < work.Count; i++) { var shift = new WorkShift(i + 1, work[i]); weekShifts.Add(shift); Console.WriteLine(shift); } weekShifts.ForEach(x => CreateAppointment(x)); //ShowWeekDay(); }