static void CleanImagesRecursiveDirectory(string SourcePath) { //Recurse sub directories foreach (string SubDirectory in Directory.GetDirectories(SourcePath)) { String SubDirectoryUpper = SubDirectory.ToUpper(); //Exclude archive,css, defaultwebtemplate and image folders from processing if (!(SubDirectoryUpper.EndsWith("\\INCLUDE") || SubDirectoryUpper.EndsWith("\\JAVASCRIPT") || SubDirectoryUpper.EndsWith("\\IMAGES") || SubDirectoryUpper.EndsWith("\\ATTACHMENTS") || SubDirectoryUpper.EndsWith("\\CSS") || SubDirectoryUpper.EndsWith("\\TEMPLATES"))) { CleanImagesRecursiveDirectory(SubDirectory); } else if (SubDirectoryUpper.EndsWith("\\IMAGES")) { //Image folder check for child directories foreach (string LanguageImageFolder in Directory.GetDirectories(SubDirectory)) { //For each file check bytes against parent directories files. foreach (string LangImageFileName in Directory.GetFiles(LanguageImageFolder)) { string INTFileName = Path.Combine(SubDirectory, Path.GetFileName(LangImageFileName)); if (File.Exists(INTFileName) && CommonUnrealFunctions.ByteEquals(File.ReadAllBytes(LangImageFileName), File.ReadAllBytes(INTFileName))) { log.Info(Language.Message("DeletingDuplicatedImage", LangImageFileName)); CommonUnrealFunctions.SetFileAttributeForReplace(new FileInfo(LangImageFileName)); File.Delete(LangImageFileName); } } } } } }
/// <summary> /// Cleans metadata in the specified directory of files /// </summary> /// <param name="SourcePath">Includes Path</param> static void CleanMetaDataDirectory(string SourcePath) { DirectoryInfo CurrentDirectory = new DirectoryInfo(SourcePath); //Process each file in each language unless language was a parameter //but only if there are any udn files in this directory if (CurrentDirectory.GetFiles("*.udn").Length > 0) { foreach (string Language in SubsetOfSupportedLanguages) { if (CurrentDirectory.GetFiles(string.Format("*.{0}.udn", Language)).Length > 0) { FileInfo InputFile = CurrentDirectory.GetFiles(string.Format("*.{0}.udn", Language))[0]; //Save file contents prior to processing String Source = FileContents(InputFile.FullName); //Process Metadata String PostProcessing = Markdown.MetaData.Replace(Source, EveryMatch => CleanMetaData(EveryMatch, InputFile.FullName)); if (!Source.Equals(PostProcessing)) { CommonUnrealFunctions.SetFileAttributeForReplace(InputFile); File.WriteAllText(InputFile.FullName, PostProcessing); } //compare files and save if different } } } }
static ConvertFileResponse ConvertFile(MarkdownSharp.Markdown markdownToHtml, string inputFileName, string language, IEnumerable <string> languagesLinksToGenerate, OutputFormat format = OutputFormat.HTML) { var result = ConvertFileResponse.NoChange; var targetFileName = GetTargetFileName(inputFileName, language); //Set up parameters in Markdown to aid in processing and generating html Markdown.MetadataErrorIfMissing = MetadataErrorIfMissing; Markdown.MetadataInfoIfMissing = MetadataInfoIfMissing; markdownToHtml.DoNotPublishAvailabilityFlag = Settings.Default.DoNotPublishAvailabilityFlag; markdownToHtml.PublishFlags = PublishFlags.ToList(); markdownToHtml.AllSupportedAvailability = AllSupportedAvailability; var fileOutputDirectory = FileHelper.GetRelativePath( SourceDirectory, Path.GetDirectoryName(inputFileName)); var currentFolderDetails = new FolderDetails( GetRelativeHTMLPath(targetFileName), OutputDirectory, SourceDirectory, fileOutputDirectory, Settings.Default.APIFolderLocation, (new DirectoryInfo(inputFileName).Parent).FullName.Replace( SourceDirectory + Path.DirectorySeparatorChar.ToString(), "") .Replace(SourceDirectory, "") .Replace(Path.DirectorySeparatorChar.ToString(), " - "), language); markdownToHtml.DefaultTemplate = DefaultTemplate; markdownToHtml.ThisIsPreview = ThisIsPreview; if (language != "INT") { currentFolderDetails.DocumentTitle += " - " + language; } if (ThisIsPreview) { currentFolderDetails.DocumentTitle += " - PREVIEW!"; } markdownToHtml.SupportedLanguages = SupportedLanguages; markdownToHtml.SupportedLanguageLabels = SupportedLanguageLabels; for (int i = 0; i < markdownToHtml.SupportedLanguages.Length; i++) { if (!markdownToHtml.SupportedLanguageMap.ContainsKey(SupportedLanguages[i])) { markdownToHtml.SupportedLanguageMap.Add(markdownToHtml.SupportedLanguages[i], markdownToHtml.SupportedLanguageLabels[i]); } } //Pass the default conversion settings to Markdown for use in the image details creation. markdownToHtml.DefaultImageDoCompress = DoCompressImages; markdownToHtml.DefaultImageFormatExtension = CompressImageType; markdownToHtml.DefaultImageFillColor = DefaultImageFillColor; markdownToHtml.DefaultImageFormat = CompressImageFormat; markdownToHtml.DefaultImageQuality = JpegCompressionRate; var errorList = new List <ErrorDetail>(); var imageDetails = new List <ImageConversion>(); var attachNames = new List <AttachmentConversionDetail>(); var output = markdownToHtml.Transform(FileContents(inputFileName), errorList, imageDetails, attachNames, currentFolderDetails, languagesLinksToGenerate, format != OutputFormat.HTML); var noFailedErrorReport = true; var stopProcessing = false; //If output empty then treat as failed, we are not converting most likely due to the publish flags and availability settings if (String.IsNullOrWhiteSpace(output)) { noFailedErrorReport = false; stopProcessing = true; result = ConvertFileResponse.NoChange; log.Info(MarkdownSharp.Language.Message("NotConverted", inputFileName)); } else { //Need to check for error types prior to processing to output log messages in the correct order. foreach (var errorInfo in errorList) { if (errorInfo.ClassOfMessage == MessageClass.Error || errorInfo.ClassOfMessage == MessageClass.Warning) { log.Info(MarkdownSharp.Language.Message("FileFailed", inputFileName)); noFailedErrorReport = false; break; } } } if (noFailedErrorReport) { log.Info(MarkdownSharp.Language.Message("Converted", inputFileName)); } //On warnings or errors stop processing the file to the publish folder but allow to continue if in preview. if (errorList.Count > 0) { Console.Write("\n"); foreach (MarkdownSharp.ErrorDetail ErrorInfo in errorList) { switch (ErrorInfo.ClassOfMessage) { case MarkdownSharp.MessageClass.Error: log.Error(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message); if (!ThisIsPreview) { stopProcessing = true; result = ConvertFileResponse.Failed; } break; case MarkdownSharp.MessageClass.Warning: log.Warn(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message); if (!ThisIsPreview) { stopProcessing = true; result = ConvertFileResponse.Failed; } break; default: log.Info(ErrorInfo.Path ?? inputFileName, ErrorInfo.Line, ErrorInfo.Column, ErrorInfo.Message); break; } } } if (!stopProcessing) { if (ThisIsPreview || !ThisIsLogOnly) { CommonUnrealFunctions.CopyDocumentsImagesAndAttachments(inputFileName, log, OutputDirectory, language, fileOutputDirectory, imageDetails, attachNames); } var expected = FileContents(targetFileName); if (output == expected) { result = ConvertFileResponse.NoChange; } else { if (!stopProcessing) { if (!AlreadyCreatedCommonDirectories) { AlreadyCreatedCommonDirectories = CommonUnrealFunctions.CreateCommonDirectories(OutputDirectory, SourceDirectory, log); } Console.Write("\n"); if (ThisIsPreview || !ThisIsLogOnly) { //Check output directory exists, if not create the full html structure for this language CommonUnrealFunctions.GenerateDocsFolderStructure(OutputDirectory, fileOutputDirectory, language); CommonUnrealFunctions.SetFileAttributeForReplace(new FileInfo(targetFileName)); File.WriteAllText(targetFileName, output); if (format == OutputFormat.PDF) { PdfHelper.CreatePdfFromHtml(targetFileName); } } result = ConvertFileResponse.Converted; } } } return(result); }