// 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(); } }
// Construct a data store by providing a name for the endpoint (replica) and // a file to which we'll persist the sync metadata (file) internal AzureBlobSyncProvider( string name, AzureBlobStore store ) { _name = name; _store = store; _replicaMetadataFile = MetadataDirectory + _name + ".Metadata"; _replicaIdFile = MetadataDirectory + _name + ".Replicaid"; // Set ItemIdFormat and ReplicaIdFormat for using Guid ids. _idFormats = new SyncIdFormatGroup(); _idFormats.ChangeUnitIdFormat.IsVariableLength = false; _idFormats.ChangeUnitIdFormat.Length = 4; _idFormats.ItemIdFormat.IsVariableLength = false; _idFormats.ItemIdFormat.Length = 24; _idFormats.ReplicaIdFormat.IsVariableLength = false; _idFormats.ReplicaIdFormat.Length = 16; }
// 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(); } }