public static double[][] Convert(DataSerieTD ds) { if (Equals(ds, null)) { return(null); } int iCount = ds.Data.Count; if (iCount < 1) { return(null); } int itmCount = ds.Data[0].List.Count(); double[][] result = new double[iCount][]; try { for (int i = 0; i < iCount; i++) { double[] dblList = new double[itmCount]; for (int j = 0; j < itmCount; j++) { dblList[j] = ds.Data[i].List[j]; } result[i] = dblList; } } catch (Exception ex) { throw ex; } return(result); }
public DataSerieTD Read_DST() { DataSerieTD ds = null; try { if (File.Exists(this.mFileName)) { ds = new DataSerieTD(); using (FileStream fs = File.Open(mFileName, FileMode.Open)) { using (StreamReader sReader = new StreamReader(fs)) { ds.Name = sReader.ReadLine(); ds.Description = sReader.ReadLine(); string title = sReader.ReadLine(); string[] titles = title.Split(';'); if (titles.Count() > 0) { ds.Title = titles[0]; ds.Titles = new List <string>(); for (int i = 1; i < titles.Count(); i++) { ds.Titles.Add(titles[i]); } } while (sReader.EndOfStream == false) { title = sReader.ReadLine(); titles = title.Split(';'); int countinItem = titles.Count(); double[] listValues = new double[(countinItem - 1)]; for (int j = 1; j < countinItem; j++) { listValues[(j - 1)] = double.Parse(titles[j]); } ds.Add(titles[0], listValues); } } fs.Close(); } } } catch (Exception ex) { throw ex; } return(ds); }
public bool Write(DataSerieTD 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); StringBuilder strb = new StringBuilder(); strb.Append(ds.Title); if (Equals(ds.Titles, null) == false) { foreach (string title in ds.Titles) { //strb.Append(";").Append(title); ") } } else { strb.Append(";"); } sw.WriteLine(strb.ToString()); if (Equals(ds.Data, null)) { return(false); } strb.Clear(); foreach (DataItemTD itm in ds.Data) { strb.Append(itm.Title); foreach (double value in itm.List) { strb.Append(";").Append(value.ToString()); } sw.WriteLine(strb.ToString()); strb.Clear(); } sw.Flush(); strb.Clear(); strb = null; result = true; } } } catch (Exception ex) { throw ex; } return(result); }
public DataSerieTD Read_DST(bool thereIsName, bool thereIsDescription, bool thereIsHeader, bool thereIsKeyColomn) { if (thereIsName && thereIsDescription && thereIsHeader && thereIsKeyColomn) { return(Read_DST()); } DataSerieTD ds = null; try { if (File.Exists(this.mFileName)) { ds = new DataSerieTD(); using (FileStream fs = File.Open(mFileName, FileMode.Open)) { using (StreamReader sReader = new StreamReader(fs)) { if (thereIsName) { ds.Name = sReader.ReadLine(); } else { ds.Name = "n/n"; } if (thereIsDescription) { ds.Description = sReader.ReadLine(); } else { ds.Description = "n/n"; } string title; string[] titles; if (thereIsHeader) { title = sReader.ReadLine(); titles = title.Split(';'); if (titles.Length > 0) { ds.Title = titles[0]; ds.Titles = new List <string>(); for (int i = 1; i < titles.Length; i++) { ds.Titles.Add(titles[i]); } } } if (thereIsKeyColomn) { while (sReader.EndOfStream == false) { title = sReader.ReadLine(); titles = title.Split(';'); int countinItem = titles.Length; double[] listValues = new double[(countinItem - 1)]; for (int j = 1; j < countinItem; j++) { listValues[(j - 1)] = double.Parse(titles[j]); } ds.Add(titles[0], listValues); } } else { int i = 0; while (sReader.EndOfStream == false) { i += 1; title = sReader.ReadLine(); titles = title.Split(';'); int countinItem = titles.Length; double[] listValues = new double[countinItem]; for (int j = 0; j < countinItem; j++) { listValues[j] = double.Parse(titles[j]); } ds.Add(i.ToString(), listValues); } } fs.Close(); } } } } catch (Exception ex) { throw ex; } return(ds); }