public JiraSprint GetBugsForSprint(string project, string versionId, string versionName)
        {

            JiraSprint sprint = new JiraSprint();
            sprint.Id = Int32.Parse(versionId);
            sprint.Name = versionName;

            // Get start and end dates from the GH configuration; DB only
            string sql = @"SELECT propertyvalue
                             FROM propertytext
                             WHERE ID = (
                             SELECT ID
                             FROM propertyentry
                             WHERE ENTITY_NAME = 'GreenHopper'
                             AND ENTITY_ID = (select project from projectversion where id = :versionId)
                             AND PROPERTY_KEY = 'CONFIGURATION' )";

            OracleConnection cn = new OracleConnection(_connectionString);
            OracleCommand cmd = new OracleCommand(sql, cn);

            OracleParameter param;
            param = cmd.Parameters.Add(":versionId", OracleDbType.Int16);
            param.Value = versionId;
            cn.Open();

            string ghXmlText = cmd.ExecuteScalar().ToString();

            XmlDocument ghXml = new XmlDocument();
            ghXml.LoadXml(ghXmlText);

            // Calculate start date
            XmlNode node;
            node = ghXml.SelectSingleNode(String.Format("/map/entry[string='BURNDOWN_START_DATE_{0}']", versionId));
            sprint.StartDate = Util.ConvertFromUnixTimestamp(Convert.ToDouble(node.SelectSingleNode("long").InnerText) / 1000);

            // Calculate end date
            node = ghXml.SelectSingleNode(String.Format("/map/entry[string='BURNDOWN_END_DATE_{0}']", versionId));
            sprint.EndDate = Util.ConvertFromUnixTimestamp(Convert.ToDouble(node.SelectSingleNode("long").InnerText) / 1000);

            #region broken
            /* Problem with rendering Chinese characters (such as those in DPS-11590). Replace with REST API */
            /*
            // Get issues for this version
            List<RemoteIssue> issues = _jss.getIssuesFromJqlSearch(_token, String.Format("project = {0} and fixVersion = '{1}' and issueType = Bug", project, versionName), 1000).ToList();
            IEnumerable<JiraIssue> jiraIssues = from i in issues
                                                select new JiraIssue
                                                {
                                                    IssueKey = i.key,
                                                    ResolutionDate = i.resolution == null ? DateTime.MaxValue : _jss.getResolutionDateById(_token, Int64.Parse(i.id))
                                                };
            */
            #endregion

            // Get issues for this version via REST
            dynamic resp = JiraRestCall(
                String.Format("{0}rest/api/2/search?maxResults=100&jql=project={1}+and+fixVersion=\"{2}\"+and+issueType=Bug", 
                _jiraPrefix, project, versionName));

            List<JiraIssue> jiraIssues = JiraRestIssuesToList(resp["issues"]);

            sprint.NumberOfIssues = jiraIssues.Count();

            // Calculate non working days
            node = ghXml.SelectSingleNode("/map/entry[string='NWDAYS']");
            string[] nwdays = node.SelectNodes("string")[1].InnerText.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            List<DateTime> nonWorkingDays = Array.ConvertAll<string, DateTime>(nwdays, delegate(string s) { return DateTime.ParseExact(s, "yyyy-M-d", System.Globalization.CultureInfo.CurrentCulture); }).ToList();

            // Build Sprint Days
            sprint.Days = BuildSprintDayList(sprint.StartDate, sprint.EndDate, nonWorkingDays, jiraIssues);

            return sprint;
        }
        public JiraSprint GetBugsForAgileSprint(string boardId, string sprintName)
        {
            dynamic resp;
            JiraSprint sprint = new JiraSprint();
            sprint.Name = sprintName;

            // Get Sprint Information
            resp = JiraRestCall(
                String.Format("{0}rest/greenhopper/1.0/xboard/work/allData?rapidViewId={1}",
                _jiraPrefix, boardId));

            foreach (dynamic sp in resp["sprintsData"]["sprints"])
            {
                if (sp["name"] == sprintName)
                {
                    sprint.StartDate = DateTime.Parse(sp["startDate"]);
                    sprint.EndDate = DateTime.Parse(sp["endDate"]);
                    sprint.Id = sp["id"];
                    break;
                }
            }

            if (sprint.StartDate == null)
                throw new Exception("Sprint not found");


            // Get issues for this version via REST
            resp = JiraRestCall(
                String.Format("{0}rest/api/2/search?maxResults=100&jql=sprint={1}+and+issueType=Bug",
                _jiraPrefix, sprint.Id));

            List<JiraIssue> jiraIssues = JiraRestIssuesToList(resp["issues"]);

            sprint.NumberOfIssues = jiraIssues.Count();

            // Can't find how to get non-working days out of the sprint API
            List<DateTime> nonWorkingDays = new DateTime[0].ToList();

            // Build Sprint Days
            sprint.Days = BuildSprintDayList(sprint.StartDate, sprint.EndDate, nonWorkingDays, jiraIssues);

            return sprint;
        }