Exemplo n.º 1
0
 /// <summary>
 /// Returns the list of files in this catalog that have the specified file contents hash, or an empty list of there are no files with that hash.
 /// </summary>
 public IReadOnlyList <FileInstance> FindFiles(Hash256 fileContentsHash)
 {
     if (this.FileInstancesByHash.ContainsKey(fileContentsHash))
     {
         return(this.FileInstancesByHash[fileContentsHash]);
     }
     else
     {
         return(new List <FileInstance>());
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="FileInstance"/> for the specified file.
        /// </summary>
        private FileInstance createFileInstance(IDirectoryInfo baseDirectory, IFileInfo file)
        {
            string relativePath = file.GetRelativePath(baseDirectory);

            using (System.IO.Stream stream = file.OpenRead())
            {
                long    fileSize         = stream.Length;
                Hash256 fileContentsHash = Hash256.GetContentsHash(stream);
                return(new FileInstance(relativePath, fileSize, fileContentsHash));
            }
        }
Exemplo n.º 3
0
 public FileInstance(string relativePath, long fileSize, Hash256 fileContentsHash)
 {
     this.RelativePath     = relativePath;
     this.FileSize         = fileSize;
     this.FileContentsHash = fileContentsHash;
 }
Exemplo n.º 4
0
 public static Catalog Read(IFileInfo fileInfo)
 {
     using (System.IO.Stream stream = fileInfo.Open(System.IO.FileMode.Open, System.IO.FileAccess.Read))
     {
         XDocument           xDocument         = XDocument.Load(stream);
         string              baseDirectoryPath = (string)xDocument.Element("Catalog").Element("BaseDirectoryPath");
         DateTime            catalogedOn       = (DateTime)xDocument.Element("Catalog").Element("CatalogedOn");
         DateTime            updatedOn         = (DateTime)xDocument.Element("Catalog").Element("UpdatedOn");
         List <FileInstance> fileInstances     = xDocument.Element("Catalog").Element("Files").Elements("f")
                                                 .Select((element) => new FileInstance(element.Attribute("p").Value, (long)element.Attribute("l"), Hash256.Parse(element.Attribute("h").Value)))
                                                 .ToList();
         return(new Catalog(baseDirectoryPath, catalogedOn, updatedOn, fileInstances));
     }
 }