private async void btTest_ClickAsync(object sender, EventArgs e) { btTest.Enabled = false; btnSave.Enabled = false; btnCancel.Enabled = false; try { AppSettings.Settings.mqtt_serverandport = tb_ServerPort.Text.Trim(); AppSettings.Settings.mqtt_password = tb_Password.Text.Trim(); AppSettings.Settings.mqtt_username = tb_Username.Text.Trim(); AppSettings.Settings.mqtt_UseTLS = cb_UseTLS.Checked; using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait()) { Global.Log("------ TESTING MQTT --------"); string topic = AITOOL.ReplaceParams(this.cam, null, tb_Topic.Text.Trim()); string payload = AITOOL.ReplaceParams(this.cam, null, tb_Payload.Text.Trim()); List <string> topics = Global.Split(topic, ";|"); List <string> payloads = Global.Split(payload, ";|"); MQTTClient mq = new MQTTClient(); MqttClientPublishResult pr = null; for (int i = 0; i < topics.Count; i++) { pr = await mq.PublishAsync(topics[i], payloads[i], cam.Action_mqtt_retain_message); } Global.Log("------ DONE TESTING MQTT --------"); if (pr != null && (pr.ReasonCode == MqttClientPublishReasonCode.Success)) { MessageBox.Show("Success! See Log for details."); } else if (pr != null) { MessageBox.Show($"Failed. See log for details. Reason={pr.ReasonCode}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { } finally { btTest.Enabled = true; btnSave.Enabled = true; btnCancel.Enabled = true; } }
private void Updateformat() { try { lbl_Confidence.Text = string.Format(tb_ConfidenceFormat.Text.Trim(), 99.123); if (!string.IsNullOrEmpty(tb_ConfidenceFormat.Text.Trim())) { AppSettings.Settings.DisplayPercentageFormat = tb_ConfidenceFormat.Text.Trim(); } lbl_Confidence.ForeColor = Color.DarkGreen; lbl_DetectionFormat.Text = AITOOL.ReplaceParams(cam, null, null, tb_DetectionFormat.Text, Global.IPType.Path); lbl_DetectionFormat.Text = lbl_DetectionFormat.Text.Replace("[]", "").Replace("()", "").Replace(" ", " ").Replace(" ", " "); } catch (Exception) { lbl_Confidence.ForeColor = Color.Red; } }
private void bt_variables_Click(object sender, EventArgs e) { try { string vars = "[Camera];[Prefix];[CamInputFolder];[InputFolder];[ImagePath];[ImagePathEscaped];[ImageFilename];[ImageFilenameNoExt];[Username];[Password];[BlueIrisServerIP];[BlueIrisURL];[SummaryNonEscaped];[Summary];[Detection];[Label];[Detail];[Result];[Position];[Confidence];[Detections];[Confidences];[SummaryJson];[DetectionsJson];[AllJson];[PercentOfImage];%DATE%;%TIME%;%DATETIME%;%TEMP%;%APPDATA%;%USERPROFILE%;%USERNAME%"; List <string> varlist = vars.SplitStr(";"); List <ClsProp> props = new List <ClsProp>(); foreach (var varitm in varlist) { string value = AITOOL.ReplaceParams(cam, null, null, varitm, Global.IPType.URL); props.Add(new ClsProp(varitm, value)); } using (Frm_Variables frm = new Frm_Variables()) { frm.props = props; frm.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void label3_Click(object sender, EventArgs e) { MessageBox.Show(AITOOL.ReplaceParams(this.cam, null, label3.Text)); }
private async void btTest_ClickAsync(object sender, EventArgs e) { this.btTest.Enabled = false; this.btnSave.Enabled = false; this.btnCancel.Enabled = false; try { AppSettings.Settings.mqtt_serverandport = this.tb_ServerPort.Text.Trim(); AppSettings.Settings.mqtt_password = this.tb_Password.Text.Trim(); AppSettings.Settings.mqtt_username = this.tb_Username.Text.Trim(); AppSettings.Settings.mqtt_UseTLS = this.cb_UseTLS.Checked; using (Global_GUI.CursorWait cw = new Global_GUI.CursorWait()) { Log("------ TESTING MQTT --------"); string topic = AITOOL.ReplaceParams(this.cam, null, null, this.tb_Topic.Text.Trim()); string payload = AITOOL.ReplaceParams(this.cam, null, null, this.tb_Payload.Text.Trim()); List <string> topics = Global.Split(topic, ";|"); List <string> payloads = Global.Split(payload, ";|"); MQTTClient mq = new MQTTClient(); MqttClientPublishResult pr = null; ClsImageQueueItem CurImg = null; for (int i = 0; i < topics.Count; i++) { if (this.cam.Action_mqtt_send_image) { if (topics[i].IndexOf("/image", StringComparison.OrdinalIgnoreCase) >= 0) { if (!string.IsNullOrEmpty(this.cam.last_image_file_with_detections) && File.Exists(this.cam.last_image_file_with_detections)) { CurImg = new ClsImageQueueItem(this.cam.last_image_file_with_detections, 0); } else if (!string.IsNullOrEmpty(this.cam.last_image_file) && File.Exists(this.cam.last_image_file)) { CurImg = new ClsImageQueueItem(this.cam.last_image_file, 0); } else { CurImg = null; } } else { CurImg = null; } } pr = await mq.PublishAsync(topics[i], payloads[i], this.cam.Action_mqtt_retain_message, CurImg); } Log("------ DONE TESTING MQTT --------"); if (pr != null && (pr.ReasonCode == MqttClientPublishReasonCode.Success)) { MessageBox.Show("Success! See Log for details."); } else if (pr != null) { MessageBox.Show($"Failed. See log for details. Reason={pr.ReasonCode}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show($"Failed. See log for details.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { } finally { this.btTest.Enabled = true; this.btnSave.Enabled = true; this.btnCancel.Enabled = true; } }