Exemple #1
0
        internal Backup(string path)
        {
            string pathBackup = @"D:\Backup storage\backup.json";
            string filter     = "*.txt";

            string[] files = Directory.GetFiles(path, filter, SearchOption.AllDirectories);

            StructureJSON fileJSON = new StructureJSON();

            List <Files> listFiles = new List <Files>();

            foreach (string filename in files)
            {
                FileStream   file1  = new FileStream(filename, FileMode.Open);
                StreamReader reader = new StreamReader(file1);

                Files file = new Files(filename, reader.ReadToEnd());
                listFiles.Add(file);

                reader.Close();
            }

            fileJSON.Files    = listFiles;
            fileJSON.DateTime = DateTime.UtcNow.ToString();

            StreamWriter sw = new StreamWriter(File.Open(pathBackup, FileMode.Append));

            sw.WriteLine(JsonConvert.SerializeObject(fileJSON));

            sw.Close();
        }
Exemple #2
0
        public Recovery()
        {
            DirectoryInfo dirInfo = new DirectoryInfo(pathBackup);

            if (!dirInfo.Exists)
            {
                NoBackup();
            }
            else
            {
                StreamReader sr     = new StreamReader(pathBackup + "\\backup.json");
                int          number = 0;

                while (sr.Peek() >= 0)
                {
                    StructureJSON versionsRestore = JsonConvert.DeserializeObject <StructureJSON>(sr.ReadLine());
                    listData.Add(versionsRestore.DateTime);
                    list.Add(number, versionsRestore.Files);

                    ++number;
                }
                sr.Close();

                if (listData.Count == 0)
                {
                    NoBackup();
                }

                else
                {
                    Console.WriteLine("Выберите дату восстановления:");
                    number = 0;

                    foreach (var item in listData)
                    {
                        Console.WriteLine($"{number++} - {item}");
                    }

                    if (int.TryParse(Console.ReadLine(), out int selectedDate))
                    {
                        DeletOldFiles(selectedDate);

                        foreach (var item in list[selectedDate])
                        {
                            Console.WriteLine(item.Name);
                            ExtractionFile(item.Name, item.FileContents, selectedDate);
                        }
                    }
                }
            }
        }