示例#1
0
        public async Task <Nav> GetNavAsync()
        {
            if (_navPerRequest != null)
            {
                return(_navPerRequest);
            }

            Nav nav = null;

            string navHash = ComputeNavHash();

            if (!string.IsNullOrWhiteSpace(navHash))
            {
                DirectoryInfo pagesDirectory = _pageIOManager.GetPagesDirectory();
                DirectoryInfo cacheDirectory = _cacheManager.GetCacheDirectory();

                _cacheManager.ClearCache();

                string navCachename = navHash + Cache.NavPostfix;
                string navCache     = await _cacheManager.LoadFromCacheAsync(navCachename);

                if (!string.IsNullOrEmpty(navCache))
                {
                    try
                    {
                        nav = JObject.Parse(navCache).ToObject <Nav>();
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Invalid nav cache");
                    }
                }
                if (nav == null)
                {
                    _cacheManager.ClearCache("*" + Cache.NavPostfix);

                    nav = new Nav(await GetNavItemsAsync(pagesDirectory, new List <Folder>()));
                    await _cacheManager.SaveToCacheAsync(navCachename, JObject.FromObject(nav).ToString(Formatting.None));
                }
            }

            return(_navPerRequest = nav ?? Nav.Empty);
        }
示例#2
0
        public byte[] ExportDump()
        {
            string path = _pageIOManager.GetPagesDirectory().FullName;

            using (MemoryStream outputMemoryStream = new MemoryStream())
            {
                using (ZipOutputStream zipOutputStream = new ZipOutputStream(outputMemoryStream))
                {
                    zipOutputStream.SetLevel(5);
                    CompressFolder(path, zipOutputStream, path.Length + (path.EndsWith("\\") ? 0 : 1));
                    zipOutputStream.IsStreamOwner = false;
                    zipOutputStream.Close();
                    outputMemoryStream.Position = 0;
                    return(outputMemoryStream.ToArray());
                }
            }
        }
示例#3
0
        public async Task <Page> EditPageAsync(PagePath pagePath, string markdown)
        {
            if (pagePath == null)
            {
                throw new ArgumentNullException(nameof(pagePath));
            }

            DirectoryInfo pagesDirectory = _pageIOManager.GetPagesDirectory();
            FileInfo      pageFileInfo   = new FileInfo(Path.Combine(pagesDirectory.FullName, pagePath.ToString()));

            string pageLocationHash = Hasher.GetMd5Hash(pagePath.Location.GetDirectoryPath());
            string pageCachename    = pageLocationHash + "_" + pageFileInfo.LastWriteTime.ToString("yyyyMMddHHmmss") + Cache.PagePostfix;

            _cacheManager.ClearCache(pageCachename);

            await _pageIOManager.SavePage(pageFileInfo.FullName, markdown);

            PageData pageData = await GetPageDataAsync(pagePath);

            PageMetadata pageMetadata = await GetPageMetadataAsync(pagePath);

            return(new Page(new PageContext(pagePath, pageMetadata), pageData));
        }