Exemplo n.º 1
0
 private void ExecuteConflictActions(IList <SyncAction> conflictList)
 {
     ExecuteActions(conflictList, a =>
     {
         if (a.ChangeType == ChangeType.NEWLY_CREATED || a.ChangeType == ChangeType.MODIFIED)
         {
             if (a.ConflictResolution == ConflictResolution.DUPLICATE_RENAME)
             {
                 SyncExecutor.DuplicateRenameInSyncFolderAndUpdateActionTable((CreateAction)a, _job);
             }
             else if (a.ConflictResolution == ConflictResolution.OVERWRITE)
             {
                 SyncExecutor.CopyToSyncFolderAndUpdateActionTable((CreateAction)a, _job);
             }
         }
         else if (a.ChangeType == ChangeType.RENAMED)
         {
             if (a.ConflictResolution == ConflictResolution.DUPLICATE_RENAME)
             {
                 SyncExecutor.ConflictRenameAndUpdateActionTable((RenameAction)a, _job, true);
             }
             else if (a.ConflictResolution == ConflictResolution.OVERWRITE)
             {
                 SyncExecutor.ConflictRenameAndUpdateActionTable((RenameAction)a, _job, false);
             }
         }
         else if (a.ChangeType == ChangeType.DELETED)
         {
             SyncExecutor.DeleteFromActionTable((DeleteAction)a, _job);
         }
     });
 }
Exemplo n.º 2
0
 private void ExecuteRenameActions(IList <SyncAction> renameList)
 {
     ExecuteActions(renameList, a =>
     {
         SyncExecutor.RenameInSyncFolderAndUpdateActionTable((RenameAction)a, _job);
     });
 }
Exemplo n.º 3
0
 private void ExecuteCreateActions(IList <SyncAction> copyList)
 {
     ExecuteActions(copyList, a =>
     {
         SyncExecutor.CopyToSyncFolderAndUpdateActionTable((CreateAction)a, _job);
     });
 }
Exemplo n.º 4
0
 private void ExecuteDeleteActions(IList <SyncAction> deleteList)
 {
     ExecuteActions(deleteList, a =>
     {
         SyncExecutor.DeleteInSyncFolderAndUpdateActionTable((DeleteAction)a, _job);
         string absolutePath = _job.IntermediaryStorage.DirtyFolderPath + a.RelativeFilePath;
         Files.FileUtils.DeleteFileAndFolderIfEmpty(_job.IntermediaryStorage.DirtyFolderPath, absolutePath, true);
     });
 }
Exemplo n.º 5
0
        private void SaveActionsAndDirtyFiles(IList <SyncAction> actions)
        {
            FileMetaData fileMetaData = MetaDataProvider.GenerateFileMetadata(_job.IntermediaryStorage.DirtyFolderPath,
                                                                              "", false, true);
            int totalProgress = actions.Count;
            int currProgress  = 0;

            foreach (SyncAction a in actions)
            {
                if (!Validator.SyncJobParamsValidated(_job.Name, _job.IntermediaryStorage.Path, _job.SyncSource.Path, null))
                {
                    return;
                }

                try
                {
                    OnProgressChanged(new SyncProgressChangedEventArgs(++currProgress, totalProgress));
                    OnSyncFileChanged(new SyncFileChangedEventArgs(a.ChangeType, a.RelativeFilePath));

                    FileMetaDataItem item = new FileMetaDataItem("", a.RelativeFilePath, a.FileHash, DateTime.Now, 0, 0);

                    if (a.ChangeType == ChangeType.NEWLY_CREATED && !fileMetaData.MetaDataItems.Contains(item, new FileMetaDataItemComparer()))
                    {
                        SyncExecutor.CopyToDirtyFolderAndUpdateActionTable(a, _job);
                    }
                    else
                    {
                        actProvider.Add(a);
                    }

                    log.Add(new LogActivity(a.RelativeFilePath, a.ChangeType.ToString(), "SUCCESS"));
                }
                catch (OutOfDiskSpaceException)
                {
                    log.Add(new LogActivity(a.RelativeFilePath, a.ChangeType.ToString(), "FAIL"));
                    throw;
                }
                catch (Exception)
                {
                    log.Add(new LogActivity(a.RelativeFilePath, a.ChangeType.ToString(), "FAIL"));
                    throw;
                }
            }
        }
Exemplo n.º 6
0
        private void SyncEmptyFolders()
        {
            //read metadata of the current folder in file system
            FolderMetadata currentItems = MetaDataProvider.GenerateFolderMetadata(_job.SyncSource.Path, _job.SyncSource.ID, false, false, true);

            //read the folder metadata of current folder stored in database
            FolderMetadata oldCurrentItems = mdProvider.LoadFolderMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_EQUALS);

            //read folder metadata of the other source stored in the database
            FolderMetadata otherItems = mdProvider.LoadFolderMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_NOT_EQUALS);

            //get the difference between current folder metadata with its previous state (from previous sync session).
            FolderMetadataComparer comparer1 = new FolderMetadataComparer(oldCurrentItems, currentItems);

            //get the difference between current folder metadata with the other folder's previous metadata
            FolderMetadataComparer compare2 = new FolderMetadataComparer(currentItems, otherItems);


            FolderMetadataComparer comparer3 = new FolderMetadataComparer(oldCurrentItems.FolderMetadataItems, compare2.LeftOnly);
            FolderMetadataComparer comparer4 = new FolderMetadataComparer(compare2.RightOnly, comparer1.LeftOnly);

            List <FolderMetadataItem> temps = comparer3.Both.ToList();

            temps.Sort(new FolderMetadataItemComparer());
            temps.Reverse();

            foreach (FolderMetadataItem item in temps)
            {
                SyncExecutor.DeleteFolder(this._job.SyncSource.Path, item.RelativePath, true);
            }

            foreach (FolderMetadataItem item in comparer4.LeftOnly)
            {
                if (item.IsEmpty == 1)
                {
                    SyncExecutor.CreateFolder(this._job.SyncSource.Path, item.RelativePath);
                }
            }

            currentItems = MetaDataProvider.GenerateFolderMetadata(_job.SyncSource.Path, _job.SyncSource.ID, false,
                                                                   false, true);
            mdProvider.UpdateFolderMetadata(oldCurrentItems, currentItems, false);
        }