Esempio n. 1
0
 static DirectoryDescription LoadFromJson(string fileName)
 {
     using (StreamReader fStream = new StreamReader(fileName)) {
         DirectoryDescription restoredDirectoryDescription = JsonSerializer.Deserialize <DirectoryDescription>(fStream.ReadToEnd());
         return(restoredDirectoryDescription);
     }
 }
Esempio n. 2
0
 public static int folCnt = 1; //Количество папок
 public void WriteDirectoryDescription(DirectoryDescription directory, string tab)
 {
     infoDirectoryTextBox.Items.Add(tab + "Name of directory: " + directory.Name);
     infoDirectoryTextBox.Items.Add(tab + "Volume of directory: " + directory.Volume);
     infoDirectoryTextBox.Items.Add(tab + "Last write time folder: " + directory.LastWriteTime.ToString());
     infoDirectoryTextBox.Items.Add(tab + "Attributes: " + directory.Attributes);
     if (directory.Files.Count() != 0)
     {
         infoDirectoryTextBox.Items.Add(tab + "Files: ");
         foreach (var file in directory.Files)
         {
             infoDirectoryTextBox.Items.Add(tab + "====================================================");
             infoDirectoryTextBox.Items.Add(tab + "Name of file: " + file.Name);
             infoDirectoryTextBox.Items.Add(tab + "Volume of file: " + file.Volume);
             infoDirectoryTextBox.Items.Add(tab + "Hashcode of file-data: " + file.Data);
             infoDirectoryTextBox.Items.Add(tab + "Attributes: " + file.Attributes);
             infoDirectoryTextBox.Items.Add(tab + "Last write time file: " + file.LastWriteTime.ToString());
             fCnt++;
         }
     }
     if (directory.SubFolders.Count() != 0)
     {
         infoDirectoryTextBox.Items.Add(tab + "Subfolders: ");
         foreach (var subfolder in directory.SubFolders)
         {
             WriteDirectoryDescription(subfolder, tab + "\t");
             folCnt++;
         }
     }
 }
Esempio n. 3
0
        static DirectoryDescription LoadFromXMLFile(string fileName)
        {
            XmlSerializer xmlFormat = new XmlSerializer(typeof(DirectoryDescription));

            using (Stream fStream = File.OpenRead(fileName)) {
                DirectoryDescription directoryDescriptionFromDisk =
                    (DirectoryDescription)xmlFormat.Deserialize(fStream);
                return(directoryDescriptionFromDisk);
            }
        }
Esempio n. 4
0
        static DirectoryDescription LoadFromBinaryFile(string fileName)
        {
            BinaryFormatter binFormat = new BinaryFormatter();

            using (Stream fStream = File.OpenRead(fileName)) {
                DirectoryDescription directoryDescriptionFromDisk =
                    (DirectoryDescription)binFormat.Deserialize(fStream);
                return(directoryDescriptionFromDisk);
            }
        }
Esempio n. 5
0
 // GetDirectoryDescriptions возвращает набор описаний вложенных в корневую папку подкаталогов DirectoryDescription
 // которые так же описываются за счет рекурсивного вызова этого метода
 public IEnumerable <DirectoryDescription> GetDirectoryDescriptions(string path)
 {
     foreach (var dir in Directory.GetDirectories(path))
     {
         var dirInfo   = new DirectoryInfo(dir);
         var directory = new DirectoryDescription {
             Name          = dirInfo.Name,
             LastWriteTime = dirInfo.LastWriteTime,
             SubFolders    = GetDirectoryDescriptions(dir).ToList(),
             Files         = GetFileDescriptions(dir).ToList(),
             Volume        = dirInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(file => file.Length),
             Attributes    = dirInfo.Attributes,
         };
         yield return(directory);
     }
 }