Пример #1
0
        public static bool TryFrom(string value, out HttpLink link)
        {
            link = null;

            var schemeParts = value.Split(new[] { Uri.SchemeDelimiter }, StringSplitOptions.None);

            if (schemeParts.Length == 2)
            {
                var pathSeparatorIndex = schemeParts[1].IndexOf('/');

                if (pathSeparatorIndex == -1 || pathSeparatorIndex == schemeParts[1].Length - 1)
                {
                    if (HttpHost.TryFrom(value, out var parsedHost))
                    {
                        link = new HttpLink(parsedHost, HttpResource.Root);
                    }
                }
                else
                {
                    var hostText     = schemeParts[0] + Uri.SchemeDelimiter + schemeParts[1].Substring(0, pathSeparatorIndex);
                    var resourceText = schemeParts[1].Substring(pathSeparatorIndex + 1);

                    if (HttpHost.TryFrom(hostText, out var parsedHost))
                    {
                        if (HttpResource.TryFrom(resourceText, out var parsedResource))
                        {
                            link = new HttpLink(parsedHost, parsedResource);
                        }
                    }
                }
            }

            return(link != null);
        }
Пример #2
0
        public static HttpLink From(HttpHost host, string resource)
        {
            if (!TryFrom(host, resource, out var link))
            {
                throw new FormatException($"Failed to parse resource: {resource}");
            }

            return(link);
        }
Пример #3
0
        public static bool TryFrom(string host, string resource, out HttpLink link)
        {
            link = null;

            if (HttpHost.TryFrom(host, out var parsedHost))
            {
                if (HttpResource.TryFrom(resource, out var parsedResource))
                {
                    link = new HttpLink(parsedHost, parsedResource);
                }
            }

            return(link != null);
        }
Пример #4
0
        public static bool TryFrom(string host, HttpResource resource, out HttpLink link)
        {
            link = HttpHost.TryFrom(host, out var parsedHost) ? new HttpLink(parsedHost, resource) : null;

            return(link != null);
        }
Пример #5
0
        //
        // Factory
        //

        public static bool TryFrom(HttpHost host, string resource, out HttpLink link)
        {
            link = HttpResource.TryFrom(resource, out var parsedResource) ? new HttpLink(host, parsedResource) : null;

            return(link != null);
        }
Пример #6
0
 public static HttpLink From(HttpHost host) =>
 From(host, HttpResource.Root);
Пример #7
0
 public static HttpLink From(HttpHost host, HttpResource resource) =>
 new HttpLink(host, resource);
Пример #8
0
 HttpLink(HttpHost host, HttpResource resource)
 {
     Host     = host;
     Resource = resource;
 }