Ejemplo n.º 1
0
        public static string GetRelativeManifestPath(this NAMESelfHostConfiguration configuration)
        {
            string normalizedPrefix = string.Empty;

            if (!string.IsNullOrWhiteSpace(configuration.ManifestUriPrefix) && configuration.ManifestUriPrefix != "/")
            {
                normalizedPrefix = '/' + configuration.ManifestUriPrefix.TrimStart('/').TrimEnd('/');
            }

            return(normalizedPrefix + Constants.MANIFEST_ENDPOINT);
        }
Ejemplo n.º 2
0
        public static string GetManifestPath(this NAMESelfHostConfiguration configuration, string requestHost, int?requestPort)
        {
            string baseUrl = $"http://{requestHost}";

            if (requestPort != null)
            {
                baseUrl += $":{requestPort}";
            }
            string normalizedPrefix = string.Empty;

            if (configuration.ManifestUriPrefix != "/")
            {
                normalizedPrefix = '/' + configuration.ManifestUriPrefix.TrimStart('/').TrimEnd('/');
            }

            return(baseUrl + normalizedPrefix + Constants.MANIFEST_ENDPOINT);
        }
Ejemplo n.º 3
0
        public static ParsedDependencies Initialize(ISelfHostServer server, IFilePathMapper pathMapper, NAMESelfHostConfiguration configuration)
        {
            NAMESettings settings;

            ParsedDependencies dependencies = ReadAndLogDependencies(configuration, configuration.LogHealthCheckToConsole, pathMapper, out settings);

            if (settings.RunningMode == SupportedNAMEBehaviours.NAMEDisabled)
            {
                LogInfo("Not starting NAME since it is disabled in the dependencies file.", configuration.LogHealthCheckToConsole);
                return(dependencies);
            }

            int portNumber = settings.SelfHostPortRangeFirst;

            try
            {
                bool result = false;
                LogInfo($"Starting the server", configuration.LogHealthCheckToConsole);
                while (portNumber <= settings.SelfHostPortRangeLast)
                {
                    result = server.Start(portNumber, settings);
                    if (result)
                    {
                        break;
                    }
                    portNumber++;
                }
                if (result == false)
                {
                    throw new NAMEException("Tried all ports, without success.");
                }

                Console.WriteLine($"Succesfully started the server. Listening on {portNumber}.");
            }
            catch (Exception ex)
            {
                LogWarning($"Could not bind to the SelfHost address: {ex.Message}.", configuration.LogHealthCheckToConsole);
                if (configuration.ThrowOnDependenciesFail)
                {
                    if (ex is NAMEException)
                    {
                        throw;
                    }
                    else
                    {
                        throw new NAMEException("Could not bind to the SelfHost address.", ex);
                    }
                }
                return(dependencies);
            }

            if (settings.RunningMode < SupportedNAMEBehaviours.BootstrapDisabled)
            {
                var register = new Registration.Register();

                register.RegisterInstance(
                    pathMapper,
                    configuration.APIName,
                    configuration.APIVersion,
                    configuration.DependenciesFilePath,
                    settings,
                    Environment.MachineName,
                    (uint)portNumber,
                    typeof(SelfHostInitializer).GetTypeInfo().Assembly.GetName().Version.ToString(),
                    (configuration.ManifestUriPrefix?.TrimEnd('/') ?? string.Empty) + Constants.MANIFEST_ENDPOINT,
                    Constants.REGISTRY_SUPPORTED_PROTOCOL_VERSIONS);
            }

            if (settings.RunningMode == SupportedNAMEBehaviours.NAMEDisabled)
            {
                LogInfo("Stopping the NAME self host server since it is disabled in the Registry.", configuration.LogHealthCheckToConsole);
                server.Dispose();
                return(dependencies);
            }

            return(dependencies);
        }