/// <summary> /// Close all the exporters. /// </summary> /// <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 Close(bool isCsvSelected, bool isMatlabSelected, bool isMatlabMatrixSelected, bool isPd0Selected, bool isEnsSelected) { // Close the files if (isCsvSelected) { csv.Close(); } if (isMatlabSelected) { matlab.Close(); } if (isMatlabMatrixSelected) { matlabMatrix.Close(); } if (isPd0Selected) { pd0.Close(); } if (isEnsSelected) { ensEx.Close(); } }
/// <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; } } } } }