Example #1
0
        private void CreateServers()
        {
            var servers = EngineConfig.GetValue("Servers", StringComparison.CurrentCultureIgnoreCase)?.Value <JArray>();

            if (servers == null)
            {
                return;
            }
            foreach (var jToken in servers)
            {
                var server  = (JObject)jToken;
                var hosts   = GetValues <string>(server, "Hosts");
                var domains = GetValues <string>(server, "Domains");
                var root    = IoUtils.ReplacePathTags(GetValue <string>(server, "Root"));
                if (!Directory.Exists(root))
                {
                    Directory.CreateDirectory(root);
                }
                var    useSsl      = GetValue <bool>(server, "SSL");
                string certificate = null;
                string password    = null;
                if (useSsl)
                {
                    certificate = IoUtils.ReplacePathTags(GetValue <string>(server, "Certificate"));
                    password    = GetValue <string>(server, "Password");
                }
                var locationManager      = ContainsKey(server, "Locations") ? new HttpLocationManager(GetValue <JToken>(server, "Default"), GetValue <JObject>(server, "Locations")) : new HttpLocationManager(GetValue <JToken>(server, "Default"), null);
                var errorMessagesManager = new ErrorMessagesManager();
                if (ContainsKey(server, "ErrorPages"))
                {
                    foreach (var(key, value) in GetValue <JObject>(server, "ErrorPages"))
                    {
                        if (int.TryParse(key, out var pageStatusCode))
                        {
                            errorMessagesManager.RegisterOverridePage(new FilePageMessage(value.Value <string>(), pageStatusCode));
                        }
                    }
                }
                var serverInfo = new HttpServerInfo(hosts.AsReadOnly(), domains, root, useSsl, certificate, password, locationManager, errorMessagesManager);
                ServersInfo.Add(serverInfo);
                foreach (var domain in domains)
                {
                    // ! ISSUE ! Need future fix, for decoding the domain between ports
                    if (DomainServers.ContainsKey(domain))
                    {
                        continue;
                    }
                    DomainServers.Add(domain, serverInfo);
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public ServersInfoWrap(ServersInfo settings,
                               UserServersInfo userSettings)
        {
            Debug.Assert(settings != null);
            Debug.Assert(userSettings != null);

            if (userSettings.Servers == null)
            {
                userSettings.Servers = new List <UserServerInfo>();
            }

            List <UserServerInfo> userServers = userSettings.Servers;

            foreach (ServerInfo info in settings.Servers)
            {
                if (!String.IsNullOrEmpty(info.Name))
                {
                    UserServerInfo userInfo = _FindServerInfo(info.Name,
                                                              userServers);

                    if (userInfo == null)
                    {
                        userInfo      = new UserServerInfo();
                        userInfo.Name = info.Name;
                        userServers.Add(userInfo);
                    }

                    ServerInfoWrap wrap = new ServerInfoWrap(info, userInfo);
                    _servers.Add(wrap);
                }
                else
                {
                    Logger.Warning("Server configuration error: invalid name.");
                }
            }
        }