Beispiel #1
0
        public void OnSync(Office.IRibbonControl control)
        {
            try
            {
                OutlookUtils.SelectCalenderModule();
                SyncForm form = new SyncForm();
                // get calender list and initialize the form
                ICollection <String> calendars = OutlookUtils.GetCalendarList(config.CalendarName);
                form.Init(calendars, config);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    config.CalendarName = form.SelectedCalendar;
                    //Get by id
                    Release release = NgaUtils.GetSelectedRelease(); //NgaUtils.GetReleaseById(releaseId);
                    EntityListResult <Sprint> sprints = NgaUtils.GetSprintsByRelease(release.Id);
                    OutlookSyncUtils.SyncSprintsToOutlook(config.CalendarName, release, sprints);

                    EntityListResult <Milestone> milestones = NgaUtils.GetMilestonesByRelease(release.Id);
                    OutlookSyncUtils.SyncMilestonesToOutlook(config.CalendarName, release, milestones);
                    String str = String.Format("Sync completed successfully.{0}Summary : {1} sprints and {2} milestones.",
                                               Environment.NewLine, sprints.data.Count, milestones.data.Count);
                    MessageBox.Show(str, "Sync completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (ServerUnavailableException)
            {
                ShowServerIsNotAvailableMsg();
            }
            catch (Exception e)
            {
                String errorMsg = "Sync failed : " + e.Message;
                MessageBox.Show(errorMsg, "Sync Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void OnLogin(Office.IRibbonControl control)
        {
            if (isLoggedIn)
            {
                // disconnect
                SettingsForm.RestConnector.Disconnect();

                isLoggedIn = false;
            }
            else
            {
                // connect
                SettingsForm form         = new SettingsForm();
                String       calendarName = null;
                if (config != null)
                {
                    calendarName = config.CalendarName;
                }
                form.Configuration = config;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    config = form.Configuration;
                    config.CalendarName = calendarName;

                    NgaUtils.init(config.SharedSpaceId, config.WorkspaceId, config.ReleaseId);
                    isLoggedIn = true;

                    // select the calendar tab
                    OutlookUtils.SelectCalenderModule();
                }
            }
            if (ribbon != null)
            {
                ribbon.Invalidate();
            }
        }
Beispiel #5
0
        public void OnLogin(Office.IRibbonControl control)
        {
            if (isLoggedIn)
            {
                // disconnect
                RestConnector.GetInstance().Disconnect();

                isLoggedIn = false;
            }
            else
            {
                // connect
                SettingsForm form         = new SettingsForm();
                var          config       = persistService.Load <LoginConfiguration>();
                var          calendarName = config.CalendarName;
                form.Configuration = config;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    loginConfig = form.Configuration;
                    loginConfig.CalendarName = calendarName;

                    //save last successful configuration
                    persistService.Save(loginConfig);
                    NgaUtils.init(loginConfig.SharedSpaceId, loginConfig.WorkspaceId, loginConfig.ReleaseId);
                    isLoggedIn = true;

                    // select the calendar tab
                    OutlookUtils.SelectCalenderTab();
                }
            }
            if (ribbon != null)
            {
                ribbon.Invalidate();
            }
        }
Beispiel #6
0
        public static void getReleaseMailReport(Release release, GroupResult groupResult, GroupResult usGroupResult)
        {
            MailItem mailItem = OutlookUtils.AddMailItem();

            mailItem.Subject    = "Release Status: #" + release.Id + " - " + release.Name + " (" + release.StartDate.ToShortDateString() + " - " + release.EndDate.ToShortDateString() + ")";
            mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
            String htmlBody = getHtmlTemplate();

            htmlBody = htmlBody.Replace("@releasename", (release.Name + " (" + release.StartDate.ToShortDateString() + " - " + release.EndDate.ToShortDateString() + ")"));
            htmlBody = htmlBody.Replace("@numofsprints", release.NumOfSprints.ToString());

            int totatDefects             = 0;
            int maxWidth                 = 100;
            int maxVal                   = 1;
            Dictionary <string, int> map = new Dictionary <string, int>();

            map.Add("list_node.severity.urgent", 0);
            map.Add("list_node.severity.very_high", 0);
            map.Add("list_node.severity.high", 0);
            map.Add("list_node.severity.medium", 0);
            map.Add("list_node.severity.low", 0);
            foreach (Group group in groupResult.groups)
            {
                map[group.value.logical_name] = group.count;
                maxVal        = (maxVal < group.count ? group.count : maxVal);
                totatDefects += group.count;
            }
            htmlBody = htmlBody.Replace("@defecttotal", totatDefects.ToString());
            int urgentVal = ((int)(map["list_node.severity.urgent"] * maxWidth / maxVal));

            htmlBody = htmlBody.Replace("@urgentwidth", urgentVal.ToString());
            htmlBody = htmlBody.Replace("@urgentcol", ((urgentVal == 0) ? "none" : "red"));
            htmlBody = htmlBody.Replace("@urgentval", (map["list_node.severity.urgent"]).ToString());

            int veryhighVal = ((int)(map["list_node.severity.very_high"] * maxWidth / maxVal));

            htmlBody = htmlBody.Replace("@veryhighwidth", veryhighVal.ToString());
            htmlBody = htmlBody.Replace("@veryhighcol", ((veryhighVal == 0) ? "none" : "#D4522F"));
            htmlBody = htmlBody.Replace("@veryhighval", (map["list_node.severity.very_high"]).ToString());

            int highVal = ((int)(map["list_node.severity.high"] * maxWidth / maxVal));

            htmlBody = htmlBody.Replace("@highwidth", highVal.ToString());
            htmlBody = htmlBody.Replace("@highcol", ((highVal == 0) ? "none" : "#D97934"));
            htmlBody = htmlBody.Replace("@highval", (map["list_node.severity.high"]).ToString());

            int mediumVal = ((int)(map["list_node.severity.medium"] * maxWidth / maxVal));

            htmlBody = htmlBody.Replace("@mediumwidth", mediumVal.ToString());
            htmlBody = htmlBody.Replace("@mediumcol", ((mediumVal == 0) ? "none" : "#EDAE66"));
            htmlBody = htmlBody.Replace("@mediumval", (map["list_node.severity.medium"]).ToString());

            int lowVal = ((int)(map["list_node.severity.low"] * maxWidth / maxVal));

            htmlBody = htmlBody.Replace("@lowwidth", lowVal.ToString());
            htmlBody = htmlBody.Replace("@lowcol", ((lowVal == 0) ? "none" : "#E3CB44"));
            htmlBody = htmlBody.Replace("@lowval", (map["list_node.severity.low"]).ToString());

            StringBuilder storiesStrBuilder = new StringBuilder(" (");
            int           totalStories      = 0;
            bool          isFirst           = true;

            foreach (Group group in usGroupResult.groups)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    storiesStrBuilder.Append(",  ");
                }
                storiesStrBuilder.Append(group.value.name + ": " + group.count);
                totalStories += group.count;
            }
            storiesStrBuilder.Append(")");
            htmlBody          = htmlBody.Replace("@userstoriestotal", totalStories.ToString() + storiesStrBuilder.ToString());
            mailItem.HTMLBody = htmlBody;
            mailItem.Display();
        }