public static void SyncMilestonesToOutlook(String calendarName, Release release, EntityListResult <Milestone> milestones) { //set sprint map Dictionary <long, Milestone> milestonesMap = new Dictionary <long, Milestone>(); foreach (Milestone milestone in milestones.data) { milestonesMap[milestone.Id] = milestone; } //iterate outlook appointments Items resultItems = OutlookUtils.GetAppointmentsInRange(calendarName, new DateTime(2015, 1, 1), new DateTime(2030, 1, 1)); foreach (AppointmentItem appointment in resultItems) { UserProperty releaseUP = appointment.UserProperties[OutlookUtils.APPOINTMENT_RELEASE_ID_FIELD]; int appointmentReleaseId = (releaseUP == null ? NO_ID_VALUE : int.Parse(releaseUP.Value)); UserProperty milestoneUP = appointment.UserProperties[OutlookUtils.APPOINTMENT_MILESTONE_ID_FIELD]; int appointmentMilestoneId = (milestoneUP == null ? NO_ID_VALUE : int.Parse(milestoneUP.Value)); if (appointmentReleaseId != NO_ID_VALUE && appointmentMilestoneId != NO_ID_VALUE) //milestone { if (milestonesMap.ContainsKey(appointmentMilestoneId)) { Milestone tempMilestone = milestonesMap[appointmentMilestoneId]; milestonesMap.Remove(appointmentMilestoneId); if (tempMilestone != null) { SyncMilestoneToOutlook(tempMilestone, appointment); } } else { //Delete a Milestone that no longer exist appointment.Delete(); } } Marshal.ReleaseComObject(appointment); } //create milestones that were not deleted from map foreach (Milestone milestone in milestonesMap.Values) { Dictionary <String, Object> customFields = new Dictionary <String, Object>(); customFields.Add(OutlookUtils.APPOINTMENT_RELEASE_ID_FIELD, ((Release)(milestone.Releases.data.ElementAt <BaseEntity>(0))).Id); customFields[OutlookUtils.APPOINTMENT_MILESTONE_ID_FIELD] = milestone.Id; String milestoneName = getMilestoneAppointmentName(milestone); MilestoneDataContainer msExtraData = getMilestoneData(milestone); OutlookUtils.AddAppointment(milestoneName, milestone.GetStartDate(), milestone.GetEndDate(), msExtraData.Category, msExtraData.ReminderMinutesBeforeStart, msExtraData.ReminderSet, customFields, true); } }
private static void SyncMilestoneToOutlook(Milestone milestone, AppointmentItem appointment) { bool modified = false; if ((appointment.Start.Date != milestone.GetStartDate().Date) || (appointment.End.Date != milestone.GetEndDate().Date)) { appointment.Start = milestone.GetStartDate(); appointment.End = milestone.GetEndDate(); modified = true; } String milestoneName = getMilestoneAppointmentName(milestone); if (!milestoneName.Equals(appointment.Subject)) { appointment.Subject = milestoneName; modified = true; } MilestoneDataContainer notificationData = getMilestoneData(milestone); if (notificationData.ReminderMinutesBeforeStart == 0 && appointment.ReminderSet) { appointment.ReminderSet = false; modified = true; } if (notificationData.ReminderMinutesBeforeStart != appointment.ReminderMinutesBeforeStart) { appointment.ReminderSet = true; appointment.ReminderMinutesBeforeStart = notificationData.ReminderMinutesBeforeStart; modified = true; } if (!String.IsNullOrEmpty(notificationData.Category) && (appointment.Categories == null || !appointment.Categories.Contains(notificationData.Category))) { appointment.Categories = appointment.Categories + notificationData.Category; modified = true; } if (modified) { appointment.Save(); } }
private static MilestoneDataContainer getMilestoneData(Milestone milestone) { MilestoneDataContainer dataContainer = new MilestoneDataContainer(); String desc = milestone.Description; if (desc != null) { string[] lines = milestone.Description.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string[] phrases = lines[i].Split('@'); if (phrases.Length > 1) { dataContainer.AddPhrase(phrases[1]); } } } return(dataContainer); }