예제 #1
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;
        }
예제 #2
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;
        }