private async Task <Models.Entities.Census> ResolveLearningProviderAsync <TContext>(ResolveFieldContext <TContext> context) { var entityId = BuildLearningProviderEntityId(context); try { return(await ResolveEntitiesAsync(new[] { entityId }, context)); } catch (Exception ex) { _logger.Error($"Error resolving census for {entityId}: {ex.Message}", ex); throw; } }
private async Task FireEvent <TE>(IEventHandler <TE> handler, TE e, ICommand c) where TE : IEvent { try { if (DungeonGlobalConfiguration.EventTrace) { loggerWrapper.BeforeEventInvoke(e, handler); } await handler.Handle(e, c); if (DungeonGlobalConfiguration.EventTrace) { loggerWrapper.AfterEventInvoke(e, handler); } } catch (Exception ex) { if (DungeonGlobalConfiguration.EventTrace) { loggerWrapper.OnEventInvokeError(e, handler, ex); } loggerWrapper.Error(ex.ToString()); } }
public async Task <Models.Entities.ManagementGroup> ResolveAsync <TContext>(ResolveFieldContext <TContext> context) { try { if (context.Source is Models.Entities.LearningProvider learningProvider) { if (_accessor == null) { throw new Exception("_accessor null"); } if (_loader == null) { throw new Exception("_loader null"); } LearningProviderPointer pointer; if (learningProvider.Urn.HasValue) { pointer = new LearningProviderPointer { SourceSystemName = SourceSystemNames.GetInformationAboutSchools, SourceSystemId = learningProvider.Urn.Value.ToString(), }; } else if (learningProvider.Ukprn.HasValue) { pointer = new LearningProviderPointer { SourceSystemName = SourceSystemNames.UkRegisterOfLearningProviders, SourceSystemId = learningProvider.Ukprn.Value.ToString(), }; } else { return(null); } pointer.Fields = GetRequestedFields(context); pointer.PointInTime = GetPointInTime(context); var loader = _accessor.Context.GetOrAddBatchLoader <LearningProviderPointer, ManagementGroup>( "GetLearningProviderManagementGroup", _loader.LoadAsync); return(await loader.LoadAsync(pointer)); } return(null); } catch (InvalidRequestException ex) { _logger.Info($"Invalid request when resolving management group - {ex.ErrorIdentifier} - {ex.Message}", ex); context.Errors.AddRange( ex.Details.Select(detailsMessage => new ExecutionError(detailsMessage))); return(null); } catch (Exception ex) { _logger.Error($"Error resolving management group", ex); throw; } }
public async Task <LearningProviderRates> ResolveAsync <TContext>(ResolveFieldContext <TContext> context) { var entityId = BuildEntityId(context); try { var request = new LoadLearningProviderRatesRequest { EntityReferences = new[] { new AggregateEntityReference { AdapterRecordReferences = new[] { new EntityReference { SourceSystemId = entityId, SourceSystemName = SourceSystemNames.Rates, }, } }, }, Live = _executionContextManager.GraphExecutionContext.QueryLive, }; var rates = await _entityRepository.LoadLearningProviderRatesAsync(request, context.CancellationToken); return(rates.SquashedEntityResults.FirstOrDefault()?.SquashedEntity); } catch (Exception ex) { _logger.Error($"Error resolving rates for {entityId}: {ex.Message}", ex); throw; } }
public void Receive(Func <Student, MessageProcessResponse> onProcess, Action <Exception> onError, Action onWait) { var options = new MessageHandlerOptions(e => { LogError(e.Exception); return(Task.CompletedTask); }) { AutoComplete = false, MaxAutoRenewDuration = TimeSpan.FromMinutes(1) }; _queueClient.RegisterMessageHandler( async(message, token) => { try { var data = Encoding.UTF8.GetString(message.Body); Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{data}"); var student = JsonConvert.DeserializeObject <Student>(data); var result = onProcess(student); if (result == MessageProcessResponse.Complete) { await _queueClient.CompleteAsync(message.SystemProperties.LockToken); } else if (result == MessageProcessResponse.Abandon) { await _queueClient.AbandonAsync(message.SystemProperties.LockToken); } else if (result == MessageProcessResponse.Dead) { await _queueClient.DeadLetterAsync(message.SystemProperties.LockToken); } onWait(); } catch (Exception ex) { _logger.Error($"Error: {ex.Message}"); await _queueClient.DeadLetterAsync(message.SystemProperties.LockToken); onError(ex); } }, options); }
public override void OnException(ExceptionContext context) { _logger.Error(context.HttpContext.TraceIdentifier, context.Exception.Message, context.Exception.StackTrace); context.Result = new JsonResult(new { StatusCode = 500, Message = $"Internal Server Error from the custom middleware. Exception message: '{context.Exception.Message}'" }); }
public async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "entities/links")] HttpRequest req, CancellationToken cancellationToken) { _executionContextManager.SetContext(req.Headers); _logger.Info($"Start processing retrieval of batch entity links..."); var requestJson = await req.ReadAsStringAsync(); var request = JsonConvert.DeserializeObject <EntityLinksRequest>(requestJson); foreach (var entityPointer in request.Entities) { entityPointer.EntityType = EntityNameTranslator.Singularise(entityPointer.EntityType); } var entities = await _searchAndRetrieveManager.RetrieveBatchAsync(request.Entities, request.PointInTime ?? DateTime.Now, cancellationToken); var results = request.Entities.Select(requestedPointer => { var registeredEntities = entities.Where(re => re.Entities.Any(e => e.EntityType.Equals(requestedPointer.EntityType, StringComparison.InvariantCultureIgnoreCase) && e.SourceSystemName.Equals(requestedPointer.SourceSystemName, StringComparison.InvariantCultureIgnoreCase) && e.SourceSystemId.Equals(requestedPointer.SourceSystemId, StringComparison.InvariantCultureIgnoreCase))) .ToArray(); if (registeredEntities.Length > 1) { var resultIds = registeredEntities.Select(x => x.Id).Aggregate((x, y) => $"{x}, {y}"); var exceptionMessage = $"Expected zero or one result for entity {requestedPointer} when getting links, however found {registeredEntities.Length}. " + $"The results ids are: {resultIds}"; _logger.Error(exceptionMessage); throw new Exception(exceptionMessage); } return(new EntityLinksResult { Entity = requestedPointer, Links = registeredEntities.SingleOrDefault()?.Links, }); }).ToArray(); return(new FormattedJsonResult(new EntityLinksResponse { Entities = results, })); }
public async Task <ManagementGroupsPagedModel> ResolveAsync <TContext>(ResolveFieldContext <TContext> context) { try { var resultSet = await SearchAsync(context, context.CancellationToken); var references = resultSet.Results.Select(d => new AggregateEntityReference { AdapterRecordReferences = d.Entities }) .ToArray(); var fields = GetRequestedFields(context); var entities = await LoadAsync(references, context.Arguments, fields, context.CancellationToken); return(new ManagementGroupsPagedModel { Results = entities, Pagination = new PaginationDetailsModel { Skipped = resultSet.Skipped, Taken = resultSet.Taken, TotalNumberOfRecords = resultSet.TotalNumberOfRecords, } }); } catch (InvalidRequestException ex) { _logger.Info($"Invalid request when resolving management groups - {ex.ErrorIdentifier} - {ex.Message}", ex); context.Errors.AddRange( ex.Details.Select(detailsMessage => new ExecutionError(detailsMessage))); return(null); } catch (Exception ex) { _logger.Error($"Error resolving management groups", ex); throw; } }
public void Init() { _receiver.Receive(student => { _logger.Info("Saving message"); if (!student.Course.HasVacancy) { _emailService.SendEmail($"Mr/Ms {student.Name} your Subscription was denided the course has no more vacancies."); return(MessageProcessResponse.Complete); } _service.SaveAsync(student).Wait(); _emailService.SendEmail($"Mr/Ms {student.Name} your Subscription was Successful!"); var course = student.Course; _service.UpdateCourseInformations(course); return(MessageProcessResponse.Complete); }, ex => { _logger.Error($"Error: {ex.Message}"); }, () => { }); }
public async Task <LearningProvider> ResolveAsync <TContext>(ResolveFieldContext <TContext> context) { try { var reference = await SearchAsync(context.Arguments, context.CancellationToken); if (reference == null) { return(null); } _logger.Info($"Found reference {reference}"); var fields = GetRequestedFields(context); var entity = await LoadAsync(reference, context.Arguments, fields, context.CancellationToken); return(entity); } catch (ResolverException ex) { _logger.Info($"Request issue resolving learning provider", ex); context.Errors.Add(new ExecutionError(ex.Message)); return(null); } catch (InvalidRequestException ex) { _logger.Info($"Invalid request when resolving learning provider - {ex.ErrorIdentifier} - {ex.Message}", ex); context.Errors.AddRange( ex.Details.Select(detailsMessage => new ExecutionError(detailsMessage))); return(null); } catch (Exception ex) { _logger.Error($"Error resolving learning provider", ex); throw; } }