private void HandleSendingSuccess(State state, string batchId) { IList <Log> removedLogs; using (_mutex.GetLock(state)) { removedLogs = _sendingBatches[batchId]; _sendingBatches.Remove(batchId); } if (SentLog != null) { foreach (var log in removedLogs) { AppCenterLog.Debug(AppCenterLog.LogTag, $"Invoke SentLog event for channel '{Name}'"); SentLog?.Invoke(this, new SentLogEventArgs(log)); } } try { _storage.DeleteLogs(Name, batchId); } catch (StorageException e) { AppCenterLog.Warn(AppCenterLog.LogTag, $"Could not delete logs for batch {batchId}", e); } CheckPendingLogs(state); }
private void HandleSendingSuccess(State state, string batchId) { if (!_mutex.IsCurrent(state)) { return; } try { _storage.DeleteLogs(Name, batchId); } catch (StorageException e) { AppCenterLog.Warn(AppCenterLog.LogTag, $"Could not delete logs for batch {batchId}", e); throw; } finally { List <Log> removedLogs; using (_mutex.GetLock(state)) { removedLogs = _sendingBatches[batchId]; _sendingBatches.Remove(batchId); } if (SentLog != null) { foreach (var log in removedLogs) { SentLog?.Invoke(this, new SentLogEventArgs(log)); } } } }
private void AnyChannelSentLog(object sender, SentLogEventArgs e) { SentLog?.Invoke(sender, e); }
private void TriggerIngestion(IList <Log> logs, State stateSnapshot, string batchId) { // Before sending logs, trigger the sending event for this channel if (SendingLog != null) { foreach (var eventArgs in logs.Select(log => new SendingLogEventArgs(log))) { _mutex.Unlock(); SendingLog?.Invoke(this, eventArgs); _mutex.Lock(stateSnapshot); } } // If the optional Install ID has no value, default to using empty GUID var installId = MobileCenter.InstallId.HasValue ? MobileCenter.InstallId.Value : Guid.Empty; var serviceCall = _ingestion.PrepareServiceCall(_appSecret, installId, logs); serviceCall.ServiceCallFailedCallback = exception => { serviceCall.Dispose(); HandleSendingFailure(batchId, exception); }; serviceCall.ServiceCallSucceededCallback = async() => { serviceCall.Dispose(); if (!_stateKeeper.IsCurrent(stateSnapshot)) { return; } try { await _storage.DeleteLogsAsync(Name, batchId).ConfigureAwait(false); } catch (StorageException e) { MobileCenterLog.Warn(MobileCenterLog.LogTag, $"Could not delete logs for batch {batchId}", e); } try { await _mutex.LockAsync(stateSnapshot).ConfigureAwait(false); var removedLogs = _sendingBatches[batchId]; _sendingBatches.Remove(batchId); if (SentLog != null) { foreach (var log in removedLogs) { _mutex.Unlock(); SentLog?.Invoke(this, new SentLogEventArgs(log)); _mutex.Lock(stateSnapshot); } } CheckPendingLogs(); } catch (StatefulMutexException) { } finally { _mutex.Unlock(); } }; serviceCall.Execute(); }