Ejemplo n.º 1
0
        public static int Main(string[] args)
        {
            ICommandLineParser parser = new CommandLineParser();
            var options = new ProgramOptions();

            if (!parser.ParseArguments(args, options, Console.Error))
            {
                return 1;
            }

            // Archiving the source to a temporary file.
            string zipFileName = Path.GetTempFileName();
            ZipCompress(options.SourcePath, zipFileName, options.ArchivePassword, options.CompressionLevel);

            // Uploading the archive to Azure Storage.
            UploadFileToBlobStorage(zipFileName, options);

            // Removing the temporary file.
            try
            {
                File.Delete(zipFileName);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }

            return 0;
        }
Ejemplo n.º 2
0
        private static void UploadFileToBlobStorage(string fileName, ProgramOptions options)
        {
            string connectionString = string.Format
            (
                "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                options.StorageAccountName,
                options.StorageAccountKey
            );

            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.GetContainerReference(options.DestinationBlobContainerName);

            // Retrieve reference to a blob.
            string blobName = GetBlobNameForUpload(options.DestinationBlobName, options.UseTimestampInBlobName);
            CloudBlob blob = container.GetBlobReference(blobName);

            // Create or overwrite the blob with contents from a local file.
            using (var fileStream = File.OpenRead(fileName))
            {
                blob.UploadFromStream(fileStream);
            }
        }