示例#1
0
文件: Processor.cs 项目: radtek/csql
 /// <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);
     }
 }
示例#2
0
文件: Processor.cs 项目: radtek/csql
        public virtual void Process()
        {
            ProcessorContext processorContext = new ProcessorContext(m_options.ScriptFile);

            try {
                using (Stream stream = OpenInputFile())
                    using (StreamReader reader = new StreamReader(stream, Encoding.Default, true)) {
                        m_ppTraces.Flush();
                        while (!reader.EndOfStream && !PreprocessorExitedWithError && !m_isCanceled)
                        {
                            string   line = reader.ReadLine();
                            LineType type = GetLineType(line);
                            switch (type)
                            {
                            case LineType.Text:
                                ProcessText(processorContext, line);
                                break;

                            case LineType.Line:
                                ProcessLine(processorContext, line);
                                break;

                            case LineType.Exec:
                                string batch = processorContext.CurrentBatch;
                                if (!IsWhiteSpaceOnly(batch))
                                {
                                    ProcessBatch(processorContext, batch);
                                    processorContext.IncrementBatchNumber();
                                }
                                processorContext.IncrementLineNumber();
                                processorContext.StartNextBatch();
                                break;

                            default:
                                throw new NotSupportedException("Unexepected line type: " + type);
                            }
                            m_ppTraces.Flush();
                        }
                    }
                if (!PreprocessorExitedWithError)
                {
                    string lastBatch = processorContext.CurrentBatch;
                    if (!IsWhiteSpaceOnly(lastBatch))
                    {
                        ProcessBatch(processorContext, lastBatch);
                        processorContext.IncrementBatchNumber();
                    }
                }
            }
            catch (TerminateException) {
                ++m_errorCount;
                throw;
            }
            catch (Exception ex) {
                string message = String.Format("{0}({1}): Error: {2}", processorContext.CurrentFile, processorContext.CurrentBatchLineNo, ex.Message);
                Trace.WriteLineIf(GlobalSettings.Verbosity.TraceError, message);
                string lastBatch = processorContext.CurrentBatch;
                if (!String.IsNullOrEmpty(lastBatch) && GlobalSettings.Verbosity.TraceInfo)
                {
                    Trace.Indent();
                    Trace.WriteLine(lastBatch);
                    Trace.Unindent();
                }
                ++m_errorCount;
                throw new TerminateException(ExitCode.SqlCommandError);
            }
        }