public MatchArchive GetMatches(uint teamId, DateTime startDate, DateTime endDate) { List <Match> matches = new List <Match>(); DateTime curMonthStart = startDate; Team team = null; // 15 minute grid endDate = endDate.AddSeconds(-endDate.Second); endDate = endDate.AddMinutes(-(endDate.Minute % 15)); while (curMonthStart < endDate) { DateTime curMonthEnd = new DateTime(curMonthStart.Year, curMonthStart.Month, 1).AddMonths(1).AddSeconds(-1); if (curMonthEnd > endDate) { curMonthEnd = endDate; } string url = new StringBuilder("file=matchesarchive&version=1.1") .Append("&teamID=").Append(teamId) .Append("&FirstMatchDate=").Append(curMonthStart.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) .Append("&LastMatchDate=").Append(curMonthEnd.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)).ToString(); XDocument doc = XDocument.Load(ChppAccessor.GetDataReader(url, DataFlags.Static)); XElement elTeam = doc.Root.AssertElement("Team"); Team compTeam = MatchParserHelper.GetTeam(elTeam, string.Empty); if (teamId != compTeam.ID) { throw new Exception("received wrong team info"); } team = compTeam; // assert dates foreach (XElement el in doc.Descendants("Match")) { matches.Add(MatchParserHelper.GetMatch(el)); } curMonthStart = curMonthEnd.AddSeconds(1); } // TODO: team may be null here (if endDate < startDate) MatchArchive ar = new MatchArchive(team, startDate, endDate); ar.Matches = matches; return(ar); }
protected override object DoImpl() { //if (_mdl == null) { ReportProgress(0, "Getting general team information"); DateTime?startDate = _startDate; DateTime?endDate = _endDate; if (_tdb != null) { TeamDetails teamDetails = _tdb.GetTeamDetails((uint)_teamId); if (teamDetails == null || teamDetails.Owner == null || teamDetails.Owner.JoinDate == null) { throw new Exception("Cannot get join date of owner"); } startDate = teamDetails.Owner.JoinDate.Value; endDate = DateTime.Now.ToHtTime(); } if (startDate == null || endDate == null) { throw new Exception("missing start and/or end date"); } //ReportProgress(10, String.Format("Getting match archive from {0} to {1}", startDate.Value.ToShortDateString(), endDate.Value.ToShortDateString())); ReportProgress(10, "Getting match archive"); MatchArchive ar = _mab.GetMatches((uint)_teamId, startDate.Value, endDate.Value); int noMatches = ar.Count(); int noCurMatch = 0; _mdl = new List <MatchDetails>(); foreach (Match m in ar.SafeEnum()) { ReportProgress(20 + (80 * noCurMatch / noMatches), String.Format("Getting match {0}/{1}", noCurMatch + 1, noMatches)); _mdl.Add(_mdb.Get((uint)m.ID)); ++noCurMatch; } } ReportProgress(100, "Done."); return(_mdl); }