Beispiel #1
0
 public void Init(string dir_path)
 {
     if (Directory.Exists(dir_path))
     {
         bool flag = true;
         foreach (MyFolder folder in FolderList)
         {
             if (dir_path == folder.Path)
             {
                 flag = false; Console.WriteLine("Директория уже отслеживается"); return;
             }
         }
         if (flag == true)
         {
             ActiveDir = new MyFolder()
             {
                 Path = dir_path
             };
             ActiveDir.InitList();
             FolderList.Add(ActiveDir);
             Console.WriteLine("Директория добавлена");
         }
     }
     else
     {
         Console.WriteLine("The folder didn't found");
     }
 }
Beispiel #2
0
        public void FileOpen(string way)
        {
            string line = "";

            using (StreamReader sr = new StreamReader("1.txt"))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    ActiveDir = new MyFolder()
                    {
                        Path = line
                    };
                    FolderList.Add(ActiveDir);
                }
                sr.Close();
            }
            var binFormat = new BinaryFormatter();

            using (var fs = new FileStream(way, FileMode.Open))
            {
                while (fs.Length != fs.Position)
                {
                    foreach (MyFolder folder in FolderList)
                    {
                        ActiveDir          = folder;
                        ActiveDir.filelist = ((List <MyFile>)binFormat.Deserialize(fs));

                        //Console.WriteLine("Имя: {0} \t Возраст: {1}", dsUser.Name, dsUser.Age);
                    }
                }
            }

            /*XmlSerializer ser = new XmlSerializer(typeof(List<MyFile>));
             * FileStream file = new FileStream(way, FileMode.Open, FileAccess.Read, FileShare.None);
             *
             * while (file.Length != file.Position)
             * {
             *
             *  //ser.Serialize(file, ActiveDir.filelist);
             *
             *  ActiveDir.filelist = (List<MyFile>)ser.Deserialize(file);
             *  //file.Close();
             * }*/


            /*formatter.Serialize(fs, people);
             * }
             *
             * using (FileStream fs = new FileStream("people.xml", FileMode.OpenOrCreate))
             * {
             *  Person[] newpeople = (Person[])formatter.Deserialize(fs);*/
        }
Beispiel #3
0
        public void CloseProgram(string way)
        {
            /*if (!File.Exists("1.txt"))
             * {
             *  StreamWriter sw = File.CreateText("1.txt");
             * }*/
            using (StreamWriter sw = new StreamWriter("1.txt"))
            {
                foreach (MyFolder folder in FolderList)
                {
                    sw.WriteLine(folder.Path);
                }
                sw.Close();
            }
            var binFormat = new BinaryFormatter();

            using (var fs = new FileStream(way, FileMode.Create))
            {
                foreach (MyFolder folder in FolderList)
                {
                    ActiveDir = folder;
                    binFormat.Serialize(fs, ActiveDir.filelist);
                }
            }

            /*FileStream file = new FileStream(way, FileMode.Create, FileAccess.Write, FileShare.None);
             * XmlSerializer ser = new XmlSerializer(typeof(List<MyFile>));
             *
             * foreach (MyFolder folder in FolderList)
             *  {
             *      ActiveDir = folder;
             *      ser.Serialize(file, ActiveDir.filelist);
             *  }
             *
             * file.Close();*/
            Environment.Exit(0);
        }
Beispiel #4
0
 public void Checkout(string str)
 {
     if (FolderList.Count == 0)
     {
         Console.WriteLine("Ни одна папка не проинициализирована");
         return;
     }
     if (int.TryParse(str, out int i))
     {
         if (i < FolderList.Count && i >= 0)
         {
             ActiveDir = FolderList[i - 1];
             Console.WriteLine("Activedirectory: {0}", ActiveDir.Path);
             return;
         }
     }
     else if (Directory.Exists(str))
     {
         int number = 1;
         foreach (MyFolder folder in FolderList)
         {
             if (str == folder.Path)
             {
                 ActiveDir = FolderList[number];
                 Console.WriteLine("Activedirectory: ", ActiveDir.Path);
                 return;
             }
             number++;
         }
         Console.WriteLine("Директория с таким именем не отслеживается");
     }
     else
     {
         Console.WriteLine("Директория не найдена");
     }
 }