/* Print a string to the file and keep the linenumber up to date */ internal static void Write(StreamWriter w, Context ctx, string value, ref int lineno, string filePath) { if (value == null) { return; } w.CheckedWrite(ref lineno, value); if (!value.EndsWith("\n")) { w.WriteLine(ref lineno); } if (!ctx.NoShowLinenos) { WriteLineInfo(ref lineno, w, lineno, filePath); } }
private static void ProcessContentEventHandlerDelegate(StreamWriter sw, object sender, ProcessContentEventData pceData) { bool debugSelected = select.IsSet(Select.Debug); bool includeExtrasSelected = select.IsSet(Select.IncludeExtras); switch (pceData.PCE) { case ProcessContentEvent.ReadingStart: case ProcessContentEvent.ReadingEnd: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } else if (includeExtrasSelected) { sw.CheckedWriteLine("${0} ts:{1:f6} {2:o}", pceData.PCE, pceData.FileDeltaTimeStamp, pceData.UTCDateTime.ToLocalTime()); } return; case ProcessContentEvent.RowStart: case ProcessContentEvent.RowEnd: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } else if (includeExtrasSelected) { sw.CheckedWriteLine("${0} rowIdx:{1} firstTS:{2:f6} {3:o} userFlags:0x{4:x16}", pceData.PCE, pceData.Row.RowIndex, pceData.FileDeltaTimeStamp, pceData.UTCDateTime.ToLocalTime(), pceData.Row.FileIndexUserRowFlagBits); } return; case ProcessContentEvent.StartOfFullGroup: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } else if (includeExtrasSelected) { sw.CheckedWriteLine("${0}", pceData.PCE); } return; case ProcessContentEvent.GroupSetEnd: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } if (select.IsSet(Select.NoData)) { } else if (pceData.FilteredGroupInfoArray.Any(gi => gi.Touched)) { sw.CheckedWrite("{0:MM/dd/yyyy HH:mm:ss.fff},{1:f6}", pceData.UTCDateTime.ToLocalTime(), pceData.FileDeltaTimeStamp); foreach (IGroupInfo gi in pceData.FilteredGroupInfoArray) { if (gi.Touched || !select.IsSet(Select.Sparse)) { foreach (var gpiVC in gi.GroupPointInfoArray.Select(gpi => gpi.VC)) { string gpiVCStr; if (gpiVC.cvt == ContainerStorageType.Boolean && select.IsSet(Select.MapBool)) { gpiVCStr = gpiVC.GetValue <int>(rethrow: false).ToString(); } else if (gpiVC.cvt.IsString() || gpiVC.IsObject || gpiVC.IsNullOrEmpty) { gpiVCStr = gpiVC.ToString(); } else { gpiVCStr = gpiVC.ValueAsObject.SafeToString(); } sw.CheckedWrite(",{0}", gpiVCStr.Replace(',', '|')); } } else { sw.CheckedWrite(new string(',', gi.GroupPointInfoArray.SafeLength())); } gi.Touched = false; } sw.CheckedWriteLine(""); } return; case ProcessContentEvent.Group: case ProcessContentEvent.PartialGroup: case ProcessContentEvent.EmptyGroup: case (ProcessContentEvent.Group | ProcessContentEvent.PartialGroup): case (ProcessContentEvent.Group | ProcessContentEvent.EmptyGroup): if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } return; case ProcessContentEvent.Occurrence: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } else if (select.IsSet(Select.IncludeOccurrences)) { sw.CheckedWriteLine("${0} ts:{1:f6} {2:o} {3} {4}", pceData.PCE, pceData.FileDeltaTimeStamp, pceData.UTCDateTime.ToLocalTime(), pceData.OccurrenceInfo.Name, pceData.VC); } return; case ProcessContentEvent.Error: case ProcessContentEvent.Message: if (debugSelected) { sw.CheckedWriteLine("$Debug {0}", pceData); } else if (includeExtrasSelected || pceData.PCE == ProcessContentEvent.Error) { sw.CheckedWriteLine("${0} ts:{1:f6} {2:o} {3}", pceData.PCE, pceData.FileDeltaTimeStamp, pceData.UTCDateTime.ToLocalTime(), pceData.MessageInfo.Message); } return; default: return; } }