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 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 CleanUp() { if (remotePro != null) { remotePro.Dispose(); } if (localPro != null) { localPro.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 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; }
/// <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) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(replicaRootPath, filter, options); provider.DetectChanges(); } finally { // Release resources 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(); } } }
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(); } }
/// <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 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 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 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(); } }
//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(); } } }
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(); } }
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(); } } }
/// <summary> /// This method is called when changes are going to be done to a file /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnApplyingChange(object sender, ApplyingChangeEventArgs args) { FileSyncProvider provider = null; string rootPath = null; try { provider = (FileSyncProvider)sender; rootPath = provider.RootDirectoryPath; switch (args.ChangeType) { case ChangeType.Delete: fileData.Add(new FileData(rootPath, args.CurrentFileData.Name, args.CurrentFileData.RelativePath, Changes.Delete, args.CurrentFileData.IsDirectory)); break; case ChangeType.Create: fileData.Add(new FileData(rootPath, args.NewFileData.Name, args.NewFileData.RelativePath, Changes.Create, args.NewFileData.IsDirectory)); break; case ChangeType.Update: fileData.Add(new FileData(rootPath, args.NewFileData.Name, args.NewFileData.RelativePath, Changes.Update, args.NewFileData.IsDirectory)); break; case ChangeType.Rename: fileData.Add(new FileData(rootPath, args.NewFileData.Name, args.NewFileData.RelativePath, Changes.Rename, args.NewFileData.IsDirectory)); break; } } finally { provider.Dispose(); } }
private void SyncFileSystem( string sourcePath, string destinationPath) { FileSyncProvider sourceProvider = null; FileSyncProvider destinationProvider = null; FileSyncScopeFilter filter = new FileSyncScopeFilter(); filter.FileNameIncludes.Add("*.zip"); FileSyncOptions options = FileSyncOptions.None; try { sourceProvider = new FileSyncProvider( sourcePath, filter, options); destinationProvider = new FileSyncProvider( destinationPath, filter, options); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Upload; agent.Synchronize(); } finally { 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(); } }
// Create a provider, and detect changes on the replica that the provider // represents. public static void DetectChangesOnFileSystemReplica( string replicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; //FileSyncProvider provider; try { //3provider = new FileSyncProvider("C:\\inetpub\\wwwroot\\MAKRO\\Repository"); provider = new FileSyncProvider(replicaRootPath, filter, options); //1provider = new FileSyncProvider(replicaRootPath); 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); 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 SyncFileSystems( string source, string dest, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider sourceProvider = null; FileSyncProvider destProvider = null; try { sourceProvider = new FileSyncProvider(source, filter, options); destProvider = new FileSyncProvider(dest, filter, options); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destProvider; agent.Direction = SyncDirectionOrder.Upload; destProvider.AppliedChange += destProvider_AppliedChange; destProvider.SkippedChange += destProvider_SkippedChange; // call backs so we can monitor... SyncCallbacks destCallbacks = destProvider.DestinationCallbacks; destCallbacks.ItemConflicting += destCallbacks_ItemConflicting; destCallbacks.ItemConstraint += destCallbacks_ItemConstraint; Console.WriteLine("sync to {0} from {1}", source, dest); agent.Synchronize(); } finally { if (sourceProvider != null) sourceProvider.Dispose(); if ( destProvider != null ) destProvider.Dispose() ; } }
/// <summary> /// Tries to initialize folder pair, result is set via State /// </summary> private void Init() { try { State = SyncPairState.Initializing; // verify paths LocalPath = Path.GetFullPath(LocalPath); RemotePath = Path.GetFullPath(RemotePath); String metafileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Consts.Application.ProfileFolder); String localMetadataFile = String.Format(Consts.Application.MetadataFileFormat, LocalGUID.ToString()); String remoteMetadataFile = String.Format(Consts.Application.MetadataFileFormat, RemoteGUID.ToString()); // set sync framework environment FileSyncScopeFilter filterLocal = new FileSyncScopeFilter(); FileSyncScopeFilter filterRemote = new FileSyncScopeFilter(); if (!Directory.Exists(metafileFolder)) { Directory.CreateDirectory(metafileFolder); } if (localProvider != null) { localProvider.Dispose(); localProvider = null; } if (remoteProvider != null) { remoteProvider.Dispose(); remoteProvider = null; } localProvider = new FileSyncProvider(LocalGUID, LocalPath, filterLocal, FileSyncOptions.RecycleConflictLoserFiles | FileSyncOptions.RecycleDeletedFiles, metafileFolder, localMetadataFile, LocalPath, null); remoteProvider = new FileSyncProvider(RemoteGUID, RemotePath, filterRemote, FileSyncOptions.RecycleConflictLoserFiles | FileSyncOptions.RecycleDeletedFiles, metafileFolder, remoteMetadataFile, RemotePath, null); localProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins; remoteProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins; if (Strategy.AutoSync) { if (localFSWatcher != null) { localFSWatcher.Dispose(); localFSWatcher = null; } if (remoteFSWatcher != null) { remoteFSWatcher.Dispose(); remoteFSWatcher = null; } localFSWatcher = new FileSystemWatcher(LocalPath); remoteFSWatcher = new FileSystemWatcher(RemotePath); localFSWatcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size; remoteFSWatcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size; localFSWatcher.Filter = Consts.FileSystem.WatcherFilter; remoteFSWatcher.Filter = Consts.FileSystem.WatcherFilter; localFSWatcher.IncludeSubdirectories = true; remoteFSWatcher.IncludeSubdirectories = true; localFSWatcher.Changed += FSEventHandler; remoteFSWatcher.Changed += FSEventHandler; localFSWatcher.Deleted += FSEventHandler; remoteFSWatcher.Deleted += FSEventHandler; localFSWatcher.Created += FSEventHandler; remoteFSWatcher.Created += FSEventHandler; localFSWatcher.Renamed += FSRenamedHander; remoteFSWatcher.Renamed += FSRenamedHander; localFSWatcher.Error += FSErrorHandler; remoteFSWatcher.Error += FSErrorHandler; localFSWatcher.EnableRaisingEvents = true; remoteFSWatcher.EnableRaisingEvents = true; if (Parameters.DebugLog) { Log.Write(String.Format("Pair [{0}]<=>[{1}] - file system watchers set, buffers local={2}, remote={3}...", LocalPath, RemotePath, localFSWatcher.InternalBufferSize, remoteFSWatcher.InternalBufferSize)); } } State = SyncPairState.Ready; } catch (Exception ex) { Log.Write(String.Format("Problems during initialization of pair [{0}]<=>[{1}], initialization will continue.", LocalPath, RemotePath), ex); State = SyncPairState.NotInitialized; } }
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 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 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; } }
public void DisposeProvider(FileSyncProvider provider) { //throw new NotImplementedException(); if (provider != null) provider.Dispose(); }
static void Main(string[] args) { _pause = false; try { if (!ParseArgs(args)) { PrintUsage(); Environment.Exit(-1); } if (!Directory.Exists(_localPathName)) { Console.WriteLine("Please ensure that the local target directory exists."); Environment.Exit(-1); } // // Setup Store and Provider // string accountName = ConfigurationManager.AppSettings.Get("AccountName"); string accountKey = ConfigurationManager.AppSettings.Get("AccountSharedKey"); string storageURL = ConfigurationManager.AppSettings.Get("AccountStorageURL"); CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(accountName, accountKey), true); AzureBlobStore blobStore = new AzureBlobStore(_containerName, storageAccount); Console.WriteLine("Successfully created/attached to container {0}.", _containerName); AzureBlobSyncProvider azureProvider = new AzureBlobSyncProvider(_containerName, blobStore); azureProvider.ApplyingChange += new EventHandler <ApplyingBlobEventArgs>(UploadingFile); FileSyncProvider fileSyncProvider = null; try { fileSyncProvider = new FileSyncProvider(_localPathName); } catch (ArgumentException) { fileSyncProvider = new FileSyncProvider(Guid.NewGuid(), _localPathName); } fileSyncProvider.ApplyingChange += new EventHandler <ApplyingChangeEventArgs>(AzureBlobSync.DownloadingFile); try { SyncOrchestrator orchestrator = new SyncOrchestrator(); orchestrator.LocalProvider = fileSyncProvider; orchestrator.RemoteProvider = azureProvider; orchestrator.Synchronize(); } finally { fileSyncProvider.Dispose(); } Console.WriteLine("Synchronization Complete"); if (_pause) { Console.ReadLine(); } } catch (Exception e) { Console.WriteLine(e); } }
/// <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(); } }
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 DetectChanges(string root, FileSyncScopeFilter filter, FileSyncOptions options) { FileSyncProvider provider = null; try { provider = new FileSyncProvider(root, filter, options); provider.DetectChanges(); } finally { if (provider != null) provider.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); } } }
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 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(); } }
/// <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(); } }
/// <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 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; } }
/// <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> /// <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(); } } }