/// <summary> /// Create the exporters to write the data. /// </summary> public ExportWriter() { csv = null; matlab = null; matlabMatrix = null; pd0 = null; ensEx = null; }
/// <summary> /// Open the exporters based off the selection. /// </summary> /// <param name="folderPath">Folder path of the exported files.</param> /// <param name="filename">File name of the exported file.</param> /// <param name="options">Options for exporting.</param> /// <param name="isCsvSelected">CSV Exporter selected.</param> /// <param name="isMatlabSelected">MATLAB exporter selected.</param> /// <param name="isMatlabMatrixSelected">MATLAB matrix selected.</param> /// <param name="isPd0Selected">PD0 exporter selected.</param> /// <param name="isEnsSelected">ENS exporter selected.</param> public void Open(string folderPath, string filename, ExportOptions options, bool isCsvSelected, bool isMatlabSelected, bool isMatlabMatrixSelected, bool isPd0Selected, bool isEnsSelected) { // Open all the exporters that are selected // The filename is name without the extension csv = new CsvExporterWriter(); matlab = new MatlabExporterWriter(); matlabMatrix = new MatlabMatrixExporterWriter(); pd0 = new Pd0ExporterWriter(); ensEx = new EnsExporterWriter(); try { if (isCsvSelected) { csv.Open(folderPath, filename + ".csv", options); } if (isMatlabSelected) { matlab.Open(folderPath, filename, options); } if (isMatlabMatrixSelected) { matlabMatrix.Open(folderPath, filename, options); } if (isPd0Selected) { pd0.Open(folderPath, filename + "_pd0" + ".pd0", options); } if (isEnsSelected) { ensEx.Open(folderPath, filename + "_rtb" + ".ens", options); } } catch (Exception ex) { log.Error("Error opening ensemble file.", ex); } }
/// <summary> /// Export the the data based off the exporter chosen. /// </summary> /// <param name="exporter">Exporter chosen.</param> private void Export(Exporters exporter) { // No project was selected if (_pm.IsProjectSelected) { IsExporting = true; string dir = _pm.SelectedProject.ProjectFolderPath + @"\"; string filename = ""; //string file = dir + filename; // Determine which exporter to use IExporterWriter writer = null; switch (exporter) { case Exporters.CSV: writer = new CsvExporterWriter(); filename = _pm.SelectedProject.ProjectName + "_export.csv"; break; case Exporters.Matlab: writer = new MatlabExporterWriter(); filename = _pm.SelectedProject.ProjectName; break; case Exporters.PD0: writer = new Pd0ExporterWriter(); filename = _pm.SelectedProject.ProjectName + "_export.pd0"; break; case Exporters.ENS: writer = new EnsExporterWriter(); filename = _pm.SelectedProject.ProjectName + "_export.ens"; break; default: break; } if (writer != null) { AdcpDatabaseReader dbReader = new AdcpDatabaseReader(); int size = dbReader.GetNumberOfEnsembles(_pm.SelectedProject); uint x = 0; try { // Display the busy indicator //IsBusyIndicator = true; // Create the directory if it does not exist if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // Open the file writer.Open(dir, filename, _Options); // Check the max value if (MaxEnsembleNumber > _pm.SelectedProject.GetNumberOfEnsembles()) { MaxEnsembleNumber = (uint)_pm.SelectedProject.GetNumberOfEnsembles(); } // Check the min value uint count = (MaxEnsembleNumber - MinEnsembleNumber) + 1; if (count < 0) { count = 0; } for (x = MinEnsembleNumber; x < count; x++) { // Get the data from the reader DataSet.Ensemble data = dbReader.GetEnsemble(_pm.SelectedProject, x); if (data != null) { // Vessel Mount Options VesselMountScreen(ref data); // Screen the data _screenDataVM.ScreenData(ref data, AdcpCodec.CodecEnum.Binary); // Verify go data if (data.IsEnsembleAvail && data.EnsembleData.EnsembleNumber != 0) { try { // Write the data to the file writer.Write(data); } catch (Exception e) { log.Error(string.Format("Error writing file {0} {1}", dir + filename, x), e); } } } } // Close the writer and save the latest options _Options = writer.Close(); //SaveDatabaseOptions(); // Remove the busy indicator IsExporting = false; } catch (IOException ex) { System.Windows.MessageBox.Show("Export file is open or check file permissions for the folder.\n" + string.Format("{0}", dir + filename), "Export IO Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); log.Error(string.Format("IO Error exporting file {0} {1}", dir + filename, x), ex); if (writer != null) { writer.Close(); IsExporting = false; } } catch (Exception e) { log.Error(string.Format("Error exporting file {0} {1}", dir + filename, x), e); if (writer != null) { writer.Close(); IsExporting = false; } } } } }