Example #1
0
        private void ResolveMissingZipArchives(ref List <FileName> fileNames)
        {
            StringBuilder   missingFiles = new StringBuilder();
            List <FileName> missingZips  = fileNames.Where(x => x.IsZipContainer && !File.Exists(x.FullPath)).ToList();

            foreach (FileName missingZip in missingZips)
            {
                // Throw if somehow the same missing zip is present more than once. May be OK to take FirstOrDefault.
                var matchingFile = (from path in Directory.GetFiles(OutputPath, missingZip.Name, SearchOption.AllDirectories)
                                    where contentUtil.GetChecksum(path).Equals(missingZip.SHA256Hash, StringComparison.OrdinalIgnoreCase)
                                    select path).SingleOrDefault();

                if (!string.IsNullOrEmpty(matchingFile))
                {
                    fileNames.Remove(missingZip);
                    string   relativePath    = (new Uri(OutputPath).MakeRelativeUri(new Uri(matchingFile))).OriginalString.Replace('/', Path.DirectorySeparatorChar);
                    FileName updatedFileName = new FileName(OutputPath, relativePath, missingZip.SHA256Hash);
                    fileNames.Add(updatedFileName);
                }
                else
                {
                    missingFiles.AppendLine($"File: {missingZip.Name} Hash: {missingZip.SHA256Hash}");
                }
            }
            if (!(missingFiles.Length == 0))
            {
                throw new FileNotFoundException($"Could not find one or more Zip-archive files referenced:\n{missingFiles}");
            }
        }
Example #2
0
        /// <summary>
        /// Build up a table of checksum to <see cref="FileName"/> instance map. This will report errors if it
        /// is unable to read any of the files off of disk.
        /// </summary>
        private ContentMap BuildContentMap(TaskLoggingHelper log)
        {
            var contentMap = new ContentMap();

            foreach (var fileName in _batchData.FileNames)
            {
                try
                {
                    if (string.IsNullOrEmpty(fileName.SHA256Hash))
                    {
                        var checksum = _contentUtil.GetChecksum(fileName.FullPath);
                        contentMap.Add(fileName, checksum);
                    }
                    else
                    {
                        if (File.Exists(fileName.FullPath))
                        {
                            contentMap.Add(fileName, fileName.SHA256Hash);
                        }
                        else
                        {
                            throw new FileNotFoundException();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!File.Exists(fileName.FullPath))
                    {
                        log.LogError($"Did not find {fileName} at {fileName.FullPath}");
                    }
                    else
                    {
                        log.LogError($"Unable to read content of {fileName.FullPath}: {ex.Message}");
                    }
                }
            }

            return(contentMap);
        }
Example #3
0
        private void GenerateOrchestrationManifest(BatchSignInput batchData, string outputPath)
        {
            _log.LogMessage(MessageImportance.High, $"Generating orchestration file manifest into {outputPath}");
            OrchestratedFileJson fileJsonWithInfo = new OrchestratedFileJson
            {
                ExcludeList = Array.Empty <string>()
            };

            var distinctSigningCombos = batchData.FilesToSign.GroupBy(fileToSign => new { fileToSign.SignInfo.Certificate, fileToSign.SignInfo.StrongName });
            var contentUtil           = new ContentUtil();

            List <OrchestratedFileSignData> newList = new List <OrchestratedFileSignData>();

            foreach (var combinationToSign in distinctSigningCombos)
            {
                var filesInThisGroup = combinationToSign.Select(combination => new FileSignDataEntry()
                {
                    FilePath         = combination.FullPath,
                    SHA256Hash       = contentUtil.GetChecksum(combination.FullPath),
                    PublishToFeedUrl = batchData.PublishUri
                });
                newList.Add(new OrchestratedFileSignData()
                {
                    Certificate = combinationToSign.Key.Certificate,
                    StrongName  = combinationToSign.Key.StrongName,
                    FileList    = filesInThisGroup.ToArray()
                });
            }
            fileJsonWithInfo.SignList = newList.ToArray();
            fileJsonWithInfo.Kind     = "orchestration";

            using (StreamWriter file = File.CreateText(outputPath))
            {
                file.Write(JsonConvert.SerializeObject(fileJsonWithInfo, Formatting.Indented));
            }
        }