protected override bool OnValidatePromptCore(FormData data) { if (model.QueryId == null) { model.Query = data.GetStringValue("tquery").Replace("\r", " ").Replace("\n", " "); if (model.IsCorrelation) { model.From = DateTime.Parse(data.GetStringValue("dtfrom"), null, System.Globalization.DateTimeStyles.RoundtripKind); model.To = DateTime.Parse(data.GetStringValue("dtto"), null, System.Globalization.DateTimeStyles.RoundtripKind); try { LmiHandler lmiHandler = new LmiHandler(model.Host, model.Query, model.UserName, model.UserPass, null, model.IsCorrelation, model.From, model.To); lmiHandler.checkConnection(); } catch (Exception e) { ErrorMessage = e.Message; return(false); } return(true); } } else { model.QueryId = data.GetStringValue("queryId"); } return(true); }
protected override bool OnValidatePromptCore(FormData data) { model.Host = data.GetStringValue("lhost"); model.UserName = data.GetStringValue("uname"); model.UserPass = data.GetStringValue("upass"); try { LmiHandler lmiHandler = new LmiHandler(model.Host, "", model.UserName, model.UserPass, null, false, model.From, model.To); lmiHandler.checkConnection(); } catch (Exception e) { ErrorMessage = e.Message; return(false); } return(true); }
private void switchToCorrResults() { queryBox.Visible = false; resultPicker.Visible = true; toLabel.Visible = false; toPicker.Visible = false; fromLabel.Visible = false; fromPicker.Visible = false; promptModel.Host = hostBox.Text; promptModel.UserName = userNameBox.Text; promptModel.UserPass = userPassBox.Text; resultPicker.Items.Clear(); resultPicker.Items.Add("Retrieving list of available correlation result sets..."); resultPicker.Update(); try { LmiHandler lmiHandler = new LmiHandler(promptModel.Host, "", promptModel.UserName, promptModel.UserPass, null, true, DateTime.MinValue, DateTime.MinValue); queryEntries = lmiHandler.getQueries(); } catch (Exception e) { string message = "Exception:" + e.ToString(); const string caption = "Error while retrieving list of correlation results from LMI"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); switchToRunQuery(); return; } resultPicker.Items.Clear(); foreach (QueryEntry queryEntry in queryEntries) { int added = resultPicker.Items.Add(queryEntry.query); if (queryEntry.queryId.Equals(promptModel.QueryId)) { resultPicker.SelectedIndex = added; } } }
/// <summary>Event handler for when the OK button is clicked. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private void OnOkButton_Click(object sender, EventArgs ea) { promptModel.Host = hostBox.Text; promptModel.UserName = userNameBox.Text; promptModel.UserPass = userPassBox.Text; if (existingResultsChoice.Checked) { promptModel.IsCorrelation = false; if (resultPicker.SelectedIndex == -1) { var result = MessageBox.Show("You must select a query from the list", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; return; } promptModel.QueryId = queryEntries[resultPicker.SelectedIndex].queryId; } else if (newQueryChoice.Checked) { promptModel.Query = queryBox.Text; promptModel.IsCorrelation = false; } else if (runCorrChoice.Checked) { promptModel.Query = queryBox.Text; promptModel.IsCorrelation = true; promptModel.From = fromPicker.Value; promptModel.To = toPicker.Value; } else if (corrResultsChoice.Checked) { promptModel.IsCorrelation = true; if (resultPicker.SelectedIndex == -1) { var result = MessageBox.Show("You must select a query from the list", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; return; } promptModel.QueryId = queryEntries[resultPicker.SelectedIndex].queryId; } if (newQueryChoice.Checked || runCorrChoice.Checked) { try { checkingLabel.Visible = true; checkingLabel.Update(); LmiHandler lmiHandler = new LmiHandler(promptModel.Host, promptModel.Query, promptModel.UserName, promptModel.UserPass, null, promptModel.IsCorrelation, promptModel.From, promptModel.To); lmiHandler.checkConnection(); } catch (Exception e) { string message = "Exception:" + e.ToString(); const string caption = "Error while checking connection to LMI"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; return; } finally { checkingLabel.Visible = false; } } // The URL was value, close the dialog and continue. this.DialogResult = DialogResult.OK; this.Close(); }
protected override void OnGetContentsCore(HtmlTextWriter writer) { writer.WriteLine("<fieldset>"); writer.WriteLine("<legend>Query details:</legend>"); string valueQueryId = model.QueryId == null ? "" : model.QueryId; if (model.QueryId == null) { writer.WriteLine("<div class=\"query\">"); writer.WriteLine("<label for=\"tquery\">Query</label>"); writer.WriteLine("<textarea id=\"tquery\" name=\"tquery\" rows=\"5\" cols=\"80\">"); writer.WriteLine(model.Query); writer.WriteLine("</textarea><br>"); writer.WriteLine("</div>"); if (model.IsCorrelation) { string fromStr = model.From.ToString("s", System.Globalization.CultureInfo.InvariantCulture); string toStr = model.To.ToString("s", System.Globalization.CultureInfo.InvariantCulture); writer.WriteLine("<div class=\"fromto\">"); writer.WriteLine("<label for=\"dtfrom\">From</label>"); writer.WriteLine("<input type=\"text\" id=\"dtfrom\" name=\"dtfrom\" value=\"" + fromStr + "\">"); writer.WriteLine("<label for=\"dtto\">To</label>"); writer.WriteLine("<input type=\"text\" id=\"dtto\" name=\"dtto\" value=\"" + toStr + "\">"); writer.WriteLine("</div>"); } } else { try { LmiHandler lmiHandler = new LmiHandler(model.Host, "", model.UserName, model.UserPass, null, model.IsCorrelation, DateTime.MinValue, DateTime.MinValue); if (!model.IsCorrelation) { queryEntries = lmiHandler.getQueries(); } else { queryEntries = lmiHandler.getCorrelationQueries(); } } catch (Exception e) { string message = "Exception:" + e.ToString(); string caption = "Error while retrieving list of results from LMI: " + message; writer.WriteLine("<span>" + caption + "</span>"); return; } writer.WriteLine("<div class=\"queryIdSelect\">"); writer.WriteLine("<select id=\"queryId\" name=\"queryId\" size=\"10\">"); int selected = 0; for (int i = 0; i < queryEntries.Length; i++) { if (queryEntries[i].queryId.Equals(model.QueryId)) { selected = i; } } for (int i = 0; i < queryEntries.Length; i++) { string selectedOption = (i == selected ? " selected" : ""); writer.WriteLine("<option value=\"" + queryEntries[i].queryId + "\"" + selectedOption + ">" + queryEntries[i].query + "</option>"); } writer.WriteLine("</select>"); writer.WriteLine("</div>"); } writer.WriteLine("</fieldset>"); }