Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
 public static HttpLink From(HttpHost host) =>
 From(host, HttpResource.Root);
Ejemplo n.º 7
0
 public static HttpLink From(HttpHost host, HttpResource resource) =>
 new HttpLink(host, resource);
Ejemplo n.º 8
0
 HttpLink(HttpHost host, HttpResource resource)
 {
     Host     = host;
     Resource = resource;
 }