Esempio n. 1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            StringBuilder sb;
            int           i = 0;
            int           j = 0;

            object[] columnValues;
            int      currentRowIndex = 0;

            while (true)
            {
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;

                    break;
                }
                else
                {
                    // Build JSON document to add rows
                    sb = new StringBuilder("{ \"rows\": [");

                    for (i = 0; i < nudBatchSize.Value; i++)
                    {
                        columnValues = new object[columnCount];

                        if (currentRowIndex == rowCount)
                        {
                            currentRowIndex = 0;
                        }
                        ;

                        for (j = 0; j < columnCount; j++)
                        {
                            columnValues[j] = eventsTable.Rows[currentRowIndex][j];
                        }

                        sb.Append(String.Format(rowTemplate, columnValues));

                        currentRowIndex++;
                    }

                    sb.Remove(sb.Length - 2, 2).Append("]}");

                    if (PowerBI.AddTableRows(mainForm.selectedGroup, mainForm.selectedDataset, mainForm.selectedTable, sb.ToString()))
                    {
                        worker.ReportProgress(requestsSent++);
                    }

                    if (nudDelayBetweenRequests.Value > 0)
                    {
                        Thread.Sleep((int)nudDelayBetweenRequests.Value * 1000);
                    }
                }
            }

            resetEvent.Set();
        }
Esempio n. 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtJsonContent.Text.Length == 0)
            {
                MessageBox.Show("You must enter the New Table Rows JSON document.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            this.Cursor = Cursors.WaitCursor;

            // If created successfully, update the application treeview
            if (PowerBI.AddTableRows(mainForm.selectedGroup, mainForm.selectedDataset, mainForm.selectedTable, txtJsonContent.Text))
            {
                btnClose_Click(null, null);
            }
            else
            {
                MessageBox.Show("Table row could not be added. Ensure that the JSON document is valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Cursor = Cursors.Default;
        }