Esempio n. 1
0
        private static UrlFormatter FormatterFor(string url)
        {
            var urlFormatter = new UrlFormatter();

            urlFormatter.FromUrl(url);
            return(urlFormatter);
        }
        public void Setup()
        {
            _formatters = new UrlFormatterCollection();

            var formatter = new UrlFormatter();

            formatter.FromUrl("https://assets.com:9110/v1");

            _formatters.Register("assets", formatter);
        }
        private static UrlFormatter FormatterFor(string url)
        {
            var f = new UrlFormatter();

            if (!f.FromUrl(url))
            {
                throw new Exception("Failed to create formatter from url: " + url);
            }
            return(f);
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts to extract the protocol name from a url. If there is a formatter registered
        /// for that protocol, then we return the service name. If not, we assume that the
        /// url may already be resolved and must reverse lookup the service with a matching
        /// protocol, base url, port.
        /// </summary>
        public string FormatterName(string url)
        {
            url = RemoveParams(url);
            var formatterName = ProtocolName(url);

            // Failed to parse protocol name from url
            if (string.IsNullOrEmpty(formatterName))
            {
                return(null);
            }

            // Check name for a formatter. If there's a registered formatter, return the name
            var formatter = Formatter(formatterName);

            if (null != formatter)
            {
                return(formatterName);
            }

            // Parse url into sub-components. Failure results in no formatter name being resolved.
            if (!_parser.FromUrl(url))
            {
                return(null);
            }

            // Check parsed url against existing formatters
            var keys = _formatters.Keys.ToList();

            for (var i = 0; i < keys.Count; ++i)
            {
                var key = keys[i];
                var f   = _formatters[key];

                // Formatter has the same protocol, base url, and port. Match
                if (IsSameBaseFormat(_parser, f))
                {
                    return(key);
                }
            }

            // Failed to resolve the formatter name
            return(null);
        }
Esempio n. 5
0
        public void FromSimple()
        {
            Assert.IsTrue(_formatter.FromUrl("http://localhost:1234/v1"));

            Assert.AreEqual("localhost", _formatter.BaseUrl);
            Assert.AreEqual("http://", _formatter.Protocol);
            Assert.AreEqual(1234, _formatter.Port);
            Assert.AreEqual("/v1", _formatter.Version);
        }