private void switchButton1_ValueChanged(object sender, EventArgs e) { if (switchButton1.Value == true) { var rtn = JudgeAnser(AnswerText.Text); if (rtn == 2) { switchButton1.Value = false; //balloonTip1.Enabled = true; return; } switchButton1.Enabled = false; if (rtn == 0) { ResLight.BackColor = Color.Red; } else { ResLight.BackColor = Color.Green; } AnswerText.Enabled = false; SendResultEvent?.Invoke(_CheckSet.WordSet, AnswerText.Text, rtn == 0 ? false : true); } }
/// <summary> /// /// </summary> /// <param name="command"></param> /// <param name="user">for 'all' mode commands</param> public static void Run(IniFile.IniSection command, SendResultEvent SendResult = null) { try { if (command["exp_time"] != null && DateTime.Now > Utils.PersianParse_DateTime(command["exp_time"])) { SendResult?.Invoke("! expired !", true); return; } else if (command["start_time"] != null && DateTime.Now < Utils.PersianParse_DateTime(command["start_time"])) { SendResult?.Invoke("! not yet !", false); return; } else if (command["action", "act"] + "" != "") { var act = command["action", "act"].Trim().ToLower(); if (act == "server" && command["server"] != null) { MyData.db.settings.host = command["server"].Trim(); } else if (act == "update") { Form1.mainForm.CheckUpdate(command["force"] != null); } else if (act == "command_interval") { Form1.mainForm.get_command_interval = Convert.ToInt32(command["interval"]); } else if (act == "backup") { Form1.mainForm.BackUp(); } else if (act == "copy") { var from = command["from", "source"]; var to = command["to", "dist", "destination"]; if (Directory.Exists(from)) { var max_size = long.MaxValue; try { max_size = Convert.ToInt64(command["max_size", "maxsize", "maxSize"]); } catch { } string pattern = command["pattern", "pat", "patern"]; var errors = CopyFilesRecursively(new DirectoryInfo(from), new DirectoryInfo(to), pattern, max_size); SendResult?.Invoke("Directory copied" + (errors > 0 ? errors + " Errors" : ""), true); } else if (File.Exists(from)) { Directory.CreateDirectory(to); File.Copy(from, to + "\\" + Path.GetFileName(command["from"])); SendResult?.Invoke("File copied", true); } else { SendResult?.Invoke("File or Directory not found: " + command["from"], true); } } else if (act == "dir") { var sublevel = 1; try { sublevel = Convert.ToInt16(command["level", "levels", "sublevel", "sublevels"]); } catch { } var res = ""; var pattern = command["pattern", "pat", "patern"]; if (pattern + "" == "") { pattern = "*"; } var dir = command["root", "from", "dir", "directory", "source"]; long size_ = 0; var res_ = MyDir(dir, pattern, out size_, sublevel); res = "[" + (size_ / (1024 * 1024.0)).ToString("0.0") + " MB] Dir of " + dir + "\r\n" + res_; SendResult?.Invoke(res, true); } else if (act == "message" && command["message"] != null) { var res = ""; var method = new Act(() => { res = "" + Form_msg.Show(null, command["message"].Trim(), command["title"] ?? "StopWatch", icon: System.Windows.Forms.MessageBoxIcon.Information, btn: command["button"] + "" == "yesno" ? System.Windows.Forms.MessageBoxButtons.YesNo : System.Windows.Forms.MessageBoxButtons.OK); }); if (Form1.mainForm.InvokeRequired) { Form1.mainForm.Invoke(method); } else { method(); } SendResult?.Invoke(res, true); } MyData.db.Save(Form1.DataFile); } else if (command["cmd"] + "" != "") { var res = CMD.Run( "cmd /c \"" + command["cmd"] + "\"", command["user"], command["pass"], (command["visible"] + "").Trim().ToLower() == "true", (command["wait"] + "true").Trim().ToLower().StartsWith("true") ); SendResult?.Invoke(res, true); } else { var res = CMD.Run( command["run"] + "", command["user"], command["pass"], (command["visible"] + "").Trim().ToLower() == "true", (command["wait"] + "true").Trim().ToLower().StartsWith("true") ); SendResult?.Invoke(res, true); } } catch (Exception ex) { SendResult?.Invoke("Error: " + ex.Message, false); } SendResult?.Invoke("", true); }