/// <summary>
 /// method of starting recursive traversal
 /// </summary>
 /// <param name="s">root of the bypass folder</param>
 /// <param name="obj">serialization object</param>
 public void Open(Sinhronizer obj)
 {
     if (!Directory.Exists(this.Root))
     {
         OperatinDirectory.CrieteDirectory(this.Root);
     }
     base.WalkRir(new DirectoryInfo(this.Root), files, dir, obj, (int)Nums.Zero, dir.Count == (int)Nums.Zero);
 }
Esempio n. 2
0
        /// <summary>
        /// method Serialization
        /// </summary>
        /// <param name="obj">serialization object</param>
        /// <param name="WaySaveFile">file save path</param>
        public static void Serialization(Sinhronizer obj, string WaySaveFile)
        {
            FileStream      fs        = new FileStream(WaySaveFile, FileMode.Create);
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                formatter.Serialize(fs, obj);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                fs.Close();
            }
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     try
     {
         var sin = Sinhronizer.Create();
         sin.CreateDir();
         sin.Comparisone();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     finally
     {
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Finish");
         Console.ReadKey();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// method for entering new roots
        /// </summary>
        /// <param name="sin">object Sinhronizer</param>
        private static void NewSinhronizer(Sinhronizer sin)
        {
            sin.Reset();
            Console.Write("Press import directory:");
            string importS = Console.ReadLine();

            Console.Write("Press export directory:");
            string exportS = Console.ReadLine();

            if (importS.CompareTo(exportS) == (int)Nums.Zero)
            {
                return;
            }
            sin.import.Root = importS;
            sin.export.Root = exportS;
            sin.import.Open(sin);
            sin.import.Complete = true;
            sin.export.Open(sin);
            sin.export.Complete = true;
        }
Esempio n. 5
0
        /// <summary>
        /// method Deserialize
        /// </summary>
        /// <param name="sin">Deserialize object</param>
        public static void Deserialize(ref Sinhronizer sin)
        {
            FileStream fs = new FileStream(sin.WaySaveFile, FileMode.Open);

            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                sin = (Sinhronizer)formatter.Deserialize(fs);
            }
            catch (SerializationException e)
            {
                fs.Close();
                fs = new FileStream(sin.WaSaveFile2, FileMode.Open);
                BinaryFormatter formatter = new BinaryFormatter();
                sin = (Sinhronizer)formatter.Deserialize(fs);
            }
            finally
            {
                fs.Close();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// method for create object and read Serialize
        /// </summary>
        /// <returns>object type Sinhronizer</returns>
        public static Sinhronizer Create()
        {
            Sinhronizer sin = new Sinhronizer();

            if (File.Exists(sin.WaySaveFile))
            {
                MySerialization.Deserialize(ref sin);
                Console.WriteLine("1)Continue synchronization");
                Console.WriteLine("Import:{0}", sin.import.Root);
                Console.WriteLine("Export:{0}", sin.export.Root);
                Console.WriteLine("2)Resync start");
                int choise = sin.TestChoise();
                if (choise == 2)
                {
                    NewSinhronizer(sin);
                }
            }
            else
            {
                NewSinhronizer(sin);
            }
            MySerialization.Serialization(sin, sin.WaySaveFile);
            return(sin);
        }
 /// <summary>
 /// recursive traversal method
 /// </summary>
 /// <param name="root">root directory</param>
 /// <param name="file">write files</param>
 /// <param name="dir">write directoru</param>
 /// <param name="obj">serialization object</param>
 /// <param name="count">file counter for serialization</param>
 /// <param name="common">flag to continue traversal</param>
 public void WalkRir(DirectoryInfo root, List <string> file, List <string> dir, Sinhronizer obj, int count = (int)Nums.Zero, bool common = false)
 {
     DirectoryInfo[] di    = null;                                                        //array for directory
     FileInfo[]      files = null;                                                        //array for files
     if (!common && dir[dir.Count - (int)Nums.One] == root.FullName)
     {
         common = true;
     }
     try
     {
         files = root.GetFiles();                                                         //add files in array files
     }
     catch (UnauthorizedAccessException e)
     {
         log.Add(e.Message);
     }
     catch (DirectoryNotFoundException e)
     {
         Console.WriteLine(e.Message);
     }
     if (files != null)                                                               //if no files
     {
         if (common)
         {
             foreach (var i in files)
             {
                 if (!file.Contains(i.FullName))
                 {
                     count++;
                     file.Add(i.FullName);
                     this.size++;
                     if (size % (int)Nums.Ten == (int)Nums.Zero)
                     {
                         Waiting();
                     }
                     if (count % (int)Nums.Ten == (int)Nums.Zero)
                     {
                         MySerialization.Serialization(obj, obj.WaySaveFile);                          //serialization 10 files
                     }
                     else if (count % (int)Nums.Fifteen == (int)Nums.Zero)
                     {
                         MySerialization.Serialization(obj, obj.WaSaveFile2);                         //serialization 15 files
                     }
                 }
             }
         }
         di = root.GetDirectories();                                                                  //add all dir root dir
         foreach (var j in di)
         {
             if (dir == null || !dir.Contains(j.FullName))
             {
                 dir.Add(j.FullName);
             }
             WalkRir(j, file, dir, obj, count, common);                                              //add dir in array dirs
         }
     }
 }
 /// <summary>
 /// method of starting recursive traversal
 /// </summary>
 /// <param name="s">root of the bypass folder</param>
 /// <param name="obj">serialization object</param>
 public void Open(Sinhronizer obj)
 {
     base.WalkRir(new DirectoryInfo(this.Root), files, dir, obj, 0, dir.Count == 0);
 }