public static IServiceCollection AddExceptionProvider <TException>( [NotNull] this IServiceCollection services, [NotNull] string httpMethod, int httpStatusCode, int providerOrder = int.MinValue, int filterOrder = default) where TException : Exception { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (httpMethod == null) { throw new ArgumentNullException(nameof(httpMethod)); } ExceptionProvider <TException> provider = new ExceptionProvider <TException>(httpMethod, httpStatusCode, providerOrder, filterOrder); services.TryAddEnumerable(ServiceDescriptor.Singleton <IApiDescriptionProvider>(provider)); return(services.Configure <MvcOptions>(x => x.Filters.Add(provider.ExceptionFilter))); }
public static void Exception <TException>(string message = null, object[] args = null, params KeyValuePair <string, object>[] data) where TException : Exception, new() { throw ExceptionProvider.GenerateException <TException>(message, args, data); }
public static InterfaceEntryNode Parse(Lexer lex) { InterfaceEntryNode n = new InterfaceEntryNode(); Token tkn; n.IsVirtual = lex.DequeueIf("virtual", out tkn); n.IsUnsafe = lex.DequeueIf("unsafe", out tkn); n.TypeName = TypeNode.Parse(lex); if (GenericParamNode.IsPresent(lex)) { n.GenericParams = GenericParamNode.Parse(lex); } tkn = lex.Dequeue(TokenType.Identifier); n.Identifier = tkn.Value; if (InterfaceFunctionNode.IsPresent(lex)) { n.Entry = InterfaceFunctionNode.Parse(lex); } else if (InterfacePropertyNode.IsPresent(lex)) { n.Entry = InterfacePropertyNode.Parse(lex); } else { throw ExceptionProvider.Syntax(lex.Peek().Cursor, "Unrecognized definition"); } return(n); }
public static EnumDefNode Parse(Lexer lex) { EnumDefNode n = new EnumDefNode(); lex.Dequeue("enum"); var tkn = lex.Dequeue(TokenType.Identifier); n.Identifier = tkn.Value; lex.Dequeue(TokenType.LBrace); bool isLast = false; while (EnumEntryNode.IsPresent(lex)) { if (isLast) { throw ExceptionProvider.Syntax(tkn.Cursor, "Expected ',' or end of enum"); } n.Entries.Add(EnumEntryNode.Parse(lex)); if (!lex.DequeueIf(TokenType.Comma, out tkn)) { isLast = true; } } lex.Dequeue(TokenType.RBrace); return(n); }
/// <summary> /// Ensure that the specified parallel options can be handled during systematic testing. /// </summary> private static void ValidateParallelOptions(ParallelOptions options) { if (options.TaskScheduler != null && options.TaskScheduler != TaskScheduler.Default) { ExceptionProvider.ThrowNotSupportedInvocationException($"using a custom task scheduler is not supported during systematic testing."); } }
/// <summary> /// Executes a foreach operation with thread-local data on a <see cref="OrderablePartitioner{TSource}"/> /// in which iterations may run in parallel, loop options can be configured, and the state of the loop /// can be monitored and manipulated. /// </summary> public static SystemParallelLoopResult ForEach <TSource, TLocal>(OrderablePartitioner <TSource> source, Func <TLocal> localInit, Func <TSource, SystemParallelLoopState, long, TLocal, TLocal> body, Action <TLocal> localFinally) { ExceptionProvider.ThrowUncontrolledInvocationException(nameof(SystemParallel.ForEach)); return(SystemParallel.ForEach(source, localInit, body, localFinally)); }
/// <summary> /// Executes a for loop with 64-bit indexes and thread-local data in which iterations /// may run in parallel, loop options can be configured, and the state of the loop /// can be monitored and manipulated. /// </summary> public static SystemParallelLoopResult For <TLocal>(long fromInclusive, long toExclusive, SystemParallelOptions parallelOptions, Func <TLocal> localInit, Func <long, SystemParallelLoopState, TLocal, TLocal> body, Action <TLocal> localFinally) { ExceptionProvider.ThrowUncontrolledInvocationException(nameof(SystemParallel.For)); return(SystemParallel.For(fromInclusive, toExclusive, parallelOptions, localInit, body, localFinally)); }
internal static void ThrowIfNull <T, TException>(this T obj, string message = null) where TException : Exception, new() { if (obj == null) { throw ExceptionProvider.GenerateException <TException>(message); } }
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemThreading.ThreadPool.UnsafeRegisterWaitForSingleObject)); return(SystemThreading.ThreadPool.UnsafeRegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce)); }
public static void Main(string[] args) { string code = @" using System; using il2c.Compiler.Parser; //Next namespace il2c.Compiler.Driver { public class A<C,G> where C : Test where G : Test2 { } interface B : D { int TestProperty { get; private set; } } struct C<A> : D where A : Test { } public enum B { A, B, C, D } }"; Tokenizer tknzr = new Tokenizer(); Lexer lexer = new Lexer(); ExceptionProvider.SetCode(code); var tkns = tknzr.Tokenize(code); foreach (Token t in tkns) { Console.WriteLine(t.ToString()); } var root = lexer.Lex(tkns); Console.WriteLine("AST:\n\n\n"); Console.WriteLine(root); }
public void IOException(string message = null, params KeyValuePair <string, object>[] data) { if (m_predicate) { throw ExceptionProvider.IOException(message, data); } }
internal static ExceptionProvider OnError(ExceptionProvider provider, ExceptionHandler handler) { Debug.Assert(provider != null); if (handler != null) handler(provider()); return provider; }
/// <summary> /// Initializes the object with a handler that will provide /// the error result when needed. /// </summary> public ValueOrError(ExceptionProvider provider) : this() { if (provider == null) { throw new ArgumentNullException("provider"); } _ep = provider; }
public void ArgumentException(string paramName, string message = null, params KeyValuePair <string, object>[] data) { if (m_predicate) { throw ExceptionProvider.ArgumentException(paramName, message, data); } }
internal static ExceptionProvider OnError(ExceptionProvider provider, ExceptionHandler handler) { Debug.Assert(provider != null); if (handler != null) { handler(provider()); } return(provider); }
public static void IfNullOrEmpty <TException>(string obj, string message = null, object[] args = null, params KeyValuePair <string, object>[] data) where TException : Exception, new() { if (string.IsNullOrWhiteSpace(obj)) { throw ExceptionProvider.GenerateException <TException>(message, args, data); } }
public static void IfNot <TException>(Func <bool> predicate, string message = null, object[] args = null, params KeyValuePair <string, object>[] data) where TException : Exception, new() { if (!predicate()) { throw ExceptionProvider.GenerateException <TException>(message, args, data); } }
public Token Dequeue(TokenType t) { var t0 = tkn_q.Peek(); if (t0.Type == t) { tkn_q.Dequeue(); return(t0); } throw ExceptionProvider.Syntax(t0.Cursor, "Expected " + t + "."); }
public Token Dequeue(string keyword) { var t0 = tkn_q.Peek(); if (t0.Type == TokenType.Keyword && t0.Value == keyword) { tkn_q.Dequeue(); return(t0); } throw ExceptionProvider.Syntax(t0.Cursor, "Expected '" + keyword + "'."); }
private static void SetRoute(IApplicationBuilder app, string route) { if (route.ToLower() != Routes.CodetableProviderController) { var controllers = GetCodetableProviderControllers(app); var routeBuilder = app.ApplicationServices.GetService <ICodetableDiscoveryRouteBuilder>(); if (routeBuilder == null) { throw ExceptionProvider.RouteBuilderNotRegistered(); } routeBuilder.SetRoute(controllers, route); } }
public static bool BindHandle(SafeHandle osHandle) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemThreading.ThreadPool.BindHandle)); #if NET5_0 if (OperatingSystem.IsWindows()) { return(SystemThreading.ThreadPool.BindHandle(osHandle)); } else { throw new NotSupportedException($"Invoking '{nameof(SystemThreading.ThreadPool.BindHandle)}' is only supported on Windows."); } #else return(SystemThreading.ThreadPool.BindHandle(osHandle)); #endif }
public static InterfacePropertyNode Parse(Lexer lex) { InterfacePropertyNode n = new InterfacePropertyNode(); lex.Dequeue(TokenType.LBrace); Token tkn; for (int i = 0; i < 2; i++) { string vis = "public"; if (VisibilitySet.Match(lex)) { tkn = lex.Dequeue(); vis = tkn.Value; } if (lex.DequeueIf("get", out tkn)) { n.Getter = true; n.GetterVisibility = vis; lex.Dequeue(TokenType.Semi); if (lex.DequeueIf(TokenType.RBrace, out tkn)) { break; } } else if (lex.DequeueIf("set", out tkn)) { n.Setter = true; n.SetterVisibility = vis; lex.Dequeue(TokenType.Semi); if (lex.DequeueIf(TokenType.RBrace, out tkn)) { break; } } else { throw ExceptionProvider.Syntax(tkn.Cursor, "Expected getter/setter declaration"); } } return(n); }
private static IEnumerable <ActionDescriptor> GetCodetableProviderControllers(IApplicationBuilder app) { var actionDescriptorProvider = app.ApplicationServices.GetService <IActionDescriptorCollectionProvider>(); if (actionDescriptorProvider == null) { throw ExceptionProvider.MvcNotRegisteredNoActionDescriptorsProvider(); } var controllers = from c in actionDescriptorProvider.ActionDescriptors.Items where c.DisplayName.ToLower().StartsWith("Digipolis.Codetable.codetableprovider", StringComparison.OrdinalIgnoreCase) select c; if (controllers.Count() == 0) { throw ExceptionProvider.MvcNotRegisteredNoControllers(); } return(controllers); }
/// <summary> /// Adds the CodetableDiscovery framework to the application so that the list of codetables can be requested. /// </summary> /// <param name="app">The IApplicationBuilder of the application.</param> /// <returns>The IApplicationBuilder the applpication.</returns> public static IApplicationBuilder UseCodetableDiscovery(this IApplicationBuilder app) { var provider = app.ApplicationServices.GetService <ICodetableProvider>(); if (provider == null) { throw ExceptionProvider.CodetableProviderNotRegistered(); } var options = app.ApplicationServices.GetService <IOptions <CodetableDiscoveryOptions> >(); var codetableDiscoveryOptions = options.Value; var assembly = codetableDiscoveryOptions.ControllerAssembly == null?Assembly.GetEntryAssembly() : codetableDiscoveryOptions.ControllerAssembly; provider.Load(assembly); if (!String.IsNullOrWhiteSpace(codetableDiscoveryOptions.Route)) { SetRoute(app, codetableDiscoveryOptions.Route); } return(app); }
public static ParallelLoopResult ForEach <TSource>(OrderablePartitioner <TSource> source, ParallelOptions parallelOptions, Action <TSource, ParallelLoopState, long> body) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.ForEach)); return(SystemTasks.Parallel.ForEach(source, parallelOptions, body)); }
public static ParallelLoopResult For(int fromInclusive, int toExclusive, Action <int, ParallelLoopState> body) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.For)); return(SystemTasks.Parallel.For(fromInclusive, toExclusive, body)); }
public static void Invoke(ParallelOptions parallelOptions, params Action[] actions) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.Invoke)); SystemTasks.Parallel.Invoke(parallelOptions, actions); }
public static ParallelLoopResult ForEach <TSource, TLocal>(OrderablePartitioner <TSource> source, ParallelOptions parallelOptions, Func <TLocal> localInit, Func <TSource, ParallelLoopState, long, TLocal, TLocal> body, Action <TLocal> localFinally) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.ForEach)); return(SystemTasks.Parallel.ForEach(source, parallelOptions, localInit, body, localFinally)); }
public static ParallelLoopResult ForEach <TSource>(IEnumerable <TSource> source, Action <TSource, ParallelLoopState> body) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.ForEach)); return(SystemTasks.Parallel.ForEach(source, body)); }
public static ParallelLoopResult For <TLocal>(long fromInclusive, long toExclusive, Func <TLocal> localInit, Func <long, ParallelLoopState, TLocal, TLocal> body, Action <TLocal> localFinally) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.For)); return(SystemTasks.Parallel.For(fromInclusive, toExclusive, localInit, body, localFinally)); }
public static ParallelLoopResult For(long fromInclusive, long toExclusive, ParallelOptions parallelOptions, Action <long, ParallelLoopState> body) { ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.For)); return(SystemTasks.Parallel.For(fromInclusive, toExclusive, parallelOptions, body)); }