示例#1
0
        private static bool InitializeBlobTransfer(ILogger logger)
        {
            bool result = true;

            BlobTransferWorker.SourceSasUriSecretFilePath = Environment.ExpandEnvironmentVariables("%BlobTrasferSourceSasUriSecretFilePath%");
            BlobTransferWorker.TargetSasUriSecretFilePath = Environment.ExpandEnvironmentVariables("%BlobTrasferTargetSasUriSecretFilePath%");

            if (string.IsNullOrEmpty(BlobTransferWorker.SourceSasUriSecretFilePath) ||
                string.IsNullOrEmpty(BlobTransferWorker.TargetSasUriSecretFilePath))
            {
                logger.LogError("Environment variable 'BlobTrasferSourceSasUriSecretFilePath' or 'BlobTrasferTargetSasUriSecretFilePath' is not set. Program exits.");
                Environment.ExitCode = ERROR_BAD_ARGUMENTS;
                result = false;
            }

            if (result && !File.Exists(BlobTransferWorker.SourceSasUriSecretFilePath) ||
                !File.Exists(BlobTransferWorker.TargetSasUriSecretFilePath))
            {
                logger.LogError($"{BlobTransferWorker.SourceSasUriSecretFilePath} or {BlobTransferWorker.SourceSasUriSecretFilePath} not found. Program exits.");
                Environment.ExitCode = ERROR_BAD_ARGUMENTS;
                result = false;
            }

            if (result && string.IsNullOrEmpty(BlobTransferWorker.GetSourceSasUri()) ||
                string.IsNullOrEmpty(BlobTransferWorker.GetTargetSasUri()))
            {
                logger.LogError("Failed to get SourceSasUri or TargetSasUri. Program exits.");
                Environment.ExitCode = ERROR_BAD_ARGUMENTS;
                result = false;
            }

            return(result);
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddConsole();
            });

            var logger = loggerFactory.CreateLogger("Program");

            if (!InitializeBlobTransfer(logger))
            {
                return;
            }

            var config        = GetConfig();
            var configuration = config.GetSection("BlobTransfer").Get <BlobTransferConfiguration>();

            var report = new TransferReport();
            var worker = new BlobTransferWorker(configuration, loggerFactory);

            try
            {
                await worker.RunAsync(report);
            }
            catch (Exception e)
            {
                logger.LogError($"Unexpected exception: {e.ToString()}.");
                Environment.ExitCode = ERROR_FAIL;
                return;
            }

            await WriteFileAsync(TransferReportNamePrefix, report);

            Environment.ExitCode = ERROR_SUCCESS;

            logger.LogInformation("Done!");
        }