private void LogItem(LoggedItem item) { try { lock (Sync) { if (!Initialized) { LoggedItems.Add(item); return; } } if (item is LoggedEvent) { var loggedEvent = (LoggedEvent)item; YandexMetrica.ReportEvent(loggedEvent.Title, loggedEvent.Values); } else if (item is LoggedException) { var loggedException = (LoggedException)item; YandexMetrica.ReportError(loggedException.Message, loggedException.Exception); } } catch (Exception) { } }
public MainPage() { Location = new YandexMetrica.Location(); InitializeComponent(); Loaded += (sender, args) => YandexMetrica.ReportEvent("Hello!"); Unloaded += (sender, args) => YandexMetrica.ReportEvent("Bye!"); LocationButton.Click += (sender, args) => YandexMetricaConfig.SetCustomLocation(Location); EventButton.Click += (sender, args) => YandexMetrica.ReportEvent(EventNameTextBox.Text); CrashButton.Click += (sender, args) => { throw new Exception(); }; ErrorButton.Click += (sender, args) => { try { throw new ArgumentException("Throw exception and catch it"); } catch (Exception exception) { YandexMetrica.ReportError(ErrorNameTextBox.Text, exception); } }; ResetButton.Click += (sender, args) => { YandexMetricaConfig.OfflineMode = false; YandexMetricaConfig.CrashTracking = true; YandexMetricaConfig.LocationTracking = true; YandexMetricaConfig.CustomAppVersion = null; YandexMetricaConfig.SetCustomLocation(null); }; JsonButton.Click += (sender, args) => YandexMetrica.ReportEvent("abc", JsonData.GetObject()); JsonButton.Click += (sender, args) => YandexMetrica.ReportEvent("abc", JsonData.GetDictionary()); }
private void Application_ThreadException(object sender, UnhandledExceptionEventArgs e) { Exception ex = (Exception)e.ExceptionObject; YandexMetrica.ReportError(ex.Message, ex); MessageBox.Show(ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public static void Log(Exception ex) { Debug.WriteLine(ex); _logger.Error(ex); YandexMetrica.ReportError("Exception", ex); }
public void LogException(Exception ex) { #if !DEBUG try { YandexMetrica.ReportError(ex.Message, ex); } catch (Exception) { } #endif }
private static void YandexReport(string msg, Exception ex) { try { YandexMetrica.ReportError(msg, ex); } catch (Exception e) { AutoCAD_PIK_Manager.Log.Error(e, "YandexReport"); } }
private void OnError(object sender, RoutedEventArgs e) { try { throw new ArgumentException("Throw exception and catch it'"); } catch (Exception ex) { YandexMetrica.ReportError("Main button error", ex); } }
public static void Error(Exception ex, string message = null) { Debug.WriteLine(message + "\r\n" + ex); YandexMetrica.ReportError(message, ex); Telemetry.TrackException(ex); #if DEBUG _logger.Error(message + ex, ex); #endif }
public static void Error(Exception ex, string message = null) { if (ex == null) { ex = new Exception(); } Debug.WriteLine(message + "\r\n" + ex); YandexMetrica.ReportError(message, ex); HockeyClient.Current.TrackException(ex); _logger.Error(message, ex); }
public void BeginPolling() { foreach (var messenger in _messengers) { messenger.MessageRecieved += message => { try { MessageRecieved?.Invoke(message); } catch (Exception e) { YandexMetrica.ReportError("Error", e); Logger.Error(e, "Error"); } }; messenger.BeginPolling(); } }
public async Task Send(SentMessage message, RecivedMessage recivedMessage) { if (message.ChatId.Messenger != MessengerId) { return; } LastMessageSent = DateTime.Now; IReplyMarkup replyMarkup; if (message.Buttons == null) { // Leave previous keyboard replyMarkup = null; } else { var markup = new KeyboardButton[message.Buttons.Length][]; var keyboard = false; for (var i = 0; i < message.Buttons.Length; i++) { var buttons = message.Buttons[i]; markup[i] = new KeyboardButton[buttons.Length]; for (var j = 0; j < buttons.Length; j++) { markup[i][j] = new KeyboardButton(buttons[j]); keyboard = true; } } if (keyboard) { replyMarkup = new ReplyKeyboardMarkup(markup) { Selective = true }; } else { replyMarkup = new ReplyKeyboardRemove { Selective = true }; } } var parseMode = message.Formatted ? ParseMode.Markdown : ParseMode.Default; var text = message.Text; if (recivedMessage?.ReplyUserId != null) { text += $"\n[@](tg://user?id={recivedMessage.ReplyUserId})"; } try { await _bot.SendTextMessageAsync( message.ChatId.Id, text, parseMode, replyMarkup : replyMarkup //replyToMessageId: recivedMessage?.ReplyId ?? 0 // Not working, because MessageId is different for each bot ); } catch (Exception e) { if (e is ForbiddenException) { // User stopped this bot. } else { YandexMetrica.ReportError("Error while sending message", e); Logger.Error(e, "Error while sending message"); } } }
private static void MessageHandler(RecivedMessage message) { if (message == null) { return; } #if DEBUG Logger.Debug($"Message from {message.UserId}@{message.ChatId}"); #endif using (var context = new UserContext(message.UserId, message.ChatId)) { User.User user = context; try { user.MessageManager.RecievedMessage = message; message.Action?.Invoke(message, user); switch (message.Text.Split('@')[0].Split(' ')[0]) { case "/start": { user.RoomManager.Go("_root", false); break; } case "/debug": { var serialized = MessageManager.Escape(MessagePackSerializer.ToJson( new PublicUser(user) )); user.MessageManager.SendImmediately(new SentMessage { Text = $"Всё про вас:\n```\n{serialized}\n```", Intent = "command-debug" }); break; } case "/lag": { user.MessageManager.SendImmediately(new SentMessage { Text = @"Если бот долго отвечает, то создайте беседу и обязательно пригласите туда @AdventureTownBot. После этого пригласите туда @PocketTownBot и @MonsterTownBot", Intent = "command-lag" }); break; } case "/repeat": { user.MessageManager.SendImmediately(user.MessageManager.LastMessages.Last()); break; } case "/token": { user.MessageManager.SendImmediately(new SentMessage { Text = $@"Ваш токен: `{user.Token}`. Используйте его чтобы связать другой аккаунт с этим персонажем (`/link {user.Info.UserId.Messenger} {user.Info.UserId.Id} {user.Token}`). Чтобы сгенерировать новый токен используйте `/revoke`", Intent = "command-token" }); break; } case "/revoke": { user.Token = Guid.NewGuid(); user.MessageManager.SendImmediately(new SentMessage { Text = $"Ваш новый токен: `{user.Token}`.", Intent = "command-revoke" }); break; } case "/link": { var splitted = message.Text.Split(' '); if (splitted.Length != 4 || !int.TryParse(splitted[1], out var messenger) || !long.TryParse(splitted[2], out var id) || !Guid.TryParse(splitted[3], out var token)) { user.MessageManager.SendImmediately(new SentMessage { Text = @"Чтобы связвть этот аккаунт с другим игровым персонажем используйте `/link <messenger_id> <user_id> <token>`", Intent = "command-link-error" }); break; } var uid = new UserId(messenger, id); if (uid.Equals(user.Info.UserId)) { user.MessageManager.SendImmediately(new SentMessage { Text = @"К сожалению, нельзя связаться с самим собой", Intent = "command-link-self" }); break; } using (var linkTo = new UserContext(uid)) { if (linkTo.User.Token != token) { user.MessageManager.SendImmediately(new SentMessage { Text = @"Не удалось связать аккаунты. Проверьте, всё ли правильно вы ввели", Intent = "command-link-forbidden" }); break; } } user.LinkedTo = new Tuple <UserId, Guid>(uid, token); user.MessageManager.SendImmediately(new SentMessage { Text = @"Отлично! Чтобы отвязать аккаунт используйте `/unlink`", Intent = "command-link" }); break; } case "/unlink": { context.Unlink(); user.MessageManager.SendImmediately(new SentMessage { Text = @"Готово!", Intent = "command-unlink" }); break; } default: { user.MessageManager.OnRecieved(message); break; } } user.MessageManager.Finish(); } catch (Exception e) { YandexMetrica.ReportError($"Error for user {message.UserId}@{message.ChatId}", e); Logger.Error(e, $"Error for user {message.UserId}@{message.ChatId}"); var error = MessageManager.Escape(e.ToString()); user.MessageManager.SendImmediately(new SentMessage { Text = $"Вы пошатнули мироздание и произошла ошибка:\n```{error}```", Intent = "error" }); } } }