Хранилище Azure DownloadToStreamAsync проваливается (без исключения) каждый раз - PullRequest
0 голосов
/ 10 декабря 2018

Следующий метод должен загружать файл csv из хранилища Azure в поток памяти.

Примечание. AzureResponse - это пользовательский класс, который возвращает bool, строку (сообщение) и либо поток, либостроковый результат

public async Task<AzureResponse> ReadCsvFileToStreamFromBlobAsync(CloudBlobContainer container, string fileName)
    {
        var ar = new AzureResponse();
        // Retrieve reference to a blob (fileName)
        var blob = container.GetBlockBlobReference(fileName);
        if (blob != null)
        {
            string message;
            try
            {
                using (var memoryStream = new MemoryStream())
                {
                   **// code gets here and then falls right through to the end of the
                   //calling method, bypassing the catch portion here** 
                   await blob.DownloadToStreamAsync(memoryStream)                          
                    **//Tried adding .ConfigureAwait(false); to the above call                    //downloads blob's content to a stream
                   //that did not work
                   //per this SO post, https://stackoverflow.com/questions/28526249/azure-downloadtostreamasync-method-hangs

                    //code doesn't reach here**
                    message = message = $"Csv file read to Stream correctly. Filename:  {fileName}.";
                    ar.Status = true;
                    ar.Message = message;
                    ar.FileAsStream = memoryStream;
                    return ar;

                }
            }
            catch (Exception ex)
            {
                message = $"Csv file was not loaded to the memory stream on {DateTime.Now} for file {fileName} with exception message {ex.Message}";
                ar.Status = false;
                ar.Message = message;
                ar.FileAsStream = null;
                return ar;
            }
        }

        ar.Status = false;
        ar.Message = $" File not found error for {fileName} on {DateTime.Now}";
        ar.FileAsStream = null;
        return ar;
    }

ПРИМЕЧАНИЕ: И этот метод вызывается в моем методе Main (это консольное приложение) со следующими строками

 az = new AzureStorageCommon(config);
        var fileContainer = az.GetAzureFilesContainer();
        var afs = new AzureFileMethods();
        var returned = afs.ReadCsvFileToStreamFromBlobAsync(fileContainer, "EarningsEvents_Dec_2018.csv");

Путь к файлу не является проблемой, когда этоUri помещается в браузер, он запрашивает загрузку файла (это проблема? Это блокирует асинхронную загрузку в поток?)

Существует перегрузка, которая принимает токен отмены, но я не могу найтичто-нибудь о том, как это правильно использовать.

Это то, что возвращается вызывающему методу

Id = 37, Status = WaitingForActivation, Method = "{null}", Result = "{Еще не вычислено} "

Каждый найденный мной учебник делает это таким образом, не зная, почему это не работает.

  1. Это потому, что этоCSV-файл?(Я сомневаюсь в этом)
  2. Это из-за того, что браузер запрашивает, хотите ли вы сохранить файл?
  3. Как вы можете запустить это с токеном отмены, чтобы убедиться, что файл действительно завершен до этого?код завершен.
...