Exemple #1
0
 private void CompareData(Dictionary <MyFile, MyFileInfo> oldData, Dictionary <MyFile, MyFileInfo> newData)
 {
     try
     {
         foreach (var key in oldData.Keys)
         {
             MyFileInfo newMfi;
             if (newData.TryGetValue(key, out newMfi))
             {
                 MyFileInfo oldMfi = oldData[key]; //возможно, т.к. key из oldData
                                                   //if (oldMfi.LastModifyTimeUtc < newMfi.LastModifyTimeUtc)
                                                   //{
                                                   //    GenerateFileModify(key);
                                                   //}
                 if (oldMfi.isModifedTo(newMfi))
                 {
                     GenerateFileModify(key);
                 }
                 //if (Math.Abs((oldMfi.LastModifyTimeUtc - newMfi.LastModifyTimeUtc).Milliseconds) > 1000)
                 //{
                 //    GenerateFileModify(key);
                 //}
             }
             else
             {
                 GenerateFileDelete(key);
             }
         }
         foreach (var key in newData.Keys)
         {
             MyFileInfo oldMfi;
             if (!oldData.TryGetValue(key, out oldMfi))
             {
                 GenerateFileCreate(key);
             }
         }
         currentData = newData;
     }
     catch (DirectoryNotFoundException exc)
     {
         OnError();
         System.Windows.Forms.MessageBox.Show(exc.Message);
     }
     catch (Exception exc)
     {
         OnError();
         System.Windows.Forms.MessageBox.Show(exc.Message);
     }
 }
Exemple #2
0
 public bool isModifedTo(MyFileInfo mfi)
 {
     if (mfi.size != this.size)
     {
         return(true);
     }
     if (mfi.lastModifyTimeUtc > this.lastModifyTimeUtc)
     {
         if (mfi.MD5 != this.MD5)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #3
0
        private void FillDictionaryWithDir(MyFolder folder, Dictionary <MyFile, MyFileInfo> dict, bool deep = true)
        {
            var files = folder.DirectoryGetFiles;

            foreach (var file in files)
            {
                MyFileInfo mfi = new MyFileInfo(file);
                dict.Add(file, mfi);
            }
            if (deep)
            {
                var dirs = folder.DirectoryGetFolders;
                foreach (var dir in dirs)
                {
                    FillDictionaryWithDir(dir, dict);
                }
            }
        }