private static EventReport ParseEventReport(string[] lines, ref int index) { EventReport eventReport = new EventReport(); int firmwareIndex; // Parse the report header eventReport.Header = ParseHeader(lines, ref index); // Skip to the next nonblank line SkipBlanks(lines, ref index); // Get the index of the line where // the firmware information is located firmwareIndex = index; // Parse the firmware and event number eventReport.Firmware = ParseFirmware(lines, ref firmwareIndex); eventReport.EventNumber = ParseEventNumber(lines, ref index); index = Math.Max(firmwareIndex, index); // Skip to the next nonblank line SkipBlanks(lines, ref index); // Parse the analog section of the report eventReport.AnalogSection = ParseAnalogSection(eventReport.Header.EventTime, lines, ref index); return(eventReport); }
public static EventFile Parse(string filename, double systemFrequency) { string[] lineSeparators = { "\r\n", "\n\r", "\r", "\n" }; EventFile parsedFile = new EventFile(); string fileText = File.ReadAllText(filename); int firstLineSeparatorIndex = lineSeparators.Select(separator => fileText.IndexOf(separator)).Where(index => index >= 0).Min(); string lineSeparator = lineSeparators.First(separator => fileText.IndexOf(separator) == firstLineSeparatorIndex); string[] lines = fileText .Split(new string[] { lineSeparator }, StringSplitOptions.None) .Select(line => line.RemoveControlCharacters()) .ToArray(); int lineIndex = 0; string command; EventReport parsedEventReport; EventHistory parsedEventHistory; CommaSeparatedEventReport parsedCommaSeparatedEventReport; while (lineIndex < lines.Length) { // Parse next command from the file command = ParseCommand(lines, ref lineIndex); // Skip to the next nonblank line SkipBlanks(lines, ref lineIndex); if (command.ToUpper().Contains("EVE")) { parsedEventReport = EventReport.Parse(systemFrequency, lines, ref lineIndex); parsedEventReport.Command = command; parsedFile.Add(parsedEventReport); } else if (command.ToUpper().Contains("CEV")) { parsedCommaSeparatedEventReport = CommaSeparatedEventReport.Parse(lines, ref lineIndex); parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command); parsedFile.Add(parsedCommaSeparatedEventReport); } else if (command.ToUpper().Contains("HIS")) { parsedEventHistory = EventHistory.Parse(lines, ref lineIndex); parsedEventHistory.Command = command; parsedFile.Add(parsedEventHistory); } // Skip to the next nonblank line SkipBlanks(lines, ref lineIndex); } return(parsedFile); }
public static EventReport Parse(double systemFrequency, string[] lines, ref int index) { EventReport eventReport = new EventReport(); int firmwareIndex; // Parse the report header eventReport.Header = Header.Parse(lines, ref index); // Skip to the next nonblank line EventFile.SkipBlanks(lines, ref index); // Get the index of the line where // the firmware information is located firmwareIndex = index; // Parse the firmware and event number eventReport.Firmware = Firmware.Parse(lines, ref firmwareIndex); eventReport.EventNumber = ParseEventNumber(lines, ref index); index = Math.Max(firmwareIndex, index); // Skip to the next nonblank line EventFile.SkipBlanks(lines, ref index); // Parse the analog section of the report eventReport.AnalogSection = AnalogSection.Parse(eventReport.Header.EventTime, systemFrequency, lines, ref index); if (lines.Length < index) { // skip digitals for now while (!lines[index].ToLower().Contains("group settings") && index < lines.Length) { ++index; } ++index; // Parse Group settings eventReport.GroupSetting = Settings.Parse(lines, ref index); EventFile.SkipBlanks(lines, ref index); // Parse Logic control equations ++index; EventFile.SkipBlanks(lines, ref index); eventReport.ControlEquations = ControlEquation.Parse(lines, ref index); EventFile.SkipBlanks(lines, ref index); // Parse Global Settings eventReport.GlobalSetting = Settings.Parse(lines, ref index); } return(eventReport); }
public void Add(EventReport eventReport) { m_sections.Add(eventReport); }
public bool Remove(EventReport eventReport) { return(m_sections.Remove(eventReport)); }
public void Add(EventReport eventReport) { m_sections.Add(eventReport); }
private static EventReport ParseEventReport(string[] lines, ref int index) { EventReport eventReport = new EventReport(); int firmwareIndex; // Parse the report header eventReport.Header = ParseHeader(lines, ref index); // Skip to the next nonblank line SkipBlanks(lines, ref index); // Get the index of the line where // the firmware information is located firmwareIndex = index; // Parse the firmware and event number eventReport.Firmware = ParseFirmware(lines, ref firmwareIndex); eventReport.EventNumber = ParseEventNumber(lines, ref index); index = Math.Max(firmwareIndex, index); // Skip to the next nonblank line SkipBlanks(lines, ref index); // Parse the analog section of the report eventReport.AnalogSection = ParseAnalogSection(eventReport.Header.EventTime, lines, ref index); return eventReport; }
public bool Remove(EventReport eventReport) { return m_sections.Remove(eventReport); }
public static EventFile Parse(string filename, double systemFrequency) { string[] lineSeparators = { "\r\n", "\n\r", "\r", "\n" }; EventFile parsedFile = new EventFile(); string fileText = File.ReadAllText(filename); int firstLineSeparatorIndex = lineSeparators.Select(separator => fileText.IndexOf(separator)).Where(index => index >= 0).Min(); string lineSeparator = lineSeparators.First(separator => fileText.IndexOf(separator) == firstLineSeparatorIndex); string[] lines = fileText .Split(new string[] { lineSeparator }, StringSplitOptions.None) .Select(line => line.RemoveControlCharacters()) .ToArray(); int lineIndex = 0; string command; EventReport parsedEventReport; EventHistory parsedEventHistory; CommaSeparatedEventReport parsedCommaSeparatedEventReport; bool parsed = false; while (lineIndex < lines.Length && !parsed) { // Parse next command from the file command = ParseCommand(lines, ref lineIndex); // Skip to the next nonblank line SkipBlanks(lines, ref lineIndex); if (command.ToUpper().Contains("EVE")) { parsedEventReport = EventReport.Parse(systemFrequency, lines, ref lineIndex); parsedEventReport.Command = command; parsedFile.Add(parsedEventReport); parsed = true; } else if (command.ToUpper().Contains("CEV") || filename.ToUpper().Contains(".CEV")) { parsedCommaSeparatedEventReport = CommaSeparatedEventReport.Parse(lines, ref lineIndex); parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command); parsedFile.Add(parsedCommaSeparatedEventReport); parsed = true; } else if (command.ToUpper().Contains("HIS")) { parsedEventHistory = EventHistory.Parse(lines, ref lineIndex); parsedEventHistory.Command = command; parsedFile.Add(parsedEventHistory); parsed = true; } else { // We do not know what type of file we are reading because the console command may be missing from the top of the file. // We can attempt to glean if it is a cev by checking if the 3rd line can be split by commas. if (lines[2].Split(',').Count() > 1) { parsedCommaSeparatedEventReport = CommaSeparatedEventReport.Parse(lines, ref lineIndex); parsedCommaSeparatedEventReport.Command = (command.ToUpper().Contains("FID") ? command.Split('\"')[0] : command); parsedFile.Add(parsedCommaSeparatedEventReport); parsed = true; } else if (!lines.Where(x => x.Contains("FID")).Contains(",")) { parsedEventReport = EventReport.Parse(systemFrequency, lines, ref lineIndex); parsedEventReport.Command = command; parsedFile.Add(parsedEventReport); parsed = true; } } // Skip to the next nonblank line SkipBlanks(lines, ref lineIndex); } return(parsedFile); }
// Static Methods public static EventReport Parse(string[] lines, ref int index) { EventReport eventReport = new EventReport(); int firmwareIndex; // Parse the report header eventReport.Header = Header.Parse(lines, ref index); // Skip to the next nonblank line EventFile.SkipBlanks(lines, ref index); // Get the index of the line where // the firmware information is located firmwareIndex = index; // Parse the firmware and event number eventReport.Firmware = Firmware.Parse(lines, ref firmwareIndex); eventReport.EventNumber = ParseEventNumber(lines, ref index); index = Math.Max(firmwareIndex, index); // Skip to the next nonblank line EventFile.SkipBlanks(lines, ref index); // Parse the analog section of the report eventReport.AnalogSection = AnalogSection.Parse(eventReport.Header.EventTime, lines, ref index); // skip digitals for now while (!lines[index].ToLower().Contains("group settings") && index < lines.Length) { ++index; } ++index; // Parse Group settings eventReport.GroupSetting = Settings.Parse(lines, ref index); EventFile.SkipBlanks(lines, ref index); // Parse Logic control equations ++index; EventFile.SkipBlanks(lines, ref index); eventReport.ControlEquations = ControlEquation.Parse(lines, ref index); EventFile.SkipBlanks(lines, ref index); // Parse Global Settings eventReport.GlobalSetting = Settings.Parse(lines, ref index); return eventReport; }
private ParsedChannel MakeParsedChannel(EventReport report, Channel<double> channel) { List<DateTime> timeSamples = report.AnalogSection.TimeChannel.Samples.ToList(); List<object> xValues = timeSamples .Select(time => time - timeSamples[0]) .Select(timeSpan => timeSpan.TotalSeconds) .Cast<object>() .ToList(); ParsedChannel parsedChannel = new ParsedChannel() { Name = string.Format("({0}) {1}", report.Command, channel.Name), TimeValues = timeSamples, XValues = xValues, YValues = channel.Samples.Cast<object>().ToList() }; return parsedChannel; }
private Channel MakeParsedDigital(EventReport report, int channelIndex) { Channel channel = new Channel(); Series series = new Series(); Channel<bool> digitalChannel = report.AnalogSection.DigitalChannels[channelIndex]; channel.Name = digitalChannel.Name; channel.HarmonicGroup = 0; channel.MeasurementType = new MeasurementType(); channel.MeasurementType.Name = "Digital"; channel.MeasurementCharacteristic = new MeasurementCharacteristic(); channel.MeasurementCharacteristic.Name = "Instantaneous"; channel.Phase = new Phase(); channel.Phase.Name = "None"; series.Channel = channel; series.SeriesType = new SeriesType(); series.SeriesType.Name = "Values"; series.SourceIndexes = channelIndex.ToString(); channel.MeasurementType.Description = channel.MeasurementType.Name; channel.MeasurementCharacteristic.Description = channel.MeasurementCharacteristic.Name; channel.Phase.Description = "No phase"; series.SeriesType.Description = series.SeriesType.Name; return channel; }
private Channel MakeParsedAnalog(EventReport report, int channelIndex) { Channel channel = new Channel(); Series series = new Series(); Channel<double> analogChannel = report.AnalogSection.AnalogChannels[channelIndex]; channel.Name = analogChannel.Name; channel.HarmonicGroup = 0; channel.MeasurementType = new MeasurementType(); channel.MeasurementCharacteristic = new MeasurementCharacteristic(); channel.MeasurementCharacteristic.Name = "Instantaneous"; channel.Phase = new Phase(); series.Channel = channel; series.SeriesType = new SeriesType(); series.SeriesType.Name = "Values"; series.SourceIndexes = channelIndex.ToString(); switch (analogChannel.Name) { case "VA": case "VB": case "VC": case "VS": case "VDC": case "Freq": channel.MeasurementType.Name = "Voltage"; break; case "IA": case "IB": case "IC": case "IN": case "IG": case "IR": channel.MeasurementType.Name = "Current"; break; default: channel.MeasurementType.Name = "Unknown"; break; } switch (analogChannel.Name) { case "VA": case "IA": case "Freq": channel.Phase.Name = "AN"; channel.Phase.Description = "A-phase to neutral"; break; case "VB": case "IB": channel.Phase.Name = "BN"; channel.Phase.Description = "B-phase to neutral"; break; case "VC": case "IC": channel.Phase.Name = "CN"; channel.Phase.Description = "C-phase to neutral"; break; case "IN": channel.Phase.Name = "NG"; channel.Phase.Description = "Neutral to ground"; break; case "IG": channel.Phase.Name = "Ground"; channel.Phase.Description = "Ground"; break; case "IR": channel.Phase.Name = "RES"; channel.Phase.Description = "Residual"; break; default: case "VS": case "VDC": channel.Phase.Name = "Unknown"; channel.Phase.Description = "Unknown"; break; } if (analogChannel.Name == "Freq") channel.MeasurementCharacteristic.Name = "Frequency"; channel.MeasurementType.Description = channel.MeasurementType.Name; channel.MeasurementCharacteristic.Description = channel.MeasurementCharacteristic.Name; series.SeriesType.Description = series.SeriesType.Name; return channel; }