Ejemplo n.º 1
0
        /// <summary>
        /// 指定された型に対するサービス定義を生成します。
        /// </summary>
        /// <param name="serviceName">サービス名</param>
        /// <param name="serviceType">サービスの型</param>
        /// <param name="serviceInstance">サービスインスタンス</param>
        /// <param name="settings">動作設定</param>
        /// <returns></returns>
        public ServerServiceDefinition BuildService(string serviceName, Type serviceType, object serviceInstance, GrpcServiceBuilderSettings settings)
        {
            settings = settings ?? new GrpcServiceBuilderSettings();

            ServerServiceDefinition.Builder builder = ServerServiceDefinition.CreateBuilder();

            Type implType = serviceInstance.GetType();

            IList <IGrpcServerMethodInvokingInterceptor> classInvokingInterceptors = GetInvokingInterceptors(implType);
            IList <IGrpcServerMethodInvokedInterceptor>  classInvokedInterceptors  = GetInvokedInterceptors(implType);

            foreach (GrpcMethodHandlerInfo method in GrpcReflection.EnumerateServiceMethods(implType))
            {
                IList <IGrpcServerMethodInvokingInterceptor> methodInvokingInterceptors = GetInvokingInterceptors(method.Handler);
                IList <IGrpcServerMethodInvokedInterceptor>  methodInvokedInterceptors  = GetInvokedInterceptors(method.Handler);

                MethodBuildContext context = new MethodBuildContext(serviceName, serviceType, serviceInstance, method.MethodType, method.RequestType, method.ResponseType, method.Handler, settings
                                                                    , Sort <IGrpcServerMethodInvokingInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokingInterceptor>[] { settings.InvokingInterceptors, classInvokingInterceptors, methodInvokingInterceptors })
                                                                    , Sort <IGrpcServerMethodInvokedInterceptor>(CompareInterceptor, new IEnumerable <IGrpcServerMethodInvokedInterceptor>[] { settings.InvokedInterceptors, classInvokedInterceptors, methodInvokedInterceptors })
                                                                    , Sort <IGrpcServerMethodExceptionHandler>(CompareInterceptor, new IEnumerable <IGrpcServerMethodExceptionHandler>[] { settings.ExceptionHandlers })
                                                                    );

                AddServiceMethod(builder, context);
            }

            return(builder.Build());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// サービスメソッド名を指定してサービス定義を生成します。
        /// </summary>
        /// <param name="serviceName">サービス名</param>
        /// <param name="methodName">メソッド名</param>
        /// <returns>サービス定義</returns>
        public static ServerServiceDefinition BuildService(string serviceName, string methodName)
        {
            ServerServiceDefinition.Builder builder = ServerServiceDefinition.CreateBuilder();

            builder.AddMethod <byte[], byte[]>(CreateMethod(serviceName, methodName), CreateHandler());
            return(builder.Build());
        }
Ejemplo n.º 3
0
        public void Register()
        {
            OnRegister();

            var serviceDefinitions = _builder
                                     .Build()
                                     .Intercept(_interceptors.ToArray());

            _endpoint.RegisterService(serviceDefinitions);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        public void Start(params Interceptor[] interceptors)
        {
            ServerServiceDefinition definition = m_Service.Build();

            if (interceptors != null)
            {
                definition = definition.Intercept(interceptors);
            }

            m_Server.Services.Add(definition);
            m_Server.Start();
        }
Ejemplo n.º 5
0
        public GrpcHost <TService> Build()
        {
            var server = new global::Grpc.Core.Server
            {
                Ports    = { { _options.Url, _options.Port, ServerCredentials.Insecure } },
                Services =
                {
                    _builder.Build()
                }
            };

            return(new GrpcHost <TService>(server));
        }
 internal ServerServiceDefinition GetInterceptedServerServiceDefinition()
 {
     return(builder.Build());
 }
Ejemplo n.º 7
0
 public ServerServiceDefinition Build()
 {
     return(builder.Build());
 }