Example #1
0
        private void btnDeleteCountry_Click(object sender, EventArgs e)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("country");

            try
            {
                var country = new CountryTableEntity
                {
                    RowKey = txtBoxDeleteCountryName.Text,
                    PartitionKey = txtBoxDeleteRegion.Text,
                    ETag = "*"
                };

                TableOperation deleteOperation = TableOperation.Delete(country);

                table.Execute(deleteOperation);

                MessageBox.Show(txtBoxNewCountryName.Text + @" deleted.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #2
0
        private void btnAddCountry_Click(object sender, EventArgs e)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("country");

            try
            {
                var country = new CountryTableEntity
                {
                    RowKey = txtBoxNewCountryName.Text,
                    PartitionKey = txtBoxNewRegion.Text,
                    NumberCode = int.Parse(txtBoxNewNumberCode.Text),
                    Alpha2Code = txtBoxNewAlpha2Code.Text,
                    Alpha3Code = txtBoxNewAlpha3Code.Text,
                    Capital = txtBoxNewCapital.Text,
                    CurrencyAlpha3Code = txtBoxNewCurrecyAlpha3Code.Text,
                    Flag = File.Exists(@"Resources\flags\" + txtBoxNewAlpha3Code.Text + ".png")
                        ? File.ReadAllBytes(@"Resources\flags\" + txtBoxNewAlpha3Code.Text + ".png")
                        : null
                };

                // Create the TableOperation that inserts the customer entity.
                TableOperation insertOperation = TableOperation.InsertOrMerge(country);

                // Execute the insert operation.
                table.Execute(insertOperation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            MessageBox.Show(txtBoxNewCountryName.Text + @" added.");
        }
Example #3
0
        private void GenerateCountries()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable table = tableClient.GetTableReference("country");

            var countries = File.ReadAllLines(@"Resources\countries.txt", Encoding.UTF8);
            var columns = new string[0];
            foreach (var country in countries)
            {
                try
                {
                    columns = country.Split('\t');

                    var countryEntity1 = new CountryTableEntity
                    {
                        RowKey = columns[3],
                        PartitionKey = columns[6],
                        NumberCode = int.Parse(columns[0]),
                        Alpha2Code = columns[1],
                        Alpha3Code = columns[2],
                        Capital = columns[4],
                        CurrencyAlpha3Code = columns[5],
                        Flag = File.Exists(@"Resources\flags\" + columns[2] + ".png")
                            ? File.ReadAllBytes(@"Resources\flags\" + columns[2] + ".png")
                            : null
                    };

                    // Create the TableOperation that inserts the customer entity.
                    TableOperation insertOperation = TableOperation.InsertOrMerge(countryEntity1);

                    // Execute the insert operation.
                    table.Execute(insertOperation);
                }
                catch (Exception ex)
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke((MethodInvoker) (() => MessageBox.Show(string.Format("{0}:{1}", columns[0], ex.Message))));
                        return;
                    }

                    MessageBox.Show(string.Format("{0}:{1}", columns[0], ex.Message));
                }
            }

            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker)(delegate { btnGenerateCountries.Enabled = true; MessageBox.Show(@"Completed."); }));
            }
            else
            {
                btnGenerateCountries.Enabled = true;
                MessageBox.Show(@"Completed.");
            }
        }