Last active
April 29, 2019 09:04
-
-
Save rmaziarka/cb8f619cf743add780751121e912751c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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