public override ChangeBatch GetChangeBatch(uint batchSize, SyncKnowledge destinationKnowledge, out object changeDataRetriever) { GetChangesParameters changesWrapper = proxy.GetChanges(batchSize, destinationKnowledge); //Retrieve the ChangeDataRetriever and the ChangeBatch changeDataRetriever = changesWrapper.DataRetriever; DbSyncContext context = changeDataRetriever as DbSyncContext; //Check to see if the data is batched. if (context != null && context.IsDataBatched) { if (this.localBatchingDirectory == null) { //Retrieve the remote peer id from the MadeWithKnowledge.ReplicaId. MadeWithKnowledge is the local knowledge of the peer //that is enumerating the changes. string remotePeerId = context.MadeWithKnowledge.ReplicaId.ToString(); //Generate a unique Id for the directory. //We use the peer id of the store enumerating the changes so that the local temp directory is same for a given source //across sync sessions. This enables us to restart a failed sync by not downloading already received files. string sessionDir = Path.Combine(this.batchingDirectory, "WebSync_" + remotePeerId); this.localBatchingDirectory = new DirectoryInfo(sessionDir); //Create the directory if it doesnt exist. if (!this.localBatchingDirectory.Exists) { this.localBatchingDirectory.Create(); } } string localFileName = Path.Combine(this.localBatchingDirectory.FullName, context.BatchFileName); FileInfo localFileInfo = new FileInfo(localFileName); //Download the file only if doesnt exist if (!localFileInfo.Exists) { byte[] remoteFileContents = this.proxy.DownloadBatchFile(context.BatchFileName); using (FileStream localFileStream = new FileStream(localFileName, FileMode.Create, FileAccess.Write)) { localFileStream.Write(remoteFileContents, 0, remoteFileContents.Length); } } //Set DbSyncContext.Batchfile name to the new local file name context.BatchFileName = localFileName; } return(changesWrapper.ChangeBatch); }
public GetChangesParameters GetChanges(uint batchSize, SyncKnowledge destinationKnowledge) { Log("GetChangeBatch: {0}", this.peerProvider.Connection.ConnectionString); GetChangesParameters changesWrapper = new GetChangesParameters(); changesWrapper.ChangeBatch = this.peerProvider.GetChangeBatch(batchSize, destinationKnowledge, out changesWrapper.DataRetriever); DbSyncContext context = changesWrapper.DataRetriever as DbSyncContext; //Check to see if data is batched if (context != null && context.IsDataBatched) { Log("GetChangeBatch: Data Batched. Current Batch #:{0}", ++this.batchCount); //Dont send the file location info. Just send the file name string fileName = new FileInfo(context.BatchFileName).Name; this.batchIdToFileMapper[fileName] = context.BatchFileName; context.BatchFileName = fileName; } return(changesWrapper); }