private void ProcessGetChanges() { DeltaSyncSummary deltaSyncSummary = new DeltaSyncSummary(); List <IEnumerable <DeltaSyncBatchResults> > list = deltaSyncSummary.Samples as List <IEnumerable <DeltaSyncBatchResults> >; this.FindTheRightCookie(); ExProgressRecord exProgressRecord = new ExProgressRecord(1, new LocalizedString("Delta Sync"), new LocalizedString("Sync Call")); ExProgressRecord exProgressRecord2 = new ExProgressRecord(2, new LocalizedString("Sync Call"), new LocalizedString("GetChanges")); exProgressRecord2.ParentActivityId = exProgressRecord.ActivityId; for (int i = 0; i < this.SampleCountForStatistics; i++) { exProgressRecord.CurrentOperation = Strings.GetMsoDiagnosticsProgressIteration(i + 1, this.SampleCountForStatistics); exProgressRecord.PercentComplete = i * 100 / this.SampleCountForStatistics; exProgressRecord.RecordType = ProgressRecordType.Processing; base.WriteProgress(exProgressRecord); byte[] lastCookie = this.Cookie; List <DeltaSyncBatchResults> list2 = new List <DeltaSyncBatchResults>(); list.Add(list2); for (int j = 0; j < this.MaxNumberOfBatches; j++) { exProgressRecord2.CurrentOperation = Strings.GetMsoDiagnosticsProgressBatch(j + 1, this.MaxNumberOfBatches); exProgressRecord2.PercentComplete = j * 100 / this.MaxNumberOfBatches; exProgressRecord2.RecordType = ProgressRecordType.Processing; base.WriteProgress(exProgressRecord2); ExDateTime now = ExDateTime.Now; GetChangesResponse changes = this.MsoSyncService.SyncProxy.GetChanges(new GetChangesRequest(lastCookie)); TimeSpan responseTime = ExDateTime.Now - now; DirectoryChanges getChangesResult = changes.GetChangesResult; if (getChangesResult != null) { DeltaSyncBatchResults deltaSyncBatchResults = new DeltaSyncBatchResults(getChangesResult); deltaSyncBatchResults.Stats.ResponseTime = responseTime; deltaSyncBatchResults.LastCookie = lastCookie; deltaSyncBatchResults.RawResponse = this.MsoSyncService.RawResponse; deltaSyncBatchResults.CalculateStats(); list2.Add(deltaSyncBatchResults); lastCookie = getChangesResult.NextCookie; } if (getChangesResult == null || !getChangesResult.More) { break; } } if (list2.Last <DeltaSyncBatchResults>().More) { this.WriteWarning(Strings.GetMsoDiagnosticsMoreDataIsAvailable); } exProgressRecord2.RecordType = ProgressRecordType.Completed; base.WriteProgress(exProgressRecord2); } exProgressRecord.RecordType = ProgressRecordType.Completed; base.WriteProgress(exProgressRecord); deltaSyncSummary.CalculateStats(); base.WriteObject(deltaSyncSummary); }
public ActionResult GetChanges() { //Create get changes response GetChangesResponse response = new GetChangesResponse(); response.Result.Changes = ComparisonWidget.GetChanges(); response.Result.ResultFileName = ComparisonWidget.helper._service.resultFileName; //Serialize response var serializer = new JavaScriptSerializer(); var serializedData = serializer.Serialize(response); return Content(serializedData); }
public ActionResult GetChanges() { //Create get changes response GetChangesResponse response = new GetChangesResponse(); response.Result.Changes = ComparisonWidget.GetChanges(); response.Result.ResultFileName = ComparisonWidget.helper._service.resultFileName; //Serialize response var serializer = new JavaScriptSerializer(); var serializedData = serializer.Serialize(response); return(Content(serializedData)); }
/// <summary> /// Get changes for a client using the knowledge that is passed in. /// </summary> /// <param name="serverBlob">Client knowledge as byte[]</param> /// <returns>Response containing the new knowledge and the list of changes.</returns> public GetChangesResponse GetChanges(byte[] serverBlob) { bool isNewClient = false; var response = new GetChangesResponse(); var syncBlob = new SyncBlob(); byte[] clientKnowledgeBlob = null; // If the incoming knowledge blob is null, then we need to initialize a new scope // for this request. if (null == serverBlob || 0 == serverBlob.Length) { // Create a new Guid and use that as the client Id. Guid clientId = Guid.NewGuid(); _clientScopeName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", _scopeName, clientId); _clientSyncId = new SyncId(clientId); CreateNewScopeForClient(); isNewClient = true; syncBlob.ClientScopeName = clientId.ToString(); } else { SyncBlob incomingBlob = SyncBlob.DeSerialize(serverBlob); PopulateClientScopeNameAndSyncId(incomingBlob); syncBlob.ClientScopeName = incomingBlob.ClientScopeName; clientKnowledgeBlob = incomingBlob.ClientKnowledge; if (null != incomingBlob.BatchCode && null != incomingBlob.NextBatch) { // This is a batched request, so handle it separately. return GetChanges(incomingBlob.ClientKnowledge, incomingBlob.BatchCode.Value, incomingBlob.NextBatch.Value); } } // Intialize a SqlSyncProvider object. _sqlSyncProvider = CreateSqlSyncProviderInstance(_clientScopeName, _serverConnectionString, _configuration.SyncObjectSchema); var sessionContext = new SyncSessionContext(_sqlSyncProvider.IdFormats, new SyncCallbacks()); _sqlSyncProvider.BeginSession(SyncProviderPosition.Remote, sessionContext); try { // Get the SyncKnowledge from the blob. If the blob is null, initialize a default SyncKnowledge object. SyncKnowledge clientKnowledge = GetSyncKnowledgeFromBlob(clientKnowledgeBlob); DbSyncContext dbSyncContext; uint changeBatchSize = (_configuration.IsBatchingEnabled) ? (uint)_configuration.DownloadBatchSizeInKB : 0; RowSorter rowSorter = null; do { object changeDataRetriever; // Get the next batch. _sqlSyncProvider.GetChangeBatch(changeBatchSize, clientKnowledge, out changeDataRetriever); dbSyncContext = (DbSyncContext)changeDataRetriever; // Only initialize the RowSorter, if the data is batched. if (null == rowSorter && _configuration.IsBatchingEnabled) { // Clone the client knowledge. var clonedClientKnowledge = clientKnowledge.Clone(); // Combine with the MadeWithKnowledge of the server. clonedClientKnowledge.Combine(dbSyncContext.MadeWithKnowledge); // Use the new knowledge and get and instance of the RowSorter class. rowSorter = GetRowSorter(clonedClientKnowledge); } // Remove version information from the result dataset. RemoveSyncVersionColumns(dbSyncContext.DataSet); // For a new client, we don't want to send tombstones. This will reduce amount of data // transferred and the client doesn't care about tombstones anyways. if (isNewClient) { RemoveTombstoneRowsFromDataSet(dbSyncContext.DataSet); } // Add the dataset to the row sorter. Only use this if batching is enabled. if (_configuration.IsBatchingEnabled) { rowSorter.AddUnsortedDataSet(dbSyncContext.DataSet); // Delete the batch file generated by the provider, since we have read it. // Otherwise we will keep accumulating files which are not needed. if (!String.IsNullOrEmpty(dbSyncContext.BatchFileName) && File.Exists(dbSyncContext.BatchFileName)) { File.Delete(dbSyncContext.BatchFileName); } } } while (!dbSyncContext.IsLastBatch && dbSyncContext.IsDataBatched); List<IOfflineEntity> entities; if (_configuration.IsBatchingEnabled) { // If batching is enabled. Batch batch = SaveBatchesAndReturnFirstBatch(rowSorter); if (null == batch) { entities = new List<IOfflineEntity>(); } else { // Conver to to entities. entities = _converter.ConvertDataSetToEntities(batch.Data); //Only combine the knowledge of this batch. clientKnowledge.Combine(SyncKnowledge.Deserialize(_sqlSyncProvider.IdFormats, batch.LearnedKnowledge)); response.IsLastBatch = batch.IsLastBatch; syncBlob.IsLastBatch = batch.IsLastBatch; if (batch.IsLastBatch) { syncBlob.NextBatch = null; syncBlob.BatchCode = null; } else { syncBlob.NextBatch = batch.NextBatch; syncBlob.BatchCode = batch.BatchCode; } } } else { // No batching. response.IsLastBatch = true; entities = _converter.ConvertDataSetToEntities(dbSyncContext.DataSet); // combine the client and the server knowledge. // the server may have an updated knowledge from the last time the client sync'd. clientKnowledge.Combine(dbSyncContext.MadeWithKnowledge); } // Save data in the response object. syncBlob.ClientKnowledge = clientKnowledge.Serialize(); response.ServerBlob = syncBlob.Serialize(); response.EntityList = entities; } finally { _sqlSyncProvider.EndSession(sessionContext); } return response; }
/// <summary> /// Gets the next batch of changes for a client. /// </summary> /// <param name="serverBlob">Client knowledge as byte[]</param> /// <param name="batchCode">batchcode for the batch</param> /// <param name="nextBatchSequenceNumber">Sequence number of the next batch</param> /// <returns>Response containing the new knowledge and the list of changes.</returns> private GetChangesResponse GetChanges(byte[] serverBlob, Guid batchCode, Guid nextBatchSequenceNumber) { WebUtil.CheckArgumentNull(serverBlob, "clientKnowledgeBlob"); // Get the next batch using the batch handler implementation. Batch batch = _batchHandler.GetNextBatch(batchCode, nextBatchSequenceNumber); if (null == batch) { // Since we did'nt get a batch, default to the full get changes call. return GetChanges(serverBlob); } // Intialize a SqlSyncProvider object. _sqlSyncProvider = CreateSqlSyncProviderInstance(_clientScopeName, _serverConnectionString, _configuration.SyncObjectSchema); SyncKnowledge clientKnowledge = GetSyncKnowledgeFromBlob(serverBlob); List<IOfflineEntity> entities = _converter.ConvertDataSetToEntities(batch.Data); //Only combine the knowledge of this batch. clientKnowledge.Combine(SyncKnowledge.Deserialize(_sqlSyncProvider.IdFormats, batch.LearnedKnowledge)); var syncBlob = new SyncBlob { ClientScopeName = _clientSyncId.GetGuidId().ToString(), ClientKnowledge = clientKnowledge.Serialize(), BatchCode = batch.BatchCode, IsLastBatch = batch.IsLastBatch, NextBatch = batch.NextBatch }; // Save data in the response object. var response = new GetChangesResponse { EntityList = entities, IsLastBatch = batch.IsLastBatch, ServerBlob = syncBlob.Serialize() }; return response; }