コード例 #1
0
        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)));
        }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Parallel.cs プロジェクト: uditagarwal97/coyote
 /// <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.");
     }
 }
コード例 #6
0
ファイル: Parallel.cs プロジェクト: ScriptBox21/MS-coyote
 /// <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));
 }
コード例 #7
0
ファイル: Parallel.cs プロジェクト: ScriptBox21/MS-coyote
 /// <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));
 }
コード例 #8
0
 internal static void ThrowIfNull <T, TException>(this T obj, string message = null) where TException : Exception, new()
 {
     if (obj == null)
     {
         throw ExceptionProvider.GenerateException <TException>(message);
     }
 }
コード例 #9
0
ファイル: ThreadPool.cs プロジェクト: uditagarwal97/coyote
 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));
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: himanshugoel2797/cs2c
        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);
        }
コード例 #11
0
 public void IOException(string message = null,
                         params KeyValuePair <string, object>[] data)
 {
     if (m_predicate)
     {
         throw ExceptionProvider.IOException(message, data);
     }
 }
コード例 #12
0
ファイル: ErrorHandling.cs プロジェクト: ASK-sa/ASK.ServEasy
		internal static ExceptionProvider OnError(ExceptionProvider provider, ExceptionHandler handler)
		{
			Debug.Assert(provider != null);

			if (handler != null)
				handler(provider());

			return provider;
		}
コード例 #13
0
        /// <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;
        }
コード例 #14
0
 public void ArgumentException(string paramName,
                               string message = null,
                               params KeyValuePair <string, object>[] data)
 {
     if (m_predicate)
     {
         throw ExceptionProvider.ArgumentException(paramName, message, data);
     }
 }
コード例 #15
0
ファイル: ErrorHandling.cs プロジェクト: hafsjold/snvrepos
        internal static ExceptionProvider OnError(ExceptionProvider provider, ExceptionHandler handler)
        {
            Debug.Assert(provider != null);

            if (handler != null)
            {
                handler(provider());
            }

            return(provider);
        }
コード例 #16
0
 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);
     }
 }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
ファイル: Lexer.cs プロジェクト: himanshugoel2797/cs2c
        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 + ".");
        }
コード例 #19
0
ファイル: Lexer.cs プロジェクト: himanshugoel2797/cs2c
        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 + "'.");
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
ファイル: ThreadPool.cs プロジェクト: arunt1204/coyote-rl
        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
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        /// <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);
        }
コード例 #25
0
 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));
 }
コード例 #26
0
 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));
 }
コード例 #27
0
 public static void Invoke(ParallelOptions parallelOptions, params Action[] actions)
 {
     ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.Invoke));
     SystemTasks.Parallel.Invoke(parallelOptions, actions);
 }
コード例 #28
0
 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));
 }
コード例 #29
0
 public static ParallelLoopResult ForEach <TSource>(IEnumerable <TSource> source, Action <TSource, ParallelLoopState> body)
 {
     ExceptionProvider.ThrowNotSupportedInvocationException(nameof(SystemTasks.Parallel.ForEach));
     return(SystemTasks.Parallel.ForEach(source, body));
 }
コード例 #30
0
 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));
 }
コード例 #31
0
 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));
 }