Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDescriptorActor"/> class.
        /// </summary>
        public WebDescriptorActor()
        {
            var description = new WebDescriptionResponse();

            var config = Context?.System?.Settings?.Config;
            var servicesConfig = config?.GetConfig("ClusterKit.Web.Services");

            var services = new List<ServiceDescription>();

            if (servicesConfig != null)
            {
                foreach (var pair in servicesConfig.AsEnumerable())
                {
                    if (!pair.Value.IsObject())
                    {
                        Context.GetLogger().Error($"ClusterKit.Web.Services configuration is broken, {pair.Key} is not a valid configuration");
                        continue;
                    }

                    var serviceConfig = servicesConfig.GetConfig(pair.Key);
                    if (serviceConfig == null || serviceConfig.IsEmpty)
                    {
                        continue;
                    }

                    var serviceDescription = new ServiceDescription
                    {
                        ListeningPort = serviceConfig.GetInt("Port", 8080),
                        LocalHostName = serviceConfig.GetString("LocalHostName"),
                        PublicHostName = serviceConfig.GetString(
                                                             "PublicHostName",
                                                             "default"),
                        Route = serviceConfig.GetString("Route")
                    };

                    if (serviceDescription.Route == null)
                    {
                        Context.GetLogger().Error($"ClusterKit.Web.Services configuration is broken, {pair.Key} is not a valid configuration");
                        continue;
                    }

                    Context.GetLogger().Info($"Web publishing {pair.Key}: {serviceDescription.LocalHostName ?? "*"}:{serviceDescription.ListeningPort}/{serviceDescription.Route} for {serviceDescription.PublicHostName}");

                    services.Add(serviceDescription);
                }
            }

            description.Services = services.AsReadOnly();
            this.webDescription = description;
            this.Receive<WebDescriptionRequest>(m => this.Sender.Tell(this.webDescription));
        }
Пример #2
0
 /// <summary>
 /// Equals operator for <seealso cref="ServiceDescription"/>
 /// </summary>
 /// <param name="other">The object to compare</param>
 /// <returns>Whether both objects are equal</returns>
 public bool Equals(ServiceDescription other)
 {
     return this.ListeningPort == other.ListeningPort && string.Equals(this.LocalHostName, other.LocalHostName) && string.Equals(this.PublicHostName, other.PublicHostName) && string.Equals(this.Route, other.Route);
 }