예제 #1
0
        /// <summary>
        /// Filters the elements of <paramref name="source"/> based on <paramref name="targetResourceType"/>
        /// </summary>
        /// <param name="source">source</param>
        /// <param name="targetResourceType">targetResourceType</param>
        /// <returns>An expression for IEnumerable(Of T) that contains elements from the source sequence of type <paramref name="targetResourceType"/>.</returns>
        internal static Expression GenerateOfType(Expression source, ResourceType targetResourceType)
        {
            if (targetResourceType.CanReflectOnInstanceType)
            {
                return(source.EnumerableOfType(targetResourceType.InstanceType));
            }

            source = Expression.Call(
                DataServiceProviderMethods.OfTypeIEnumerableMethodInfo.MakeGenericMethod(
                    BaseServiceProvider.GetIEnumerableElement(source.Type),
                    targetResourceType.InstanceType),
                source,
                Expression.Constant(targetResourceType));

            return(source.EnumerableCast(targetResourceType.InstanceType));
        }
예제 #2
0
        public virtual void ConfigureGameServices(IServiceCollection serviceCollection)
        {
            serviceCollection.AddSingleton(new GameSynchronizerOptions(Options.ServerIpAddress, Options.ServerPort,
                                                                       Options.NetworkRoomId));
            serviceCollection.AddSingleton(new AssetManagerOptions(Options.ContentFolderPath));
            serviceCollection.UseGameComponent();
            serviceCollection.UseGameContent();
            serviceCollection.UseGameSynchronization();
            serviceCollection.UseScriptActions();
            var graphicsDeviceManager = (GraphicsDeviceManager)BaseServiceProvider.GetService(typeof(IGraphicsDeviceManager));

            serviceCollection.AddSingleton <IGraphicsDeviceManager>(graphicsDeviceManager);
            serviceCollection.AddSingleton <IGraphicsDeviceService>(graphicsDeviceManager);
            serviceCollection.AddLogging(builder => builder.AddFile($"{Options.LogFolderPath}\\Log.txt"));
            //serviceCollection.AddLogging(builder => builder.AddDebug());
        }
예제 #3
0
        /// <summary>
        /// Compose SelectMany() to expression
        /// </summary>
        /// <param name="genericMethodInfo">SelectMany MethodInfo</param>
        /// <param name="source">Source expression</param>
        /// <param name="selector">Selector expression</param>
        /// <returns>Expression with SelectMany()</returns>
        private static Expression SelectMany(MethodInfo genericMethodInfo, Expression source, LambdaExpression selector)
        {
            Debug.Assert(genericMethodInfo != null && genericMethodInfo.IsGenericMethod, "genericMethodInfo != null && genericMethodInfo.IsGenericMethod");
            Debug.Assert(source != null, "source != null");
            Debug.Assert(selector != null, "selector != null");

            Type elementType = source.ElementType();

            Debug.Assert(elementType != null, "elementType != null");

            Type       resultElementType = BaseServiceProvider.GetIEnumerableElement(selector.Body.Type);
            MethodInfo selectManyMethod  = genericMethodInfo.MakeGenericMethod(elementType, resultElementType);

            // Note the ParameterType on an IQueryable mehtod is Expression<Func<>> where as the ParameterType
            // on an IEnumerable method is Func<>.
            Debug.Assert(
                selectManyMethod.GetParameters()[1].ParameterType == selector.GetType() ||
                selectManyMethod.GetParameters()[1].ParameterType == selector.Type,
                "selector should be of type Expression<Func<TSource, IEnumerable<TResult>>>");
            return(Expression.Call(null, selectManyMethod, source, selector));
        }
예제 #4
0
 /// <summary>
 /// Returns the element type of the expression.
 /// </summary>
 /// <param name="source">Source expression.</param>
 /// <returns>Returns the element type of the expression.</returns>
 internal static Type ElementType(this Expression source)
 {
     Debug.Assert(source != null, "source != null");
     return(BaseServiceProvider.GetIEnumerableElement(source.Type) ?? source.Type);
 }
예제 #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IWebHostEnvironment env,
                              Microsoft.AspNetCore.Hosting.IApplicationLifetime applicationLifetime)
        {
            //nlog
            loggerFactory.AddNLog();

            #region 启用压缩与缓存

            app.UseResponseCompression();
            app.UseResponseCaching();

            #endregion

            if (Configuration.GetSection("AppConfig")["ServiceDiscovery"].ConvertToBool(false))
            {
                app.UseConsul(applicationLifetime.ApplicationStopped);
            }

            if (env.IsDevelopment() || env.EnvironmentName == "Debug")
            {
                app.UseDeveloperExceptionPage();
            }

            //如果当前时开发者模式
            if (env.IsDevelopment())
            {
                //从管道中捕获同步和异步System.Exception实例并生成HTML错误响应。
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            //跨域、启用定时任务
            app.UseCustomerCors();

            app.UseAuthentication(); //认证
            app.UseAuthorization();  //授权

            app.UseTimer();

            app.UseEndpoints(endpoints =>
            {
                Type workerType = typeof(Microsoft.AspNetCore.Builder.GrpcEndpointRouteBuilderExtensions);
                MethodInfo staticDoWorkMethod = workerType.GetMethod("MapGrpcService");
                new EInfrastructure.Core.Tools.Component.ServiceProvider().GetServices <IGrpcService>().ToList().ForEach(
                    type =>
                {
                    if (staticDoWorkMethod != null && type.GetType().IsClass&& !type.GetType().IsAbstract)
                    {
                        MethodInfo curMethod = staticDoWorkMethod.MakeGenericMethod(type.GetType());
                        curMethod.Invoke(null, new[] { endpoints });   //Static method
                    }
                });

                endpoints.MapGet("/Check/Healthy",
                                 async context =>
                {
                    await context.Response.WriteAsync(
                        "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
                });
                endpoints.MapControllers();
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}", null,
                                             new LowercaseRouteConstraint())
                .RequireAuthorization();
            });

            BaseServiceProvider.Configuration();
        }