public bool Write(DataSerie3D ds) { bool result = false; try { using (FileStream fs = File.Open(this.mFileName, FileMode.OpenOrCreate)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine(ds.Name); sw.WriteLine(ds.Description); sw.WriteLine(string.Format("{0}; {1}; {2}; {3}", ds.Title, ds.X_Title, ds.Y_Title, ds.Z_Title)); if (object.Equals(ds.Data, null)) { return(false); } foreach (DataItem3D itm in ds.Data) { sw.WriteLine(string.Format("{0}; {1}; {2}; {3}", itm.Title, itm.X_Value, itm.Y_Value, itm.Z_Value)); } sw.Flush(); result = true; } } } catch (Exception ex) { throw ex; } return(result); }
public DataSerie3D Read_DS3(string fileName) { DataSerie3D ds3 = null; try { if (fileName == string.Empty) { return(null); } if (File.Exists(fileName)) { using (FileStream fs = File.Open(fileName, FileMode.Open)) { ds3 = new DataSerie3D(); BinaryReader bnryReader = new BinaryReader(fs); int dCount = 0; ds3.Name = bnryReader.ReadString(); ds3.Description = bnryReader.ReadString(); ds3.X_Title = bnryReader.ReadString(); ds3.Y_Title = bnryReader.ReadString(); ds3.Z_Title = bnryReader.ReadString(); dCount = bnryReader.ReadInt32(); if (dCount > 0) { string title; double x, y, z; for (int i = 0; i < dCount; i++) { title = bnryReader.ReadString(); x = bnryReader.ReadDouble(); y = bnryReader.ReadDouble(); z = bnryReader.ReadDouble(); ds3.Add(title, x, y, z); } } bnryReader.Close(); } } else { throw new FileNotFoundException("File not found", fileName); } } catch (Exception ex) { throw ex; } return(ds3); }
public DataSerie3D Read_DS3() { DataSerie3D ds3 = null; try { if (File.Exists(this.mFileName)) { ds3 = new DataSerie3D(); using (FileStream fs = File.Open(this.mFileName, FileMode.Open)) { using (StreamReader sReader = new StreamReader(fs)) { ds3.Name = sReader.ReadLine(); ds3.Description = sReader.ReadLine(); string title = sReader.ReadLine(); string[] titles = title.Split(';'); if (titles.Count() == 3) { ds3.Title = titles[0]; ds3.X_Title = titles[1]; ds3.Y_Title = titles[2]; ds3.Y_Title = titles[3]; } double xx, yy, zz; while (sReader.EndOfStream == false) { title = sReader.ReadLine(); titles = title.Split(';'); if (titles.Count() == 4) { xx = double.Parse(titles[1]); yy = double.Parse(titles[2]); zz = double.Parse(titles[3]); ds3.Add(titles[0], xx, yy, zz); } } } } } } catch (Exception ex) { throw ex; } return(ds3); }
public bool Write(ref DataSerie3D ds3) { bool result = false; if (object.Equals(ds3, null)) { return(result); } try { using (FileStream fs = File.Open(FileName, FileMode.OpenOrCreate)) { using (BinaryWriter bnrWriter = new BinaryWriter(fs)) { bnrWriter.Write(ds3.Name); bnrWriter.Write(ds3.Description); bnrWriter.Write(ds3.X_Title); bnrWriter.Write(ds3.Y_Title); bnrWriter.Write(ds3.Z_Title); if (object.Equals(ds3.Data, null)) { bnrWriter.Write(0); } else { bnrWriter.Write(ds3.Data.Count); foreach (DataItem3D di3 in ds3.Data) { bnrWriter.Write(di3.Title); bnrWriter.Write(di3.X_Value); bnrWriter.Write(di3.Y_Value); bnrWriter.Write(di3.Z_Value); } } bnrWriter.Flush(); bnrWriter.Close(); result = true; } //fs.Flush(); //fs.Close(); } } catch (Exception ex) { throw ex; } return(result); }