Skip to content

Instantly share code, notes, and snippets.

@rmaziarka
Last active April 29, 2019 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmaziarka/cb8f619cf743add780751121e912751c to your computer and use it in GitHub Desktop.
Save rmaziarka/cb8f619cf743add780751121e912751c to your computer and use it in GitHub Desktop.
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
try
{
await CreateTableAsync("tags");
Console.WriteLine("udalo sie");
}
catch (Exception e)
{
Console.WriteLine("nie udalo sie");
}
}
public static CloudStorageAccount CreateStorageAccountFromConnectionString(string storageConnectionString)
{
CloudStorageAccount storageAccount;
try
{
storageAccount = CloudStorageAccount.Parse(storageConnectionString);
}
catch (FormatException)
{
Console.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the application.");
throw;
}
catch (ArgumentException)
{
Console.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
Console.ReadLine();
throw;
}
return storageAccount;
}
public static async Task<CloudTable> CreateTableAsync(string tableName)
{
string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=rm-azureupskill-table;AccountKey={hidden};";
// Retrieve storage account information from connection string.
CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(storageConnectionString);
// Create a table client for interacting with the table service
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
Console.WriteLine("Create a Table for the demo");
// Create a table client for interacting with the table service
CloudTable table = tableClient.GetTableReference(tableName);
if (await table.CreateIfNotExistsAsync())
{
Console.WriteLine("Created Table named: {0}", tableName);
}
else
{
Console.WriteLine("Table {0} already exists", tableName);
}
Console.WriteLine();
return table;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment