private static void MakeFile(string source, string dest, CtpCompressionMode mode, EncodingMethod encoding) { using (var fs = new FileStream(source, FileMode.Open)) using (var fs2 = new FileStream(dest, FileMode.Create)) using (var ctp = new SttpFileReader(fs, false)) using (var ctp2 = new SttpFileWriter(fs2, false, mode, encoding)) { while (true) { switch (ctp.Next()) { case FileReaderItem.ProducerMetadata: var md = ctp.GetMetadata(); ctp2.ProducerMetadata(md); break; case FileReaderItem.DataPoint: var dp = new SttpDataPoint(); while (ctp.ReadDataPoint(dp)) { ctp2.AddDataPoint(dp); } break; case FileReaderItem.EndOfStream: return; default: throw new ArgumentOutOfRangeException(); } } } }
private void BenchmarkFile(string source, string dest, CtpCompressionMode mode, EncodingMethod encoding) { string newFileName = Path.ChangeExtension(source, ".txt"); //using (var raw = new StreamWriter(newFileName, false)) using (var fs = new FileStream(source, FileMode.Open)) using (var fs2 = new FileStream(dest, FileMode.Create)) using (var ctp = new SttpFileReader(fs, false)) using (var ctp2 = new SttpFileWriter(fs2, false, mode, encoding)) { while (true) { switch (ctp.Next()) { case FileReaderItem.ProducerMetadata: var md = ctp.GetMetadata(); ctp2.ProducerMetadata(md); break; case FileReaderItem.DataPoint: var dp = new SttpDataPoint(); while (ctp.ReadDataPoint(dp)) { //if (dp.Value.AsSingle > 3000000) //{ // dp.Value = dp.Value; //} //if (dp.Metadata.DataPointID.AsString.EndsWith(":DFreq0")) //{ // dp.Value = new CtpNumeric((long)(dp.Value.AsSingle * 100), 2); //} //Names.Add(dp.Metadata.DataPointID.AsString); //raw.WriteLine(dp.ToString()); PointCount++; //dp.Value = (double)dp.Value; //dp.Value = (long)dp.Value*1000; ctp2.AddDataPoint(dp); } break; case FileReaderItem.EndOfStream: return; default: throw new ArgumentOutOfRangeException(); } } } }
private void ReadSttp(string fileName) { DataTable dt = new DataTable(); dt.Columns.Add("Command", typeof(string)); dt.Columns.Add("Count", typeof(int)); dt.Columns.Add("Record", typeof(string)); using (var fs = new FileStream(fileName, FileMode.Open)) using (var ctp = new SttpFileReader(fs, false)) { while (true) { switch (ctp.Next()) { case FileReaderItem.ProducerMetadata: var md = ctp.GetMetadata(); dt.Rows.Add("Metadata", md.ToCommand().ToXML().Length, md.ToString()); break; case FileReaderItem.DataPoint: var sb = new StringBuilder(); var dp = new SttpDataPoint(); int cnt = 0; while (ctp.ReadDataPoint(dp)) { cnt++; sb.Append(dp.Value.AsString); sb.Append(" "); } dt.Rows.Add("Points", cnt, sb.ToString()); break; case FileReaderItem.EndOfStream: dataGridView1.DataSource = dt; return; default: throw new ArgumentOutOfRangeException(); } } } }