public void ShouldLoadEntryIntoHtmlFileFromMarkdown() { var projectRoot = this.TestContext.ShouldGetAssemblyDirectoryParent(this.GetType(), expectedLevels: 2); #region test properties: var markdownPath = this.TestContext.Properties["markdownPath"].ToString(); this.TestContext.ShouldFindFile(markdownPath); var entryPath = this.TestContext.Properties["entryPath"].ToString(); entryPath = FrameworkFileUtility.GetCombinedPath(projectRoot, entryPath); this.TestContext.ShouldFindFile(entryPath); #endregion var markdown = File.ReadAllText(markdownPath); var entry = CommonMark.CommonMarkConverter.Convert(markdown); var contentHtml = string.Format("<content>{0}</content>", entry); var content = XElement.Parse(contentHtml); content.Element("h1").Name = "h2"; var html = File.ReadAllText(entryPath); var xDoc = XDocument.Parse(html); var body = xDoc.Root.Element("body"); body.Value = string.Empty; body.Add(content.Elements()); File.WriteAllText(entryPath, xDoc.ToString()); }
/// <summary>Combines path and root based /// on the current value of <see cref="Path.DirectorySeparatorChar"/> /// of the current OS.</summary> /// <param name="directoryInfo">The directory information.</param> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="NullReferenceException">The expected root path is not here. /// or /// The expected path is not here.</exception> /// <remarks>For detail, see https://github.com/BryanWilhite/SonghayCore/issues/14.</remarks> public static string ToCombinedPath(this DirectoryInfo directoryInfo, string path) { if (directoryInfo == null) { throw new NullReferenceException($"The expected {nameof(DirectoryInfo)} is not here."); } return(FrameworkFileUtility.GetCombinedPath(directoryInfo.FullName, path)); }
internal void DownloadFeedFiles(CloudBlobContainer container) { var tasks = this._jsonFiles.Select(i => { var jsonFile = FrameworkFileUtility.GetCombinedPath(this._dataRoot, $"{i}.json"); traceSource?.TraceInformation($"downloading {jsonFile}.json..."); var @ref = container.GetBlobReference(blobName: $"{i}.json"); return(@ref.DownloadToFileAsync(jsonFile, FileMode.Create)); }).ToArray(); Task.WaitAll(tasks); }
internal void WriteFeedFiles(JObject appJO) { var feedsRoot = this._metaSet.TryGetValueWithKey("feedsRoot", throwException: true); this._jsonFiles.ForEachInEnumerable(i => { traceSource?.TraceInformation($"writing {feedsRoot}/{i}..."); var jsonFile = FrameworkFileUtility.GetCombinedPath(this._dataRoot, $"{i}.json"); if (!File.Exists(jsonFile)) { throw new FileNotFoundException("The expected feeds file is not here."); } var jO_feed = JObject.Parse(File.ReadAllText(jsonFile)); appJO[feedsRoot][i] = jO_feed; }); }
internal void SetDataRoot(string basePath) { this._dataRoot = FrameworkFileUtility.GetCombinedPath(basePath, this._metaSet.TryGetValueWithKey("dataRoot", throwException: true)); if (this._dataRoot.StartsWith("./")) { FrameworkFileUtility.GetCombinedPath(basePath, this._dataRoot); } this._dataRoot = Path.GetFullPath(this._dataRoot); if (!Directory.Exists(this._dataRoot)) { Directory.CreateDirectory(this._dataRoot); } traceSource?.TraceVerbose($"verifying {this._dataRoot}..."); if (!Directory.Exists(this._dataRoot)) { throw new DirectoryNotFoundException("The expected data root is not here."); } }
internal string GetAppFile() => FrameworkFileUtility.GetCombinedPath(this._dataRoot, this._appFileName);