謝謝Stephen。我使用了你的邏輯並修改了一下以適應我的需求。我在下面列出了我的代碼,再次感謝你!
UserUI()
public static List<string> UserUI()
{
List<string> accessCredentials = new List<string>();
Console.WriteLine("Account Name: ");
string accountName = Console.ReadLine();
accessCredentials.Add(accountName);
Console.WriteLine("Account Key: ");
string accountKey = Console.ReadLine();
accessCredentials.Add(accountKey);
return accessCredentials;
}
ApplicationStartFromUserOptions()
public static string ApplicatonStartFromUserOptions(List<string> accessCredentials)
{
var connectionString = $"DefaultEndpointsProtocol=https;AccountName={accessCredentials[0]};AccountKey={accessCredentials[1]}";
return connectionString;
}
我再從ApplicationStartFromUserOptions()
的connectionString
和傳遞到我GetConfig()
,可處理大部分繁重的工作。
GetConfig()
public static StartConfig GetConfig(string connectionString)
{
var config = new StartConfig();
// Retrieve storage account from connection string.
config.StorageAccount = CloudStorageAccount.Parse(connectionString);
// Create the blob object.
config.BlobClient = config.StorageAccount.CreateCloudBlobClient();
config.ListContainerData = ListContainer(config);
foreach (var item in config.ListContainerData.Item2)
{
config.Container = config.BlobClient.GetContainerReference(item);
ShowSasTokenForContainer(config);
}
//Create the container if it does not exisit.
config.Container.CreateIfNotExists();
return config;
}
最後我我的控制檯應用程序內的StartConfig config = GetConfig(ApplicatonStartFromUserOptions(UserUI()));
調用這個內我
Main()
所有