private async Task <bool> UploadStoredRequests() { StoredRequest sr = null; lock (sync) { if (uploadInProgress) { return(true); } uploadInProgress = true; if (StoredRequests.Count > 0) { sr = StoredRequests.Peek(); Debug.Assert(sr != null); } } if (sr != null) { ResultResponse resultResponse = await Api.Instance.SendStoredRequest(ServerUrl, sr); if (resultResponse != null && resultResponse.IsSuccess) { lock (sync) { uploadInProgress = false; //remove the excecuted request StoredRequest srd = null; try { srd = StoredRequests.Dequeue(); } catch { } Debug.Assert(srd != null); Debug.Assert(srd == sr); bool success = SaveStoredRequests().Result;//todo, handle this in the future } return(true); } else { lock (sync) { uploadInProgress = false; } return(false); } } else { lock (sync) { uploadInProgress = false; } return(true); } }
internal async Task AddRequest(String networkRequest, bool isIdMerge = false) { Debug.Assert(networkRequest != null); if (networkRequest == null) { return; } lock (sync) { StoredRequest sr = new StoredRequest(networkRequest, isIdMerge); StoredRequests.Enqueue(sr); SaveStoredRequests(); } }
protected async Task HaltInternal() { lock (sync) { ServerUrl = null; AppKey = null; SessionTimerStop(); Events?.Clear(); Sessions?.Clear(); Exceptions?.Clear(); breadcrumb = String.Empty; DeviceData = new Device(); StoredRequests?.Clear(); if (UserDetails != null) { UserDetails.UserDetailsChanged -= OnUserDetailsChanged; } userDetails = null;//set it null so that it can be loaded from the file system (if needed) consentRequired = false; givenConsent = new Dictionary <ConsentFeatures, bool>(); } await Storage.Instance.DeleteFile(eventsFilename); await Storage.Instance.DeleteFile(sessionsFilename); await Storage.Instance.DeleteFile(exceptionsFilename); await Storage.Instance.DeleteFile(userDetailsFilename); await Storage.Instance.DeleteFile(storedRequestsFilename); await Storage.Instance.DeleteFile(Device.deviceFilename); }