Esempio n. 1
0
        private void ButtonTableUpdateClick(object sender, EventArgs e)
        {
            if (textBoxTablePartitionKey.Text.Trim() == string.Empty || textBoxTableRowKey.Text.Trim() == string.Empty)
            {
                MessageBox.Show(@"Partition key or Row key cannot be empty", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // update table
            UpdateEntity newLine = CreateEntity(textBoxTableBlobUrl.Text, textBoxTableComments.Text,
                                                textBoxTableEnabled.Text, textBoxTableHCode.Text, textBoxTableHCode.Text,
                                                textBoxTableMachineName.Text, textBoxTableMode.Text, textBoxTableStatus.Text,
                                                textBoxTableTargetDate.Text, textBoxTablePartitionKey.Text, textBoxTableRowKey.Text, false);

            try
            {
                //insert into Azure table
                UpdateTable(newLine);
                MessageBox.Show(@"The line has been updated into the Azure Table", @"OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exception)
            {
                MessageBox.Show($@"The line has not been updated into the Azure Table. Error: {exception.Message}", @"KO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Refresh the table
            ButtonLoadTableClick(sender, e);
        }
Esempio n. 2
0
        private static UpdateEntity CreateEntity(string blobUrl, string comment, string enableEntity, string HCode, string HId, string machineName, string modeEntity, string statusEntity, string targetDate, string partitionKey, string rowKey, bool insertNewLine = true)
        {
            UpdateEntity newLine = new UpdateEntity();

            newLine.BlobUrl  = blobUrl;
            newLine.Comments = comment;
            bool enabled = false;

            if (!bool.TryParse(enableEntity, out enabled))
            {
                enabled = false;
            }

            newLine.Enabled     = enabled;
            newLine.HCode       = HCode;
            newLine.HId         = HId;
            newLine.MachineName = machineName.Replace(' ', new char());
            int mode = 0;

            if (!int.TryParse(modeEntity, out mode))
            {
                mode = 0;
            }

            newLine.Mode = mode;

            int status = 0;

            if (!int.TryParse(statusEntity, out status))
            {
                status = 0;
            }

            newLine.Status = status;
            DateTime targetDateTime;

            if (!DateTime.TryParse(targetDate, out targetDateTime))
            {
                targetDateTime = DateTime.Now;
            }

            newLine.TargetDate   = targetDateTime;
            newLine.PartitionKey = partitionKey;
            newLine.RowKey       = rowKey;
            newLine.Timestamp    = DateTime.Now;

            // check if line already exists in Azure and if so ask for confirmation to replace and add *
            newLine.ETag = insertNewLine ? string.Empty : "*";

            return(newLine);
        }