Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public static void SyncSprintsToOutlook(String calendarName, Release release, EntityListResult <Sprint> sprints)
        {
            //set sprint map
            Dictionary <long, Sprint> sprintMap = new Dictionary <long, Sprint>();

            foreach (Sprint sprint in sprints.data)
            {
                sprintMap[sprint.Id] = sprint;
            }

            //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 sprintUP            = appointment.UserProperties[OutlookUtils.APPOINTMENT_SPRINT_ID_FIELD];
                int          appointmentSprintId = (sprintUP == null ? NO_ID_VALUE : int.Parse(sprintUP.Value));

                if (appointmentReleaseId != NO_ID_VALUE && appointmentSprintId != NO_ID_VALUE) //sprint
                {
                    if (sprintMap.ContainsKey(appointmentSprintId))
                    {
                        Sprint tempSprint = sprintMap[appointmentSprintId];
                        sprintMap.Remove(appointmentSprintId);


                        if (tempSprint != null)
                        {
                            SyncSprintToOutlook(tempSprint, appointment);
                        }
                    }
                    else
                    {
                        //Delete a Sprint that no longer exist
                        appointment.Delete();
                    }
                }

                Marshal.ReleaseComObject(appointment);
            }

            //create sprints that were not deleted from map
            foreach (Sprint sprint in sprintMap.Values)
            {
                Dictionary <String, Object> customFields = new Dictionary <String, Object>();
                customFields.Add(OutlookUtils.APPOINTMENT_RELEASE_ID_FIELD, sprint.Release.Id);
                customFields[OutlookUtils.APPOINTMENT_SPRINT_ID_FIELD] = sprint.Id;
                String sprintName = getSprintAppointmentName(sprint);
                OutlookUtils.AddAppointment(sprintName, sprint.StartDate, sprint.EndDate, "", 0, false, customFields, true);
            }
        }