Exemple #1
0
        public AspNetCoreGrpcServer(FunctionRpc.FunctionRpcBase service, IScriptEventManager scriptEventManager, ILogger <AspNetCoreGrpcServer> logger)
        {
            int port = WorkerUtilities.GetUnusedTcpPort();

            _grpcHostBuilder = AspNetCoreGrpcHostBuilder.CreateHostBuilder(service, scriptEventManager, port);
            _logger          = logger;
            Uri = new Uri($"http://{WorkerConstants.HostName}:{port}");
        }
        private void ConfigureWorkerDescription(HttpWorkerOptions options, IConfigurationSection workerSection)
        {
            workerSection.Bind(options);
            HttpWorkerDescription httpWorkerDescription = options.Description;

            if (httpWorkerDescription == null)
            {
                throw new HostConfigurationException($"Missing worker Description.");
            }

            var argumentsList = GetArgumentList(workerSection, argumentsSectionName);

            if (argumentsList != null)
            {
                httpWorkerDescription.Arguments = argumentsList;
            }

            var workerArgumentList = GetArgumentList(workerSection, workerArgumentsSectionName);

            if (workerArgumentList != null)
            {
                httpWorkerDescription.WorkerArguments = workerArgumentList;
            }

            httpWorkerDescription.ApplyDefaultsAndValidate(_scriptJobHostOptions.RootScriptPath, _logger);

            // Set default working directory to function app root.
            if (string.IsNullOrEmpty(httpWorkerDescription.WorkingDirectory))
            {
                httpWorkerDescription.WorkingDirectory = _scriptJobHostOptions.RootScriptPath;
            }
            else
            {
                // Compute working directory relative to fucntion app root.
                if (!Path.IsPathRooted(httpWorkerDescription.WorkingDirectory))
                {
                    httpWorkerDescription.WorkingDirectory = Path.Combine(_scriptJobHostOptions.RootScriptPath, httpWorkerDescription.WorkingDirectory);
                }
            }

            options.Arguments = new WorkerProcessArguments()
            {
                ExecutablePath = options.Description.DefaultExecutablePath,
                WorkerPath     = options.Description.DefaultWorkerPath
            };

            options.Arguments.ExecutableArguments.AddRange(options.Description.Arguments);
            options.Arguments.WorkerArguments.AddRange(options.Description.WorkerArguments);
            options.Port = WorkerUtilities.GetUnusedTcpPort();
        }
        public void GetUnusedTcpPort_Succeeds()
        {
            int         unusedPort  = WorkerUtilities.GetUnusedTcpPort();
            TcpListener tcpListener = null;

            try
            {
                tcpListener = new TcpListener(IPAddress.Loopback, unusedPort);
                tcpListener.Start();
            }
            finally
            {
                tcpListener?.Stop();
            }
        }