Exemple #1
0
        private bool CheckForParseCommands(string line)
        {
            if (line.StartsWith("Chatlogger Id:"))
            {
                var parserId = line.Substring(line.IndexOf(":") + 1).Trim();
                _parserContainer = _manager.GetParser(parserId);
                if (_parserContainer == null)
                {
                    _monitor.Log($"No parser for chatlogger id: {parserId}");
                }
                else
                {
                    _monitor.Log($"Converting from {_formaterContainer.Id} to {_parserContainer.Id} ...");
                }
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public IEnumerable <string> ConvertLog(string file, LogFormaterContainer formater, ProgressMonitorAdapter monitor)
        {
            _file              = file ?? throw new ArgumentNullException(nameof(file));
            _monitor           = monitor ?? throw new ArgumentNullException(nameof(monitor));
            _formaterContainer = formater ?? throw new ArgumentNullException(nameof(formater));

            try
            {
                ConvertLog();
                var result = _result;
                return(result);
            }
            finally
            {
                _file              = null;
                _monitor           = null;
                _parserContainer   = null;
                _formaterContainer = null;
                _result            = null;
            }
        }
Exemple #3
0
        private void ConvertLog()
        {
            _result           = new List <string>();
            _monitor.Progress = 0;

            var lines = ReadFile();

            if (lines.Length == 0)
            {
                return;
            }

            _result.Add($"Chatlogger Id: {_formaterContainer.Id}");
            _parserContainer = _manager.GetParser("ACTv1"); //act logs don't have an id, so this will be the default parser.

            for (var lineIdx = 0; lineIdx < lines.Length; ++lineIdx)
            {
                _monitor.Progress = lineIdx / lines.Length;
                var line = lines[lineIdx];

                try
                {
                    if (CheckForParseCommands(line))
                    {
                        continue;
                    }

                    if (_parserContainer == null)
                    {
                        continue;
                    }

                    var parser   = _parserContainer.Parser;
                    var formater = _formaterContainer.Formater;

                    parser.Read(line);

                    if (!parser.NeedMore)
                    {
                        foreach (var parsedLine in parser.GetResults().Select(e => formater.Format(e)).SelectMany(e => e))
                        {
                            _result.Add(parsedLine);
                        }
                    }

                    if (parser.ReparseLines > 0)
                    {
                        lineIdx = Math.Max(0, lineIdx - parser.ReparseLines);
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Error in line {lineIdx}: {line}");
                    _monitor.Log(ex.Message);
                    throw;
                }
            }

            if (_parserContainer.Parser.NeedMore)
            {
                _monitor.Log("Log incomplete");
            }

            _monitor.Progress = 1;
        }