public async Task TestNonSeekableStreamAsync() { foreach (var recordSize in new long[] { 24, 28, 32 }) { foreach (var ipVersion in new[] { 4, 6 }) { var file = Path.Combine(_testDataRoot, "MaxMind-DB-test-ipv" + ipVersion + "-" + recordSize + ".mmdb"); using (var stream = new NonSeekableStreamWrapper(File.OpenRead(file))) { using (var reader = await Reader.CreateAsync(stream).ConfigureAwait(false)) { TestMetadata(reader, ipVersion); if (ipVersion == 4) { TestIPV4(reader, file); } else { TestIPV6(reader, file); } } } } } }
public async Task ExportAsync(Guid competitionId, Stream stream, CultureInfo culture) { // Work-around as per https://connect.microsoft.com/VisualStudio/feedback/details/816411/ziparchive-shouldnt-read-the-position-of-non-seekable-streams // TODO: Check if this is still necessary in .NET Framework 4.6 if (!stream.CanSeek) { stream = new NonSeekableStreamWrapper(stream); } using (var context = contextFactory()) using (var archive = new ZipArchive(stream, ZipArchiveMode.Create)) { var pattern = $"[{Regex.Escape(new string(Path.GetInvalidPathChars()))}]"; var removeInvalidChars = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant); //ReSharper disable once AccessToDisposedClosure await ExportPeopleAsync(context, competitionId, folder => archive.CreateEntry($"{removeInvalidChars.Replace(folder, "")}/{PeopleFileName}").Open(), culture); using (var eventStream = archive.CreateEntry(EventFileName).Open()) await ExportEventAsync(context, competitionId, eventStream, culture); using (var scheduleStream = archive.CreateEntry(ScheduleFileName).Open()) await ExportScheduleAsync(context, competitionId, scheduleStream, culture); } }
public async Task ExportAsync(Guid competitionId, Stream stream, CultureInfo culture) { if (!stream.CanSeek) { stream = new NonSeekableStreamWrapper(stream); } using (var context = contextFactory()) using (var archive = new ZipArchive(stream, ZipArchiveMode.Create)) { var competition = await context.Competitions .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Results))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Times))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Transponders.Select(t => t.Transponder)))) .FirstOrDefaultAsync(c => c.Id == competitionId); if (competition == null) { throw new CompetitionNotFoundException(); } await context.Competitors.Where(c => c.List.CompetitionId == competitionId).LoadAsync(); using (var scheduleStream = archive.CreateEntry(ScheduleFileName).Open()) ExportSchedule(competition, scheduleStream); var distances = competition.Distances.Where(d => d.Discipline.StartsWith("SpeedSkating.LongTrack.PairsDistance")).ToList(); foreach (var distance in distances) { using (var racesStream = archive.CreateEntry(GetDistanceFileName(distance, 'C')).Open()) ExportRaces(distance, distances.Where(d => d.Number < distance.Number), racesStream); using (var transpondersStream = archive.CreateEntry(GetDistanceFileName(distance, 'A')).Open()) ExportTransponders(distance, transpondersStream); } } }
public void TestNonSeekableStream() { foreach (var recordSize in new long[] { 24, 28, 32 }) { foreach (var ipVersion in new[] { 4, 6 }) { var file = Path.Combine(_testDataRoot, "MaxMind-DB-test-ipv" + ipVersion + "-" + recordSize + ".mmdb"); using var stream = new NonSeekableStreamWrapper(File.OpenRead(file)); using var reader = new Reader(stream); TestMetadata(reader, ipVersion); if (ipVersion == 4) { TestIPV4(reader, file); } else { TestIPV6(reader, file); } } } }