/// <summary> /// Produce the complete image in one pass. This will get all the ensembles /// from the database. It will then draw the image. /// </summary> private void ProduceCompleteImage() { AdcpDatabaseReader reader = new AdcpDatabaseReader(); Cache <long, DataSet.Ensemble> ensembles = reader.GetAllEnsembles(SelectedProject); // Create the image // This will generate the image // Then save it to PNG in CombineWithProjectImage CombineWithProjectImage(CreateImage(ensembles)); }
/// <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; } } } } }
/// <summary> /// Initialize the object /// </summary> private void Initialize() { // Create reader and writers _ensembleWriter = new AdcpBinaryWriter(this); _dbWriter = new AdcpDatabaseWriter() { SelectedProject = this }; _dbReader = new AdcpDatabaseReader(); // Subscribe to the events of the writer _dbWriter.EnsembleWriteEvent += new AdcpDatabaseWriter.EnsembleWriteEventHandler(_dbWriter_EnsembleWriteEvent); _ensembleWriter.EnsembleWriteEvent += new AdcpBinaryWriter.EnsembleWriteEventHandler(_binaryWriter_EnsembleWriteEvent); // Get the options from the db Options = GetProjectOptions(); // If a backup project folder path is given, create the backup writer if (!string.IsNullOrEmpty(Options.BackupProjectFolderPath)) { CreateBackupWriter(Options.ProjectName, Options.BackupProjectFolderPath, SerialNumber.ToString(), GetMaxBinaryFileSize()); } //SetMaxBinaryFileSize(Options.MaxFileSize); if (_ensembleWriter != null) { _ensembleWriter.MaxFileSize = Options.MaxFileSize; } if (_ensembleWriterBackup != null) { _ensembleWriterBackup.MaxFileSize = Options.MaxFileSize; } // Check the if the serial number can // be set from the first ensemble if it is empty CheckSerialNumber(); // Write the current project options to the database //WriteProjectOptions(); }