private static int RunPushPackage(PushPackageOptions options)
{
if (CloudStorageAccount.TryParse(options.ConnectionString, out var storageAccount))
{
try
{
// Create the CloudBlobClient that represents the Blob storage endpoint for the storage account.
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
var cloudBlobContainer = cloudBlobClient.GetContainerReference(options.PackageName.Replace(".", "-").ToLower());
if (!cloudBlobContainer.ExistsAsync().GetAwaiter().GetResult())
{
console.WriteLine($"Package: {options.PackageName} does not exist.");
return(2);
}
if (!File.Exists(options.File))
{
console.WriteLine($"File not found: {options.File}");
return(2);
}
switch (options.Platform)
{
case "any":
case "win-x64":
case "osx-x64":
case "linux-x64":
break;
default:
console.WriteLine($"Platform {options.Platform} is not valid.");
return(2);
}
var ver = Version.Parse(options.Version);
// Get a reference to the blob address, then upload the file to the blob.
// Use the value of localFileName for the blob name.
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference($"{options.PackageName}.{options.Platform}.{options.Version}.avpkg");
var fileInfo = new FileInfo(options.File);
var progress = new Progress <StorageProgress>(p =>
{
console?.OverWrite($"Uploaded: [{(((float)p.BytesTransferred / fileInfo.Length) * 100.0f).ToString("0.00")}%] {ByteSizeHelper.ToString(p.BytesTransferred)}/{ByteSizeHelper.ToString(fileInfo.Length)} ");
});
cloudBlockBlob.Metadata["platform"] = options.Platform;
cloudBlockBlob.Metadata["version"] = ver.ToString();
console.WriteLine("Uploading...");
cloudBlockBlob.UploadFromFileAsync(options.File, default(AccessCondition), default(BlobRequestOptions), default(OperationContext), progress, new System.Threading.CancellationToken()).Wait();
console.WriteLine($"Package uploaded: {cloudBlockBlob.Uri}");
return(1);
}
catch (Exception e)
{
console.WriteLine("Error: " + e.Message);
return(2);
}
}
else
{
console.WriteLine("Invalid connection string");
return(2);
}
}