aboutsummaryrefslogtreecommitdiffstats
path: root/Software/PMR/Messages/ThreadLoading/StopThreadLoadingRequest.proto
blob: 03f5df91fb712deeb6c7fc4fe8e5822fd8203876 (plain)
1
2
3
4
5
6
7
8
9
syntax = "proto3";

package Tango.PMR.ThreadLoading;
option java_package = "com.twine.tango.pmr.threadloading";

message StopThreadLoadingRequest
{

}
{ color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Tango.Integration.Operation;
using Tango.Logging;
using Tango.Settings;

namespace Tango.MachineStudio.Logging.Parsing
{
    public class EmbeddedLogFileParser : ILogFileParser<EmbeddedLogItem>
    {
        public List<LogFile> GetLogFiles()
        {
            List<LogFile> logFiles = new List<LogFile>();

            FileLogger logger = MachineOperator.EmbeddedLogManager.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger)) as FileLogger;

            String logFile = logger != null ? logger.LogFile : null;

            if (Directory.Exists(MachineOperator.EmbeddedLogsFolder))
            {
                foreach (var file in Directory.GetFiles(MachineOperator.EmbeddedLogsFolder, "*.log").Where(x => x != logFile))
                {
                    String dateString = Path.GetFileNameWithoutExtension(file).Replace(MachineOperator.EmbeddedLogsTag + "-", "");
                    DateTime date = DateTime.ParseExact(dateString, "dd-MM-yyyy_HH-mm-ss", CultureInfo.InvariantCulture);
                    logFiles.Add(new LogFile() { DateTime = date, File = file });
                }
            }

            return logFiles;
        }

        public List<EmbeddedLogItem> Parse(LogFile logFile)
        {
            List<EmbeddedLogItem> logItems = new List<EmbeddedLogItem>();

            String text = File.ReadAllText(logFile.File);
            var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])");

            for (int i = 1; i < logs.Length; i += 2)
            {
                try
                {
                    DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture);
                    String rest = logs[i + 1];

                    var entries = Regex.Split(rest, @"\[(.*?)\]");

                    EmbeddedLogItem item = new EmbeddedLogItem(new PMR.Debugging.StartDebugLogResponse()
                    {
                        Category = (PMR.Debugging.DebugLogCategory)Enum.Parse(typeof(PMR.Debugging.DebugLogCategory), entries[1]),
                        FileName = entries[3],
                        LineNumber = uint.Parse(entries[5]),
                        ModuleId = uint.Parse(entries[7]),
                        Filter = uint.Parse(entries[9]),
                        Message = new String(entries[10].Skip(2).ToArray())
                    });

                    item.TimeStamp = new DateTime(logFile.DateTime.Year, logFile.DateTime.Month, logFile.DateTime.Day, date.Hour, date.Minute, date.Second, date.Millisecond);

                    logItems.Add(item);
                }
                catch (Exception ex)
                {
                    LogManager.Default.Log(ex, "Could not parse log line: " + logs[i]);
                }
            }

            return logItems;
        }
    }
}