public async Task ForwardReadsNextAsync() { var firstPageCount = 10; var nextPageCount = 3; var logReader = new PageReaderData() { Id = Fixture.TestName, Count = firstPageCount }; long pageTop = PageReaderData.EOF; long pageBottom = (firstPageCount) * Fixture.TextLine(0).Length; Assert.True(Fixture.LineCount > firstPageCount + nextPageCount, "Not enough lines to perform test."); await PageReader.ReadFirstAsync(logReader); Assert.Equal(pageTop, logReader.PageTop); Assert.Equal(pageBottom, logReader.PageBottom); Assert.Equal(firstPageCount, logReader.Lines.Count()); pageTop = pageBottom; pageBottom = (firstPageCount + nextPageCount) * Fixture.TextLine(0).Length; logReader.Count = nextPageCount; await PageReader.ReadNextAsync(logReader); Assert.Equal(pageTop, logReader.PageTop); Assert.Equal(pageBottom, logReader.PageBottom); Assert.Equal(nextPageCount, logReader.Lines.Count()); for (var i = 0; i < nextPageCount; i++) { Assert.Equal(Fixture.Text(firstPageCount + i + 1), logReader.Lines.Skip(i).First()); } }
public async Task ExportParticipantListToExcelAsync(Stream stream, IRegistrationExportService.Options options = null) { using var spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook); var workbookPart = spreadsheetDocument.AddWorkbookPart(); workbookPart.Workbook = new Workbook(); var worksheetPart = workbookPart.AddNewPart <WorksheetPart>(); var sheetData = new SheetData(); if (options?.ExportHeader == true) { WriteHeader(sheetData); } var reader = new PageReader <Registration>(async(offset, limit, token) => await _registrationRetrievalService.ListRegistrationsAsync( new RegistrationListRequest { Offset = offset, Limit = limit, OrderBy = RegistrationListOrder.RegistrationTime, Descending = true, Filter = new RegistrationFilter { EventInfoId = options?.EventInfoId } }, new RegistrationRetrievalOptions { IncludeUser = true, IncludeEventInfo = true, IncludeOrders = true, IncludeProducts = true, }, token)); while (await reader.HasMoreAsync()) { foreach (var registration in await reader.ReadNextAsync()) { WriteRow(sheetData, registration); } } worksheetPart.Worksheet = new Worksheet(sheetData); // Add Sheets to the Workbook. var sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); // Append a new worksheet and associate it with the workbook. sheets.Append(new Sheet { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Participants" }); workbookPart.Workbook.Save(); spreadsheetDocument.Close(); }
private async Task <EventSynchronizationResult> SyncAllRegistrationsAsync(IExternalSyncProviderService syncProviderService, EventInfo eventInfo, CancellationToken cancellationToken) { var result = new EventSynchronizationResult(syncProviderService.Name); var reader = new PageReader <Registration>(async(offset, limit, token) => await _registrationRetrievalService.ListRegistrationsAsync( new IRegistrationRetrievalService.Request { Offset = offset, Limit = limit, EventInfoId = eventInfo?.EventInfoId, IncludingUser = true, IncludingEventInfo = true, VerifiedOnly = true, OrderBy = IRegistrationRetrievalService.Order.RegistrationTime }, token)); while (await reader.HasMoreAsync(cancellationToken)) { foreach (var registration in await reader.ReadNextAsync(cancellationToken)) { var externalAccount = await CreateExternalAccountIfNotExists(syncProviderService, registration, result); if (externalAccount != null) { await SyncRegistrationAsync(syncProviderService, registration, externalAccount, result); } } } return(result); }
public async Task ForwardReadsPrevAsync() { var lastPageCount = 10; var prevPageCount = 3; var logReader = new PageReaderData() { Id = Fixture.TestName, Count = lastPageCount }; long pageTop = (Fixture.LineCount - lastPageCount) * Fixture.TextLine(0).Length; long pageBottom = PageReaderData.EOF; Assert.True(Fixture.LineCount > lastPageCount, "Not enough lines to perform test."); await PageReader.ReadLastAsync(logReader); Assert.Equal(pageTop, logReader.PageTop); Assert.Equal(pageBottom, logReader.PageBottom); Assert.Equal(lastPageCount, logReader.Lines.Count()); pageBottom = pageTop; pageTop = (Fixture.LineCount - lastPageCount - prevPageCount) * Fixture.TextLine(0).Length; logReader.Count = prevPageCount; await PageReader.ReadPrevAsync(logReader); Assert.Equal(pageTop, logReader.PageTop); Assert.Equal(pageBottom, logReader.PageBottom); Assert.Equal(prevPageCount, logReader.Lines.Count()); for (var i = 0; i < prevPageCount; i++) { Assert.Equal(Fixture.Text(lastPageCount + prevPageCount + i), logReader.Lines.Skip(i).First()); } }
private async Task <AllocationMapPage> GetAllocationPage(int databaseId, PageAddress addresss) { var page = await PageReader.Read(databaseId, addresss); var result = new AllocationMapParser().Parse(page); return(result); }
public async Task <ActionResult> Forward(string id) { return(List(await PageReader.ReadFirstAsync(new PageReaderData() { Id = id, Count = CountOptions[0] }))); }
public async Task <ActionResult> Index() { var fileList = await PageReader.GetFilesAsync(); var model = fileList.Select(file => new LogFileListModel(file)); return(View(model)); }
/// <summary> /// Create a Page with a supplied PageReader /// </summary> public Page(PageReader reader) { this.reader = reader; LoadPage(); PageAddress = reader.Header.PageAddress; }
public void ListsFiles() { var fileList = PageReader.GetFiles(); Assert.Single(fileList); Assert.Equal(Fixture.TestName, fileList.First().Name); Assert.Equal(Fixture.FileLength, fileList.First().Length); }
public async Task ListsFilesAsync() { var fileList = await PageReader.GetFilesAsync(); Assert.Single(fileList); Assert.Equal(Fixture.TestName, fileList.First().Name); Assert.Equal(Fixture.FileLength, fileList.First().Length); }
private async Task <List <NotificationRecipient> > GetRecipientsAsync( NotificationType notificationType, int eventId, int?productId, Registration.RegistrationStatus[] registrationStatuses, Registration.RegistrationType[] registrationTypes) { var recipients = new List <NotificationRecipient>(); // Default status if not provided: Verified, attended and finished registrationStatuses ??= new[] { Registration.RegistrationStatus.Verified, Registration.RegistrationStatus.Attended, Registration.RegistrationStatus.Finished }; // Default registration type is participants registrationTypes ??= new[] { Registration.RegistrationType.Participant }; var reader = new PageReader <Registration>(async(offset, limit, token) => await _registrationRetrievalService.ListRegistrationsAsync( new RegistrationListRequest { Limit = limit, Offset = offset, Filter = new RegistrationFilter { EventInfoId = eventId, ProductIds = productId.HasValue ? new[] { productId.Value } : null, ActiveUsersOnly = true, HavingStatuses = registrationStatuses, HavingTypes = registrationTypes } }, new RegistrationRetrievalOptions { LoadUser = true, ForUpdate = true }, token)); while (await reader.HasMoreAsync()) { recipients.AddRange((from registration in await reader .ReadNextAsync() select NotificationRecipient.Create(registration, notificationType)) .Where(r => r != null)); // user may have no phone, or email } return(recipients); }
static void Main(string[] args) { string path = @"D:\Wikipedia\jawiki-latest-pages-articles.xml"; using (var reader = new PageReader(path)) { foreach (var item in reader.Read()) { Console.WriteLine(item.title); } } }
public static async Task <List <ApplicationUser> > ListUsersAsync( this IUserRetrievalService userRetrievalService) { return((await PageReader <ApplicationUser> .ReadAllAsync( (offset, limit, token) => userRetrievalService .ListUsers(new UserListRequest { Limit = limit, Offset = offset }, UserRetrievalOptions.Default, token))) .ToList()); }
public static async Task <List <EventInfo> > GetPastEventsAsync( this IEventInfoRetrievalService service, EventInfoFilter filter = null, EventInfoRetrievalOptions options = null, CancellationToken cancellationToken = default) { return((await PageReader <EventInfo> .ReadAllAsync((offset, limit, token) => service.ListEventsAsync(new EventListRequest(offset, limit) { Filter = EventInfoFilter.PastEvents(filter) }, options, token), cancellationToken)) .ToList()); }
public Page(string connectionString, string database, PageAddress pageAddress) { PageAddress = pageAddress; DatabaseId = GetDatabaseId(connectionString, database); var compatabilityLevel = Database.GetCompatabilityLevel(connectionString, database); Database = new Database(connectionString, DatabaseId, database, 1, compatabilityLevel); reader = new DatabasePageReader(connectionString, PageAddress, DatabaseId); LoadPage(); }
/// <summary> /// Create a Page with a DatabasePageReader /// </summary> public Page(Database database, PageAddress pageAddress) { PageAddress = pageAddress; Database = database; DatabaseId = database.DatabaseId; if (pageAddress.FileId == 0) { return; } reader = new DatabasePageReader(Database.ConnectionString, PageAddress, DatabaseId); LoadPage(); }
public void DoTheJob() { try { string page = PageReader.ReadPage(url, true); int resultsStart = page.IndexOf("Search Results", StringComparison.InvariantCulture); if (resultsStart != -1) { page = page.Substring(resultsStart); } Regex rex = new Regex(@"<a.*?href=.*?</\s*a>", RegexOptions.IgnoreCase | RegexOptions.Singleline); MatchCollection coll = rex.Matches(page); int total = coll.Count; if (total > 0) { for (int i = 0; i < coll.Count; i++) { if (coll[i].Value.Contains(searchFor)) { string description = Regex.Replace(coll[i].Value, "(<.*?>)|(;.*?&)|(&.*?;)", "", RegexOptions.IgnoreCase | RegexOptions.Singleline); Positions.Add(new KeyValuePair <int, string>(i + 1, description)); } } double normalizer = 2.5; double newOne = (double)total / (double)resultsPerPage; if (newOne > normalizer) { normalizer = newOne; } for (int i = 0; i < Positions.Count; i++) { Positions[i] = new KeyValuePair <int, string>((int)(Math.Round((double)Positions[i].Key / normalizer, 0)), Positions[i].Value); if (Positions[i].Key == 0) { Positions[i] = new KeyValuePair <int, string>(Positions[i].Key + 1, Positions[i].Value); } } } } catch (Exception e) { this.Error = e.Message; } }
public void ForwardReadsLast() { var count = 3; var logReader = new PageReaderData() { Id = Fixture.TestName, Count = count }; long pageTop = (Fixture.LineCount - count) * Fixture.TextLine(0).Length; long pageBottom = PageReaderData.EOF; Assert.True(Fixture.LineCount > logReader.Count, "Not enough lines to perform test."); PageReader.ReadLast(logReader); Assert.Equal(pageTop, logReader.PageTop); Assert.Equal(pageBottom, logReader.PageBottom); Assert.Equal(count, logReader.Lines.Count()); for (var i = 0; i < count; i++) { Assert.Equal(Fixture.Text(Fixture.LineCount - count + i + 1), logReader.Lines.Skip(i).First()); } }
public void Initialize(IProvider linkage, IProvider command) { _loader = new PageLoader(command.Get <WorkerPool>(), command.Get <Book>()); _reader = new PageReader(); }
public async Task <ActionResult> ForwardPrev(PageReaderData logReader) { return(List(await PageReader.ReadPrevAsync(logReader))); }
public async Task <ActionResult <NotificationResponseDto> > SendEmail(EmailNotificationDto dto, CancellationToken cancellationToken) { var email = new EmailNotification { Subject = dto.Subject, BodyMarkdown = dto.BodyMarkdown }; if (dto.Recipients?.Any() != true && dto.Filter?.IsDefined != true) { return(BadRequest("Either recipient list of registrant filter must be specified")); } var recipients = dto.Recipients ?? Array.Empty <string>(); if (dto.Filter?.IsDefined == true) { var reader = new PageReader <Registration>(async(offset, limit, token) => await _registrationRetrievalService.ListRegistrationsAsync( new RegistrationListRequest { Limit = limit, Offset = offset, Filter = new RegistrationFilter { EventInfoId = dto.Filter.EventId, AccessibleOnly = true, ActiveUsersOnly = true, HavingEmailConfirmedOnly = true, HavingStatuses = dto.Filter.RegistrationStatuses, HavingTypes = dto.Filter.RegistrationTypes } }, new RegistrationRetrievalOptions { IncludeUser = true }, token)); var recipientList = new List <string>(); while (await reader.HasMoreAsync(cancellationToken)) { recipientList.AddRange(from registration in await reader .ReadNextAsync(cancellationToken) let userName = registration.User?.Name let userEmail = registration.User?.Email where !string.IsNullOrEmpty(userEmail) select $"{userName} <{userEmail}>"); } recipients = recipientList .Distinct() .ToArray(); } if (recipients.Any()) { await _emailNotificationService.SendEmailToRecipientsAsync(email, recipients, cancellationToken); } else { _logger.LogWarning("No recipients were selected by the notification filter criteria"); } return(Ok(new NotificationResponseDto { TotalRecipients = recipients.Length })); }
public void PageReaderWithEmptyXmlReader() { var reader = new PageReader(reader: null); }
public void PageReaderWithEmptyPath() { var reader = new PageReader(path: ""); }