public void ValidZipFileAllZeroLuxParses() { _filename = Path.GetTempFileName(); using (var file = File.Create(LUX_BIN)) for (int i = 0; i < 27; i++) { file.WriteByte(0); } using (File.Create(ACTIVITY_BIN)) { } CreateInfoTxtFile(true, true, true); using (ZipFile zip = new ZipFile()) { zip.AddFile(ACTIVITY_BIN); zip.AddFile(LUX_BIN); zip.AddFile(INFO_TXT); zip.Save(_filename); } var g = new Gt3XFile(_filename); foreach (var sample in g.LuxEnumerator()) { Assert.Equal(0, sample.Lux); } }
public void ValidZipFileSampleLuxParses() { _filename = Path.GetTempFileName(); List <byte> bytes = new List <byte>(10) { 0x00, 0x00, 0x13, 0x00, 0xFF, 0xFF, 0x98, 0x08, 0x4C, 0x04 }; using (var file = File.Create(LUX_BIN)) foreach (var b in bytes) { file.WriteByte(b); } using (File.Create(ACTIVITY_BIN)) { } CreateInfoTxtFile(true, true, true); using (ZipFile zip = new ZipFile()) { zip.AddFile(ACTIVITY_BIN); zip.AddFile(LUX_BIN); zip.AddFile(INFO_TXT); zip.Save(_filename); } var g = new Gt3XFile(_filename); List <double> expectedLux = new List <double>(5) { 0, 0, 0, 2500, 1375 }; int counter = 0; foreach (var luxSample in g.LuxEnumerator()) { Assert.Equal(expectedLux[counter++], luxSample.Lux); } }
private void ExportFile() { //make sure file is still good Gt3XFile g; try { g = new Gt3XFile(_fileName); } catch (Exception ex) { MessageBox.Show(this, "Unable to open gt3x File:\r\n\r\n" + ex.Message, "Invalid gt3x File", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string exportFileName; using (var savefile = new SaveFileDialog()) { savefile.Filter = comboBoxFormat.SelectedIndex == 0 ? "CSV File (*.csv)|*.csv" : "JSON File (*.json)|*.json"; savefile.Title = "Save Export"; if (savefile.ShowDialog() != DialogResult.OK) { return; } exportFileName = savefile.FileName; } using (var writer = new StreamWriter(exportFileName)) { if (comboBoxData.SelectedIndex == 0) { if (comboBoxFormat.SelectedIndex == 0) { var csv = new CsvWriter(writer); csv.Configuration.RegisterClassMap <AcclererationClassMap>(); csv.WriteRecords(g.ActivityEnumerator()); } else if (comboBoxFormat.SelectedIndex == 1) { writer.Write(JsonConvert.SerializeObject(g.ActivityEnumerator(), Formatting.Indented)); } } else if (comboBoxData.SelectedIndex == 1) { if (comboBoxFormat.SelectedIndex == 0) { var csv = new CsvWriter(writer); csv.Configuration.RegisterClassMap <LuxClassMap>(); csv.WriteRecords(g.LuxEnumerator()); } else if (comboBoxFormat.SelectedIndex == 1) { writer.Write(JsonConvert.SerializeObject(g.LuxEnumerator(), Formatting.Indented)); } } } Process.Start(exportFileName); }