Esempio n. 1
0
        private void OnEvent_btnConvert_Click(object sender, EventArgs e)
        {
            Progress = 0;
            ClearLog();
            btnConvert.Enabled = false;

            try
            {
                using (var progressMonitor = new ProgressMonitorAdapter(this))
                {
                    var selectedFile = txtFileSelection.Text ?? "";
                    selectedFile = selectedFile.Trim();
                    if (selectedFile.Length == 0)
                    {
                        AppendLog("No file selected");
                        return;
                    }

                    if (!File.Exists(selectedFile))
                    {
                        AppendLog($"File not found: {selectedFile}");
                        return;
                    }

                    var converter = new LogConverter(_manager);
                    var result    = converter.ConvertLog(selectedFile, _chosenFormater, progressMonitor);

                    if (!ckbReplaceOldLog.Checked)
                    {
                        var idx = selectedFile.LastIndexOf(".");
                        if (idx < 0)
                        {
                            selectedFile += $".{_chosenFormater.Id}.log";
                        }
                        else
                        {
                            selectedFile = selectedFile.Substring(0, idx) + $".{_chosenFormater.Id}" + selectedFile.Substring(idx);
                        }
                    }

                    progressMonitor.Log($"Saving log: {selectedFile}");
                    File.WriteAllLines(selectedFile, result, System.Text.Encoding.UTF8);
                }
            }
            catch (Exception ex)
            {
                AppendLog("Error");
                AppendLog($"{ex}");
            }
            finally
            {
                btnConvert.Enabled = true;
                Progress           = 1;
            }
        }
Esempio n. 2
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;
        }