public void ExecuteNextRequest() { if (this.offlineRequests == null) { return; } while (this.nextRequestIndex < this.offlineRequests.Count) { var recentMostRequest = this.offlineRequests[this.offlineRequests.Count - this.nextRequestIndex - 1]; UPOfflineRequest request = recentMostRequest; request.LoadFromOfflineStorage(); if (!request.CanSync()) { ++this.nextRequestIndex; this.Logger.LogDebug($"UPSync: request {request.RequestNr} cannot be synced ({request})", LogFlag.LogUpSync); continue; } if (request.NeedsWLANForSync && ServerSession.CurrentSession.ConnectionWatchDog.LastServerReachabilityStatus != ReachabilityStatus.ReachableViaWiFi) { ++this.nextRequestIndex; this.Logger.LogDebug($"UPSync: request {request.RequestNr} cannot be synced because no WLAN available ({request})", LogFlag.LogUpSync); continue; } ++this.nextRequestIndex; this.TheDelegate?.OfflineStorageDidProceedToStepNumberOfSteps(this, this.nextRequestIndex, this.offlineRequests.Count); this.Logger.LogDebug($"UPSync: syncing request {request.RequestNr} ({request})", LogFlag.LogUpSync); if (request.StartSync(this)) { continue; } } if (this.TheDelegate != null) { this.offlineRequests = null; UPOfflineStorageSyncDelegate _delegate = this.TheDelegate; this.TheDelegate = null; this.syncIsActive = false; if (this.blockingRequest?.RequestNr <= 0) { this.blockOnlineRecordRequest = false; } this.Logger.LogDebug("UPSync finished.", LogFlag.LogUpSync); _delegate.OfflineStorageDidFinishWithResult(this, null); } }
/// <summary> /// Offlines the request data context did fail with error. /// </summary> /// <param name="request">The request.</param> /// <param name="data">The data.</param> /// <param name="context">The context.</param> /// <param name="error">The error.</param> public void OfflineRequestDidFailWithError(UPOfflineRequest request, object data, object context, Exception error) { if (error.IsConnectionOfflineError()) { if (this.TheDelegate != null) { this.offlineRequests = null; UPOfflineStorageSyncDelegate _delegate = this.TheDelegate; this.TheDelegate = null; this.syncIsActive = false; _delegate.OfflineStorageDidFailWithError(this, error); } return; } this.ExecuteNextRequest(); }
/// <summary> /// Synchronizes the specified delegate. /// </summary> /// <param name="_delegate">The delegate.</param> /// <returns>true sync was done, false if sync is already in progress</returns> public bool Sync(UPOfflineStorageSyncDelegate _delegate) { lock (this) { if (this.syncIsActive) { return(false); } this.syncIsActive = true; this.TheDelegate = _delegate; } this.offlineRequests = this.OfflineRequests; this.nextRequestIndex = 0; this.ExecuteNextRequest(); return(true); }