public TeamMatchesAdapter(IEnumerable <Team> teams, IEnumerable <Match> matches, IEnumerable <League> leagues, int teamId) { foreach (var league in leagues) { ListItems.Add(new ListItem { Index = MainHeaders.Count, Type = 0 }); MainHeaders.Add(new HeaderModel { Title = league.Name }); foreach (var match in matches.Where(m => m.LeagueId == league.Id).OrderBy(m => m.Date)) { ListItems.Add(new ListItem { Index = SubHeaders.Count, Type = 1 }); SubHeaders.Add(new HeaderModel { Title = match.Round.ToString() + ". forduló" }); ListItems.Add(new ListItem { Index = Contents.Count, Type = 2 }); if (teamId == match.HomeTeamId) { Contents.Add(new MatchResultModel { HomeTeam = teams.Where(t => t.Id == match.HomeTeamId).First().Name + " ", HomeScore = match.ScoreH.ToString(), AwayTeam = teams.Where(t => t.Id == match.AwayTeamId).First().Name, AwayScore = match.ScoreA.ToString(), Id = match.Id }); } else { Contents.Add(new MatchResultModel { AwayTeam = teams.Where(t => t.Id == match.HomeTeamId).First().Name + " ", AwayScore = match.ScoreH.ToString(), HomeTeam = teams.Where(t => t.Id == match.AwayTeamId).First().Name, HomeScore = match.ScoreA.ToString(), Id = match.Id }); } } } }
public LeagueMatchesAdapter(IEnumerable <Team> teams, IEnumerable <Match> matches, int rounds) { for (int i = 0; i < rounds; i++) { ListItems.Add(new ListItem { Index = MainHeaders.Count, Type = 0 }); MainHeaders.Add(new HeaderModel { Title = (i + 1) + ". forduló" }); List <Match> matchesInRound = matches.Where(m => m.Round == i + 1).OrderBy(m => m.Date).ThenBy(m => m.Time).ToList(); int j = 0; while (j < matchesInRound.Count) { ListItems.Add(new ListItem { Index = SubHeaders.Count, Type = 1 }); SubHeaders.Add(new HeaderModel { Title = matchesInRound.ElementAt(j).Date.ToString() }); int k = j; while (k < matchesInRound.Count && matchesInRound.ElementAt(j).Date == matchesInRound.ElementAt(k).Date&& matchesInRound.ElementAt(j).Time == matchesInRound.ElementAt(k).Time) { ListItems.Add(new ListItem { Index = Contents.Count, Type = 2 }); Contents.Add(new MatchResultModel { HomeTeam = teams.Where(t => t.Id == matchesInRound.ElementAt(k).HomeTeamId).First().Name + " ", HomeScore = matchesInRound.ElementAt(j).ScoreH.ToString(), AwayTeam = teams.Where(t => t.Id == matchesInRound.ElementAt(k).AwayTeamId).First().Name, AwayScore = matchesInRound.ElementAt(j).ScoreA.ToString(), Id = matchesInRound.ElementAt(j).Id }); k++; } j = k; } } }
private bool LoadSubFiles(int offset, byte[] source) { if (offset < 0) return false; SFFSUBHEADER header = new SFFSUBHEADER(); int headerSize = Marshal.SizeOf(header); if (headerSize + offset > source.Length) { // File is Eof return true; } IntPtr headerBuf = Marshal.AllocHGlobal(headerSize); try { Marshal.Copy(source, offset, headerBuf, headerSize); header = (SFFSUBHEADER)Marshal.PtrToStructure(headerBuf, typeof(SFFSUBHEADER)); } finally { Marshal.FreeHGlobal(headerBuf); } SubHeaders.Add(header); // load pcx /* KeyValuePair<PCXHEADER, PCXDATA> pcxData; if (!LoadPcx(offset, header, source, out pcxData)) return false; KeyValuePair<short, short> key = new KeyValuePair<short, short>(header.GroubNumber, header.ImageNumber); */ if (header.NextSubheaderFileOffset != 0) { if (header.NextSubheaderFileOffset >= source.Length) return true; if (!LoadSubFiles((int)header.NextSubheaderFileOffset, source)) return false; } return true; }
private void OnSffReaderV2(sff.sffReader reader, sff.sprMsgV2 spr, int linkGoup, int linkIndex, int linkPalGroup, int linkPalIndex, byte[] rawData) { bool isImageLink = linkGoup >= 0 && linkIndex >= 0; if (!isImageLink) { KeyValuePair<uint, uint> key = new KeyValuePair<uint, uint>((uint)spr.group, (uint)spr.index); if (mPcxDataMap.ContainsKey(key)) return; PCXHEADER header = new PCXHEADER (); header.widht = spr.width; header.height = spr.height; // header.x = (ushort)spr.x; //header.y = (ushort)spr.y; header.x = 0; header.y = 0; header.NPlanes = 1; if (rawData != null && rawData.Length > 0) { int chgSize = header.NPlanes * header.widht; byte[] temp = null; if (m_lineBuffer != null && m_lineBuffer.Length >= chgSize) temp = m_lineBuffer; else { temp = new byte[chgSize]; m_lineBuffer = temp; } for (int y = 0; y < (int)header.height / 2; ++y) { int x = ((int)header.height - 1 - y); int s = y * chgSize; int d = x * chgSize; Buffer.BlockCopy (rawData, d, temp, 0, chgSize); Buffer.BlockCopy (rawData, s, rawData, d, chgSize); Buffer.BlockCopy (temp, 0, rawData, s, chgSize); } } PCXDATA data = new PCXDATA (); data.data = rawData; bool isPalletLink = (linkPalGroup >= 0 && linkPalIndex >= 0) && ((linkPalGroup != spr.group) || (linkPalIndex != spr.index)); if (!isPalletLink) { byte[] pal = reader.GetPal (spr.group, spr.index); //data.pallet = GetPalletFromByteArr (pal); data.pallet = pal; data.palletLink = new KeyValuePair<short, short> (-1, -1); } else { data.palletLink = new KeyValuePair<short, short> ((short)linkPalGroup, (short)linkPalIndex); data.pallet = null; } KeyValuePair<PCXHEADER, PCXDATA> value = new KeyValuePair<PCXHEADER, PCXDATA> (header, data); mPcxDataMap.Add (key, value); } SFFSUBHEADER subHeader = new SFFSUBHEADER (); subHeader.GroubNumber = (short)spr.group; subHeader.ImageNumber = (short)spr.index; subHeader.x = spr.x; subHeader.y = spr.y; if (isImageLink) { subHeader.IndexOfPrevious = (short)GetSubHeaderIndex (linkGoup, linkIndex); subHeader.LenghtOfSubheader = 0; } else { subHeader.IndexOfPrevious = -1; } SubHeaders.Add(subHeader); }
private void Init(string title, string noMatchString, IEnumerable <Match> matches) { ListItems.Add(new ListItem { Index = MainHeaders.Count, Type = 0 }); MainHeaders.Add(new HeaderModel { Title = title }); int i = 0; if (matches.Count() == 0) { ListItems.Add(new ListItem { Index = Contents.Count, Type = 3 }); Contents.Add(new LiveMatchModelBase { Text = noMatchString }); } while (i < matches.Count()) { Match actualMatch = matches.ElementAt(i); League actualLeague = Leagues.First(l => l.Id == actualMatch.LeagueId); ListItems.Add(new ListItem { Index = SubHeaders.Count, Type = 1 }); SubHeaders.Add(new HeaderModel { Title = actualLeague.Name, Country = actualLeague.Country }); int j = i; //While in the same league while (j < matches.Count() && matches.ElementAt(j).LeagueId == actualMatch.LeagueId) { Team homeTeam = Teams.First(t => t.Id == actualMatch.HomeTeamId); Team awayTeam = Teams.First(t => t.Id == actualMatch.AwayTeamId); ListItems.Add(new ListItem { Index = Contents.Count, Type = 2 }); Contents.Add(new LiveMatchModel { Date = actualMatch.Date, Time = actualMatch.Time, HomeTeam = homeTeam.Name, AwayTeam = awayTeam.Name, HomeScore = actualMatch.ScoreH, AwayScore = actualMatch.ScoreA, MatchId = actualMatch.Id, State = actualMatch.State }); actualMatch = matches.ElementAt(j); j++; } i = j; } }