Exemple #1
0
        public static void SetHostOverride(string serviceName, string host)
        {
            SetUpStorage();

            var overrides = TryGetValue <RequestOverrides>(OVERRIDES_KEY);

            if (overrides == null)
            {
                overrides = new RequestOverrides();
                SetValue(OVERRIDES_KEY, overrides);
            }

            if (overrides.Hosts == null)
            {
                overrides.Hosts = new List <HostOverride>();
            }

            var hostOverride = overrides.Hosts.SingleOrDefault(o => o.ServiceName == serviceName);

            if (hostOverride == null)
            {
                hostOverride = new HostOverride {
                    ServiceName = serviceName
                };
                overrides.Hosts.Add(hostOverride);
            }

            hostOverride.Host = host;
        }
Exemple #2
0
        public static void SetHostOverride(string serviceName, string host, int?port = null)
        {
            var overrides = (RequestOverrides)Implementation.Get(OVERRIDES_KEY);

            if (overrides == null)
            {
                overrides = new RequestOverrides();
                Implementation.Set(OVERRIDES_KEY, overrides);
            }

            if (overrides.Hosts == null)
            {
                overrides.Hosts = new List <HostOverride>();
            }

            var hostOverride = overrides.Hosts.SingleOrDefault(o => o.ServiceName == serviceName);

            if (hostOverride == null)
            {
                hostOverride = new HostOverride {
                    ServiceName = serviceName,
                };
                overrides.Hosts.Add(hostOverride);
            }

            hostOverride.Host = host;
            hostOverride.Port = port;
        }
Exemple #3
0
        public void CheckRequestOverridesShallowClone()
        {
            RequestOverrides ro  = new RequestOverrides();
            HostOverride     ho1 = new HostOverride {
                Host = "testHost1", Port = 1234, ServiceName = "testService1"
            };

            ho1.AdditionalProperties = new Dictionary <string, object>();
            ho1.AdditionalProperties.Add("ho1Key", "ho1Value");

            HostOverride ho2 = new HostOverride {
                Host = "testHost2", Port = 1235, ServiceName = "testService2"
            };

            ho2.AdditionalProperties = new Dictionary <string, object>();
            ho2.AdditionalProperties.Add("ho2Key", "ho2Value");

            ro.Hosts = new List <HostOverride>(new [] { ho1, ho2 });
            ro.PreferredEnvironment = "pe1";
            ro.AdditionalProperties = new Dictionary <string, object>();
            ro.AdditionalProperties.Add("roKey", "roValue");

            RequestOverrides roResult = ro.ShallowCloneWithOverrides("pe2", CacheSuppress.UpToNextServices);

            Assert.AreEqual(ro.Hosts.Count, roResult.Hosts.Count);
            Assert.AreEqual(ro.Hosts.Join(roResult.Hosts, h => new { h.Host, h.Port, h.ServiceName }, hr => new { hr.Host, hr.Port, hr.ServiceName }, (h, hr) => hr).Count(), roResult.Hosts.Count);
            Assert.AreEqual(roResult.Hosts[0].AdditionalProperties["ho1Key"], "ho1Value");
            Assert.AreEqual(roResult.Hosts[1].AdditionalProperties["ho2Key"], "ho2Value");
            Assert.AreEqual(roResult.AdditionalProperties["roKey"], "roValue");
            Assert.AreEqual(ro.PreferredEnvironment, "pe1");
            Assert.AreEqual(roResult.PreferredEnvironment, "pe2");
            Assert.AreEqual(roResult.SuppressCaching, CacheSuppress.UpToNextServices);
        }
        private void AddHostOverride(IConfigurationSection hostOverride)
        {
            string    host = string.Empty;
            string    zone = string.Empty;
            IPAddress ip   = IPAddress.None;

            try
            {
                if (string.IsNullOrEmpty(hostOverride["host"]))
                {
                    throw new Exception("'host' cannot be empty for host override");
                }
                if (string.IsNullOrEmpty(hostOverride["zone"]))
                {
                    throw new Exception("'zone' cannot be empty for host override");
                }
                if (string.IsNullOrEmpty(hostOverride["ip"]))
                {
                    throw new Exception("'ip' cannot be empty for host override");
                }
                if (!IPAddress.TryParse(hostOverride["ip"], out ip))
                {
                    throw new Exception("'ip' cannot be parsed properly");
                }
                host = hostOverride["host"];
                zone = hostOverride["zone"];
                var newHostOverride = new HostOverride(host, zone, ip);
                HostOverrides.Add(newHostOverride);

                Logger.Debug($"'{newHostOverride}' has been added to Host Overrides");
            }
            catch (Exception ex)
            {
                Logger.Error($"Could not add Host Override", ex);
            }
        }
        private HttpRequestMessage CreateHttpRequest(HttpServiceRequest request, JsonSerializerSettings jsonSettings, HostOverride node)
        {
            string uri = $"{(HttpSettings.UseHttps ? "https" : "http")}://{node.Host}:{node.Port ?? HttpSettings.BasePort}/{ServiceName}.{request.Target.MethodName}";

            return(new HttpRequestMessage(HttpMethod.Post, uri)
            {
                Content = new StringContent(JsonConvert.SerializeObject(request, jsonSettings), Encoding.UTF8, "application/json")
                {
                    Headers = { { GigyaHttpHeaders.ProtocolVersion, HttpServiceRequest.ProtocolVersion } }
                }
            });
        }