/// <summary> /// Updates the directives in the page file to use razor syntax. /// </summary> /// <param name="fileName">The file being processed.</param> /// <param name="sourceData">The source data to be updated.</param> /// <returns>The updated content.</returns> private async Task <String> SetRazorPageDirectives(string fileName, Dictionary <string, string> sourceData) { //String result = String.Empty; SourceFormatter result = new SourceFormatter(); try { var pageData = sourceData["HeaderData"]; Regex regex = new Regex(@"(?<=\bMasterPageFile="")[^""]*"); Match match = regex.Match(pageData); string layout = match.Value; layout = layout.Replace(".", ""); //remove the old-style Site.Master layout to read SiteMaster result.AppendCode($"@page \"/{fileName}\" "); if (layout.Length > 0) { //Making sure the ~ gets removed from directives result.AppendCodeLine(0, $"@layout { layout.Replace("~/", "")}"); } //result += $"@inherits {fileName}Base\r\n\r\n {sourceData["alteredSource"]}"; result.AppendCodeLine(0); result.AppendCodeLine(0); result.AppendCodeLine(0, $"{sourceData["alteredSource"]}"); } catch (Exception unhandledError) { await _statusTracking.UpdateCurrentStatusAsync(MigrationStepEnum.AspxPages, MessageTypeEnum.Error, $"The following unhandled error occured while setting the razor page directives in the file {fileName}. '{unhandledError.Message}'"); } return(result.ReturnSource()); }