Пример #1
0
        /// <summary>
        ///		Carga la sentencia para subir un archivo
        /// </summary>
        private BaseSentence LoadUploadBlobSentence(MLNode rootML)
        {
            UploadBlobSentence sentence = new UploadBlobSentence();

            // Carga los datos de la sentencia
            AssignBlobSentences(sentence, rootML);
            sentence.StorageKey       = rootML.Attributes[TagTarget].Value;
            sentence.Target.Container = rootML.Attributes[TagBlobContainer].Value;
            sentence.Target.Blob      = rootML.Attributes[TagBlobFile].Value;
            sentence.FileName         = rootML.Attributes[TagFileName].Value;
            // Devuelve la sentencia
            return(sentence);
        }
Пример #2
0
        /// <summary>
        ///		Sube un archivo al blob
        /// </summary>
        private async Task ProcessUploadAsync(BlockLogModel parent, UploadBlobSentence sentence)
        {
            using (BlockLogModel block = parent.CreateBlock(LogModel.LogType.Info, $"Start uploading to '{sentence.Target.ToString()}'"))
            {
                CloudConnection connection = GetConnection(sentence.StorageKey);

                if (connection == null)
                {
                    AddError(block, $"Can't find the connection for '{sentence.StorageKey}'");
                }
                else
                {
                    string fileName = Step.Project.GetFullFileName(sentence.FileName);

                    if (!System.IO.File.Exists(fileName))
                    {
                        AddError(block, $"Can't find the file '{fileName}'");
                    }
                    else
                    {
                        try
                        {
                            // Sube el archivo
                            using (ICloudStorageManager manager = new StorageManager().OpenAzureStorageBlob(connection.StorageConnectionString))
                            {
                                await manager.UploadAsync(GetContainerName(sentence.Target.Container), sentence.Target.Blob, fileName);
                            }
                            // Log
                            block.Info($"Uploaded file '{sentence.FileName}' to '{sentence.Target.ToString()}'");
                        }
                        catch (Exception exception)
                        {
                            AddError(block, $"Error when upload '{sentence.FileName}' to '{sentence.Target.ToString()}'", exception);
                        }
                    }
                }
            }
        }