private bool ReadCsvLines(StreamReader stream, string filename) { bool foundAChange = false; int lineNum = 0; string line = stream.ReadLine(); if (line != null) { lineNum++; //List<string> headers = GetCsvHeaders(line); while ((line = stream.ReadLine()) != null) { lineNum++; string[] info = line.Split(','); MxeWord tempWord = new MxeWord(Int16.MinValue, "hId"); tempWord.CheckOriginal = false; tempWord.SetValue(tempWord.Header, info[0]); int indexId = tempWord.GetValueAsRawInt(); if (!_indexes.ContainsKey(indexId)) { Console.Out.WriteLine(String.Format(CSV_MATCH_ERROR, filename, indexId)); continue; } List <string> data = info.ToList(); MtpIndexEntry index = _indexes[indexId]; bool thisOneChanged = HandleSentenceLengthChanges(data, index); foundAChange = thisOneChanged || foundAChange; } } return(foundAChange); }
public bool ReadCsvData(List <string> data) { bool ret = false; if (data.Count < 1) { Console.Out.WriteLine("Insufficient sentence data count. Skipping record."); return(ret); } string newSentence = data[0].Replace("\\n", "\n").Replace("\\r", "\r").Replace("~", ","); string sent = Encoding.UTF8.GetString(_sentence.GetRawBytes().ToArray(), 0, _sentence.Length); if (!sent.Equals(newSentence)) { Console.Out.WriteLine(String.Format(@"Changing [{0}] original value [{1}] to new value [{2}]", "sentence", sent, newSentence)); byte[] bytes = Encoding.UTF8.GetBytes(newSentence); _size.SetValue(_size.Header, String.Empty + bytes.Length, true); _sentence.SetBytes(bytes); ret = true; } TrimData(data); return(ret); }
public virtual bool ReadCsvLineData(List <string> data) { bool ret = false; if (data.Count < 10) { Console.Out.WriteLine("Insufficient data count. Skipping record."); return(ret); } //ret = _id.SetValue(_id.Header, data[0], true) || ret; // id should be read only ret = _actor.SetValue(_actor.Header, data[1], true) || ret; //ret = _start.SetValue(_start.Header, data[2], true) || ret; // start should be read only ret = _unknown.SetValue(_unknown.Header, data[3], true) || ret; data.RemoveRange(0, 4); if (_timing != null) { ret = _timing.ReadCsvData(data) || ret; } else { MtpTimingEntry.TrimData(data); } if (_sentence != null) { ret = _sentence.ReadCsvData(data) || ret; } else { MtpSentence.TrimData(data); } return(ret); }
public bool ReadCsvData(List <string> data) { bool ret = false; if (data.Count < 5) { Console.Out.WriteLine("Insufficient timing data count. Skipping record."); return(ret); } //ret = CompareAndSetFilename(data[0], ret); // filename should also be read only //ret = _id.SetValue(_id.Header, data[1], true) || ret; // id should be read only ret = _frames.SetValue(_frames.Header, data[2], true) || ret; ret = _unknown1.SetValue(_unknown1.Header, data[3], true) || ret; ret = _unknown2.SetValue(_unknown2.Header, data[4], true) || ret; TrimData(data); return(ret); }
private bool HandleSentenceLengthChanges(List <string> data, MtpIndexEntry index) { string d0 = data[0]; int previousSentenceLength = index.Sentence.Size.GetValueAsRawInt(); bool thisOneChanged = index.ReadCsvLineData(data); if (thisOneChanged) { int diff = index.Sentence.Size.GetValueAsRawInt() - previousSentenceLength; if (diff != 0) { if (diff % 4 != 0) { diff += 4 - diff % 4; // addresses are word aligned, so difference changes need to be word aligned as well. } Console.Out.WriteLine(String.Format(@"Adjusting positions of other objects due to length change of [{0}]", d0)); _eofcOne.SetValue(_eofcOne.Header, String.Empty + (_eofcOne.GetValueAsRawInt() + diff), true); _eofcTwo.SetValue(_eofcTwo.Header, String.Empty + (_eofcTwo.GetValueAsRawInt() + diff), true); _restOfIt.Position += diff; int changePosition = index.Sentence.Size.Position; foreach (MtpIndexEntry mie in _indexes.Values) { if (mie.Sentence.Size.Position > changePosition) { mie.Sentence.Size.Position += diff; mie.Sentence.Sentence.Position += diff; int thisStart = mie.Start.GetValueAsRawInt(); mie.Start.SetValue("ziStart", String.Empty + (thisStart + diff), true); } } Console.Out.WriteLine(String.Format(@"Done with positions of other objects due to length change of [{0}]", d0)); } } return(thisOneChanged); }