public async Task WriteAsync(object record) { var wrapper = new LogRecordWrapperModel { ApplicationName = ApplicationName, FileName = fileName, Record = record }; await queue.AddMessageAsync(wrapper); }
public async Task WriteAsync(LogLevel logLevel, LogEntryModel logEntry) { var wrapper = new LogEventWrapperModel { ApplicationName = ApplicationName, LogLevel = logLevel, LogEntry = logEntry }; await queue.AddMessageAsync(wrapper); }
public async Task <Subscription> SaveSubscriptionAsync(Guid userId, EventId eventId) { // enqueue var message = new SaveSubscriptionMessage { UserId = userId, EventId = eventId }; await _queue.AddMessageAsync(message, TimeSpan.Zero); // persist return(await _subscriptionStore.SaveSubscriptionAsync(userId, eventId)); }
public async Task <Page <T> > SearchMovieReleaseEventsAsync(string query, PageOffset pageOffset) { // check for a recent search DocumentId documentId = _externalDocumentClient.SearchMovies(query, pageOffset); IEnumerable <DocumentMetadata> documentMetadataList = await _documentStore.ListDocumentMetadataAsync(documentId, DateTimeOffset.UtcNow.Subtract(_documentCacheDuration)); DocumentMetadata[] documentMetadataArray = documentMetadataList.ToArray(); // get the document from the cache or from the external source Document document; if (documentMetadataArray.Any()) { // get the latest document from the cache DocumentMetadata documentMetadata = documentMetadataArray.OrderByDescending(m => m.Created).First(); document = await _documentStore.GetDocumentAsync(documentId, documentMetadata.Id); } else { // query Rotten Tomatoes API document = await _externalDocumentClient.GetDocumentAsync(documentId); // persist the document DocumentMetadata documentMetadata = await _documentStore.SaveDocumentAsync(document); // enqueue the process queue message if the document is new if (!documentMetadata.Duplicate) { await _queue.AddMessageAsync(new ProcessDocumentMessage { DocumentMetadata = documentMetadata }, TimeSpan.Zero); } } // extract the events T[] entries = _eventExtractor.Extract(document.Content).ToArray(); return(new Page <T> { Offset = pageOffset, Entries = entries, HasNextPage = entries.Length >= pageOffset.Size }); }
public async Task UploadAsync(List <DnBOrgsModel> newOrgs) { if (newOrgs == null || newOrgs.Count == 0) { throw new ArgumentNullException(nameof(newOrgs)); } //Check new file var count = newOrgs.Count(o => string.IsNullOrWhiteSpace(o.DUNSNumber)); if (count > 0) { throw new Exception($"There are {count} organisations in the D&B file without a DUNS number"); } var allDnBOrgs = await GetAllDnBOrgsAsync(); //Check for no organisation name count = allDnBOrgs == null ? 0 : allDnBOrgs.Count(o => string.IsNullOrWhiteSpace(o.OrganisationName)); if (count > 0) { throw new Exception($"There are {count} organisations with no OrganisationName detected."); } //Check for no addresses count = allDnBOrgs == null ? 0 : allDnBOrgs.Count(o => !o.IsValidAddress()); if (count > 0) { await ExecuteWebjobQueue.AddMessageAsync(new QueueWrapper("CompaniesHouseCheck")); throw new Exception( $"There are {count} organisations with invalid addresses (i.e., no UK postcode or pobox, or any foreign address field)."); } //Check for duplicate DUNS count = newOrgs.Count() - newOrgs.Select(o => o.DUNSNumber).Distinct().Count(); if (count > 0) { throw new Exception($"There are {count} duplicate DUNS numbers detected"); } //Check for duplicate employer references var employerReferences = newOrgs.Where(o => !string.IsNullOrWhiteSpace(o.EmployerReference)).Select(o => o.EmployerReference); count = employerReferences.Count() - employerReferences.Distinct().Count(); if (count > 0) { throw new Exception($"There are {count} duplicate EmployerReferences detected"); } //Fix Company Number Parallel.ForEach( newOrgs.Where(o => !string.IsNullOrWhiteSpace(o.CompanyNumber)), dnbOrg => { if (dnbOrg.CompanyNumber.IsNumber()) { dnbOrg.CompanyNumber = dnbOrg.CompanyNumber.PadLeft(8, '0'); } }); //Check for duplicate company numbers var companyNumbers = newOrgs.Where(o => !string.IsNullOrWhiteSpace(o.CompanyNumber)).Select(o => o.CompanyNumber); count = companyNumbers.Count() - companyNumbers.Distinct().Count(); if (count > 0) { throw new Exception($"There are {count} duplicate CompanyNumbers detected"); } //Copy all old settings to new if (allDnBOrgs != null) { Parallel.ForEach( newOrgs, newOrg => { var oldOrg = allDnBOrgs.FirstOrDefault(o => o.DUNSNumber == newOrg.DUNSNumber); //Make sure missing old orgs are copied accross if (oldOrg == null) { return; } if (string.IsNullOrWhiteSpace(newOrg.EmployerReference) && !string.IsNullOrWhiteSpace(oldOrg.EmployerReference)) { newOrg.EmployerReference = oldOrg.EmployerReference; } }); } }