Ejemplo n.º 1
0
        public async Task <ActionResult> Post(TranscriptionReferenceRequest reference, [FromServices] DaprClient daprClient, CancellationToken cancellationToken)
        {
            var dapr            = new DaprHelper(daprClient);
            var TranscriptionId = Guid.NewGuid();

            try{
                _logger.LogInformation($"{TranscriptionId}. Request to transcribe {reference.blobURL} was received");

                var state = await dapr.UpdateState(TranscriptionId, reference.blobURL);

                _logger.LogInformation($"{TranscriptionId}. Record was successfullly saved as to {Components.StateStoreName} State Store");

                await dapr.PublishEvent(TranscriptionId, reference.blobURL, cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. {reference.blobURL} was successfullly published to {Components.PubSubName} pubsub store");

                return(Ok(new { TranscriptionId = TranscriptionId, StatusMessage = state.Value.Status, LastUpdated = state.Value.LastUpdateTime }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Failed to transcribe {reference.blobURL} - {ex.Message}");
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Post([FromForm] IFormFile file, [FromServices] DaprClient daprClient, CancellationToken cancellationToken)
        {
            var dapr            = new DaprHelper(daprClient, file);
            var TranscriptionId = Guid.NewGuid();

            _logger.LogInformation($"File upload request was received.");
            try{
                _logger.LogInformation($"{TranscriptionId}. Base64 encoding file and uploading via Dapr to {Components.BlobStoreName}.");

                var response = await dapr.UploadFile(cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. File was successfullly saved to {Components.BlobStoreName} blob storage");

                var sasUrl = await dapr.GetBlobSasToken(response.blobURL, Environment.GetEnvironmentVariable("MSI_CLIENT_ID"));

                _logger.LogInformation($"{TranscriptionId}. File was successfullly saved to {Components.BlobStoreName} blob storage");

                var state = await dapr.UpdateState(TranscriptionId, sasUrl);

                _logger.LogInformation($"{TranscriptionId}. Record was successfullly saved as to {Components.StateStoreName} State Store");

                await dapr.PublishEvent(TranscriptionId, sasUrl, cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. {sasUrl} was successfullly published to {Components.PubSubName} pubsub store");

                return(Ok(new { TranscriptionId = TranscriptionId, StatusMessage = state.Value.Status, LastUpdated = state.Value.LastUpdateTime }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Failed to create {file.FileName} - {ex.Message}");

                if (ex.InnerException != null)
                {
                    _logger.LogWarning("Inner exception: {0}", ex.InnerException);
                }
            }

            return(BadRequest());
        }
Ejemplo n.º 3
0
 public TranscriberService(ILogger <TranscriberService> logger)
 {
     _daprClient = new DaprHelper(new DaprClientBuilder().Build());
     _logger     = logger;
 }