Exemple #1
0
        /// <summary>
        /// Write values from the given log entry to the stream
        /// </summary>
        /// <param name="row">collection of columns, values, and conversions</param>
        public void LogEntry(ILogRow row)
        {
            int extraColumns = 0;

            if (this.insertTimeColumns)
            {
                extraColumns = 2;
            }

            string[] values = new string[row.ColumnCount + extraColumns];

            if (this.insertTimeColumns)
            {
                TimeSpan elapsedTime = DateTime.Now.Subtract(this.startTime);
                values[0] = ((int)elapsedTime.TotalMilliseconds).ToString(CultureInfo.InvariantCulture);
                values[1] = DateTime.Now.ToString("yyyy-MM-dd T HH:mm:ss:fff", CultureInfo.InvariantCulture);
            }

            int i = extraColumns;

            for (int index = 0; index < row.ColumnCount; index++)
            {
                values[i] = row.GetColumnValueAsString(index);
                i++;
            }

            string entry = string.Join(", ", values);

            writer.WriteLine(entry);
        }
Exemple #2
0
        /// <summary>
        /// Write the names of the colums
        /// </summary>
        /// <param name="row">collection of columns, values, and conversions</param>
        public void LogStart(ILogRow row)
        {
            this.startTime = DateTime.Now;

            int extraColumns = 0;

            if (this.insertTimeColumns)
            {
                extraColumns = 2;
            }

            string[] names = new string[row.ColumnCount + extraColumns];

            if (this.insertTimeColumns)
            {
                names[0] = "Time";
                names[1] = "Clock";
            }

            int i = extraColumns;

            for (int index = 0; index < row.ColumnCount; index++)
            {
                names[i] = row.GetColumnName(index);
                i++;
            }

            string header = string.Join(", ", names);

            writer.WriteLine(header);
        }
Exemple #3
0
        /// <summary>
        /// Create and dispose log writer as necessary
        /// </summary>
        /// <param name="row">row of data from the SSM interface</param>
        /// <returns>true if </returns>
        private bool ManageWriterState(LogRow row)
        {
            if (this.ShouldLog(row))
            {
                if (this.writer == null)
                {
                    this.writer = this.factory();

                    if (this.queue.Count == 0)
                    {
                        this.writer.LogStart(row);
                    }
                    else
                    {
                        ILogRow first = this.queue.Dequeue();
                        this.writer.LogStart(first);
                        this.writer.LogEntry(first);

                        while (this.queue.Count > 0)
                        {
                            this.writer.LogEntry(this.queue.Dequeue());
                        }
                    }
                }
                return(true);
            }
            else
            {
                // Keep the values from the most recent N rows in the queue for later replay.
                this.queue.Enqueue(new HistoryRow(row));
                if (this.queue.Count > extraRows)
                {
                    this.queue.Dequeue();
                }

                this.SafelyDisposeWriter();
                return(false);
            }
        }