protected virtual void OnResponseReceived(LongPollResponseEventArgs e) { var handler = ResponseReceived; handler?.Invoke(this, e); }
/// <summary> /// Обработка входящего сообщения. /// </summary> /// <param name="sender">Объект, в котором вызвано событие.</param> /// <param name="e">Аргументы события.</param> private void LpOnResponseReceived(object sender, LongPollResponseEventArgs e) { var lpe = e; var resp = lpe.RawResponse; var resp1 = lpe.Response; //Console.WriteLine(resp.RawJson); Log.Trace(resp.RawJson.TrimEnd()); if (resp1.Failed != null) { Log.Warn("Ошибка сервера, перезапуск"); LongPoller.Start(); return; } if (resp1.Updates.Count == 0) { return; } try { if (resp1.Updates[0].Type != "message_new") { return; } var msg = resp1.Updates[0].Object; var msgtext = msg.Text; if (msgtext == "") { return; } var spl = msgtext.Split(); var a = 0; var b = 0; if (spl.Length != 2) { return; } try { a = Int32.Parse(spl[0]); b = Int32.Parse(spl[1]); } catch { return; } var chatConfig = (from i in Config.ChatConfigs where i.PeerId == msg.PeerId select i).First(); var compiler = new Compiler(chatConfig); var ans = compiler.Compile((Day)a, (Week)b); Log.Trace($"Ответ сформирован:\r\n{ans.Trim()}"); Api.Messages.Send(new MessagesSendParams { PeerId = msg.PeerId, Message = ans }); Log.Debug("Отвечено"); } catch (Exception ex) { Log.Warn(ex); //Console.WriteLine(ex); } }