예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManifestValidator"/> class.
        /// </summary>
        /// <param name="manifest">The manifest instance to be validated.</param>
        /// <param name="localDirectory">The directory that will be used to locate files with relative paths.</param>
        public ManifestValidator(Manifest manifest, String localDirectory)
        {
            _manifest = manifest;
            _localDirectory = localDirectory;
            _running = false;
            _complete = false;

            var contents = manifest.Contents;

            _results = new List<ManifestValidatorResult>();
            _processed = new List<ManifestEntry>(contents.Count);
            _remaining = new Queue<ManifestEntry>(contents.Count);
        }
예제 #2
0
        /// <summary>
        /// Creates a new manifest using the specified parameters.
        /// </summary>
        /// <param name="directory">The directory containing the files to include in the manifest.</param>
        /// <param name="hashAlgorithm">A valid parameter for the <seealso cref="System.Security.Cryptography.HashAlgorithm" />.<seealso cref="System.Security.Cryptography.HashAlgorithm.Create(string)" /> method.</param>
        /// <param name="description">A description to be included in the manifest.</param>
        /// <returns></returns>
        public static async Task<Manifest> CreateManifest(String directory, String hashAlgorithm = null, String description = null)
        {
            var work = await Task.Factory.StartNew(() =>
            {
                List<ManifestEntry> entries = new List<ManifestEntry>();
                var files = ManifestHelper.GetFiles(directory);
                foreach (var file in files)
                {
                    var entry = CreateManifestEntry(directory, file.Replace(directory, ""), null, hashAlgorithm);
                    if (entry == null) { continue; }
                    entries.Add(entry);
                }
                Manifest manifest = new Manifest
                {
                    ID = Guid.NewGuid(),
                    Description = description,
                    HashAlgorithm = hashAlgorithm,
                    TimestampUtc = DateTime.UtcNow,
                    Contents = entries,
                };
                return manifest;
            });

            return work;
        }
예제 #3
0
        private static Manifest CreateManifestManually()
        {
            var files = ManifestHelper.GetFiles(path);

            Manifest m = new Manifest();
            m.AddFiles(files);

            String commonAncestor;
            m.Contents = Manifest.FindCommonAncestor(m.Contents, out commonAncestor).ToList();

            m.HashAlgorithm = hashingAlgorithm;
            // Skip files larger than 10MB, for the sake of speed.
            const long tenMegs = 10485760;
            m.CalculateHashes(commonAncestor, tenMegs);

            return m;
        }