コード例 #1
0
        /// <summary>
        /// Gets the version directory.
        /// </summary>
        /// <param name="directoryName">Name of the directory.</param>
        /// <returns></returns>
        public DirectoryInfo GetVersionDirectory(string directoryName)
        {
            var directory = new DirectoryInfo(directoryName);
            if (!directory.Exists)
                throw new InvalidOperationException();

            var subDirectories = (from subDir in directory.GetDirectories()
                                  let match = VersionPattern.Match(subDir.Name)
                                  where match.Success
                                  orderby
                                  	int.Parse(match.Groups["major"].Value),
                                  	int.Parse(match.Groups["minor"].Value),
                                  	int.Parse(match.Groups["build"].Value),
                                  	int.Parse(match.Groups["revision"].Value)
                                  select subDir).ToList();

            for (int i = subDirectories.Count - 1; i >= 0; i--)
            {
                var subDirectory = subDirectories[i];
                var hash = new DirectoryHash(subDirectory.FullName);
                try
                {
                    hash.Validate();
                    return subDirectory;
                }
                catch (HashValidationException ex)
                {
                    log.Info(string.Format("Error, when trying to validate the directory '{0}':", subDirectory.FullName));
                    log.Info(ex.Message);
                }
            }
            return null;
        }
コード例 #2
0
        public void HashValidationFailsIfSomeEntryIsAbsent()
        {
            var directoryHash1 = new DirectoryHash(location);
            directoryHash1.Save();

            var sb = new StringBuilder();

            string directoryHashFile = Path.Combine(location, "directory.hash");
            using (var sr = new StreamReader(directoryHashFile))
            {
                var index = 0;
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (index != 1)
                    {
                        sb.AppendLine(line);
                    }
                    index++;
                }
            }

            using (var sw = new StreamWriter(directoryHashFile))
            {
                sw.Write(sb.ToString());
            }

            var directoryHash = new DirectoryHash(location);
            Assert.Throws<HashValidationException>(directoryHash.Validate);
        }
コード例 #3
0
        public void HashIsValidatedIfNothingWasChanged()
        {
            var directoryHash = new DirectoryHash(location);
            directoryHash.Save();

            var directoryHash2 = new DirectoryHash(location);
            directoryHash2.Validate();
        }
コード例 #4
0
        /// <summary>
        /// Runs the task.
        /// </summary>
        /// <returns>
        /// true if successful; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            IList<string> filesToIgnore = null;
            IEnumerable<string> mandatoryFilesWithAnyContent = null;

            if (FilesToIgnore != null)
                filesToIgnore = FilesToIgnore.Select(item => item.ItemSpec).ToList();

            if (FilesWithAnyContents != null)
                mandatoryFilesWithAnyContent = FilesWithAnyContents.Select(item => item.ItemSpec);

            var directoryHash = new DirectoryHash(Path, filesToIgnore, mandatoryFilesWithAnyContent);

            directoryHash.Save();
            return true;
        }
コード例 #5
0
        public void HashValidationFailsIfSomeFileIsAbsent()
        {
            const string tempFile = "folder2/temp.file";
            CreateFile(tempFile);
            var directoryHash = new DirectoryHash(location);
            directoryHash.Save();

            File.Delete(Path.Combine(location, tempFile));

            var directoryHash2 = new DirectoryHash(location);
            Assert.Throws<HashValidationException>(directoryHash2.Validate);
        }
コード例 #6
0
 public void HashValidationFailsIfDirectoryHashFileIsAbsent()
 {
     var directoryHash = new DirectoryHash(location);
     Assert.Throws<HashValidationException>(directoryHash.Validate);
 }
コード例 #7
0
 public void HashIsSaved()
 {
     var directoryHash = new DirectoryHash(location);
     directoryHash.Save();
     Assert.That(File.Exists(Path.Combine(location, "directory.hash")));
 }
コード例 #8
0
 public void HashIsCalculated()
 {
     var directoryHash = new DirectoryHash(location);
     Assert.That(directoryHash.Hash.Count, Is.Not.EqualTo(0));
 }
コード例 #9
0
        public void HashValidationSuccedesWhenFileWithChangingContentsAbsents()
        {
            CreateFile("optional.contents");
            var directoryHash = new DirectoryHash(location, mandatoryFilesWithAnyContent: new[] { "optional.contents" });
            directoryHash.Save();

            File.Delete(Path.Combine(location, "optional.contents"));
            var directoryHash2 = new DirectoryHash(location);
            Assert.Throws<HashValidationException>(directoryHash2.Validate);
        }
コード例 #10
0
        public void HashValidationSuccedesWhenContentsChangesInFileWithChangingContents()
        {
            CreateFile("optional.contents");
            var directoryHash = new DirectoryHash(location, mandatoryFilesWithAnyContent: new[]{"optional.contents"});
            directoryHash.Save();

            CreateFile("optional.contents");
            var directoryHash2 = new DirectoryHash(location);
            Assert.DoesNotThrow(directoryHash2.Validate);
        }
コード例 #11
0
        public void HashValidationFailsIfWholeKeyHashIsAbsent()
        {
            var directoryHash1 = new DirectoryHash(location);
            directoryHash1.Save();

            var sb = new StringBuilder();

            string directoryHashFile = Path.Combine(location, "directory.hash");
            using (var sr = new StreamReader(directoryHashFile))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line == null || !line.StartsWith(":::"))
                    {
                        sb.AppendLine(line);
                    }
                }
            }

            using (var sw = new StreamWriter(directoryHashFile))
            {
                sw.Write(sb.ToString());
            }

            var directoryHash = new DirectoryHash(location);
            Assert.Throws<HashValidationException>(directoryHash.Validate);
        }
コード例 #12
0
        public void HashValidationFailsIfSomeFileIsChanged()
        {
            CreateFile("folder2/temp.file");
            var directoryHash = new DirectoryHash(location);
            directoryHash.Save();

            // Recreate file with different contents
            CreateFile("folder2/temp.file");
            var directoryHash2 = new DirectoryHash(location);
            Assert.Throws<HashValidationException>(directoryHash2.Validate);
        }