Example #1
0
        /// <summary>
        ///		Descarga un archivo del blob
        /// </summary>
        private async Task ProcessDownloadAsync(BlockLogModel parent, DownloadBlobSentence sentence)
        {
            using (BlockLogModel block = parent.CreateBlock(LogModel.LogType.Info, $"Start downloading from '{sentence.Source.ToString()}'"))
            {
                CloudConnection connection = GetConnection(sentence.StorageKey);

                if (connection == null)
                {
                    AddError(block, $"Can't find the connection for '{sentence.StorageKey}'");
                }
                else
                {
                    try
                    {
                        // Descarga el archivo
                        using (ICloudStorageManager manager = new StorageManager().OpenAzureStorageBlob(connection.StorageConnectionString))
                        {
                            string fileName = Step.Project.GetFullFileName(sentence.FileName);

                            // Crea el directorio
                            LibHelper.Files.HelperFiles.MakePath(System.IO.Path.GetDirectoryName(fileName));
                            // Descarga el archivo
                            await manager.DownloadAsync(GetContainerName(sentence.Source.Container), sentence.Source.Blob, fileName);
                        }
                        // Log
                        block.Info($"Downloaded file '{sentence.FileName}' to '{sentence.Source.ToString()}'");
                    }
                    catch (Exception exception)
                    {
                        AddError(block, $"Error when download '{sentence.FileName}' to '{sentence.Source.ToString()}'", exception);
                    }
                }
            }
        }
        /// <summary>
        ///		Carga la sentencia para descargar un archivo
        /// </summary>
        private BaseSentence LoadDownloadBlobSentence(MLNode rootML)
        {
            DownloadBlobSentence sentence = new DownloadBlobSentence();

            // Carga los datos de la sentencia
            AssignBlobSentences(sentence, rootML);
            sentence.StorageKey       = rootML.Attributes[TagSource].Value;
            sentence.Source.Container = rootML.Attributes[TagBlobContainer].Value;
            sentence.Source.Blob      = rootML.Attributes[TagBlobFile].Value;
            sentence.FileName         = rootML.Attributes[TagFileName].Value;
            // Devuelve la sentencia
            return(sentence);
        }