/// <summary> /// Asynchronously deletes all logs in a particular batch /// </summary> /// <param name="channelName">The name of the channel associated with the batch</param> /// <param name="batchId">The batch identifier</param> /// <exception cref="StorageException"/> public Task DeleteLogs(string channelName, string batchId) { return(AddTaskToQueue(() => { try { AppCenterLog.Debug(AppCenterLog.LogTag, $"Deleting logs from storage for channel '{channelName}' with batch id '{batchId}'"); var identifiers = _pendingDbIdentifierGroups[GetFullIdentifier(channelName, batchId)]; _pendingDbIdentifierGroups.Remove(GetFullIdentifier(channelName, batchId)); var deletedIdsMessage = "The IDs for deleting log(s) is/ are:"; foreach (var id in identifiers) { deletedIdsMessage += "\n\t" + id; _pendingDbIdentifiers.Remove(id); } AppCenterLog.Debug(AppCenterLog.LogTag, deletedIdsMessage); foreach (var id in identifiers) { _storageAdapter .DeleteAsync <LogEntry>(entry => entry.Channel == channelName && entry.Id == id) .GetAwaiter().GetResult(); } } catch (KeyNotFoundException e) { throw new StorageException(e); } })); }
/// <summary> /// Asynchronously deletes all logs in a particular batch /// </summary> /// <param name="channelName">The name of the channel associated with the batch</param> /// <param name="batchId">The batch identifier</param> /// <exception cref="StorageException"/> public async Task DeleteLogsAsync(string channelName, string batchId) { using (await _taskLockSource.GetTaskLockAsync().ConfigureAwait(false)) { MobileCenterLog.Debug(MobileCenterLog.LogTag, $"Deleting logs from storage for channel '{channelName}' with batch id '{batchId}'"); try { var identifiers = _pendingDbIdentifierGroups[GetFullIdentifier(channelName, batchId)]; _pendingDbIdentifierGroups.Remove(GetFullIdentifier(channelName, batchId)); var deletedIdsMessage = "The IDs for deleting log(s) is/ are:"; foreach (var id in identifiers) { deletedIdsMessage += "\n\t" + id; _pendingDbIdentifiers.Remove(id); } MobileCenterLog.Debug(MobileCenterLog.LogTag, deletedIdsMessage); foreach (var id in identifiers) { await _storageAdapter.DeleteAsync <LogEntry>(entry => entry.Channel == channelName && entry.Id == id).ConfigureAwait(false); } } catch (KeyNotFoundException e) { throw new StorageException(e); } } }
/// <summary> /// Asynchronously deletes all logs in a particular batch /// </summary> /// <param name="channelName">The name of the channel associated with the batch</param> /// <param name="batchId">The batch identifier</param> /// <exception cref="StorageException"/> public Task DeleteLogs(string channelName, string batchId) { var task = new Task(() => { try { MobileCenterLog.Debug(MobileCenterLog.LogTag, $"Deleting logs from storage for channel '{channelName}' with batch id '{batchId}'"); var identifiers = _pendingDbIdentifierGroups[GetFullIdentifier(channelName, batchId)]; _pendingDbIdentifierGroups.Remove(GetFullIdentifier(channelName, batchId)); var deletedIdsMessage = "The IDs for deleting log(s) is/ are:"; foreach (var id in identifiers) { deletedIdsMessage += "\n\t" + id; _pendingDbIdentifiers.Remove(id); } MobileCenterLog.Debug(MobileCenterLog.LogTag, deletedIdsMessage); foreach (var id in identifiers) { _storageAdapter .DeleteAsync <LogEntry>(entry => entry.Channel == channelName && entry.Id == id) .Wait(); } } catch (KeyNotFoundException e) { throw new StorageException(e); } }); try { _queue.Add(task); } catch (InvalidOperationException) { throw new StorageException("The operation has been cancelled"); } _flushSemaphore.Release(); return(task); }