private bool ShouldExcludeFromCdnForPathCore(string resourceUri, CdnProviderOptions providerOptions)
        {
            if (string.IsNullOrWhiteSpace(resourceUri) || resourceUri.StartsWith("~"))
            {
                return(true);
            }

            return(this.ShouldExcludeFromCdnForPath(resourceUri, providerOptions));
        }
        protected virtual bool ShouldExcludeFromCdnForPath(string resourceUri, CdnProviderOptions providerOptions)
        {
            if (!string.IsNullOrWhiteSpace(providerOptions.ExcludePattern))
            {
                var excludePattern = new Regex(
                    providerOptions.ExcludePattern,
                    RegexOptions.CultureInvariant | RegexOptions.Singleline);

                return(excludePattern.IsMatch(resourceUri));
            }

            return(false);
        }
        protected virtual bool ShouldIncludeVersion(string resourceUri, CdnProviderOptions providerOptions)
        {
            if (!string.IsNullOrWhiteSpace(providerOptions.VersionPattern))
            {
                var includeVersion = new Regex(
                    providerOptions.VersionPattern,
                    RegexOptions.CultureInvariant | RegexOptions.Singleline);

                return(includeVersion.IsMatch(resourceUri));
            }

            return(false);
        }
        private Uri GetUri(string resourceUri, CdnProviderOptions providerOptions)
        {
            if (Uri.IsWellFormedUriString(resourceUri, UriKind.Absolute) ||
                this.ShouldExcludeFromCdnForPathCore(resourceUri, providerOptions))
            {
                return(new Uri(resourceUri, UriKind.RelativeOrAbsolute));
            }

            resourceUri = resourceUri.StartsWith("/") ? resourceUri : $"/{resourceUri}";

            var cdnUriBuilder = new UriBuilder(providerOptions.Host)
            {
                Path = providerOptions.Prefix.Add(resourceUri)
            };

            var cdnUri = cdnUriBuilder.Uri;

            if (this.ShouldIncludeVersionCore(resourceUri, providerOptions))
            {
                return(this.GetCdnUriWithVersion(cdnUri, this.cdnUriVersionProvider.GetVersion(resourceUri, providerOptions)));
            }

            return(cdnUri);
        }
示例#5
0
 public string GetVersion(string resourceUri, CdnProviderOptions cdnProviderOptions)
 {
     return(Convert.ToBase64String(Encoding.UTF8.GetBytes(GetAssemblyVersionStamp())));
 }
 private bool ShouldIncludeVersionCore(string resourceUri, CdnProviderOptions providerOptions)
 {
     return(this.ShouldIncludeVersion(resourceUri, providerOptions));
 }
示例#7
0
 public string GetVersion(string resourceUri, CdnProviderOptions cdnProviderOptions)
 {
     return(DateTimeOffset.UtcNow.Ticks.ToString());
 }