public void Synchronize(SyncDirectionOrder syncDirection, KnowledgeSyncProvider localProvider, KnowledgeSyncProvider remoteProvider, uint batchSize) { FileStoreSync fileStoreSync = localProvider as FileStoreSync; fileStoreSync.RequestedBatchSize = batchSize; ((FileStoreProxy)remoteProvider).RequestedBatchSize = batchSize; // Use sync-callbacks for conflicting items SyncCallbacks destCallbacks = localProvider.DestinationCallbacks; destCallbacks.ItemConflicting += new EventHandler <ItemConflictingEventArgs>(OnItemConflicting); destCallbacks.ItemConstraint += new EventHandler <ItemConstraintEventArgs>(OnItemConstraint); localProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins; remoteProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins; // 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 FileStoreSync InitializeSyncFileSystem(string folder, SyncDirectionOrder syncDirection, string[] filters) { FileStoreSync fsSync = new FileStoreSync(folder, syncDirection, filters); // Register event handlers for file system sync FotoShoutUtils.Log.LogManager.Info(_logger, "Registering event handlers for file system sync..."); fsSync.AppliedChange += new AppliedChangeEventHandler(OnFileSystemAppliedChange); fsSync.SkippedChange += new SkippedChangeEventHandler(OnFileSystemSkippedChange); fsSync.ItemConflicting += new FotoShoutSyncService.ItemConflictingEventHandler(OnFileSystemItemConflicting); fsSync.ItemConstraint += new FotoShoutSyncService.ItemConstraintEventHandler(OnFileSystemItemConstraint); fsSync.Synchronized += new FotoShoutSyncService.SynchronizedEventHandler(OnFileSystemSynchronized); FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully registered event handlers for file system sync..."); return(fsSync); }
private void SynchronizeFiles(EventTDO ev) { FileStoreSync fsClientSync = null; FileStoreProxy fsServerSync = null; try { string evFolder = ev.EventFolder; if (string.IsNullOrEmpty(evFolder)) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The event folder name for the \"{0}\" event is empty.", ev.EventName)); return; } DirectoryInfo di = new DirectoryInfo(evFolder); if (!di.Exists) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The \"{0}\" folder of the \"{1}\" event not found.", evFolder, ev.EventName)); return; } FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Synchronizing photos of the \"{0}\" event.", ev.EventName)); string[] imgExts = ImageUtils.GetImageExts().Split('|'); fsClientSync = InitializeSyncFileSystem(evFolder, SyncDirectionOrder.Upload, imgExts); fsServerSync = new FileStoreProxy(evFolder, SyncEngine.WFC_SERVICE_FILESERVER, imgExts); FotoShoutUtils.Log.LogManager.Info(_logger, fsServerSync.Ping()); fsClientSync.Synchronize(fsServerSync, SyncDetails.BATCHSIZE_DEFAULT); FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Successfully Synchronized photos of the \"{0}\" event.", ev.EventName)); } catch (Exception ex) { FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception when synchronizing photos of the \"{0}\" event.\n{1}", ev.EventName, ex.ToString())); } finally { if (fsClientSync != null) { // De-register event handlers for file system sync fsClientSync.AppliedChange -= new AppliedChangeEventHandler(OnFileSystemAppliedChange); fsClientSync.SkippedChange -= new SkippedChangeEventHandler(OnFileSystemSkippedChange); fsClientSync.ItemConflicting -= new FotoShoutSyncService.ItemConflictingEventHandler(OnFileSystemItemConflicting); fsClientSync.ItemConstraint -= new FotoShoutSyncService.ItemConstraintEventHandler(OnFileSystemItemConstraint); fsClientSync.Synchronized -= new FotoShoutSyncService.SynchronizedEventHandler(OnFileSystemSynchronized); } } }