Пример #1
0
        public void Refresh(Log.LogLine logLine)
        {
            if (InvokeRequired)
            {
                this.Invoke(new MethodInvoker(
                                delegate() { Refresh(logLine); }));
                return;
            }

            Log.Variable var = logLine.GetVariableByName(sessionVariable.Name);
            if (var != null)
            {
                this.chart1.Series[0].Points[0].YValues[0] = (double)var.Value;
                this.chart1.Invalidate();
            }
        }
Пример #2
0
        private void Parse(string line, LogLine last)
        {
            string[] values = line.Split(LogLine.COLUMN_SEP);

            if (last == null)
            {
                try
                {
                    TimeStamp = decimal.Parse(values[0], VisualME7Logger.Log.ME7LoggerLog.CultureInfo);
                }
                catch
                {
                    try
                    {
                        TimeStampDateTime = DateTime.Parse(values[0]);
                        TimeStamp         = 0;
                    }
                    catch
                    {
                        TimeStampDateTime = DateTime.ParseExact(values[0], "HH:mm:ss:ffff", System.Globalization.CultureInfo.CurrentCulture);
                        TimeStamp         = 0;
                        timeOnly          = true;
                    }
                }
            }
            else
            {
                if (!last.TimeStampDateTime.HasValue)
                {
                    TimeStamp = decimal.Parse(values[0], VisualME7Logger.Log.ME7LoggerLog.CultureInfo);
                }
                else
                {
                    if (!last.timeOnly)
                    {
                        TimeStampDateTime = DateTime.Parse(values[0]);
                    }
                    else
                    {
                        TimeStampDateTime = DateTime.ParseExact(values[0], "HH:mm:ss:ffff", System.Globalization.CultureInfo.CurrentCulture);
                        timeOnly          = true;
                    }
                    TimeStamp = last.TimeStamp + (decimal)TimeStampDateTime.Value.Subtract(last.TimeStampDateTime.Value).TotalSeconds;
                }
            }

            int i = 1;

            foreach (SessionVariable sv in Log.Session.Variables.Values)
            {
                string value = string.Empty;
                if (values.Length > i)
                {
                    value = values[i].Trim();
                }
                Variable v = new Variable(this, sv, value);
                variables.Add(v);
                if (!variablesByName.ContainsKey(v.SessionVariable.Name))
                {
                    variablesByName.Add(v.SessionVariable.Name, v);
                }
                i++;
            }
        }
Пример #3
0
 internal LogLine ReadLine(string line, LogLine last)
 {
     return(new LogLine(this, line, ++lineNumber, last));
 }
Пример #4
0
 public LogLine(ME7LoggerLog log, string line, int lineNumber, LogLine last)
 {
     this.Log        = log;
     this.LineNumber = lineNumber;
     this.Parse(line, last);
 }
Пример #5
0
        private void OpenFromLogFile(object parameter)
        {
            string logFilePath = (string)((object[])parameter)[0];
            bool   tailFile    = (bool)((object[])parameter)[1];

            if (tailFile)
            {
                while (true)
                {
                    if (File.Exists(logFilePath))
                    {
                        break;
                    }
                    if (stop)
                    {
                        return;
                    }
                    System.Threading.Thread.Sleep(250);
                }
            }

            using (StreamReader sr = new StreamReader(
                       new FileStream(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                       Encoding.UTF7))
            {
                bool     ready = false;
                string   line;
                DateTime time = DateTime.Now;

                this.CurrentPosition = 0;
                this.TotalFileSize   = sr.BaseStream.Length;

                if (tailFile && this.TotalFileSize > 0)
                {
                    this.CurrentPosition   = this.TotalFileSize;
                    sr.BaseStream.Position = this.TotalFileSize;
                    ready = true;
                }

                LogLine last = null;
                while (!stop)
                {
                    while ((line = sr.ReadLine()) != null && !stop)
                    {
                        if (tailFile && ready && Session.Variables != null &&
                            line.Split(',').Length != Session.Variables.LogVariablesCount + 1)
                        {
                            break;
                        }
                        this.CurrentPosition = sr.BaseStream.Position;

                        if (!ready)
                        {
                            if (this.Session.DataRead != null && !tailFile)
                            {
                                this.Session.DataRead(line);
                            }

                            if (line.StartsWith("\"TIME") ||
                                line.StartsWith("Marker,STAMP") ||
                                line.StartsWith("Time,") ||
                                line.StartsWith("Time (sec),"))
                            {
                                ready = true;
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(line) || line[0] == '#')
                            {
                                //handles multiple logs in the same file
                                ready = false;
                                continue;
                            }
                            try
                            {
                                if (this.LogType == LogTypes.VCDS)
                                {
                                    foreach (LogLine logLine in this.ReadVCDSLine(line, last))
                                    {
                                        Session.LineRead(logLine);
                                        Session.CurrentSamplesPerSecond = (short)(((logLine.TimeStamp - (last == null ? 0 : last.TimeStamp)) * 100));
                                        last = logLine;
                                    }
                                }
                                else
                                {
                                    LogLine logLine = this.ReadLine(line, last);
                                    Session.LineRead(logLine);
                                    if (this.LogType == LogTypes.Eurodyne ||
                                        this.LogType == LogTypes.Normal)
                                    {
                                        Session.CurrentSamplesPerSecond = (short)(((logLine.TimeStamp - (last == null ? 0 : last.TimeStamp)) * 100));
                                    }
                                    last = logLine;
                                }

                                if (!tailFile)
                                {
                                    if (!noWait)
                                    {
                                        int waitTime =
                                            (int)((1 / (double)Session.CurrentSamplesPerSecond) * 1000) -
                                            (int)DateTime.Now.Subtract(time).TotalMilliseconds;

                                        if (waitTime > 0 && waitTime < 2500)
                                        {
                                            System.Threading.Thread.Sleep(waitTime);
                                        }
                                    }
                                }
                            }
                            catch { }
                        }

                        #region Control
                        if (!tailFile)
                        {
                            while (this.controlQueue.Count > 0)
                            {
                                string control = controlQueue.Dequeue();
                                try
                                {
                                    switch (control)
                                    {
                                    case "pause":
                                        while (!stop && controlQueue.Count == 0)
                                        {
                                            System.Threading.Thread.Sleep(25);
                                        }
                                        break;

                                    case "reverse":
                                        sr.BaseStream.Seek(-SmallStep, SeekOrigin.Current);
                                        break;

                                    case "reverseLarge":
                                        sr.BaseStream.Seek(-LargeStep, SeekOrigin.Current);
                                        break;

                                    case "forward":
                                        sr.BaseStream.Seek(SmallStep, SeekOrigin.Current);
                                        break;

                                    case "forwardLarge":
                                        sr.BaseStream.Seek(LargeStep, SeekOrigin.Current);
                                        break;

                                    default:
                                        if (control.StartsWith("setPosition:"))
                                        {
                                            sr.BaseStream.Seek(long.Parse(control.Split(':')[1]), SeekOrigin.Begin);
                                        }
                                        break;
                                    }
                                }
                                catch { }
                            }
                        }
                        #endregion

                        time = DateTime.Now;
                    }

                    if (tailFile)
                    {
                        if (sr.BaseStream.Length == this.CurrentPosition)
                        {
                            System.Threading.Thread.Sleep(25);
                        }
                    }
                    else if (line == null)
                    {
                        stop = true;
                    }
                }
            }
            Session.Close();
        }