public async Task DeleteAsync(string fileName, string userId) { lock (_deleteLockObj) { if (_deleteTask == null) { _deleteTask = Task.Run(async() => await _fileClient.DeleteAsync(fileName, userId), _cts.Token); } } await _deleteTask; }
private async Task QueueText(string text, int index, AWSSpeechRequest request, AWSSpeechResult result) { var synthesizeSpeechRequest = new StartSpeechSynthesisTaskRequest { OutputFormat = request.OutputFormat, VoiceId = request.VoiceId, Text = text, OutputS3BucketName = _translationOptions.Bucket, OutputS3KeyPrefix = Guid.NewGuid().ToString() }; var response = await _pollyClient.StartSpeechSynthesisTaskAsync(synthesizeSpeechRequest); using (var waitHandle = new AutoResetEvent(false)) using (new Timer( callback: async(e) => { await CheckSynthesisTask(response.SynthesisTask.TaskId, waitHandle); }, state: null, dueTime: TimeSpan.Zero, period: TimeSpan.FromSeconds(_translationOptions.PollRate) ) ) { waitHandle.WaitOne(); } var task = await _pollyClient.GetSpeechSynthesisTaskAsync(new GetSpeechSynthesisTaskRequest { TaskId = response.SynthesisTask.TaskId }); if (task.SynthesisTask.TaskStatus == Amazon.Polly.TaskStatus.Failed) { throw new InvalidOperationException(); } var key = task.SynthesisTask.OutputUri.Split('/').Last(); var fileResult = await _fileClient.DownloadAsync(key, ""); using (var stream = await fileResult.OpenStreamAsync()) { await result.DigestBytes(index, stream); } if (request.CallBack != null) { await request.CallBack(text.Length); } await _fileClient.DeleteAsync(key, ""); }
public Task DeleteSourceAsync(string directoryName, string fileName) { return(_fileClient.DeleteAsync(directoryName, fileName)); }