public static SyncOrchestrator CreateAgent( FileSyncProvider sourceProvider, FileSyncProvider destinationProvider ) { sourceProvider.AppliedChange += OnAppliedChange; sourceProvider.SkippedChange += OnSkippedChange; destinationProvider.AppliedChange += OnAppliedChange; destinationProvider.SkippedChange += OnSkippedChange; var agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.DownloadAndUpload //SyncDirectionOrder.Upload // Sync source to destination ; Console.WriteLine( "Synchronizing changes between {0} <-> {1}", sourceProvider.RootDirectoryPath, destinationProvider.RootDirectoryPath ); return (agent); }
//Creates/updates metadata file in root folders for synchronization public void DetectChangesInAllRootFolders() { FileSyncProvider provider = null; try { if (RootPathsList != null && RootPathsList.Count > 1) { for (int i = 0; i < RootPathsList.Count; i++) { provider = new FileSyncProvider(RootPathsList[i], Filter, FileSyncOptions.None); provider.DetectChanges(); } } else { throw new Exception("Exception: List of paths is null or contain less than 2 pathes"); } } catch (Exception) { throw; } finally { if (provider != null) { provider.Dispose(); } } }
public override void _sync(object input) { DiskService other = (DiskService)input; var diskSettings = this.DeployerSettings.castTo <DiskServiceSettings>(); var storage = this.GlobalSettings.GetDefaultContentStorage(); // Generate a unique virtual disk for this application DiskServiceSettings otherSettings = other.DeployerSettings.castTo <DiskServiceSettings>(); foreach (var mount in diskSettings.mounts) { string pathOri = UtilsSystem.EnsureDirectoryExists(other.Deployment.GetRuntimeSettingsToDeploy()["services." + otherSettings.id + ".mount.files.path"]); string pathDest = UtilsSystem.EnsureDirectoryExists(this.Deployment.GetRuntimeSettingsToDeploy()["services." + diskSettings.id + ".mount.files.path"]); FileSyncProvider ori = new FileSyncProvider(pathOri); FileSyncProvider dest = new FileSyncProvider(pathDest); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = ori; agent.RemoteProvider = dest; agent.Direction = SyncDirectionOrder.Upload; SyncOperationStatistics syncStats = agent.Synchronize(); this.Logger.LogInfo( true, "Synchronization stats \n\n local provider {0} to remote {1}\n upload changes applied {2}\n {3} upload changes failed", pathOri, pathDest, syncStats.UploadChangesApplied, syncStats.UploadChangesFailed); ori.Dispose(); dest.Dispose(); } }
public void SetLocalSource(string FqDirName) { if (!Directory.Exists(FqDirName)) { Console.WriteLine("Please ensure that the local target directory exists."); throw new ArgumentException("Please ensure that the local target directory exists."); } string _localPathName = FqDirName; FileSyncProvider fileSyncProvider = null; FileSyncScopeFilter filter = new FileSyncScopeFilter(); filter.FileNameExcludes.Add(".*"); filter.FileNameExcludes.Add("filesync.metadata"); // TODO: Exclude subdirectories and remove this hack for (int i = 0; i < 100; i++) { filter.SubdirectoryExcludes.Add("" + i); } try { fileSyncProvider = new FileSyncProvider(_localPathName, filter, new FileSyncOptions()); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), _localPathName, filter, new FileSyncOptions()); } //fileSyncProvider.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(DownloadingFile); orchestrator.LocalProvider = fileSyncProvider; }
public static void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); agent.Synchronize(); } finally { // Release resources if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); } }
public static void synchronize() { string s2 = str[1]; string st = folderA + "\\" + s2; try { FileSyncProvider providerA = new FileSyncProvider(Guid.NewGuid(), st); FileSyncProvider providerB = new FileSyncProvider(Guid.NewGuid(), s); // Ask providers to detect changes providerA.DetectChanges(); providerB.DetectChanges(); // Sync changes SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = providerA; agent.RemoteProvider = providerB; agent.Direction = SyncDirectionOrder.UploadAndDownload; agent.Synchronize(); Console.WriteLine("Files are synchronized"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Synchronize(SyncDirectionOrder syncDirection, KnowledgeSyncProvider localProvider, KnowledgeSyncProvider remoteProvider) { // Register event handlers FileSyncProvider fileSyncProvider = localProvider as FileSyncProvider; fileSyncProvider.AppliedChange += new EventHandler <AppliedChangeEventArgs>(OnAppliedChange); fileSyncProvider.SkippedChange += new EventHandler <SkippedChangeEventArgs>(OnSkippedChange); // Use sync-callbacks for conflicting items SyncCallbacks destCallbacks = localProvider.DestinationCallbacks; destCallbacks.ItemConflicting += new EventHandler <ItemConflictingEventArgs>(OnItemConflicting); destCallbacks.ItemConstraint += new EventHandler <ItemConstraintEventArgs>(OnItemConstraint); // Initiate orchestrator and sync SyncOrchestrator orchestrator = new SyncOrchestrator(); orchestrator.LocalProvider = localProvider; orchestrator.RemoteProvider = remoteProvider; // Set sync direction orchestrator.Direction = syncDirection; // Execute the synchronize process SyncOperationStatistics syncStats = orchestrator.Synchronize(); // Notify a synchronization took place FileSystemSynchronizedEventArgs ev = new FileSystemSynchronizedEventArgs(syncStats); OnSynchronized(orchestrator, ev); }
private void DetectChanges(Guid syncId, string path, FileSyncScopeFilter filter) { using (FileSyncProvider provider = new FileSyncProvider(syncId, path, filter, this.syncOptions)) { provider.DetectChanges(); } }
public static void OneWaySyncFileSystemReplicas(string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider path1Provider = null; FileSyncProvider path2Provider = null; try { path1Provider = new FileSyncProvider(sourceReplicaRootPath, filter, options); path2Provider = new FileSyncProvider(destinationReplicaRootPath, filter, options); path2Provider.SkippedChange += OnSkippedChange; path2Provider.AppliedChange += OnAppliedChange; SyncOrchestrator manager = new SyncOrchestrator(); manager.LocalProvider = path1Provider; manager.RemoteProvider = path2Provider; manager.Direction = SyncDirectionOrder.Upload; manager.Synchronize(); } finally { if (path1Provider != null) { path1Provider.Dispose(); } if (path2Provider != null) { path2Provider.Dispose(); } } }
private static void Main(string[] args) { const string replica1RootPath = "_R0"; const string replica2RootPath = "_R1"; if (Directory.Exists(replica1RootPath)) { Directory.Delete(replica1RootPath, true); } Directory.CreateDirectory(replica1RootPath); if (Directory.Exists(replica2RootPath)) { Directory.Delete(replica2RootPath, true); } Directory.CreateDirectory(replica2RootPath); try { // Set options for the synchronization operation const FileSyncOptions options = FileSyncOptions.ExplicitDetectChanges | FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates | FileSyncOptions.RecycleConflictLoserFiles; var filter = new FileSyncScopeFilter(); //filter.FileNameExcludes.Add("*.lnk"); // Exclude all *.lnk files Guid replica1Guid = Guid.Parse("181517DE-B950-4e62-9582-56F01884288D"); Guid replica2Guid = Guid.Parse("86C9D79E-679D-4d33-A051-AA4EEFF17E55"); using (var provider0 = new FileSyncProvider(replica1Guid, replica1RootPath, filter, options)) { using (var provider1 = new FileSyncProvider(replica2Guid, replica2RootPath, filter, options)) //using (var provider1 = new TestProvider(replica2Guid, Path.Combine(replica2RootPath, "_replica.sdf"))) { var agent = CreateAgent( provider0, provider1 ); while (true) { provider0.DetectChanges(); provider1.DetectChanges(); agent.Synchronize(); Thread.Sleep(25); } } } } catch (Exception e) { Console.WriteLine("\nException from File Synchronization Provider:\n" + e); } }
public void Dispose() { if (Provider != null) { Provider.Dispose(); Provider = null; } }
// Main sync happens here private static void SynchronizeOnce( FileSyncScopeFilter filter, string localPathName, string containerName, CloudStorageAccount storageAccount) { // Setup Provider AzureBlobStore blobStore = new AzureBlobStore(containerName, storageAccount); AzureBlobSyncProvider azureProvider = new AzureBlobSyncProvider(containerName, blobStore); azureProvider.ApplyingChange += new EventHandler <ApplyingBlobEventArgs>(UploadingFile); FileSyncProvider fileSyncProvider = null; if (filter == null) { try { fileSyncProvider = new FileSyncProvider(localPathName); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), localPathName); } } else { try { fileSyncProvider = new FileSyncProvider(localPathName, filter, FileSyncOptions.None); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), localPathName, filter, FileSyncOptions.None); } } fileSyncProvider.ApplyingChange += new EventHandler <ApplyingChangeEventArgs>(WindowsAzureBlob2FileSystemSync.DownloadingFile); try { SyncOrchestrator orchestrator = new SyncOrchestrator(); orchestrator.LocalProvider = fileSyncProvider; orchestrator.RemoteProvider = azureProvider; orchestrator.Direction = SyncDirectionOrder.DownloadAndUpload; orchestrator.Synchronize(); } catch (Exception ex) { Trace.TraceError("Failed to Synchronize. Error: {0}", ex.Message); } finally { fileSyncProvider.Dispose(); } }
private bool ShouldSkip(string mode, FileSyncProvider provider, ApplyingChangeEventArgs args) { //the built-in directory system is lame, you can't just specify the name of the directory //this changes the behavior to do just that if (args.NewFileData != null && args.NewFileData.IsDirectory) { if (_currentGroup.ShouldSkipSubDirectory(args.NewFileData)) { _progress.WriteVerbose("{0} [{1}] Skipping Folder {2}", mode, _currentGroup.Name, GetPathFromArgs(args)); return(true); } return(false); } if (args.CurrentFileData != null && args.CurrentFileData.IsDirectory) { if (_currentGroup.ShouldSkipSubDirectory(args.CurrentFileData)) { _progress.WriteVerbose("{0} [{1}] Skipping Folder {2}", mode, _currentGroup.Name, GetPathFromArgs(args)); return(true); } return(false); } if (args.NewFileData != null) { if (_alreadyAccountedFor.Contains(args.NewFileData.RelativePath)) { _progress.WriteVerbose("[{0}] Skipping new file because it was already backed up by a previous group: {1}", _currentGroup.NewFileCount, GetPathFromArgs(args)); return(true); } if (_currentGroup.ShouldSkipFile(args.NewFileData.RelativePath)) { _progress.WriteVerbose("[{0}] Skipping new file: {1}", _currentGroup.Name, GetPathFromArgs(args)); return(true); } return(false); } if (args.CurrentFileData != null) { if (_alreadyAccountedFor.Contains(args.CurrentFileData.RelativePath)) { _progress.WriteVerbose("Skipping current file because it was already backed up by a previous group: " + args.CurrentFileData.RelativePath + " " + args.CurrentFileData.Name); return(true); } if (_currentGroup.ShouldSkipFile(args.CurrentFileData.RelativePath)) { _progress.WriteVerbose("Skipping current file: " + args.CurrentFileData.RelativePath + " " + args.CurrentFileData.Name); return(true); } } return(false); }
private Guid DetectChanges(string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { if (Provider == null) { Provider = GenerateProvider(); } Provider.DetectChanges(); return(Provider.ReplicaId); }
public void GatherInformation() { _cancelRequested = false; _files = 0; PredictedSpaceInKiloBytes = 0; _totalFilesThatWillBeBackedUp = 0; var options = FileSyncOptions.None; foreach (var group in _groups) { if (_cancelRequested) { break; } _currentSource = group; //used by callbacks group.ClearStatistics(); if (PredictedSpaceInKiloBytes >= _maxInKilobytes) { group.Disposition = FileSource.DispositionChoice.WillBeSkipped; InvokeGroupProgress(); continue; } group.Disposition = FileSource.DispositionChoice.Calculating; InvokeGroupProgress(); using (var sourceProvider = new FileSyncProvider(group.SourceGuid, group.RootFolder, group.Filter, options)) using (var destinationProvider = new FileSyncProvider(group.DestGuid, group.GetDestinationSubFolder(DestinationRootForThisUser), group.Filter, options)) { destinationProvider.PreviewMode = true; destinationProvider.ApplyingChange += (OnDestinationPreviewChange); sourceProvider.DetectingChanges += (x, y) => InvokeProgress(); //just to detect cancel PreviewOrSynchronizeCore(destinationProvider, sourceProvider); } //would this push us over the limit? if (PredictedSpaceInKiloBytes >= _maxInKilobytes) { group.Disposition = FileSource.DispositionChoice.WillBeSkipped; } else { _totalFilesThatWillBeBackedUp += group.UpdateFileCount + group.NewFileCount; group.Disposition = FileSource.DispositionChoice.WillBeBackedUp; } } InvokeGroupProgress(); _files = 0; }
/// <summary> /// Replicates the <see cref="TVA.Historian.IArchive"/>. /// </summary> protected override void ReplicateArchive() { // Connect to remote share if specified. string archiveLocation = ArchiveLocation; string replicaLocation = ReplicaLocation; if (replicaLocation.StartsWith(@"\\") && replicaLocation.Contains(':') && replicaLocation.Contains('@')) { // Format: \\[<domain>\]<username>:<password>@<network share> string share = @"\\" + replicaLocation.Substring(replicaLocation.IndexOf('@') + 1); string login = replicaLocation.Substring(2, replicaLocation.IndexOf(':') - 2); string password = replicaLocation.Substring(replicaLocation.IndexOf(':') + 1, replicaLocation.IndexOf('@') - replicaLocation.IndexOf(':') - 1); replicaLocation = share; string[] loginParts = login.Split('\\'); if (loginParts.Length == 2) FilePath.ConnectToNetworkShare(replicaLocation, loginParts[0], password, loginParts[1]); else FilePath.ConnectToNetworkShare(replicaLocation, login, password, Environment.UserDomainName); } FileSyncProvider syncSource = null; FileSyncProvider syncDestination = null; try { // Setup file synchronization filter. FileSyncScopeFilter synchFilter = new FileSyncScopeFilter(); synchFilter.FileNameIncludes.Add("*_to_*.d"); // Setup file synchronization providers. syncSource = new FileSyncProvider(archiveLocation, synchFilter, FileSyncOptions.CompareFileStreams); syncDestination = new FileSyncProvider(replicaLocation, synchFilter, FileSyncOptions.CompareFileStreams); syncDestination.ApplyingChange += SyncDestination_ApplyingChange; syncDestination.AppliedChange += SyncDestination_AppliedChange; // Setup and start file synchronization agent. SyncOrchestrator syncAgent = new SyncOrchestrator(); syncAgent.LocalProvider = syncSource; syncAgent.RemoteProvider = syncDestination; syncAgent.Direction = SyncDirectionOrder.Upload; syncAgent.Synchronize(); } finally { // Release resource used by synchronization providers. if (syncSource != null) syncSource.Dispose(); if (syncDestination != null) syncDestination.Dispose(); } }
public static void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { // Instantiate source and destination providers, with a null filter (the filter // was specified in DetectChangesOnFileSystemReplica()), and options for both. sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); // Register event handlers so that we can write information // to the console. //destinationProvider.AppliedChange += // new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); //destinationProvider.SkippedChange += // new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); // Use SyncCallbacks for conflicting items. //SyncCallbacks destinationCallbacks = destinationProvider.DestinationCallbacks; //destinationCallbacks.ItemConflicting += new EventHandler<ItemConflictingEventArgs>(OnItemConflicting); //destinationCallbacks.ItemConstraint += new EventHandler<ItemConstraintEventArgs>(OnItemConstraint); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Upload changes from the source to the destination. Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); agent.Synchronize(); } finally { // Release resources. if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
private void PreviewOrSynchronizeCore(FileSyncProvider destinationProvider, FileSyncProvider sourceProvider) { _agent.LocalProvider = sourceProvider; _agent.RemoteProvider = destinationProvider; _agent.Direction = SyncDirectionOrder.Upload; // Synchronize source to destination try { _agent.Synchronize(); } catch (Microsoft.Synchronization.SyncAbortedException err) { //swallow } }
private void button2_Click_1(object sender, EventArgs e) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { FileSyncScopeFilter filter = new FileSyncScopeFilter(); filter.FileNameExcludes.Add("*.metadata"); FileSyncOptions options = FileSyncOptions.None; sourceProvider = new FileSyncProvider(sourceRootPath, filter, options); destinationProvider = new FileSyncProvider(destRootPath, filter, options); //destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); //destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; //agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination agent.Direction = SyncDirectionOrder.DownloadAndUpload; // Sync source to destination Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); agent.Synchronize(); stopwatch.Stop(); this.richTextBox1.Text = "Sync framework test total time:" + stopwatch.ElapsedMilliseconds + "ms"; } catch (Exception exc) { throw exc; } finally { // Release resources if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
private static void DetectChangesOnFileSystemReplica(string replicaPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaPath, filter, options); provider.DetectChanges(); } finally { if (provider != null) { provider.Dispose(); } } }
//Uploads shanges from source to destination private void syncTwoFoldersOneWayUpload(string sourceRootPath, string destinationRootPath) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider(sourceRootPath, Filter, FileSyncOptions.None); destinationProvider = new FileSyncProvider(destinationRootPath, Filter, FileSyncOptions.None); destinationProvider.AppliedChange += FolderSynchronizator_OnAppliedChangeEventHandler; destinationProvider.SkippedChange += FolderSynchronizator_OnSkippedChangeEventHandler; sourceProvider.AppliedChange += FolderSynchronizator_OnAppliedChangeEventHandler; sourceProvider.SkippedChange += FolderSynchronizator_OnSkippedChangeEventHandler; SyncOrchestrator orchrstrator = new SyncOrchestrator(); orchrstrator.Direction = SyncDirectionOrder.Upload; orchrstrator.LocalProvider = sourceProvider; orchrstrator.RemoteProvider = destinationProvider; OnStartingTwoFoldersSynchronizationOneWayEventHandler("Upload", sourceRootPath, destinationRootPath); orchrstrator.Synchronize(); } catch (Exception e) { throw e; } finally { if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } destinationProvider.AppliedChange -= FolderSynchronizator_OnAppliedChangeEventHandler; destinationProvider.SkippedChange -= FolderSynchronizator_OnSkippedChangeEventHandler; sourceProvider.AppliedChange -= FolderSynchronizator_OnAppliedChangeEventHandler; sourceProvider.SkippedChange -= FolderSynchronizator_OnSkippedChangeEventHandler; }
public static void DetectChangesOnFileSystemReplica( string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaRootPath, filter, options); provider.DetectChanges(); } finally { // Release resources if (provider != null) provider.Dispose(); } }
/// <summary> /// Detect the changes done to the folder /// <para>Updates the metadata</para> /// </summary> /// <param name="replicaRootPath">This parameter is the folder path to be checked</param> /// <param name="filter">This parameter is the filter which will be used during synchronization</param> /// <param name="options">This parameter holds the synchronization options</param> private static void DetectChangesonFileSystemReplica(string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaRootPath, filter, options); provider.DetectChanges(); } finally { // Release resources or memory if (provider != null) { provider.Dispose(); } } }
public static void DetectChangesOnFileSystemReplica(string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, string metadataPath, string metadataFile, string tempDir, string trashDir) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaRootPath, filter, options, metadataPath, metadataFile, tempDir, trashDir); provider.DetectChanges(); } finally { // Release resources if (provider != null) { provider.Dispose(); } } }
/// <summary> /// Synchronize two folders (source and destination). The sync operation is ONE WAY only (From source to destination) /// </summary> /// <param name="sourceReplicaRootPath">source syncing path</param> /// <param name="destinationReplicaRootPath">destination syncing path</param> /// <param name="filter">syncing filter</param> /// <param name="options">syncing options</param> private void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); destinationProvider.AppliedChange += new EventHandler <AppliedChangeEventArgs>(OnAppliedChange); destinationProvider.SkippedChange += new EventHandler <SkippedChangeEventArgs>(OnSkippedChange); destinationProvider.ApplyingChange += DestinationProvider_ApplyingChange; SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination var ret = agent.Synchronize(); if (ret.UploadChangesTotal != 0) { Logger.Log("Synchronizing '{0}', tot changes={1} ({2} done/{3} errors)", LogInfo.Info, VerbosityInfoLevel.V3, destinationProvider.RootDirectoryPath, ret.UploadChangesTotal, ret.UploadChangesApplied, ret.UploadChangesFailed); } } finally { // Release resources if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
/// <summary> /// Start the synchronization in one direction /// </summary> /// <param name="sourcePath">This parameter holds the source folder path</param> /// <param name="destPath">This parameter holds the destination folder path</param> /// <param name="filter">This parameter is the filter which will be used during synchronization</param> /// <param name="options">This parameter holds the synchronization options</param> private void SyncFileSystemReplicasOneWay(string sourcePath, string destPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destProvider = null; try { sourceProvider = new FileSyncProvider(sourcePath, filter, options); destProvider = new FileSyncProvider(destPath, filter, options); sourceProvider.PreviewMode = true; destProvider.PreviewMode = true; destProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined; SyncCallbacks destinationCallBacks = destProvider.DestinationCallbacks; destinationCallBacks.ItemConflicting += new EventHandler <ItemConflictingEventArgs>(OnItemConflicting); destinationCallBacks.ItemConstraint += new EventHandler <ItemConstraintEventArgs>(OnItemConstraint); destProvider.ApplyingChange += new EventHandler <ApplyingChangeEventArgs>(OnApplyingChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destProvider; agent.Direction = SyncDirectionOrder.Upload; agent.Synchronize(); } finally { if (sourceProvider != null) { sourceProvider.Dispose(); } if (destProvider != null) { destProvider.Dispose(); } } }
public static void GravarMetadados(string pasta, FileSyncScopeFilter filtro) { FileSyncProvider provider = null; const FileSyncOptions opcoes = FileSyncOptions.ExplicitDetectChanges | FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates | FileSyncOptions.RecycleConflictLoserFiles; try { provider = new FileSyncProvider(pasta, filtro, opcoes); provider.DetectChanges(); } finally { if (provider != null) provider.Dispose(); } }
public void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); destinationProvider.AppliedChange += new EventHandler <AppliedChangeEventArgs>(OnAppliedChange); destinationProvider.SkippedChange += new EventHandler <SkippedChangeEventArgs>(OnSkippedChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.DownloadAndUpload; // Sync source to destination //Console.WriteLine("Synchronizing changes to replica: " + // destinationProvider.RootDirectoryPath); logException.LogExceptionToDisk("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); agent.Synchronize(); } finally { // Release resources if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
public bool Synchronize(String source, String destination) { SyncOperationStatistics syncOperationStatistics; //Assign Unique Guids to the source and destination replicas sourceReplicaID = GetReplicaID(Path.Combine(source, "ReplicaID")); destinationReplicaID = GetReplicaID(Path.Combine(destination, "ReplicaID")); //Create the source Sync Provider, attach the path and assign the ReplicaID sourceProvider = new FileSyncProvider(sourceReplicaID, source); //Create the destination Sync Provider, attach the path and assign the ReplicaID destinationProvider = new FileSyncProvider(destinationReplicaID, destination); SyncOrchestrator synchronizationAgent = new SyncOrchestrator(); synchronizationAgent.LocalProvider = sourceProvider; synchronizationAgent.RemoteProvider = destinationProvider; try { syncOperationStatistics = synchronizationAgent.Synchronize(); } catch (Microsoft.Synchronization.SyncException se) { //MessageBox.Show(se.Message, "Sync Files - Error"); return(false); } finally { // Release resources once done if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } return(true); }
public void DetectChangesOnFileSystemReplica( Guid replicaId, string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaId, replicaRootPath, filter, options); provider.DetectChanges(); } finally { // Release resources if (provider != null) { provider.Dispose(); } } }
public void SyncFileSystemReplicasOneWay( Guid sourceReplicaId, Guid destinationReplicaId, string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaId, sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaId, destinationReplicaRootPath, filter, options); destinationProvider.AppliedChange += OnAppliedChange; destinationProvider.SkippedChange += OnSkippedChange; var agent = new SyncOrchestrator { LocalProvider = sourceProvider, RemoteProvider = destinationProvider, Direction = SyncDirectionOrder.Upload }; InfoFormat("Synchronizing changes to replica: {0}", destinationProvider.RootDirectoryPath); agent.Synchronize(); } finally { // Release resources if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
public static void DetectChangesOnFileSystemReplica( SyncId syncid, string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, DirectoryInfo syncDir, string metadataName) { FileSyncProvider provider = null; try { provider = new FileSyncProvider( syncid.GetGuidId(), replicaRootPath, filter, options, syncDir.FullName, metadataName, syncDir.FullName, null); provider.DetectChanges(); } finally { // Release resources if (provider != null) provider.Dispose(); } }
private void SyncFiles(Guid sourceSyncId, Guid destinationSyncId, FileSyncScopeFilter filter) { using (FileSyncProvider sourceProvider = new FileSyncProvider(sourceSyncId, this.Source.GetMetadata("FullPath"), filter, this.syncOptions)) { using (FileSyncProvider destinationProvider = new FileSyncProvider(destinationSyncId, this.Destination.GetMetadata("FullPath"), filter, this.syncOptions)) { if (this.ShowOutput) { // Hook up some events so the user can see what is happening destinationProvider.AppliedChange += this.OnAppliedChange; destinationProvider.SkippedChange += this.OnSkippedChange; sourceProvider.AppliedChange += this.OnAppliedChange; sourceProvider.SkippedChange += this.OnSkippedChange; } SyncOrchestrator agent = new SyncOrchestrator { LocalProvider = sourceProvider, RemoteProvider = destinationProvider, Direction = this.direction }; agent.Synchronize(); } } }
private static void SyncFileSystemReplicaOneWay(string replicaSourcePath, string replicaTargetPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider targetProvider = null; try { sourceProvider = new FileSyncProvider(replicaSourcePath, filter, options); targetProvider = new FileSyncProvider(replicaTargetPath, filter, options); targetProvider.AppliedChange += new EventHandler <AppliedChangeEventArgs>(OnAppliedChange); targetProvider.SkippedChange += new EventHandler <SkippedChangeEventArgs>(OnSkippedChange); SyncCallbacks targetCallbacks = targetProvider.DestinationCallbacks; targetCallbacks.ItemConflicting += new EventHandler <ItemConflictingEventArgs>(OnItemConflicting); targetCallbacks.ItemConstraint += new EventHandler <ItemConstraintEventArgs>(OnItemConstraint); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = targetProvider; agent.Direction = SyncDirectionOrder.Upload; Console.WriteLine("Sincronizando cambios: {0}", targetProvider.RootDirectoryPath); agent.Synchronize(); } finally { if (sourceProvider != null) { sourceProvider.Dispose(); } if (targetProvider != null) { targetProvider.Dispose(); } } }
public static void Sincronizar(string pastaOrigem, string pastaDestino, FileSyncScopeFilter filtro) { FileSyncProvider providerOrigem = null; FileSyncProvider providerDestino = null; try { const FileSyncOptions opcoes = FileSyncOptions.ExplicitDetectChanges | FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates | FileSyncOptions.RecycleConflictLoserFiles; providerOrigem = new FileSyncProvider(pastaOrigem, filtro, opcoes); providerDestino = new FileSyncProvider(pastaDestino, filtro, opcoes); providerDestino.AppliedChange += OnAppliedChange; providerDestino.SkippedChange += OnSkippedChange; var agent = new SyncOrchestrator { LocalProvider = providerOrigem, RemoteProvider = providerDestino, Direction = SyncDirectionOrder.Upload }; Console.WriteLine("Sincronizando: {0}", providerDestino.RootDirectoryPath); agent.Synchronize(); } finally { if (providerOrigem != null) providerOrigem.Dispose(); if (providerDestino != null) providerDestino.Dispose(); } }
//public static void SyncFileSystemReplicasOneWay(string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, string metadataPath1, string metadataFile1, string metadataPath2, string metadataFile2, string tempDir = null, string trashDir = null) //{ // FileSyncProvider sourceProvider = null; // FileSyncProvider destProvider = null; // try // { // sourceProvider = new FileSyncProvider(sourceReplicaRootPath, filter, options); // destProvider = new FileSyncProvider(destinationReplicaRootPath, filter, options); // sourceProvider.DetectChanges(); // destProvider.DetectChanges(); // //启动和控制同步会话。 // SyncOrchestrator agent = new SyncOrchestrator(); // agent.LocalProvider = sourceProvider; // agent.RemoteProvider = destProvider; // agent.Direction = SyncDirectionOrder.Upload; // agent.Synchronize(); //此处开始执行文件(夹)同步。 // } // finally // { // if (sourceProvider != null) sourceProvider.Dispose(); // if (destProvider != null) destProvider.Dispose(); // } //} public static void SyncFileSystemReplicasOneWay(string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, string metadataPath1, string metadataFile1, string metadataPath2, string metadataFile2, string tempDir, string trashDir, ref SyncOperationStatistics syncOperationStatistics) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider(sourceReplicaRootPath, filter, options, metadataPath1, metadataFile1, tempDir, trashDir); destinationProvider = new FileSyncProvider(destinationReplicaRootPath, filter, options, metadataPath2, metadataFile2, tempDir, trashDir); //destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); //destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); syncOperationStatistics = agent.Synchronize(); } catch (Exception e) { throw e; } finally { // Release resources if (sourceProvider != null) { sourceProvider.Dispose(); } if (destinationProvider != null) { destinationProvider.Dispose(); } } }
private void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); destinationProvider.CopyingFile += new EventHandler<CopyingFileEventArgs>(OnCopyingFile); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; agent.Synchronize(); notifier.NotifyInfo("Backup in progress.."); } catch(Exception ex) { notifier.NotifyError(ex.Message); } finally { if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); } }
private void Synchronize(bool startFromScratch = false) { lock (startSyncLock) { if (isSyncing) { changesWhileSync = true; return; } isSyncing = true; changesWhileSync = false; } if (SyncStarted != null) { SyncStarted(this, null); } if (startFromScratch) { if (File.Exists(metadataFile)) { File.Delete(metadataFile); } } var fileProvider = new FileSyncProvider( localFolder, new FileSyncScopeFilter(), FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecycleConflictLoserFiles, Path.GetDirectoryName(metadataFile), Path.GetFileName(metadataFile), Path.GetTempPath(), null ); fileProvider.AppliedChange += (s, e) => AppliedChange(s, e.ChangeType, e.OldFilePath, e.NewFilePath); fileProvider.SkippedChange += (s, e) => { var t = e; }; var remote = new MegaKnowledgeProvider(remoteStore); if (startFromScratch) { remote.ResetDatabase(); } remote.AppliedChange += (s, e) => AppliedChange(s, e.ChangeType, e.OldFilePath, e.NewFilePath); // do we need this? remote.DestinationCallbacks.ItemConstraint += (s, e) => { e.SetResolutionAction(ConstraintConflictResolutionAction.SkipChange); }; remote.DestinationCallbacks.ItemConflicting += (s, e) => { e.SetResolutionAction(ConflictResolutionAction.Merge); }; try { var agent = new SyncOrchestrator(); agent.RemoteProvider = remote; agent.Direction = SyncDirectionOrder.UploadAndDownload; agent.LocalProvider = fileProvider; var status = agent.Synchronize(); remoteStore.CleanTemp(); if (remote.NeedResync) { syncTimer.Stop(); syncTimer.Start(); } } catch (Exception e) { remote.ResetDatabase(); if (File.Exists(metadataFile)) { File.Delete(metadataFile); } OnError("Sync has encountered a severe problem. Trying to resync from scratch...", e); syncTimer.Stop(); syncTimer.Start(); } finally { fileProvider.Dispose(); remote = null; lock (startSyncLock) { if (changesWhileSync) { syncTimer.Stop(); syncTimer.Start(); } isSyncing = false; } if (SyncEnded != null) { SyncEnded(this, null); } } }
/// <summary> /// Start the synchronization in one direction /// </summary> /// <param name="sourcePath">This parameter holds the source folder path</param> /// <param name="destPath">This parameter holds the destination folder path</param> /// <param name="filter">This parameter is the filter which will be used during synchronization</param> /// <param name="options">This parameter holds the synchronization options</param> /// <param name="isPreview">This parameter is a boolean which indicates if this method should be run in preview mode</param> /// <returns>Returns a boolean to indicate if the the synchronization was successful</returns> private bool SyncFileSystemReplicasOneWay(string sourcePath, string destPath, FileSyncScopeFilter filter, FileSyncOptions options, bool isPreview) { FileSyncProvider sourceProvider = null; FileSyncProvider destProvider = null; try { sourceProvider = new FileSyncProvider(sourcePath, filter, options); destProvider = new FileSyncProvider(destPath, filter, options); // When it's in preview mode, no actual changes are done. // This mode is used to compute the number of changes that will be carried out later if (isPreview) { sourceProvider.PreviewMode = true; destProvider.PreviewMode = true; } else { sourceProvider.PreviewMode = false; destProvider.PreviewMode = false; } if (isPreview) { if (!isCheckForLeftDone) { freeDiskSpaceForLeft = GetFreeDiskSpaceInBytes(sourcePath.Substring(0, 1)); freeDiskSpaceForRight = GetFreeDiskSpaceInBytes(destPath.Substring(0, 1)); } } destProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined; SyncCallbacks destinationCallBacks = destProvider.DestinationCallbacks; destinationCallBacks.ItemConflicting += new EventHandler<ItemConflictingEventArgs>(OnItemConflicting); if (isPreview) destProvider.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(OnApplyingChange); else destProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destProvider; agent.Direction = SyncDirectionOrder.Upload; agent.Synchronize(); if (isPreview) return CheckSpace(); return true; } catch (SyncAbortedException e) { throw e; } finally { if (sourceProvider != null) sourceProvider.Dispose(); if (destProvider != null) destProvider.Dispose(); } }
/// <summary> /// Start the synchronization in one direction /// </summary> /// <param name="sourcePath">This parameter holds the source folder path</param> /// <param name="destPath">This parameter holds the destination folder path</param> /// <param name="filter">This parameter is the filter which will be used during synchronization</param> /// <param name="options">This parameter holds the synchronization options</param> private void SyncFileSystemReplicasOneWay(string sourcePath, string destPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destProvider = null; try { sourceProvider = new FileSyncProvider(sourcePath, filter, options); destProvider = new FileSyncProvider(destPath, filter, options); sourceProvider.PreviewMode = true; destProvider.PreviewMode = true; destProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined; SyncCallbacks destinationCallBacks = destProvider.DestinationCallbacks; destinationCallBacks.ItemConflicting += new EventHandler<ItemConflictingEventArgs>(OnItemConflicting); destinationCallBacks.ItemConstraint += new EventHandler<ItemConstraintEventArgs>(OnItemConstraint); destProvider.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(OnApplyingChange); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destProvider; agent.Direction = SyncDirectionOrder.Upload; agent.Synchronize(); } finally { if (sourceProvider != null) sourceProvider.Dispose(); if (destProvider != null) destProvider.Dispose(); } }
private void SyncFileSystemReplicasOneWay(string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { // Instantiate source and destination providers, with a null filter (the filter // was specified in DetectChangesOnFileSystemReplica()), and options for both. sourceProvider = new FileSyncProvider(sourceReplicaRootPath, filter, options); destinationProvider = new FileSyncProvider(destinationReplicaRootPath, filter, options); // Register event handlers so that we can write information // to the console. destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); // Use SyncCallbacks for conflicting items. SyncCallbacks destinationCallbacks = destinationProvider.DestinationCallbacks; destinationCallbacks.ItemConflicting += new EventHandler<ItemConflictingEventArgs>(OnItemConflicting); destinationCallbacks.ItemConstraint += new EventHandler<ItemConstraintEventArgs>(OnItemConstraint); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Upload changes from the source to the destination. //Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); if (logger != null) { logger.Info("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); } agent.Synchronize(); } finally { // Release resources. if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); } }
public FileSyncProvider AttachDetectedChangeEventHandler(FileSyncProvider provider) { //throw new NotImplementedException(); provider.DetectedChanges += new EventHandler<DetectedChangesEventArgs>(OnDetectedChange); return provider; }
public void BigTest() { NinjectReg = new Registrator(); var FileEngine = NinjectReg.kernel.Get<FileEngine>(); FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( @"C:\testSource", null, FileEngine.SetOptions()); destinationProvider = new FileSyncProvider( @"C:\targetDir", null, FileEngine.SetOptions()); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination Console.WriteLine("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); //agent.Synchronize(); Assert.IsTrue(true); } finally { // Release resources if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); } }
public bool DetectChanges(FileSyncProvider provider) { //throw new NotImplementedException(); try { provider = AttachDetectedChangeEventHandler(provider); provider.DetectChanges(); } finally { // Release resources DisposeProvider(provider); } return true; }
public void DisposeProvider(FileSyncProvider provider) { //throw new NotImplementedException(); if (provider != null) provider.Dispose(); }
//This is our way of abstracting out this dependency since I'm sure it probably ties // us to the filesystem. private FileSyncProvider createFileSyncProvider(Guid replicaId, string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { var provider = new FileSyncProvider(replicaId, replicaRootPath, filter, options); return provider; }
public FileSyncProvider SetPreviewModeFlag(FileSyncProvider provider, bool flag) { //throw new NotImplementedException(); provider.PreviewMode = flag; return provider; }
private void Synchronize() { if (isSyncing) { return; } isSyncing = true; if (SyncStarted != null) { SyncStarted(this, null); } FileSyncProvider fileProvider = null; try { fileProvider = new FileSyncProvider( localFolder, new FileSyncScopeFilter(), FileSyncOptions.RecycleDeletedFiles| FileSyncOptions.RecycleConflictLoserFiles, Path.GetDirectoryName(metadataFile), Path.GetFileName(metadataFile), Path.GetTempPath(), null ); } catch (Exception e) { OnError("Could not initialize the FileSyncProvider. Check the sync framework install", e); return; } fileProvider.AppliedChange += local_AppliedChange; if (remote == null) { try { remote = new MegaProvider(api, remoteFolder); remote.ChangePerformed += (s, e) => Notify(e.Message, false); remote.ChangeError += (s, e) => Notify("Error: " + e.Message, false); remote.ProgressChanged += (s, e) => OnProgressChanged(); } catch (Exception e) { OnError("Could not initialize the MegaProvider. Check the sync framework install", e); return; } } try { var agent = new SyncOrchestrator(); agent.RemoteProvider = remote; agent.Direction = SyncDirectionOrder.UploadAndDownload; agent.LocalProvider = fileProvider; agent.Synchronize(); } catch (Exception e) { OnError("Synchronization error", e); remote.ResetState(); } finally { isSyncing = false; fileProvider.Dispose(); if (SyncEnded != null) { SyncEnded(this, null); } } }
public static void OneWaySyncFileSystemReplicas(string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider path1Provider = null; FileSyncProvider path2Provider = null; try { path1Provider = new FileSyncProvider(sourceReplicaRootPath, filter, options); path2Provider = new FileSyncProvider(destinationReplicaRootPath, filter, options); path2Provider.SkippedChange += OnSkippedChange; path2Provider.AppliedChange += OnAppliedChange; SyncOrchestrator manager = new SyncOrchestrator(); manager.LocalProvider = path1Provider; manager.RemoteProvider = path2Provider; manager.Direction = SyncDirectionOrder.Upload; manager.Synchronize(); } finally { if (path1Provider != null) path1Provider.Dispose(); if (path2Provider != null) path2Provider.Dispose(); } }
public static void SyncFileSystemReplicasOneWay( SyncId sourceId, SyncId destId, string sourceReplicaRootPath, string destinationReplicaRootPath, DirectoryInfo syncDir, string sourceMetadata, string targetMetadata, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceId.GetGuidId(), sourceReplicaRootPath, filter, options, syncDir.FullName, sourceMetadata, syncDir.FullName, null); destinationProvider = new FileSyncProvider( destId.GetGuidId(), destinationReplicaRootPath, filter, options, syncDir.FullName, targetMetadata, syncDir.FullName, null); destinationProvider.AppliedChange += OnAppliedChange; destinationProvider.SkippedChange += OnSkippedChange; SyncOrchestrator agent = new SyncOrchestrator { LocalProvider = sourceProvider, RemoteProvider = destinationProvider, Direction = SyncDirectionOrder.Upload }; // Sync source to destination //Console.WriteLine("Synchronizing changes to replica: " + // destinationProvider.RootDirectoryPath); agent.Synchronize(); } finally { // Release resources if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); } }
//public static void DetectChangesOnFileSystemReplica( //string replicaRootPath, //FileSyncScopeFilter filter, FileSyncOptions options) //{ // FileSyncProvider provider = null; // try // { // provider = new FileSyncProvider(replicaRootPath, filter, options); // provider.DetectChanges(); // } // finally // { // // Release resources // if (provider != null) // provider.Dispose(); // } //} public static void SyncFileSystemReplicasOneWay( string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; try { sourceProvider = new FileSyncProvider( sourceReplicaRootPath, filter, options); //filter.SubdirectoryExcludes.Add(@".\"); destinationProvider = new FileSyncProvider( destinationReplicaRootPath, filter, options); sourceProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange); sourceProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); sourceProvider.DetectChanges(); sourceProvider.CopyingFile += (s, a) => { string file = a.FilePath; int percent = a.PercentCopied; }; sourceProvider.AppliedChange += (s, a) => { string file = a.NewFilePath; var change = a.ChangeType; }; sourceProvider.DetectedChanges += (s, a) => { //a.TotalDirectoriesFound }; destinationProvider.CopyingFile += (s, a) => { string file = a.FilePath; int percent = a.PercentCopied; FileIO.FileTransferProgress(null, new FileTransferProgressEventArgs(percent, Path.GetFileName(file))); }; destinationProvider.AppliedChange += (s, a) => { string file = a.NewFilePath; }; destinationProvider.AppliedChange += (s, a) => { if (a.ChangeType == ChangeType.Delete) return; string file = a.NewFilePath; string serverPath = FileIO.GetPath(destinationReplicaRootPath) + file; if (FileIO.IsDirectory(serverPath)) return; FileIO.FinshedFileTransfer(null, new FinshedFileTransferEventArgs(Path.GetFileName(serverPath))); string localDirectory = FileIO.GetPath(FileIO.GetPath(sourceReplicaRootPath) + file); string localFile = localDirectory + Path.GetFileName(file); string topLevelDir = FileIO.GetPath(sourceReplicaRootPath) + FileIO.GetTopLevelFolder(file); try { File.Delete(localFile); } catch (Exception ex) { Logging.Log(ex.Message); } if (topLevelDir == FileIO.GetPath(sourceReplicaRootPath)) return; //bool isMoreTransfers = filter.FileNameIncludes.Any(x => Directory.GetFiles(localDirectory, x) != null); foreach(string filterVal in filter.FileNameIncludes) { if (Directory.EnumerateFiles(topLevelDir, filterVal, SearchOption.AllDirectories).Count() > 0) return; } //if (isMoreTransfers) return; try { FileIO.ForceDeleteDirectory(topLevelDir); } catch (Exception ex) { Logging.Log(ex.Message); } }; //SyncOrchestrator agent = new SyncOrchestrator(); _agent.LocalProvider = sourceProvider; _agent.RemoteProvider = destinationProvider; _agent.Direction = SyncDirectionOrder.Upload; Logging.Log("Synchronizing changes to replica: " + destinationProvider.RootDirectoryPath); _agent.StateChanged += (s, a) => { if (a.OldState == SyncOrchestratorState.Uploading && a.NewState == SyncOrchestratorState.Ready) { string path = FileIO.GetPath(destinationReplicaRootPath); string metadataFile = path + _metadataFile; try { Logging.Log("Syncronization complete, cleanning up..."); File.Delete(metadataFile); foreach (string tmpFile in Directory.EnumerateFiles(path, "*.tmp")) { File.Delete(tmpFile); } //FileSync.WatchFileSystem(sourceReplicaRootPath, destinationReplicaRootPath); } catch (Exception ex) { Logging.LogError(ex.Message); } } }; _agent.SessionProgress += (s, a) => { uint p = a.CompletedWork; }; _agent.Synchronize(); //keep background worker alive //while (true) { }; } catch (Exception ex) { Logging.Log(ex.Message); } finally { // Release resources if (sourceProvider != null) sourceProvider.Dispose(); if (destinationProvider != null) destinationProvider.Dispose(); //if (_agent != null) _agent.Cancel(); _agent = null; } }
// Main sync happens here private static void SynchronizeOnce( FileSyncScopeFilter filter, string localPathName, string containerName, CloudStorageAccount storageAccount) { // Setup Provider AzureBlobStore blobStore = new AzureBlobStore(containerName, storageAccount); AzureBlobSyncProvider azureProvider = new AzureBlobSyncProvider(containerName, blobStore); azureProvider.ApplyingChange += new EventHandler<ApplyingBlobEventArgs>(UploadingFile); FileSyncProvider fileSyncProvider = null; if (filter == null) { try { fileSyncProvider = new FileSyncProvider(localPathName); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), localPathName); } } else { try { fileSyncProvider = new FileSyncProvider(localPathName, filter, FileSyncOptions.None); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), localPathName, filter, FileSyncOptions.None); } } fileSyncProvider.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(WindowsAzureBlob2FileSystemSync.DownloadingFile); try { SyncOrchestrator orchestrator = new SyncOrchestrator(); orchestrator.LocalProvider = fileSyncProvider; orchestrator.RemoteProvider = azureProvider; orchestrator.Direction = SyncDirectionOrder.DownloadAndUpload; orchestrator.Synchronize(); } catch (Exception ex) { Trace.TraceError("Failed to Synchronize. Error: {0}", ex.Message); } finally { fileSyncProvider.Dispose(); } }
public SyncOrchestrator CreateSyncOrchestrator(FileSyncProvider source, FileSyncProvider destination) { //throw new NotImplementedException(); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = source; agent.RemoteProvider = destination; return agent; }
public FileSyncProvider AttachSkippedChangeEventHandler(FileSyncProvider provider) { //throw new NotImplementedException(); provider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); return provider; }
public FileSyncProvider AttachApplyingChangeEventHandler(FileSyncProvider provider) { //throw new NotImplementedException(); provider.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(OnApplyingChange); return provider; }
public FileSyncProvider CreateProvider(string RootPath, FileSyncScopeFilter filter, FileSyncOptions options) { //throw new NotImplementedException(); FileSyncProvider provider = null; try { provider = new FileSyncProvider(RootPath, filter, options); } catch (Exception e) { throw e; } return provider; }
private void synchronizeProviders(FileSyncProvider destinationProvider, FileSyncProvider sourceProvider) { var sync = new SyncOrchestrator { LocalProvider = sourceProvider, RemoteProvider = destinationProvider, Direction = SyncDirectionOrder.Upload }; sync.Synchronize(); }