/// <summary> /// Generate the sync preview containing actions to be executed. /// The returned SyncPreviewResult can then be passed to Synchronize method /// as an argument for the actions to be executed. /// </summary> /// <exception cref="DirectoryNotFoundException"></exception> public SyncPreviewResult GenerateSyncPreview(StatusCallbackDelegate statusCallback) { OnStatusChanged(new SyncStatusChangedEventArgs(m_ResourceManager.GetString("lbl_peparingToSync"))); // Load actions to be executed. IList <SyncAction> actions = actProvider.Load(_job.SyncSource.ID, SourceOption.SOURCE_ID_NOT_EQUALS); // Generate current folder's metadata FileMetaData currentItems = MetaDataProvider.GenerateFileMetadata(_job.SyncSource.Path, _job.SyncSource.ID, false, statusCallback); // Load current folder metadata from database FileMetaData oldCurrentItems = mdProvider.LoadFileMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_EQUALS); // Load the other folder metadata from database FileMetaData oldOtherItems = mdProvider.LoadFileMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_NOT_EQUALS); return(new SyncPreviewResult(actions, currentItems, oldCurrentItems, oldOtherItems)); }
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; } } }
/// <summary> /// Generates SyncActions to be executed by other PC by comparing the metadata /// of current SyncSource and the metadata of other PC. /// </summary> private IList <SyncAction> GenerateActions() { //Metadata mdCurrent = UpdateSyncSourceMetadata(); //Metadata mdOther = mdProvider.Load(_job.SyncSource.ID, SourceOption.SOURCE_ID_NOT_EQUALS); FileMetaData mdCurrent = MetaDataProvider.GenerateFileMetadata( _job.SyncSource.Path, _job.SyncSource.ID, false, false); FileMetaData mdOldCurrent = mdProvider.LoadFileMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_EQUALS); mdProvider.UpdateFileMetadata(mdOldCurrent, mdCurrent); FileMetaData mdOther = mdProvider.LoadFileMetadata(_job.SyncSource.ID, SourceOption.SOURCE_ID_NOT_EQUALS); //generate list of sync actions by comparing 2 metadata var differences = new FileMetaDataComparer(mdCurrent, mdOther); return(actProvider.Generate(mdCurrent.SourceId, differences.LeftOnly, differences.RightOnly, differences.BothModified)); }