mirror of
https://github.com/salexdv/Telemonitor1C.git
synced 2026-06-19 22:57:53 +02:00
add params for commands
This commit is contained in:
+4
-2
@@ -25,11 +25,13 @@ namespace Telemonitor
|
||||
/// <summary>
|
||||
/// Сообщение с командой
|
||||
/// </summary>
|
||||
public TelegramMessage message { get; set; }
|
||||
public TelegramMessage Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Команда для выполнения
|
||||
/// </summary>
|
||||
public Command command { get; set; }
|
||||
public Command Command { get; set; }
|
||||
|
||||
public string Parameters { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ namespace Telemonitor
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return text.Trim().ToLower();
|
||||
return text.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+38
-10
@@ -242,34 +242,59 @@ namespace Telemonitor
|
||||
private void ExecuteCommand(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
TelegramCommand tCommand = (TelegramCommand)e.Argument;
|
||||
V8Connector connector = new V8Connector(tCommand.command);
|
||||
V8Connector connector = new V8Connector(tCommand.Command, tCommand.Parameters);
|
||||
|
||||
Logger.Debug(tmSettings, "Запуск команды " + tCommand.command.ID + " на выполнение", false, mutLogger);
|
||||
Logger.Debug(tmSettings, "Запуск команды " + tCommand.Command.ID + " на выполнение", false, mutLogger);
|
||||
// Создание ComConnector и выполнение кода команды
|
||||
V8Answer result = connector.Execute(mutLogger);
|
||||
Logger.Debug(tmSettings, "Команда " + tCommand.command.ID + " выполнена", false, mutLogger);
|
||||
Logger.Debug(tmSettings, "Команда " + tCommand.Command.ID + " выполнена", false, mutLogger);
|
||||
|
||||
if (connector.Success) {
|
||||
if (!String.IsNullOrEmpty(result.Text))
|
||||
SendMessage(tCommand.message.chat.id, result.Text);
|
||||
SendMessage(tCommand.Message.chat.id, result.Text);
|
||||
|
||||
if (!String.IsNullOrEmpty(result.FileName))
|
||||
SendDocument(tCommand.message.chat.id, result.FileName);
|
||||
SendDocument(tCommand.Message.chat.id, result.FileName);
|
||||
|
||||
if (String.IsNullOrEmpty(result.Text) && String.IsNullOrEmpty(result.FileName))
|
||||
SendMessage(tCommand.message.chat.id, "Команда выполнена");
|
||||
SendMessage(tCommand.Message.chat.id, "Команда выполнена");
|
||||
}
|
||||
else
|
||||
SendMessage(tCommand.message.chat.id, "Ошибка при выполнении команды");
|
||||
SendMessage(tCommand.Message.chat.id, "Ошибка при выполнении команды");
|
||||
|
||||
connector.Dispose();
|
||||
|
||||
messageOrder.Remove(tCommand.message.message_id);
|
||||
messageOrder.Remove(tCommand.Message.message_id);
|
||||
|
||||
((BackgroundWorker)sender).CancelAsync();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает параметры из команды (все что отделено пробелом).
|
||||
/// Текст команды при этом приводится к чистому виду.
|
||||
/// </summary>
|
||||
/// <param name="cmd">Текст поступившей команды</param>
|
||||
/// <returns>Параметры команды, разделенные запятыми</returns>
|
||||
private string extractParamForCommand(string cmd, out string newCmd)
|
||||
{
|
||||
string param = "";
|
||||
|
||||
string[] subStr = cmd.Split(' ');
|
||||
newCmd = subStr[0];
|
||||
|
||||
for (int i = 1; i < subStr.Length; i++) {
|
||||
param += subStr[i];
|
||||
param += ',';
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(param))
|
||||
param = param.Remove(param.Length - 1);
|
||||
|
||||
return param;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Разбирает полученное сообщение и определяет, что с ним делать
|
||||
/// <PARAM name="message">Сообщение TelegramMessage</PARAM>
|
||||
@@ -277,6 +302,8 @@ namespace Telemonitor
|
||||
private void listener_CheckMessage(TelegramMessage message)
|
||||
{
|
||||
string text = message.ToString();
|
||||
string param = extractParamForCommand(text, out text);
|
||||
text = text.ToLower();
|
||||
|
||||
if (text == "/start") {
|
||||
// Запрошен список команд
|
||||
@@ -294,8 +321,9 @@ namespace Telemonitor
|
||||
// Запрошена команда из списка
|
||||
if (!messageOrder.ContainsKey(message.message_id)) {
|
||||
TelegramCommand tCommand = new TelegramCommand();
|
||||
tCommand.message = message;
|
||||
tCommand.command = (Command)cmd;
|
||||
tCommand.Message = message;
|
||||
tCommand.Command = (Command)cmd;
|
||||
tCommand.Parameters = param;
|
||||
messageOrder.Add(message.message_id, tCommand);
|
||||
BackgroundWorker executer = new BackgroundWorker();
|
||||
executer.WorkerSupportsCancellation = true;
|
||||
|
||||
+11
-4
@@ -23,6 +23,11 @@ namespace Telemonitor
|
||||
/// </summary>
|
||||
private Command excCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Параметры выполняемой команды
|
||||
/// </summary>
|
||||
private string excParams;
|
||||
|
||||
/// <summary>
|
||||
/// Тип для создания ComConnector
|
||||
/// </summary>
|
||||
@@ -63,13 +68,14 @@ namespace Telemonitor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор класса
|
||||
/// <PARAM name="cmdName">Имя команды</PARAM>
|
||||
/// Конструктор класса
|
||||
/// <PARAM name="cmdObj">Команда</PARAM>
|
||||
/// <PARAM name="parameters">Параметры команды</PARAM>
|
||||
/// </summary>
|
||||
public V8Connector(Command cmdObj)
|
||||
public V8Connector(Command cmdObj, string parameters)
|
||||
{
|
||||
this.excCommand = cmdObj;
|
||||
this.excParams = parameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,7 +99,8 @@ namespace Telemonitor
|
||||
Connection = v80Type.InvokeMember("Connect", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.InvokeMethod, null, v8Connector, new object[1] { this.excCommand.ConnectionString });
|
||||
object externalData = GetProperty(null, "ExternalDataProcessors");
|
||||
object executer = Method(externalData, "Create", new object[1] { runPath + "executer" + v8version + ".tep" });
|
||||
SetProperty(executer, "Код", this.excCommand.Code);
|
||||
SetProperty(executer, "Код", this.excCommand.Code);
|
||||
SetProperty(executer, "ПараметрыКоманды", this.excParams);
|
||||
Method(executer, "ExecuteCode", new object[0]);
|
||||
result = (string)GetProperty(executer, "Результат");
|
||||
fName = (string)GetProperty(executer, "Результат_Файл");
|
||||
|
||||
Reference in New Issue
Block a user