Exemple #1
0
        public void AddOrUpdateHistoricItem(Historic h, ListViewItem lvi = null)
        {
            if (lstHistoricsQueries.InvokeRequired)
            {
                AddOrUpdateHistoricItemCallback cb = new AddOrUpdateHistoricItemCallback(AddOrUpdateHistoricItem);
                this.Invoke(cb, new object[] { h, lvi });
            }
            else
            {
                lstHistoricsQueries.BeginUpdate();

                try
                {
                    if (lvi == null)
                    {
                        // No ListViewItem given, try to find a matching row
                        foreach (ListViewItem lvi_candidate in lstHistoricsQueries.Items)
                        {
                            if (h.getHash() == ((Historic)lvi_candidate.Tag).getHash())
                            {
                                lvi = lvi_candidate;
                                break;
                            }
                        }
                    }

                    if (h.isDeleted())
                    {
                        if (lvi != null)
                        {
                            lstHistoricsQueries.Items.Remove(lvi);
                        }
                    }
                    else
                    {
                        if (lvi == null)
                        {
                            // Still not found it, add it
                            lvi = lstHistoricsQueries.Items.Add(h.getName());
                            lvi.SubItems.Add(h.getStatus());
                            lvi.SubItems.Add(h.getProgress().ToString());
                            lvi.SubItems.Add(h.getStartDate().ToString());
                            lvi.SubItems.Add(h.getEndDate().ToString());
                            lvi.SubItems.Add(string.Join(", ", h.getSources().ToArray()));
                        }
                        else
                        {
                            // Already exists, update the pieces
                            lvi.SubItems[0].Text = h.getName();
                            lvi.SubItems[1].Text = h.getStatus();
                            lvi.SubItems[2].Text = h.getProgress().ToString();
                            lvi.SubItems[3].Text = h.getStartDate().ToString();
                            lvi.SubItems[4].Text = h.getEndDate().ToString();
                            lvi.SubItems[5].Text = string.Join(", ", h.getSources().ToArray());
                        }

                        // Store the Historic in the item
                        lvi.Tag = h;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                lstHistoricsQueries.EndUpdate();
            }
        }
Exemple #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            UseWaitCursor = true;
            Enabled       = false;

            string errors = "";

            // Validate stuff
            if (txtName.Text.Trim().Length == 0)
            {
                errors += "Please enter a name for your new Historics query\n";
            }
            if (txtStreamHash.Text.Trim().Length == 0)
            {
                errors += "Please specify a stream hash\n";
            }
            if (lbSourcesSelected.Items.Count == 0)
            {
                errors += "Please select one or more data sources\n";
            }
            if (cmbSampleRate.Text.Length == 0)
            {
                errors += "Please select a sample rate\n";
            }

            if (errors.Length > 0)
            {
                // The data is not good enough to try the API
                MessageBox.Show(this, errors, "Form errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Gather the data
                string        name        = txtName.Text.Trim();
                string        stream_hash = txtStreamHash.Text.Trim();
                DateTime      start_date  = dtStartDate.Value;
                DateTime      end_date    = dtEndDate.Value;
                List <string> sources     = new List <string>();
                foreach (string item in lbSourcesSelected.Items)
                {
                    sources.Add(item.Trim());
                }
                double sample = Convert.ToDouble(cmbSampleRate.Text.Trim().Substring(0, cmbSampleRate.Text.Length - 1));

                // Get the user object and make the call
                User user = Program.Inst().dsuser;
                try
                {
                    Historic h = user.createHistoric(stream_hash, start_date, end_date, sources, sample, name);
                    h.prepare();
                    if (m_frmHistoricsQueriesList != null)
                    {
                        m_frmHistoricsQueriesList.AddOrUpdateHistoricItem(h);
                        m_frmHistoricsQueriesList.SelectHistoric(h.getHash());
                    }
                    else
                    {
                        MessageBox.Show(this, "Historic query '" + h.getHash() + "' created successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    Close();
                }
                catch (DataSiftException ex)
                {
                    MessageBox.Show(this, ex.Message, "API Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            UseWaitCursor = false;
            Enabled       = true;
        }