Beispiel #1
0
        }         // func SetSize

        /// <summary></summary>
        /// <param name="line"></param>
        public void Add(DELogLine line)
        {
            var lineData = Encoding.Default.GetBytes(line.ToLineData() + windowsLineEnding);

            lock (logFileLock)
            {
                if (isDisposed)                 // check if the log is disposed
                {
                    return;
                }

                try
                {
                    if (logData.Length + lineData.Length > MaximumSize)
                    {
                        TruncateLog(MinimumSize);                         // truncate the log file, calculate the new size
                    }
                    // set the position to the end and mark the offset
                    logData.Seek(0, SeekOrigin.End);
                    AddToLogLineCache(logData.Position);
                    logLineCount++;

                    // add the line data
                    logData.Write(lineData, 0, lineData.Length);
                    logData.Flush();
                }
                catch (Exception e)
                {
                    Debug.Print(e.GetMessageString());
                    ResetLog();
                }
            }

            LinesAdded?.Invoke(this, EventArgs.Empty);
        }         // proc Add
Beispiel #2
0
        private void AddToLog(LogType type, uint id, string text)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine($"TESTCONNECTION {type} {id}: {text}");
                m_lastLogLine = new LogLineData(m_lastLogLine, type, id, text);
                if (m_firstLogLine == null)
                {
                    m_firstLogLine = m_lastLogLine;
                }
                switch (type)
                {
                case LogType.ReceivedEnd:
                case LogType.ReceivedPartial:
                case LogType.ReceivedError:
                    if (m_currentExecutingCommand != null)
                    {
                        var logger = m_currentExecutingCommand?.Context?.Logger;
                        if (logger != null && m_currentExecutingCommand.Context.LoggingEnabled)
                        {
                            logger.LogDetail(this.DisplayName, "Received: " + text);
                        }
                    }
                    break;

                case LogType.ReceivedAsync:
                    if (m_mainLogger != null)
                    {
                        m_mainLogger.LogAsync(m_name, "Event: " + text);
                    }
                    if (m_asyncLogLineReader != null)
                    {
                        lock (m_eventLogSync)
                        {
                            m_lastEventLogLine = new LogLineData(m_lastEventLogLine, type, id, text);
                            m_asyncLogLineReader.NotifyNew(m_lastEventLogLine);
                        }
                    }
                    break;

                default:
                    break;
                }
                LinesAdded?.Invoke(this, new LogLineEventArgs(m_lastLogLine));
            }
            catch (Exception ex)
            {
                StepBro.Core.Main.RootLogger.LogError("SerialTestConnection.AddToLog", $"Unexpected error. Exception: {ex}");
            }
        }
Beispiel #3
0
        }         // proc Add

        private void CreateLogLineCache(ManualResetEventSlim started)
        {
            lock (logFileLock)
            {
                started.Set();
                try
                {
                    int  readed;
                    long lastLinePosition = 0;

                    // reset data
                    ResetLog();

                    do
                    {
                        readed = logData.Read(logFileBuffer, 0, logFileBuffer.Length);

                        for (var i = 0; i < readed; i++)
                        {
                            if (logFileBuffer[i] == '\n')
                            {
                                AddToLogLineCache(lastLinePosition);
                                logLineCount++;

                                lastLinePosition = logData.Position - readed + i + 1;
                            }
                        }
                    } while (readed > 0);
                }
                catch (Exception e)
                {
                    Debug.Print(e.GetMessageString());

                    ResetLog(true);
                }
            }

            if (logLineCount != 0)
            {
                LinesAdded?.Invoke(this, EventArgs.Empty);
            }
        }         // proc CreateLogLineCache
        private void Children_UpdatedLineType(object sender, LineEventArgs e)
        {
            var index = stpLinesContainer.Children.IndexOf(sender as UIElement);

            if (index > -1)
            {
                var newDoc = new BsonDocument();
                var value  = new BsonValue("");
                newDoc.Add("newValue", value);
                var newLine  = new KeyValuePair <string, BsonValue>("newDocument", newDoc);
                var childDoc = new DocumentViewerLineGroup(newLine, DocumentNestingLevel + 1, ++LineCounter);
                LineCounter          = childDoc.LoadDocument();
                childDoc.LinesAdded += ChildDoc_LinesAdded;
                ((DocumentEditorComponent)childDoc).ActivateEdition();
                stpLinesContainer.Children.Remove(sender as UIElement);
                stpLinesContainer.Children.Insert(index, childDoc);

                LinesAdded?.Invoke(this, new EventArgs());
            }
        }
        private void Children_AddNewLine(object sender, LineEventArgs e)
        {
            var line = sender as DocumentViewerLine;

            if (line != null)
            {
                var index = stpLinesContainer.Children.IndexOf(line);

                if (index > -1)
                {
                    BsonValue          value   = new BsonValue("");
                    DocumentViewerLine newLine = new DocumentViewerLine("newVariable", value, e.LineNumber + 1, DocumentNestingLevel * DocumentViewerLine.DEFAULT_TAB_LENGTH);
                    newLine.UpdatedLineType     += Children_UpdatedLineType;
                    newLine.AddNewLine          += Children_AddNewLine;
                    newLine.InnerDocumentDelete += StartLine_InnerDocumentDelete;
                    ((DocumentEditorComponent)newLine).ActivateEdition();

                    stpLinesContainer.Children.Insert(index + 1, newLine);

                    LinesAdded?.Invoke(this, new EventArgs());
                }
            }
        }
 private void ChildDoc_LinesAdded(object sender, EventArgs e)
 {
     LinesAdded?.Invoke(this, new EventArgs());
 }