Пример #1
0
        public LogsMonitorEventArgs(CharacterName characterName, LogType logType, IEnumerable <LogEntry> wurmLogEntries, string pmRecipientNormalized = null)
        {
            if (characterName == null)
            {
                throw new ArgumentNullException(nameof(characterName));
            }
            if (wurmLogEntries == null)
            {
                throw new ArgumentNullException(nameof(wurmLogEntries));
            }
            if (pmRecipientNormalized == null)
            {
                pmRecipientNormalized = string.Empty;
            }

            CharacterName         = characterName;
            LogType               = logType;
            WurmLogEntries        = wurmLogEntries;
            PmRecipientNormalized = pmRecipientNormalized;
        }
Пример #2
0
        /// <summary>
        /// Attempts to parse server name from a log entry.
        /// Null if parsing failed.
        /// </summary>
        /// <param name="logEntry"></param>
        /// <param name="logger">Optional, will log parsing errors.</param>
        /// <param name="sourceCharacterName">Optional, will be appended to log message.</param>
        /// <returns></returns>
        public static ServerStamp TryGetServerFromLogEntry(this LogEntry logEntry, IWurmApiLogger logger = null, CharacterName sourceCharacterName = null)
        {
            ServerStamp result = null;

            // attempt some faster matchers first, before trying actual parse
            if (Regex.IsMatch(logEntry.Content, @"other players are online", RegexOptions.Compiled))
            {
                result = TryGetMatchResult(TryMatch1(logEntry), logEntry);
                if (result == null)
                {
                    result = TryGetMatchResult(TryMatch2(logEntry), logEntry);
                }
                if (result == null)
                {
                    logger?.Log(
                        LogLevel.Warn,
                        string.Format(
                            "ServerHistoryProvider found 'other players are online' log line, but could not parse it. Character: {0} Entry: {1}",
                            sourceCharacterName,
                            logEntry),
                        "ServerParsingHelper",
                        null);
                }
            }
            return(result);
        }