Beispiel #1
0
 public sealed override bool Equals(BasicUrlHandler other) =>
 other is StaticFile otherFile && otherFile.isFrameworkFile == isFrameworkFile && otherFile.relativeFilePath == relativeFilePath &&
        internal static string GetCanonicalUrl(BasicUrlHandler basicHandler, bool secure)
        {
            UrlHandler parent           = null;
            var        canonicalHandler = basicHandler;

            if (basicHandler is UrlHandler handler)
            {
                parent = handler.GetParent();
                if (parent != null)
                {
                    var pair = parent.GetCanonicalHandlerPair(handler);
                    parent           = pair.parent;
                    canonicalHandler = pair.child;
                }
            }
            var encoder = canonicalHandler.GetEncoder();

            var    segments = new List <string>();
            string query    = null;

            (IEnumerable <(string name, string value)> segmentParameters, IEnumerable <(string name, string value)> queryParameters)parameters;
            while (parent != null)
            {
                EncodingUrlSegment segment = null;
                foreach (var i in parent.GetChildPatterns())
                {
                    segment = i.Generator(encoder);
                    if (segment != null)
                    {
                        break;
                    }
                    encoder.ResetState();
                }
                if (segment == null)
                {
                    throw new ApplicationException("The handler does not match any of the parent’s child URL patterns.");
                }
                if (segment.Segment.Length == 0)
                {
                    throw new ApplicationException("The segment must not be the empty string.");
                }
                parameters = segment.Parameters.Get(encoder);
                segments.Add(generateSegment(segment.Segment, generateSegmentParameters(parameters.segmentParameters)));
                if (query == null)
                {
                    query = generateQuery(parameters.queryParameters);
                }

                encoder = parent.GetEncoder();
                parent  = parent.GetParent();
            }

            EncodingBaseUrl baseUrl = null;

            foreach (var i in EwfApp.Instance.GetBaseUrlPatterns())
            {
                baseUrl = i.Generator(encoder);
                if (baseUrl != null)
                {
                    break;
                }
                encoder.ResetState();
            }
            if (baseUrl == null)
            {
                throw new ApplicationException("The handler does not match any of the base URL patterns for the application.");
            }
            parameters = baseUrl.Parameters.Get(encoder);
            var baseUrlParameters = generateSegmentParameters(parameters.segmentParameters);

            if (query == null)
            {
                query = generateQuery(parameters.queryParameters);
            }

            var baseUrlString  = baseUrl.BaseUrl.CompleteWithDefaults(EwfConfigurationStatics.AppConfiguration.DefaultBaseUrl).GetUrlString(secure);
            var path           = generatePath(baseUrlParameters, segments.AsEnumerable().Reverse());
            var appRelativeUrl = generateAppRelativeUrl(path, query);

            var resolvedHandler = urlResolver(baseUrlString, appRelativeUrl);

            if (!EwlStatics.AreEqual(resolvedHandler, basicHandler))
            {
                throw new ApplicationException("The handler’s canonical URL does not resolve back to the same handler.");
            }

            return(baseUrlString + (path.Length > 0 ? "/" : "") + appRelativeUrl);
        }
 public HandlerAdapter(BasicUrlHandler handler)
 {
     this.handler = handler;
 }
Beispiel #4
0
 public sealed override bool Equals(BasicUrlHandler other) =>
 other is StaticFileFolderSetup otherFs && otherFs.isFrameworkFolder == isFrameworkFolder && otherFs.folderPath == folderPath;