示例#1
0
        private static bool GenerateAzureFileInfoForMigration(
            string repositoryRoot,
            RewriterToolArguments rewriterToolArguments,
            string azureDocumentUriPrefix,
            AzureFileInformationCollection azureFileInformationCollection)
        {
            var azureMarkdownFileInfoMapping        = new ConcurrentDictionary <string, AzureFileInfo>();
            var azureResourceFileInfoMapping        = new ConcurrentDictionary <string, AzureFileInfo>();
            var azureIncludeMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();
            var azureIncludeResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();

            bool hasDupliateMdFileName = false;
            var  files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories);

            Parallel.ForEach(
                files,
                new ParallelOptions {
                MaxDegreeOfParallelism = 8
            },
                file =>
            {
                var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file);
                if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration))
                {
                    return;
                }

                var filePath      = PathUtility.NormalizePath(file);
                var fileName      = Path.GetFileName(file);
                var azureFileInfo = new AzureFileInfo
                {
                    FileName = fileName,
                    FilePath = PathUtility.NormalizePath(file),
                    NeedTransformToAzureExternalLink = false,
                    UriPrefix = string.Empty
                };

                var isIncludeFile = filePath.Split(new[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)
                                    .Any(folder => folder.Equals("includes", StringComparison.OrdinalIgnoreCase));
                var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase);

                AzureFileInfo conflictFile = null;
                var isSucceed = true;
                if (!isIncludeFile && isMarkdownFile)
                {
                    isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                }
                else if (!isIncludeFile && !isMarkdownFile)
                {
                    // For resource file, even if has conflicts, we regards that as succeed
                    azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                }
                else if (isIncludeFile && isMarkdownFile)
                {
                    isSucceed = azureIncludeMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    azureIncludeMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                }
                else
                {
                    // For resource file, even if has conflicts, we regards that as succeed
                    azureIncludeResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                }

                if (!isSucceed)
                {
                    hasDupliateMdFileName = true;
                    Logger.LogError($"Error: GenerateAzureFileInfo failed. File: {file} name confilicts with: {conflictFile?.FilePath}");
                }
            });

            azureFileInformationCollection.AzureMarkdownFileInfoMapping        = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureResourceFileInfoMapping        = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureIncludeMarkdownFileInfoMapping = azureIncludeMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureIncludeResourceFileInfoMapping = azureIncludeResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);

            return(!hasDupliateMdFileName);
        }
示例#2
0
        private static bool GenerateAzureFileInfo(
            string repositoryRoot,
            RewriterToolArguments rewriterToolArguments,
            string azureDocumentUriPrefix,
            AzureFileInformationCollection azureFileInformationCollection)
        {
            var azureMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();
            var azureResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();

            var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories);

            Parallel.ForEach(
                files,
                new ParallelOptions {
                MaxDegreeOfParallelism = 8
            },
                file =>
            {
                var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file);
                if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration))
                {
                    return;
                }

                var isSucceed = true;
                var azureTransformArguments = rewriterToolArguments.AzureTransformArgumentsList.FirstOrDefault(a => PathUtility.IsPathUnderSpecificFolder(file, a.SourceDir));

                // By default, all the link should be transformed to external link with azure uri prefix
                // However, if we find that the file is under one of the folder that need to be transformed. Then the prefix uri should be docs but not auzre
                var needTransformToAzureExternalLink = true;
                var uriPrefix = azureDocumentUriPrefix;
                if (azureTransformArguments != null)
                {
                    needTransformToAzureExternalLink = false;
                    uriPrefix = azureTransformArguments.DocsHostUriPrefix;
                }

                var fileName      = Path.GetFileName(file);
                var azureFileInfo = new AzureFileInfo
                {
                    FileName = fileName,
                    FilePath = PathUtility.NormalizePath(file),
                    NeedTransformToAzureExternalLink = needTransformToAzureExternalLink,
                    UriPrefix = uriPrefix
                };

                AzureFileInfo conflictFile;
                var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase);
                if (isMarkdownFile)
                {
                    isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                }
                else
                {
                    isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    azureResourceFileInfoMapping.TryGetValue(fileName, out conflictFile);
                }

                if (!isSucceed)
                {
                    Console.WriteLine($"GenerateAzureFileInfo warning: can't insert file: {file}, confilicts with: {conflictFile?.FilePath}");
                }
            });

            azureFileInformationCollection.AzureMarkdownFileInfoMapping = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureResourceFileInfoMapping = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            return(true);
        }
示例#3
0
文件: Program.cs 项目: vicancy/docfx
        private static bool GenerateAzureFileInfo(
            string repositoryRoot,
            RewriterToolArguments rewriterToolArguments,
            string azureDocumentUriPrefix,
            AzureFileInformationCollection azureFileInformationCollection)
        {
            var azureMarkdownFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();
            var azureResourceFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();

            var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories);
            Parallel.ForEach(
                files,
                new ParallelOptions { MaxDegreeOfParallelism = 8 },
                file =>
                {
                    var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file);
                    if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration))
                    {
                        return;
                    }

                    var isSucceed = true;
                    var azureTransformArguments = rewriterToolArguments.AzureTransformArgumentsList.FirstOrDefault(a => PathUtility.IsPathUnderSpecificFolder(file, a.SourceDir));

                    // By default, all the link should be transformed to external link with azure uri prefix
                    // However, if we find that the file is under one of the folder that need to be transformed. Then the prefix uri should be docs but not auzre
                    var needTransformToAzureExternalLink = true;
                    var uriPrefix = azureDocumentUriPrefix;
                    if (azureTransformArguments != null)
                    {
                        needTransformToAzureExternalLink = false;
                        uriPrefix = azureTransformArguments.DocsHostUriPrefix;
                    }

                    var fileName = Path.GetFileName(file);
                    var azureFileInfo = new AzureFileInfo
                    {
                        FileName = fileName,
                        FilePath = PathUtility.NormalizePath(file),
                        NeedTransformToAzureExternalLink = needTransformToAzureExternalLink,
                        UriPrefix = uriPrefix
                    };

                    AzureFileInfo conflictFile;
                    var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase);
                    if (isMarkdownFile)
                    {
                        isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                        azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                    }
                    else
                    {
                        isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                        azureResourceFileInfoMapping.TryGetValue(fileName, out conflictFile);
                    }

                    if (!isSucceed)
                    {
                        Console.WriteLine($"GenerateAzureFileInfo warning: can't insert file: {file}, confilicts with: {conflictFile?.FilePath}");
                    }
                });

            azureFileInformationCollection.AzureMarkdownFileInfoMapping = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureResourceFileInfoMapping = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            return true;
        }
示例#4
0
文件: Program.cs 项目: vicancy/docfx
        private static bool GenerateAzureFileInfoForMigration(
            string repositoryRoot,
            RewriterToolArguments rewriterToolArguments,
            string azureDocumentUriPrefix,
            AzureFileInformationCollection azureFileInformationCollection)
        {
            var azureMarkdownFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();
            var azureResourceFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();
            var azureIncludeMarkdownFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();
            var azureIncludeResourceFileInfoMapping = new ConcurrentDictionary<string, AzureFileInfo>();

            bool hasDupliateMdFileName = false;
            var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories);
            Parallel.ForEach(
                files,
                new ParallelOptions { MaxDegreeOfParallelism = 8 },
                file =>
                {
                    var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file);
                    if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration))
                    {
                        return;
                    }

                    var filePath = PathUtility.NormalizePath(file);
                    var fileName = Path.GetFileName(file);
                    var azureFileInfo = new AzureFileInfo
                    {
                        FileName = fileName,
                        FilePath = PathUtility.NormalizePath(file),
                        NeedTransformToAzureExternalLink = false,
                        UriPrefix = string.Empty
                    };

                    var isIncludeFile = filePath.Split(new[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)
                                            .Any(folder => folder.Equals("includes", StringComparison.OrdinalIgnoreCase));
                    var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase);

                    AzureFileInfo conflictFile = null;
                    var isSucceed = true;
                    if (!isIncludeFile && isMarkdownFile)
                    {
                        isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                        azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                    }
                    else if (!isIncludeFile && !isMarkdownFile)
                    {
                        // For resource file, even if has conflicts, we regards that as succeed
                        azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }
                    else if (isIncludeFile && isMarkdownFile)
                    {
                        isSucceed = azureIncludeMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                        azureIncludeMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile);
                    }
                    else
                    {
                        // For resource file, even if has conflicts, we regards that as succeed
                        azureIncludeResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }

                    if (!isSucceed)
                    {
                        hasDupliateMdFileName = true;
                        Logger.LogError($"Error: GenerateAzureFileInfo failed. File: {file} name confilicts with: {conflictFile?.FilePath}");
                    }
                });

            azureFileInformationCollection.AzureMarkdownFileInfoMapping = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureResourceFileInfoMapping = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureIncludeMarkdownFileInfoMapping = azureIncludeMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);
            azureFileInformationCollection.AzureIncludeResourceFileInfoMapping = azureIncludeResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value);

            return !hasDupliateMdFileName;
        }
示例#5
0
文件: Program.cs 项目: wanyi01/docfx
        private static Tuple <Dictionary <string, AzureFileInfo>, Dictionary <string, AzureFileInfo> > GenerateAzureFileInfo(string repositoryRoot, RewriterToolArguments rewriterToolArguments, string azureDocumentUriPrefix)
        {
            var azureMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();
            var azureResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>();

            var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories);

            Parallel.ForEach(
                files,
                new ParallelOptions {
                MaxDegreeOfParallelism = 4
            },
                file =>
            {
                var relativePath   = PathUtility.MakeRelativePath(repositoryRoot, file);
                var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase);
                if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration))
                {
                    return;
                }

                bool isSucceed = true;
                var azureTransformArguments = rewriterToolArguments.AzureTransformArgumentsList.FirstOrDefault(a => PathUtility.IsPathUnderSpecificFolder(file, a.SourceDir));
                var fileName = Path.GetFileName(file);

                if (azureTransformArguments == null)
                {
                    var azureFileInfo = new AzureFileInfo
                    {
                        FileName = fileName,
                        FilePath = PathUtility.NormalizePath(file),
                        NeedTransformToAzureExternalLink = true,
                        UriPrefix = azureDocumentUriPrefix
                    };

                    if (isMarkdownFile)
                    {
                        isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }
                    else
                    {
                        isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }
                }
                else
                {
                    var azureFileInfo = new AzureFileInfo
                    {
                        FileName = fileName,
                        FilePath = PathUtility.NormalizePath(file),
                        NeedTransformToAzureExternalLink = false,
                        UriPrefix = azureTransformArguments.DocsHostUriPrefix,
                    };

                    if (isMarkdownFile)
                    {
                        isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }
                    else
                    {
                        isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo);
                    }
                }

                if (!isSucceed)
                {
                    Console.WriteLine($"GenerateAzureFileInfo failed: can't insert file with external prefix {file}");
                }
            });

            return(Tuple.Create(azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value), azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value)));
        }