/// <summary> /// Creates and registers an <see cref="IExceptionHandler"/> implementation to use /// for this application. This implementation avoid propagation of exceptions. /// </summary> /// <param name="configuration">The <see cref="ProcessorConfiguration"/> for which /// to register the created exception handler.</param> /// <remarks>The returned DefaultExceptionHandler may be further configured to change it's default settings.</remarks> /// <returns>The <see cref="DefaultExceptionHandler"/> which was created and registered.</returns> public static IExceptionHandler EnableGlobalExceptionHandler(this ProcessorConfiguration configuration) { if (configuration == null) { throw Error.ArgumentNull("configuration"); } DefaultExceptionHandler exceptionHandler = new DefaultExceptionHandler(); configuration.Services.Replace(typeof(IExceptionHandler), exceptionHandler); return(exceptionHandler); }
private IExceptionHandler CreateExceptionHandlersChain() { IExceptionHandler exceptionsHandlerList = new MessageNotFoundExceptionHandler(); IExceptionHandler invalidMessageStateExceptionHandler = new InvalidMessageStateExceptionHandler(); IExceptionHandler smtpClientExceptionHandler = new SmtpClientExceptionHandler(); IExceptionHandler sendEmailExceptionHandler = new SendEmailExceptionHandler(); IExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler(); exceptionsHandlerList.SetNext(invalidMessageStateExceptionHandler); invalidMessageStateExceptionHandler.SetNext(smtpClientExceptionHandler); smtpClientExceptionHandler.SetNext(sendEmailExceptionHandler); sendEmailExceptionHandler.SetNext(defaultExceptionHandler); return(exceptionsHandlerList); }
public static IFlagshipVisitor Create(string environmentId, string apiKey, string visitorId, IDictionary <string, object> context, DecisionResponse mockResponse, HttpClient customClient = null) { var mockClient = new Mock <IDecisionManager>(); mockClient.Setup(foo => foo.GetResponse(It.IsAny <DecisionRequest>())).Returns(Task.FromResult(mockResponse)); var logger = new DefaultLogger(); var errorHandler = new DefaultExceptionHandler(); var flagshipContext = new FlagshipContext(environmentId, apiKey); var sender = new Sender(flagshipContext); if (customClient != null) { var senderClient = sender.GetType().GetField("httpClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); senderClient.SetValue(sender, customClient); } var contextSender = flagshipContext.GetType().GetField("Sender", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); contextSender.SetValue(flagshipContext, sender); var flagshipVisitorService = new FlagshipVisitorService(flagshipContext); var decisionManager = flagshipVisitorService.GetType().GetField("decisionManager", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); decisionManager.SetValue(flagshipVisitorService, mockClient.Object); var flagship = new FlagshipClient(flagshipContext); var fsVisService = flagship.GetType().GetField("fsVisitorService", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); fsVisService.SetValue(flagship, flagshipVisitorService); var flagshipVisitor = flagship.NewVisitor(visitorId, context); return(flagshipVisitor); }
public IActionResult Put(Environment newEnv) { currentEnv = newEnv; var logger = new DefaultLogger(); var exceptionHandler = new DefaultExceptionHandler(logger, true); var builder = new FlagshipOptions.Builder() .WithErrorHandler(exceptionHandler) .WithDecisionMode(newEnv.Bucketing ? Mode.Bucketing : Mode.API) .WithBucketingOptions(System.TimeSpan.FromMilliseconds(newEnv.PollingInterval)); if (newEnv.Timeout > 0) { builder.WithAPIOptions(System.TimeSpan.FromSeconds(newEnv.Timeout)); } Client = Flagship.FlagshipBuilder.Start( newEnv.Id, newEnv.ApiKey, builder.Build() ); return(Ok(currentEnv)); }
public ErrorHandlingMiddleware(ProblemDetailsExceptionHandler problemDetailsExceptionHandler, DefaultExceptionHandler defaultExceptionHandler) { this.problemDetailsExceptionHandler = problemDetailsExceptionHandler; this.defaultExceptionHandler = defaultExceptionHandler; }