Example #1
0
        public bool TryGetPage(string fromVirtualPath, string virtualPath, out SharpPage page, out SharpCodePage codePage)
        {
            var pathMapKey = nameof(GetPage) + ">" + fromVirtualPath;
            var mappedPath = GetPathMapping(pathMapKey, virtualPath);

            if (mappedPath != null)
            {
                var mappedPage = Pages.GetPage(mappedPath);
                if (mappedPage != null)
                {
                    page     = mappedPage;
                    codePage = null;
                    return(true);
                }
                RemovePathMapping(pathMapKey, mappedPath);
            }

            var tryExactMatch = virtualPath.IndexOf('/') >= 0; //if nested path specified, look for an exact match first

            if (tryExactMatch)
            {
                var cp = GetCodePage(virtualPath);
                if (cp != null)
                {
                    codePage = cp;
                    page     = null;
                    return(true);
                }

                var p = Pages.GetPage(virtualPath);
                if (p != null)
                {
                    page     = p;
                    codePage = null;
                    return(true);
                }
            }

            //otherwise find closest match from page.VirtualPath
            var parentPath = fromVirtualPath.IndexOf('/') >= 0
                ? fromVirtualPath.LastLeftPart('/')
                : "";

            do
            {
                var seekPath = parentPath.CombineWith(virtualPath);
                var cp       = GetCodePage(seekPath);
                if (cp != null)
                {
                    codePage = cp;
                    page     = null;
                    return(true);
                }

                var p = Pages.GetPage(seekPath);
                if (p != null)
                {
                    page     = p;
                    codePage = null;
                    SetPathMapping(pathMapKey, virtualPath, seekPath);
                    return(true);
                }

                if (parentPath == "")
                {
                    break;
                }

                parentPath = parentPath.IndexOf('/') >= 0
                    ? parentPath.LastLeftPart('/')
                    : "";
            } while (true);

            page     = null;
            codePage = null;
            return(false);
        }
Example #2
0
        public static bool TryGetPage(this ScriptScopeContext scope, string virtualPath, out SharpPage page, out SharpCodePage codePage)
        {
            if (scope.PageResult.Partials.TryGetValue(virtualPath, out page))
            {
                codePage = null;
                return(true);
            }

            if (!scope.Context.TryGetPage(scope.PageResult.VirtualPath, virtualPath, out page, out codePage))
            {
                return(false);
            }

            codePage?.Init();

            if (codePage is IRequiresRequest requiresRequest)
            {
                if (scope.GetValue(ScriptConstants.Request) is IRequest request)
                {
                    requiresRequest.Request = request;
                }
            }

            return(true);
        }
Example #3
0
 public void GetPage(string fromVirtualPath, string virtualPath, out SharpPage page, out SharpCodePage codePage)
 {
     if (!TryGetPage(fromVirtualPath, virtualPath, out page, out codePage))
     {
         throw new FileNotFoundException($"Page at path was not found: '{virtualPath}'");
     }
 }
 public static async Task WritePageAsync(this ScriptScopeContext scope, SharpPage page, SharpCodePage codePage, Dictionary <string, object> pageParams, CancellationToken token = default(CancellationToken))
 {
     await scope.PageResult.WritePageAsync(page, codePage, scope.ScopeWithParams(pageParams), token);
 }