private static Task <HttpResponseMessage> GetHttpResponseMessage(Context context, CancellationToken token) { OperationChaosSetting chaosSettings = context.GetOperationChaosSettings(); if (chaosSettings == null) { return(NoHttpResponse); } int statusCode = chaosSettings.StatusCode; if (statusCode < 200) { return(NoHttpResponse); } try { return(Task.FromResult(new HttpResponseMessage((HttpStatusCode)statusCode))); } catch { return(NoHttpResponse); } }
private static Task <Double> GetInjectionRate(Context context, CancellationToken token) { OperationChaosSetting chaosSettings = context.GetOperationChaosSettings(); if (chaosSettings == null) { return(NoInjectionRate); } return(Task.FromResult(chaosSettings.InjectionRate)); }
private static Task <bool> GetEnabled(Context context, CancellationToken token) { OperationChaosSetting chaosSettings = context.GetOperationChaosSettings(); if (chaosSettings == null) { return(NotEnabled); } return(Task.FromResult(chaosSettings.Enabled)); }
private static Task <TimeSpan> GetLatency(Context context, CancellationToken token) { OperationChaosSetting chaosSettings = context.GetOperationChaosSettings(); if (chaosSettings == null) { return(NoLatency); } int milliseconds = chaosSettings.LatencyMs; if (milliseconds <= 0) { return(NoLatency); } return(Task.FromResult(TimeSpan.FromMilliseconds(milliseconds))); }
private static Task <Exception> GetException(Context context, CancellationToken token) { OperationChaosSetting chaosSettings = context.GetOperationChaosSettings(); if (chaosSettings == null) { return(NoExceptionResult); } string exceptionName = chaosSettings.Exception; if (String.IsNullOrWhiteSpace(exceptionName)) { return(NoExceptionResult); } try { Type exceptionType = Type.GetType(exceptionName); if (exceptionType == null) { return(NoExceptionResult); } if (!typeof(Exception).IsAssignableFrom(exceptionType)) { return(NoExceptionResult); } var instance = Activator.CreateInstance(exceptionType); return(Task.FromResult(instance as Exception)); } catch { return(NoExceptionResult); } }