protected void OnProcessCacheRequestCompleted(ProcessCacheRequestCompletedEventArgs args)
 {
     if (this.ProcessCacheRequestCompleted != null)
     {
         this.ProcessCacheRequestCompleted(this, args);
     }
 }
 protected void OnProcessCacheRequestCompleted(ProcessCacheRequestCompletedEventArgs args)
 {
     if (this.ProcessCacheRequestCompleted != null)
     {
         this.ProcessCacheRequestCompleted(this, args);
     }
 }
Example #3
0
        /// <summary>
        /// Called whenever the CacheRequestHandler proceeses an upload/download request. It is also responsible for
        /// issuing another request if it wasnt the last batch. In case of receiving an Upload response it calls the
        /// underlying provider with the status of the upload. In case of Download it notifies the local provider of the
        /// changes that it needs to save.
        /// </summary>
        /// <param name="sender">Object invoking this method. Usually its the CacheRequestHandler</param>
        /// <param name="e">The result of processing the CacheRequest</param>
        void ProcessCacheRequestCompleted(object sender, ProcessCacheRequestCompletedEventArgs e)
        {
            /* try
             * {*/
            if (e.Error != null)
            {
                // Check to see if it was a UploadRequest in which case we will have to call OnChangeSetUploaded
                // with error to reset the dirty bits.
                if (e.ChangeSetResponse != null)
                {
                    // its an response to a upload
                    this._localProvider.OnChangeSetUploaded(e.Id, e.ChangeSetResponse);
                }

                // Finally complete Refresh with error.
                CompleteAsyncWithException(e.Error);
            }
            else if (e.ChangeSetResponse != null)
            {
                // its an response to a upload
                this._localProvider.OnChangeSetUploaded(e.Id, e.ChangeSetResponse);

                if (e.ChangeSetResponse.Error != null)
                {
                    CompleteAsyncWithException(e.ChangeSetResponse.Error);
                    return;
                }

                // Update refresh stats
                e.ChangeSetResponse.ConflictsInternal.ForEach((e1) =>
                {
                    if (e1 is SyncConflict)
                    {
                        this.refreshStats.TotalSyncConflicts++;
                    }
                    else
                    {
                        this.refreshStats.TotalSyncErrors++;
                    }
                });

                // Dont enqueue another request if its been cancelled
                if (!this.Cancelled)
                {
                    if (!((bool)e.State))
                    {
                        // Check to see if this was the last batch or else enqueue another pending Upload request
                        this.EnqueueUploadRequest();
                    }
                    else
                    {
                        // That was the last batch. Issue an Download request
                        this.EnqueueDownloadRequest();
                    }
                }
                else
                {
                    // This will process the queued Cancellation request
                    this._asyncWorkManager.CheckAndSendCancellationNotice();
                }
            }
            else // It means its an Download response
            {
                Debug.Assert(e.ChangeSet != null, "Completion is not for a download request.");

                this.LocalProvider.SaveChangeSet(e.ChangeSet);

                // Dont enqueue another request if its been cancelled
                if (!this.Cancelled)
                {
                    if (!e.ChangeSet.IsLastBatch)
                    {
                        // Enqueue the next download
                        this.EnqueueDownloadRequest();
                    }
                    else
                    {
                        // Uploads and downloads are done. Mark the session as complete
                        this._asyncWorkManager.EndChainedAsyncSession();
                        this._asyncWorkManager.CompleteWorkRequest(this._refreshRequestWorker, null);
                    }
                }
                else
                {
                    // This will process the queued Cancellation request
                    this._asyncWorkManager.CheckAndSendCancellationNotice();
                }
            }

            /* }
             * catch (Exception exp)
             * {
             *   if (ExceptionUtility.IsFatal(exp))
             *   {
             *       throw;
             *   }
             *   // Calling in to user code here (OnChangeSetUploaded and SaveChangeSet). Catch exceptions and fail
             *   CompleteAsyncWithException(exp);
             * }*/
        }
        /// <summary>
        /// Called whenever the CacheRequestHandler proceeses an upload/download request. It is also responsible for
        /// issuing another request if it wasnt the last batch. In case of receiving an Upload response it calls the
        /// underlying provider with the status of the upload. In case of Download it notifies the local provider of the
        /// changes that it needs to save.
        /// </summary>
        /// <param name="sender">Object invoking this method. Usually its the CacheRequestHandler</param>
        /// <param name="e">The result of processing the CacheRequest</param> 
        void ProcessCacheRequestCompleted(object sender, ProcessCacheRequestCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    // Check to see if it was a UploadRequest in which case we will have to call OnChangeSetUploaded
                    // with error to reset the dirty bits.
                    if (e.ChangeSetResponse != null)
                    {
                        // its an response to a upload
                        this._localProvider.OnChangeSetUploaded(e.Id, e.ChangeSetResponse);
                    }

                    // Finally complete Refresh with error.
                    CompleteAsyncWithException(e.Error);
                }
                else if (e.ChangeSetResponse != null)
                {
                    // its an response to a upload
                    this._localProvider.OnChangeSetUploaded(e.Id, e.ChangeSetResponse);

                    if (e.ChangeSetResponse.Error != null)
                    {
                        CompleteAsyncWithException(e.ChangeSetResponse.Error);
                        return;
                    }

                    // Increment the ChangeSets uploaded count
                    refreshStats.TotalChangeSetsUploaded++;
                    refreshStats.TotalUploads += (uint)e.BatchUploadCount;

                    // Update refresh stats
                    e.ChangeSetResponse.ConflictsInternal.ForEach((e1) =>
                    {
                        if (e1 is SyncConflict)
                        {
                            this.refreshStats.TotalSyncConflicts++;
                        }
                        else
                        {
                            this.refreshStats.TotalSyncErrors++;
                        }
                    });

                    // Dont enqueue another request if its been cancelled
                    if (!this.Cancelled)
                    {
                        if (!((bool)e.State))
                        {
                            // Check to see if this was the last batch or else enqueue another pending Upload request
                            this.EnqueueUploadRequest();
                        }
                        else
                        {
                            // That was the last batch. Issue an Download request
                            this.EnqueueDownloadRequest();
                        }
                    }
                    else
                    {
                        // This will process the queued Cancellation request
                        this._asyncWorkManager.CheckAndSendCancellationNotice();
                    }

                }
                else // It means its an Download response
                {
                    Debug.Assert(e.ChangeSet != null, "Completion is not for a download request.");

                    // Increment the refresh stats
                    this.refreshStats.TotalChangeSetsDownloaded++;
                    this.refreshStats.TotalDownloads += (uint)e.ChangeSet.Data.Count;

                    this.LocalProvider.SaveChangeSet(e.ChangeSet);

                    // Dont enqueue another request if its been cancelled
                    if (!this.Cancelled)
                    {
                        if (!e.ChangeSet.IsLastBatch)
                        {
                            // Enqueue the next download
                            this.EnqueueDownloadRequest();
                        }
                        else
                        {
                            // Uploads and downloads are done. Mark the session as complete
                            this._asyncWorkManager.EndChainedAsyncSession();
                            this._asyncWorkManager.CompleteWorkRequest(this._refreshRequestWorker, null);
                        }
                    }
                    else
                    {
                        // This will process the queued Cancellation request
                        this._asyncWorkManager.CheckAndSendCancellationNotice();
                    }
                }
            }
            catch (Exception exp)
            {
                if (ExceptionUtility.IsFatal(exp))
                {
                    throw;
                }
                // Calling in to user code here (OnChangeSetUploaded and SaveChangeSet). Catch exceptions and fail
                CompleteAsyncWithException(exp);
            }
        }