public void LoadFile(string vsFilename) { string sLine; FileStream fs; StreamReader sr; HexFileLine hexline; if (!System.IO.File.Exists(vsFilename)) { throw new ArgumentException(String.Format("Die Datei '{0}' existiert nicht", vsFilename)); } this._Filename = vsFilename; // Datei öffnen try { fs = new FileStream(vsFilename, FileMode.Open); sr = new StreamReader(fs); } catch { throw new Exception(string.Format("Fehler beim Öffnen der Datei '{0}'", vsFilename)); } // Zeilen einlesen try { while (!sr.EndOfStream) { sLine = sr.ReadLine(); //Trace.TraceInformation(this.GetType().Name + "." + MethodInfo.GetCurrentMethod().Name.ToString() + "(): " // + String.Format("Less HexLine {0}: '{1}'", this.HexFileLines.Count, sLine)); hexline = new HexFileLine(sLine); this._HexFileLines.Add(hexline); this._filesize += 5 + hexline.NumBytes; //1 Byte Number of Data, 2 Byte Address, 1 Byte type of Record , 1Byte Checksum if (hexline.Errorflag == 1) { this._ErrorCounter++; } Thread.Sleep(0); } } catch (Exception e) { throw e; } finally { sr.Close(); fs.Close(); } }
public void LoadFile(string vsFilename) { string sLine; FileStream fs; StreamReader sr; HexFileLine hexline; if (!System.IO.File.Exists(vsFilename)) throw new ArgumentException(String.Format("Die Datei '{0}' existiert nicht", vsFilename)); this._Filename = vsFilename; // Datei öffnen try { fs = new FileStream(vsFilename, FileMode.Open); sr = new StreamReader(fs); } catch { throw new Exception(string.Format("Fehler beim Öffnen der Datei '{0}'", vsFilename)); } // Zeilen einlesen try { while (!sr.EndOfStream) { sLine = sr.ReadLine(); //Trace.TraceInformation(this.GetType().Name + "." + MethodInfo.GetCurrentMethod().Name.ToString() + "(): " // + String.Format("Less HexLine {0}: '{1}'", this.HexFileLines.Count, sLine)); hexline = new HexFileLine(sLine); this._HexFileLines.Add(hexline); this._filesize += 5 + hexline.NumBytes; //1 Byte Number of Data, 2 Byte Address, 1 Byte type of Record , 1Byte Checksum if (hexline.Errorflag == 1) { this._ErrorCounter++; } Thread.Sleep(0); } } catch (Exception e) { throw e; } finally { sr.Close(); fs.Close(); } }