public object GetView(string extension, Stream stream)
        {
            var builder = new StringBuilder();

            var store = new SymbolStoreManager();

            builder.AppendLine("Symbol hash:");
            builder.AppendLine(store.ReadHash(stream));

            builder.AppendLine("");

            var extractor = new ManagedSourceExtractor();

            builder.AppendLine("Compiled sources:");
            var sources = extractor.ReadSources(null, stream);

            foreach (var source in sources)
            {
                builder.AppendLine(source);
            }

            return(builder);
        }
示例#2
0
        public static IEnumerable <PackageIssue> Validate(IPackage package)
        {
            var binaryStore = new BinaryStoreManager();
            var symbolStore = new SymbolStoreManager();

            var files = package.GetFiles().ToArray();

            var hasSymbols = files.Where(PackageHelper.IsSymbolFile).Any();
            var hasSources = files.Where(PackageHelper.IsSourceFile).Any();

            var hasName        = package.FileName != null && package.FileName.EndsWith(".nupkg", StringComparison.CurrentCultureIgnoreCase);
            var hasSymbolsName = hasName && package.FileName.EndsWith(".symbols.nupkg", StringComparison.CurrentCultureIgnoreCase);

            var isSymbolPackage = hasSymbolsName || hasSymbols || hasSources;

            if (!hasName)
            {
                yield return(UnableToVerifyPackageName(package.FileName));
            }
            else
            {
                if (!hasSymbolsName && (hasSymbols || hasSources))
                {
                    yield return(IncorrectSymbolPackageName(package.FileName));
                }

                if (hasSymbolsName && !hasSymbols && !hasSources)
                {
                    yield return(IncorrectPackageName(package.FileName));
                }
            }

            foreach (var binaryFile in files.Where(PackageHelper.IsBinaryFile))
            {
                string binaryHash;

                using (var stream = binaryFile.GetStream())
                    binaryHash = binaryStore.ReadPdbHash(stream);

                if (binaryHash == null)
                {
                    yield return(NoSymbolSupportIssue(binaryFile.Path));
                }

                var symbolPath = Path.ChangeExtension(binaryFile.Path, ".pdb");
                var symbolFile = GetSingleFile(files, symbolPath);

                if (isSymbolPackage && symbolFile == null)
                {
                    yield return(MissingSymbolFileIssue(binaryFile.Path, symbolPath));
                }

                if (!isSymbolPackage && symbolFile != null)
                {
                    yield return(UnnecessarySymbolFileIssue(binaryFile.Path, symbolFile.Path));
                }

                if (symbolFile != null)
                {
                    string symbolHash;

                    using (var stream = symbolFile.GetStream())
                        symbolHash = symbolStore.ReadHash(stream);

                    if (binaryHash != symbolHash)
                    {
                        yield return(HashMismatchIssue(binaryFile.Path, binaryHash, symbolFile.Path, symbolHash));
                    }
                }
            }

            foreach (var symbolFile in files.Where(PackageHelper.IsSymbolFile))
            {
                var paths = new[] { ".dll", ".exe", ".winmd" }
                .Select(extension => Path.ChangeExtension(symbolFile.Path, extension))
                .ToArray();

                if (paths.All(path => GetSingleFile(files, path) == null))
                {
                    yield return(OrphanSymbolFileIssue(symbolFile.Path, paths));
                }
            }
        }