/// <summary>
        ///		Carga la sentencia para descargar un directorio del storage
        /// </summary>
        private BaseSentence LoadDownloadPathSentence(MLNode rootML)
        {
            DownloadBlobFolderSentence sentence = new DownloadBlobFolderSentence();

            // 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[TagStoragePath].Value;
            sentence.Path             = rootML.Attributes[TagPath].Value;
            // Devuelve la sentencia
            return(sentence);
        }
示例#2
0
        /// <summary>
        ///		Procesa la sentencia de descarga de una carpeta
        /// </summary>
        private async Task ProcessDownloadFolderAsync(BlockLogModel parent, DownloadBlobFolderSentence sentence, CancellationToken cancellationToken)
        {
            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
                    {
                        string path      = Step.Project.GetFullFileName(sentence.Path);
                        string container = GetContainerName(sentence.Source.Container);

                        // Log
                        block.Info($"Start download '{container}/{sentence.Source.Blob}' to '{path}'");
                        // Crea la carpeta
                        LibHelper.Files.HelperFiles.MakePath(path);
                        // Descarga la carpeta
                        using (ICloudStorageManager manager = new StorageManager().OpenAzureStorageBlob(connection.StorageConnectionString))
                        {
                            List <LibBlobStorage.Metadata.BlobModel> blobs = await manager.ListBlobsAsync(container, sentence.Source.Blob);

                            foreach (LibBlobStorage.Metadata.BlobModel blob in blobs)
                            {
                                if (blob.Length != 0 && !cancellationToken.IsCancellationRequested)
                                {
                                    string fileName = System.IO.Path.Combine(path, blob.LocalFileName);

                                    // Log
                                    block.Info($"Download '{blob.FullFileName}'");
                                    // Crea el directorio
                                    LibHelper.Files.HelperFiles.MakePath(System.IO.Path.GetDirectoryName(fileName));
                                    // Descarga el archivo
                                    await manager.DownloadAsync(container, blob.FullFileName, fileName);
                                }
                            }
                        }
                        // Log
                        block.Info($"End download '{container}/{sentence.Source.Blob}' to '{path}'");
                    }
                    catch (Exception exception)
                    {
                        AddError(block, $"Error when download to '{sentence.Path}'", exception);
                    }
                }
            }
        }