示例#1
0
        bool IsNewPart(string line, out ReadPartIntermediateResult result)
        {
            if (line.StartsWith("[Message summarized"))
            {
                result = new ReadPartIntermediateResult(null, Constants.PREFIX_MESSAGESUMMARIZED, null, null);
                return(false);
            }

            var match = util.regexPrefix.Match(line);

            if (match.Success)
            {
                var prefix     = match.Groups[1].Value;
                var dateStr    = match.Groups[2].Value;
                var restOfLine = match.Groups[3].Value;
                result = new ReadPartIntermediateResult(line, prefix, dateStr, restOfLine);
                return(true);
            }

            foreach (var noBracePrefix in noBracePrefixes)
            {
                if (line.StartsWith(noBracePrefix))
                {
                    var prefix = noBracePrefix;
                    result = new ReadPartIntermediateResult(line, prefix, null, line);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
示例#2
0
        public async Task <ICollection <IMtgaOutputLogPartResult> > ProcessIntoMessagesAsync(string userId, Stream streamMtgaOutputLog)
        {
            var ret = new List <IMtgaOutputLogPartResult>();

            void AddMessage(ReadPartIntermediateResult part, DateTime logDateTime)
            {
                if (part == null || part.Part.Contains("Failing to send Text Message due to disconnection") || part.Part.StartsWith(BI_ERROR))
                {
                    return;
                }

                try
                {
                    if (converters.ContainsKey(part.Prefix))
                    {
                        IEnumerable <IMtgaOutputLogPartResult> messages = converters[part.Prefix].ParsePart(part.LeftToParse);

                        if (messages == null)
                        {
                            return;
                        }

                        foreach (var m in messages)
                        {
                            if (m is IgnoredResult && converters.ContainsKey(part.Prefix) && m.LogTextKey == null)
                            {
                                m.LogTextKey = part.Prefix;
                            }

                            convertersUsage.Add(new ConverterUsage
                            {
                                Converter  = converters[part.Prefix].GetType().Name,
                                LogTextKey = m.LogTextKey,
                                LastUsed   = logDateTime,
                                Prefix     = part.Prefix,
                                Result     = m.GetType().Name
                            });
                        }

                        if (logDateTime == default)
                        {
                            messages = messages.Where(m => m.GetType().IsDefined(typeof(AddMessageEvenIfDateNullAttribute), false));
                        }

                        ret.AddRange(messages.Select(m => m.SetCommonFields(part.Part, part.Prefix, logDateTime)));
                    }
                    else
                    {
                        ret.Add(new UnknownResult().SetCommonFields(part.Part, part.Prefix, logDateTime));
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Invalid JSON"))
                    {
                        Log.Error(ex, "(Managed) {outputLogError} Unknown error [{exceptionMessage}] in AddMessage with part: <<{part}>>", "OUTPUTLOG", ex.Message, part);
                    }
                    else
                    {
                        Log.Warning("(Managed) {outputLogError} Unknown error [{exceptionMessage}] in AddMessage", "OUTPUTLOG", ex.Message);
                    }
                    ret.Add(new UnknownResult().SetCommonFields(part.Part, part.Prefix, logDateTime));
                }
            }

            using (var streamReader = new StreamReader(streamMtgaOutputLog, Encoding.UTF8, true, 4096))
            {
                ReadPartIntermediateResult currentPart = null;

                string line;
                while ((line = await streamReader.ReadLineAsync()) != null)
                {
                    if (currentPart == null) // first line
                    {
                        if (line.StartsWith("<!DOCTYPE html>") ||
                            line.StartsWith("<html"))
                        {
                            throw new ParseCollectionInvalidHtmlFoundException();
                        }

                        if (line.StartsWith("using manifest Manifest_") ||
                            line.StartsWith("SAMPLES") ||
                            line.StartsWith("Source Manifest Hashes"))
                        {
                            throw new ParseCollectionInvalidFileException();
                        }
                    }

                    //if (line.Contains("[{\"collationId\":100017,\"count\":-10}]")) System.Diagnostics.Debugger.Break();

                    //if (line.Contains("[UnityCrossThreadLogger]8/3/2019 12:11:45 AM: Match to 933E5CE627155485: AuthenticateResponse")) System.Diagnostics.Debugger.Break();
                    //if (line.Contains("STATE CHANGED MatchCompleted -> Disconnected")) System.Diagnostics.Debugger.Break();

                    TryDeduceAndSetDateTime(userId, line);

                    if (IsNewPart(line, out var newPart))
                    {
                        // New part started, add previous part as message
                        AddMessage(currentPart, LogDateTime);
                        currentPart = newPart;

                        TrySetLogDate(userId, currentPart.DateTimeStr);
                    }
                    else if (currentPart != null)
                    {
                        // Message summarized is only written in the second line of a "Match to" GreToClientEvent
                        if (newPart != null)
                        {
                            currentPart.Prefix = newPart.Prefix;
                        }

                        currentPart.AddLine(line);
                    }
                }

                // Don't forget to process last part
                AddMessage(currentPart, LogDateTime);
            }

            return(ret);
        }