/// <summary> /// Format a error or warning message that occurred in the current context. /// </summary> /// <param name="severity"> /// The severity of the (error) message. /// </param> /// <param name="message"> /// The error message. /// </param> /// <param name="errorLineNumber"> /// The line number where error was reported. /// </param> /// <returns>The formated message.</returns> public string FormatError(TraceLevel severity, string message, int errorLineNumber) { IList <BatchContext> batchContexts = BatchContexts; int contextCount = batchContexts.Count; BatchContext context = null; for (int i = contextCount - 1; i >= 0; --i) { context = batchContexts[i]; if (context.BatchOffset <= errorLineNumber) { break; } } Debug.Assert(context != null); if (context == null) { string error = String.Format("{0}({1}): {2}: {3}", CurrentFile, errorLineNumber, severity, message); return(error); } else { string contextFile = context.File; int contextLineNumber = context.LineNumber + errorLineNumber - context.BatchOffset; string error = String.Format("{0}({1}): {2}: {3}", contextFile, contextLineNumber, severity, message); return(error); } }
/// <summary> /// Clear the batch context. /// </summary> private void ResetBatchContext() { m_currentBatchContexts.Clear(); if (!String.IsNullOrEmpty(m_currentFile)) { BatchContext initialContext = new BatchContext(m_currentBatchLineNo, m_currentFile, m_currentFileLineNo); m_currentBatchContexts.Add(initialContext); } }
/// <summary> /// Process a line that appends to the current command batch. /// </summary> /// <param name="line">The line.</param> private static void ProcessText(ProcessorContext processorContext, string line) { // As long as the batch is still empty skip any leading empty lines // and adjust the start context information instead. if (String.IsNullOrEmpty(line.Trim()) && String.IsNullOrEmpty(processorContext.CurrentBatch)) { BatchContext startContext = processorContext.FirstBatchContext; startContext.LineNumber = processorContext.CurrentFileLineNumber; processorContext.IncrementLineNumber(); return; } else { processorContext.AppendLine(line); } }
public void SetNewBatchContext(string file, int lineNumber) { m_currentFile = file; m_currentFileLineNo = lineNumber; if (m_batchBuilder.Length == 0) { BatchContext startContext = FirstBatchContext; startContext.File = m_currentFile; startContext.LineNumber = m_currentFileLineNo; } else { BatchContext newContext = new BatchContext(m_currentBatchLineNo, m_currentFile, m_currentFileLineNo); m_currentBatchContexts.Add(newContext); } }