/// <summary> /// Converts the string to command parameters. /// </summary> public static bool Parse(string s, out CmdParams cmdParams, out string errMsg) { try { cmdParams = new CmdParams(); string[] lines = (s ?? "").Split('\n'); foreach (string line in lines) { int idx = line.IndexOf('='); if (idx > 0) { string key = line.Substring(0, idx).Trim().ToLowerInvariant(); string value = line.Substring(idx + 1).Trim(); if (key == "cmd") { cmdParams.Action = Enum.TryParse(value, true, out CmdAction action) ? action : CmdAction.None; } else if (key == "mindt") { cmdParams.MinDT = DateTime.Parse(value, DateTimeFormatInfo.InvariantInfo); } else if (key == "maxdt") { cmdParams.MaxDT = DateTime.Parse(value, DateTimeFormatInfo.InvariantInfo); } } } if (cmdParams.Action != CmdAction.None && cmdParams.MinDT > DateTime.MinValue && cmdParams.MaxDT > DateTime.MinValue) { errMsg = ""; return(true); } else { errMsg = Localization.UseRussian ? "Некорректная команда" : "Incorrect command"; return(false); } } catch { cmdParams = null; errMsg = Localization.UseRussian ? "Ошибка при разборе команды" : "Error parsing command"; return(false); } }
/// <summary> /// Enqueues the command for execution. /// </summary> public void EnqueueCmd(int outCnlNum, Command cmd, ref bool passToClients) { if (cmd == null) { throw new ArgumentNullException(nameof(cmd)); } if (outCnlNum == exporterConfig.GeneralOptions.OutCnlNum) { passToClients = false; if (CmdParams.Parse(cmd.GetCmdDataStr(), out CmdParams cmdParams, out string errMsg)) { switch (cmdParams.Action) { case CmdAction.ArcUpload: if (arcDataQueue == null) { log.WriteError(Localization.UseRussian ? "Невозможно выполнить команду, потому что экспорт архивов отключен" : "Unable to execute a command because archive export is disabled"); } else { log.WriteError(Localization.UseRussian ? "Получена команда экспорта архивов" : "Archive export command received"); taskUploadState = new ArcUploadState() { SnapshotDate = cmdParams.MinDT.Date, MinSnapshotDT = cmdParams.MinDT, MaxSnapshotDT = cmdParams.MaxDT }; } break; case CmdAction.EvUpload: if (eventQueue == null) { log.WriteError(Localization.UseRussian ? "Невозможно выполнить команду, потому что экспорт событий отключен" : "Unable to execute a command because event export is disabled"); } else { log.WriteError(Localization.UseRussian ? "Получена команда экспорта событий" : "Event export command received"); ExportEventsFromFile(cmdParams.MinDT, cmdParams.MaxDT); } break; default: log.WriteError(Localization.UseRussian ? "Неизвестная команда" : "Unknown command"); break; } } else { log.WriteError(errMsg); } }