/// <summary>
        /// Starts the grpc server, binds the <see cref="QualityVerificationGrpcImpl"/> together
        /// with the <see cref="IServiceHealth"/> implementation and returns a handle for both.
        /// </summary>
        /// <param name="arguments">The microserver command line / config arguments.</param>
        /// <param name="inputsFactoryMethod">The factory method that creates the
        /// <see cref="IBackgroundVerificationInputs"/> instance. If no factory is proveded, only
        /// stand-alone verification (such as XML) can be used.</param>
        /// <param name="checkout3dAnalyst"></param>
        /// <param name="markUnhealthyOnExceptions"></param>
        /// <returns></returns>
        public static StartedGrpcServer StartVerificationServer(
            [NotNull] MicroserverArguments arguments,
            [CanBeNull]
            Func <VerificationRequest, IBackgroundVerificationInputs> inputsFactoryMethod,
            bool checkout3dAnalyst,
            bool markUnhealthyOnExceptions)
        {
            var healthService = new HealthServiceImpl();

            IServiceHealth health = new ServiceHealth(healthService);

            var wuVerificationServiceImpl =
                new QualityVerificationGrpcImpl(inputsFactoryMethod,
                                                arguments.MaxParallel)
            {
                Checkout3DAnalyst = checkout3dAnalyst
            };

            if (markUnhealthyOnExceptions)
            {
                wuVerificationServiceImpl.Health = health;
            }

            health.SetStatus(wuVerificationServiceImpl.GetType(), true);

            ServerCredentials serverCredentials =
                GrpcServerUtils.GetServerCredentials(arguments.Certificate,
                                                     arguments.PrivateKeyFile,
                                                     arguments.EnforceMutualTls);

            var oneGb = (int)Math.Pow(1024, 3);

            IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb);

            var server =
                new Grpc.Core.Server(channelOptions)
            {
                Services =
                {
                    QualityVerificationGrpc.BindService(wuVerificationServiceImpl),
                    Health.BindService(healthService)
                },
                Ports =
                {
                    new ServerPort(arguments.HostName, arguments.Port, serverCredentials)
                }
            };

            server.Start();

            _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName,
                            arguments.Port);

            return(new StartedGrpcServer(server, health));
        }
Exemple #2
0
        private static Grpc.Core.Server StartGrpcServer(
            MicroserverArguments arguments,
            [NotNull] QualityVerificationGrpcImpl verificationServiceImpl,
            [NotNull] HealthServiceImpl healthService,
            [NotNull] LoadReportingGrpcImpl loadReporting)
        {
            var services = new List <ServerServiceDefinition>(
                new[]
            {
                QualityVerificationGrpc.BindService(verificationServiceImpl),
                Health.BindService(healthService),
                LoadReportingGrpc.BindService(loadReporting)
            });

            return(StartGrpcServer(services, arguments));
        }