Beispiel #1
0
        private static int SaveCsv <TReading>(IEnumerable <TReading> readings, string csvFileName) where TReading : IReading
        {
            csvFileName = Path.ChangeExtension(csvFileName, "csv");
            var iniFileName = Path.ChangeExtension(csvFileName, "ini");

            using (FileStream
                   iniStream = File.Open(iniFileName, FileMode.Create, FileAccess.ReadWrite),
                   csvStream = File.Open(csvFileName, FileMode.Create, FileAccess.ReadWrite)
                   ) {
                using (StreamWriter
                       iniWriter = new StreamWriter(iniStream),
                       csvWriter = new StreamWriter(csvStream)
                       ) {
                    var dataWriter = new CsvDataFileWriter(
                        csvWriter, iniWriter,
                        Path.GetFileName(csvFileName));

                    foreach (var reading in readings)
                    {
                        dataWriter.Write(reading);
                    }

                    Console.WriteLine("Saving to {0}", csvFileName);

                    iniWriter.Flush();
                    csvWriter.Flush();
                }
            }
            return(0);
        }
Beispiel #2
0
        private bool ExecuteExportRaw(string csvFileName)
        {
            int c = 0;

            csvFileName = Path.ChangeExtension(csvFileName, "csv");
            var iniFileName = Path.ChangeExtension(csvFileName, "ini");

            using (FileStream
                   iniStream = File.Open(iniFileName, FileMode.Create, FileAccess.ReadWrite),
                   csvStream = File.Open(csvFileName, FileMode.Create, FileAccess.ReadWrite)
                   ) {
                using (StreamWriter
                       iniWriter = new StreamWriter(iniStream),
                       csvWriter = new StreamWriter(csvStream)
                       ) {
                    var dataWriter = new CsvDataFileWriter(
                        csvWriter, iniWriter,
                        Path.GetFileName(csvFileName));

                    var readings = _dataStore.GetReadings(
                        comboChooseSensor.SelectedText,
                        dateTimeRangePicker.Min,
                        dateTimeRangePicker.Max.Subtract(dateTimeRangePicker.Min));

                    foreach (var reading in readings)
                    {
                        dataWriter.Write(reading);
                        c++;
                    }

                    iniWriter.Flush();
                    csvWriter.Flush();
                }
            }
            return(c > 0);
        }
Beispiel #3
0
        private bool ExecuteExportRaw(string csvFileName)
        {
            int c = 0;
            csvFileName = Path.ChangeExtension(csvFileName, "csv");
            var iniFileName = Path.ChangeExtension(csvFileName, "ini");
            using (FileStream
                iniStream = File.Open(iniFileName, FileMode.Create, FileAccess.ReadWrite),
                csvStream = File.Open(csvFileName, FileMode.Create, FileAccess.ReadWrite)
            ) {
                using (StreamWriter
                    iniWriter = new StreamWriter(iniStream),
                    csvWriter = new StreamWriter(csvStream)
                ) {
                    var dataWriter = new CsvDataFileWriter(
                        csvWriter, iniWriter,
                        Path.GetFileName(csvFileName));

                    var readings = _dataStore.GetReadings(
                        comboChooseSensor.SelectedText,
                        dateTimeRangePicker.Min,
                        dateTimeRangePicker.Max.Subtract(dateTimeRangePicker.Min));

                    foreach (var reading in readings) {
                        dataWriter.Write(reading);
                        c++;
                    }

                    iniWriter.Flush();
                    csvWriter.Flush();
                }
            }
            return c > 0;
        }