public async Task<TreeNode<NavigationNode>> GetTree() { // ultimately we will need to cache sitemap per site if (rootNode == null) { NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); await cache.ConnectAsync(); byte[] bytes = await cache.GetAsync(cacheKey); if (bytes != null) { string xml = Encoding.UTF8.GetString(bytes); XDocument doc = XDocument.Parse(xml); rootNode = converter.FromXml(doc); } else { rootNode = await BuildTree(); string xml2 = converter.ToXmlString(rootNode); await cache.SetAsync( cacheKey, Encoding.UTF8.GetBytes(xml2), new DistributedCacheEntryOptions().SetSlidingExpiration( TimeSpan.FromSeconds(100)) ); } } return rootNode; }
private async Task <TreeNode <NavigationNode> > BuildTree() { string filePath = ResolveFilePath(); if (!File.Exists(filePath)) { log.LogError("unable to build navigation tree, could not find the file " + filePath); return(null); } string xml; using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream)) { xml = await streamReader.ReadToEndAsync(); } } XDocument doc = XDocument.Parse(xml); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); TreeNode <NavigationNode> result = converter.FromXml(doc); return(result); }
private async Task<TreeNode<NavigationNode>> BuildTree() { string filePath = ResolveFilePath(); if (!File.Exists(filePath)) { log.LogError("unable to build navigation tree, could not find the file " + filePath); return null; } string xml; using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream)) { xml = await streamReader.ReadToEndAsync(); } } XDocument doc = XDocument.Parse(xml); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); TreeNode<NavigationNode> result = converter.FromXml(doc); return result; }
public async Task <TreeNode <NavigationNode> > GetTree() { // ultimately we will need to cache sitemap per site // we will implement a custom ICacheKeyResolver to resolve multi tenant cache keys if (rootNode == null) { log.LogDebug("rootnode was null so checking distributed cache"); string cacheKey = cacheKeyResolver.ResolveCacheKey(options.CacheKey); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); await cache.ConnectAsync(); byte[] bytes = await cache.GetAsync(cacheKey); if (bytes != null) { log.LogDebug("rootnode was found in distributed cache so deserializing"); string xml = Encoding.UTF8.GetString(bytes); XDocument doc = XDocument.Parse(xml); rootNode = converter.FromXml(doc); } else { log.LogDebug("rootnode was not in cache so building"); rootNode = await implementation.GetTree(); string xml2 = converter.ToXmlString(rootNode); await cache.SetAsync( cacheKey, Encoding.UTF8.GetBytes(xml2), new DistributedCacheEntryOptions().SetSlidingExpiration( TimeSpan.FromSeconds(options.CacheDurationInSeconds)) ); } } return(rootNode); }
public async Task<TreeNode<NavigationNode>> GetTree() { // ultimately we will need to cache sitemap per site // we will implement a custom ICacheKeyResolver to resolve multi tenant cache keys if (rootNode == null) { log.LogDebug("rootnode was null so checking distributed cache"); string cacheKey = cacheKeyResolver.ResolveCacheKey(options.CacheKey); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); await cache.ConnectAsync(); byte[] bytes = await cache.GetAsync(cacheKey); if (bytes != null) { log.LogDebug("rootnode was found in distributed cache so deserializing"); string xml = Encoding.UTF8.GetString(bytes); XDocument doc = XDocument.Parse(xml); rootNode = converter.FromXml(doc); } else { log.LogDebug("rootnode was not in cache so building"); rootNode = await implementation.GetTree(); string xml2 = converter.ToXmlString(rootNode); await cache.SetAsync( cacheKey, Encoding.UTF8.GetBytes(xml2), new DistributedCacheEntryOptions().SetSlidingExpiration( TimeSpan.FromSeconds(options.CacheDurationInSeconds)) ); } } return rootNode; }
private async Task <TreeNode <NavigationNode> > BuildTreeInternal(NavigationTreeBuilderService service) { string filePath = ResolveFilePath(); if (!File.Exists(filePath)) { _log.LogError("unable to build navigation tree, could not find the file " + filePath); NavigationNode rootNav = new NavigationNode(); rootNav.Key = "filenotfound"; //rootNav.IsRootNode = true; rootNav.Text = filePath + " not found"; rootNav.Url = "/"; var treeRoot = new TreeNode <NavigationNode>(rootNav); return(treeRoot); } string xml; using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream)) { xml = await streamReader.ReadToEndAsync(); } } XDocument doc = XDocument.Parse(xml); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); TreeNode <NavigationNode> result = await converter.FromXml(doc, service).ConfigureAwait(false); return(result); }
public async Task <TreeNode <NavigationNode> > GetTree() { // ultimately we will need to cache sitemap per site if (rootNode == null) { NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); await cache.ConnectAsync(); byte[] bytes = await cache.GetAsync(cacheKey); if (bytes != null) { string xml = Encoding.UTF8.GetString(bytes); XDocument doc = XDocument.Parse(xml); rootNode = converter.FromXml(doc); } else { rootNode = await BuildTree(); string xml2 = converter.ToXmlString(rootNode); await cache.SetAsync( cacheKey, Encoding.UTF8.GetBytes(xml2), new DistributedCacheEntryOptions().SetSlidingExpiration( TimeSpan.FromSeconds(100)) ); } } return(rootNode); }
private async Task<TreeNode<NavigationNode>> BuildTreeInternal(NavigationTreeBuilderService service) { string filePath = ResolveFilePath(); if (!File.Exists(filePath)) { log.LogError("unable to build navigation tree, could not find the file " + filePath); NavigationNode rootNav = new NavigationNode(); rootNav.Key = "filenotfound"; rootNav.IsRootNode = true; rootNav.Text = filePath + " not found"; rootNav.Url = "/"; var treeRoot = new TreeNode<NavigationNode>(rootNav); return treeRoot; } string xml; using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream)) { xml = await streamReader.ReadToEndAsync(); } } XDocument doc = XDocument.Parse(xml); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); TreeNode<NavigationNode> result = await converter.FromXml(doc, service).ConfigureAwait(false); return result; }
public async Task Can_Roundtrip_Serialize_To_Xml() { // Assemble HardCodedNavigationTreeBuilder builder = new HardCodedNavigationTreeBuilder(); TreeNode<NavigationNode> rootNode = await builder.GetTree(); NavigationTreeXmlConverter converter = new NavigationTreeXmlConverter(); //Act string xml = converter.ToXmlString(rootNode); Assert.True(xml.Length > 10); //using (StreamWriter stream = File.CreateText("dumpxml.txt")) //{ // stream.WriteLine(xml); //} }