public override string GetPathByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values,
                                                    RouteValueDictionary ambientValues = null, PathString?pathBase = null, FragmentString fragment = new FragmentString(),
                                                    LinkOptions options = null)
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc/>
 public override string GetPathByAddress <TAddress>(TAddress address, RouteValueDictionary values, PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 {
     return(_innerGenerator.GetPathByAddress <TAddress>(address, values, pathBase, fragment, options));
 }
    public async Task <string> CreateUrlAsync(Repository repository, FileInfo file, LinkOptions options)
    {
        if (repository.Remote is null)
        {
            throw new InvalidOperationException("The repository must have a remote.");
        }

        string       remote;
        StaticServer address;
        LinkType     type;
        string       url;
        TemplateData data;
        Hash         hash;


        // If a link type wasn't specified, then we'll use
        // the default type that's defined in the settings.
        type = options.Type ?? await _settings.GetDefaultLinkTypeAsync();

        // Adjust the remote URL so that it's in a
        // standard format that we can manipulate.
        remote = UrlHelpers.Normalize(repository.Remote.Url);

        address = await GetAddressAsync(remote);

        data = TemplateData
               .Create()
               .Add("base", address.Http)
               .Add("repository", GetRepositoryPath(remote, address))
               .Add("ref", await GetRefAsync(type, repository.Root, repository.Remote))
               .Add("commit", await GetRefAsync(LinkType.Commit, repository.Root, repository.Remote))
               .Add("file", GetRelativePath(repository.Root, file.FilePath))
               .Add("type", type == LinkType.Commit ? "commit" : "branch");

        if (file.Selection is not null)
        {
            data.Add("startLine", file.Selection.StartLine);
            data.Add("startColumn", file.Selection.StartColumn);
            data.Add("endLine", file.Selection.EndLine);
            data.Add("endColumn", file.Selection.EndColumn);
        }

        foreach (string key in _definition.SettingsKeys)
        {
            data.Add(key, await _settings.GetHandlerSettingAsync(key));
        }

        hash = data.ToHash();
        url  = _definition.Url.Render(hash);

        if (file.Selection is not null)
        {
            url += _definition.Selection.Render(hash);
        }

        url = ApplyModifications(
            url,
            _definition.Query.Where((x) => x.Pattern.IsMatch(file.FilePath)).ToList()
            );

        return(url);
    }
示例#4
0
 public AtawLinkOptionCreator()
 {
     fLinkOptions = new LinkOptions();
     BaseOptions  = fLinkOptions;
 }
        /// <inheritdoc/>
        public override string GetPathByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
        {
            object odataPathValue;

            if (values.TryGetValue("odataPath", out odataPathValue))
            {
                string odataPath = odataPathValue as string;
                if (odataPath != null)
                {
                    IPerRouteContainer perRouteContainer = httpContext.RequestServices.GetRequiredService <IPerRouteContainer>();
                    string             routePrefix       = perRouteContainer.GetRoutePrefix(httpContext.Request.ODataFeature().RouteName);

                    bool canGenerateDirectLink = routePrefix == null || routePrefix.IndexOf('{') == -1;
                    if (!canGenerateDirectLink)
                    {
                        routePrefix = BindPrefixTemplate(routePrefix, values, ambientValues);
                    }
                    string link = CombinePathSegments(routePrefix, odataPath);
                    link = UriEncode(link);
                    return(link);
                }
            }

            return(_innerGenerator.GetPathByAddress(httpContext, address, values, ambientValues, pathBase, fragment, options));
        }
        public override string GetUriByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, string scheme = null, HostString?host = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
        {
            var promotedValues = PromoteAmbientValues(values, ambientValues);

            return(_inner.GetUriByAddress(httpContext,
                                          address,
                                          promotedValues.newValues,
                                          promotedValues.newAmbientValues,
                                          scheme,
                                          host,
                                          pathBase,
                                          fragment,
                                          options));
        }
示例#7
0
 public override string GetUriByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, string scheme = null, HostString?host = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
 {
     TryCopyCultureTokenToExplicitValues(httpContext, address);
     return(_inner.GetUriByAddress(httpContext, address, values, ambientValues, scheme, host, pathBase, fragment, options));
 }
        public override string GetPathByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
        {
            var nonRoundTripUsingQueryStringValues = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);

            var routeValues = GetValuesDictionary(values);

            foreach (var routeDataStringKey in _options.AmbientRouteDataKeys)
            {
                if (!routeValues.ContainsKey(routeDataStringKey.RouteDataKey) &&
                    ambientValues.TryGetValue(routeDataStringKey.RouteDataKey, out var value))
                {
                    if (!routeDataStringKey.RoundTripUsingQueryString)
                    {
                        nonRoundTripUsingQueryStringValues.Add(routeDataStringKey.RouteDataKey, value);
                    }

                    routeValues[routeDataStringKey.RouteDataKey] = value;
                }
                else if (!routeValues.ContainsKey(routeDataStringKey.RouteDataKey) && httpContext.Request.Query.TryGetValue(routeDataStringKey.RouteDataKey, out var queryStringValues))
                {
                    if (!routeDataStringKey.RoundTripUsingQueryString)
                    {
                        nonRoundTripUsingQueryStringValues.Add(routeDataStringKey.RouteDataKey, queryStringValues.First());
                    }

                    routeValues[routeDataStringKey.RouteDataKey] = queryStringValues.First();
                }
            }

            var url = _generator.GetPathByAddress <TAddress>(httpContext, address, routeValues, ambientValues, pathBase, fragment, options);

            if (url != null)
            {
                var uri = new Uri(url, UriKind.RelativeOrAbsolute);
                if (!uri.IsAbsoluteUri)
                {
                    uri = new Uri($"http://www.domain.com{url}");
                }

                var queryDictionary = QueryHelpers.ParseQuery(uri.Query);

                if (queryDictionary.Keys.Any(k => nonRoundTripUsingQueryStringValues.ContainsKey(k)))
                {
                    foreach (var key in queryDictionary.Keys.Where(k => nonRoundTripUsingQueryStringValues.ContainsKey(k)))
                    {
                        routeValues.Remove(key);
                    }

                    url = _generator.GetPathByAddress <TAddress>(httpContext, address, routeValues, ambientValues, pathBase, fragment, options);
                }
            }

            return(url);
        }
示例#9
0
 public override string GetPathByAddress <TAddress>(TAddress address, RouteValueDictionary values, PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public static string RouteUrl(this LinkGenerator generator, string routeName, object values = null,
                               PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 {
     //var context = EngineContext.Current.Resolve<IHttpContextAccessor>().HttpContext;
     return(generator.GetPathByRouteValues(routeName, values, pathBase, fragment, options));
 }
示例#11
0
        public static string RouteUrl(this LinkGenerator generator, HttpContext httpContext, string routeName, object values = null,
                                      PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
        {
            var resultRoute = generator.GetPathByRouteValues(routeName, values, pathBase, fragment, options);

            if (resultRoute == null)
            {
                if (values is string)
                {
                    resultRoute = httpContext.Request.PathBase.Value + values;
                }
                else if (values != null)
                {
                    resultRoute = httpContext.Request.PathBase.Value;
                    var routeValues = values.GetType().GetProperties();
                    foreach (var prop in routeValues)
                    {
                        resultRoute += prop.GetValue(values).ToString();
                    }
                }
            }
            return(resultRoute);
        }
        /// <inheritdoc/>
        public override string GetPathByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
        {
            object odataPathValue;

            if (values.TryGetValue("odataPath", out odataPathValue))
            {
                string odataPath = odataPathValue as string;
                if (odataPath != null)
                {
                    IPerRouteContainer perRouteContainer = httpContext.RequestServices.GetRequiredService <IPerRouteContainer>();
                    string             routePrefix       = perRouteContainer.GetRoutePrefix(httpContext.Request.ODataFeature().RouteName);

                    bool canGenerateDirectLink = routePrefix == null || routePrefix.IndexOf('{') == -1;
                    if (!canGenerateDirectLink)
                    {
                        routePrefix = BindPrefixTemplate(routePrefix, values, ambientValues);
                    }
                    string link = CombinePathSegments(routePrefix, odataPath);
                    link = UriEncode(link);

                    // A workaround to include the PathBase, a good solution is to use ASP.NET Core provided the APIs
                    // at https://github.com/dotnet/aspnetcore/blob/master/src/Http/Http.Extensions/src/UriHelper.cs#L48
                    // to build the absolute Uri. But, here only needs the "PathBase + Path (without OData path)",
                    HttpRequest request = httpContext.Request;
                    if (request != null && request.PathBase != null && request.PathBase.HasValue)
                    {
                        return(request.PathBase.Value + "/" + link);
                    }

                    return(link);
                }
            }

            return(_innerGenerator.GetPathByAddress(httpContext, address, values, ambientValues, pathBase, fragment, options));
        }
 public override string GetUriByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, string scheme = null, HostString?host = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
 {
     RewriteValuesDictionary(values);
     return(linkGenerator.GetUriByAddress(httpContext, address, values, ambientValues, scheme, host, pathBase, fragment, options));
 }
示例#14
0
 public override string GetPathByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
 {
     var(newValues, newAmbientValues) = PromoteAmbientValues(values, ambientValues);
     return(_inner.GetPathByAddress(httpContext,
                                    address,
                                    newValues,
                                    newAmbientValues,
                                    pathBase,
                                    fragment,
                                    options));
 }
 public override string GetUriByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values,
                                                   RouteValueDictionary ambientValues = null, string scheme                       = null, HostString?host = null, PathString?pathBase = null,
                                                   FragmentString fragment            = new FragmentString(), LinkOptions options = null)
 {
     return("https://domain.com/some/path");
 }
示例#16
0
 public override string GetUriByAddress <TAddress>(HttpContext httpContext, TAddress address, RouteValueDictionary values, RouteValueDictionary ambientValues = null, string scheme = null, HostString?host = null, PathString?pathBase = null, FragmentString fragment = default, LinkOptions options = null)
 => Url;
 public override string GetUriByAddress <TAddress>(TAddress address, RouteValueDictionary values, string scheme, HostString host,
                                                   PathString pathBase = new PathString(), FragmentString fragment = new FragmentString(), LinkOptions options = null)
 {
     throw new NotImplementedException();
 }
示例#18
0
 public override string GetUriByAddress <TAddress>(TAddress address, RouteValueDictionary values, string scheme, HostString host, PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 => Url;
 public override string GetUriByAddress <TAddress>(TAddress address, RouteValueDictionary values, string scheme, HostString host, PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 {
     return(_inner.GetUriByAddress(address,
                                   values,
                                   scheme,
                                   host,
                                   pathBase,
                                   fragment,
                                   options));
 }
示例#20
0
 /// <summary>
 /// Generates a URL with an absolute path from the specified route values and link options.
 /// </summary>
 /// <param name="values">An object that contains route values.</param>
 /// <param name="options">The <see cref="LinkOptions"/>.</param>
 /// <returns>The generated URL.</returns>
 public abstract string MakeUrl(object values, LinkOptions options);
示例#21
0
 public override string GetPathByAddress <TAddress>(TAddress address, RouteValueDictionary values, PathString pathBase = default, FragmentString fragment = default, LinkOptions options = null)
 {
     TryCopyCultureTokenToExplicitValues(_httpContextAccessor.HttpContext, address);
     return(_inner.GetPathByAddress(address, values, pathBase, fragment, options));
 }
示例#22
0
 static int RunLink(LinkOptions opts)
 {
     return(0);
 }