Пример #1
0
        /// <summary>
        ///		Carga una sentencia de copia entre blobs
        /// </summary>
        private BaseSentence LoadCopyBlobSentence(MLNode rootML, bool move)
        {
            CopyBlobSentence sentence = new CopyBlobSentence();

            // Carga los datos básicos de la sentencia
            AssignBlobSentences(sentence, rootML);
            // Carga el resto de datos
            sentence.StorageKey        = rootML.Attributes[TagSource].Value;
            sentence.Move              = move;
            sentence.TransformFileName = rootML.Attributes[TagTransformFileName].Value.GetBool();
            foreach (MLNode nodeML in rootML.Nodes)
            {
                switch (nodeML.Name)
                {
                case TagFrom:
                    sentence.Source.Container = nodeML.Attributes[TagBlobContainer].Value;
                    sentence.Source.Blob      = nodeML.Attributes[TagBlobFile].Value;
                    break;

                case TagTo:
                    sentence.Target.Container = nodeML.Attributes[TagBlobContainer].Value;
                    sentence.Target.Blob      = nodeML.Attributes[TagBlobFile].Value;
                    break;
                }
            }
            // Devuelve la sentencia
            return(sentence);
        }
Пример #2
0
        /// <summary>
        ///		Procesa una copia de archivos
        /// </summary>
        private async Task ProcessCopyAsync(BlockLogModel parent, CopyBlobSentence sentence, CancellationToken cancellationToken)
        {
            string processType = sentence.Move ? "move" : "copy";
            string blobTarget  = sentence.Target.Blob;

            // Obtiene el nombre del archivo destino si hay que transformarlo en un nombre único
            if (sentence.TransformFileName)
            {
                blobTarget = System.IO.Path.GetFileNameWithoutExtension(sentence.Target.Blob) +
                             $" {DateTime.UtcNow:yyyy-MM-dd HH_mm_ss_ms}" +
                             System.IO.Path.GetExtension(sentence.Target.Blob);
            }
            // Procesa la instrucción
            using (BlockLogModel block = parent.CreateBlock(LogModel.LogType.Info, $"Start {processType} from '{sentence.Source.ToString()}' to '{sentence.Target.Container}/{blobTarget}'"))
            {
                CloudConnection connection = GetConnection(sentence.StorageKey);

                if (connection == null)
                {
                    AddError(block, $"Can't find the connection for '{sentence.StorageKey}'");
                }
                else
                {
                    try
                    {
                        // Copia / mueve el archivo
                        using (ICloudStorageManager manager = new StorageManager().OpenAzureStorageBlob(connection.StorageConnectionString))
                        {
                            if (sentence.Move)
                            {
                                await manager.MoveAsync(GetContainerName(sentence.Source.Container), sentence.Target.Blob,
                                                        GetContainerName(sentence.Target.Container), blobTarget, cancellationToken);
                            }
                            else
                            {
                                await manager.CopyAsync(GetContainerName(sentence.Source.Container), sentence.Target.Blob,
                                                        GetContainerName(sentence.Target.Container), blobTarget, cancellationToken);
                            }
                        }
                        // Log
                        block.Info($"End {processType} from '{sentence.Source.ToString()}' to '{sentence.Target.Container}/{blobTarget}'");
                    }
                    catch (Exception exception)
                    {
                        AddError(block, $"Error when {processType} from '{sentence.Source.ToString()}' to '{sentence.Target.Container}/{blobTarget}'", exception);
                    }
                }
            }
        }