public void patch(BDFFile file, int off, int recordCount) { if (!(off >= 0 && off + recordCount <= file.Header.RecordCount)) { throw new ArgumentOutOfRangeException("Incorrect intrerval for patching!"); } if (header == null) { patchHeader(file.Header); } if (!(header.compatible(file.Header))) { throw new BDFPatchException(String.Format("Cannnot patch file {0} to file {1}", file.FileName, fileName)); } if (header.StartDateTime.AddSeconds((double)recordCountWrote).CompareTo(file.Header.StartDateTime.AddSeconds((double)off)) > 0) { throw new BDFPatchException("Begin of patching piece belows sooner than end of file"); } for (int dataRecord = 0; dataRecord < recordCount; dataRecord++) { for (int channel = 0; channel < header.ChannelCount; channel++) { for (int sample = 0; sample < header.ChannelHeaders[channel].SamplesPerDataRecord; sample++) { patchByteInt(file.Channels[channel].Data[dataRecord * header.ChannelHeaders[channel].SamplesPerDataRecord + sample], 3); } } } recordCountWrote += recordCount; }
public void patch(BDFFile file, int off, int recordCount) { if (!(off >= 0 && off + recordCount <= file.Header.RecordCount)) throw new ArgumentOutOfRangeException("Incorrect intrerval for patching!"); if (header == null) { patchHeader(file.Header); } if (!(header.compatible(file.Header))) throw new BDFPatchException(String.Format("Cannnot patch file {0} to file {1}", file.FileName, fileName)); if (header.StartDateTime.AddSeconds((double)recordCountWrote).CompareTo(file.Header.StartDateTime.AddSeconds((double)off)) > 0) throw new BDFPatchException("Begin of patching piece belows sooner than end of file"); for (int dataRecord = 0; dataRecord < recordCount; dataRecord++) { for (int channel = 0; channel < header.ChannelCount; channel++) { for (int sample = 0; sample < header.ChannelHeaders[channel].SamplesPerDataRecord; sample++) { patchByteInt(file.Channels[channel].Data[dataRecord * header.ChannelHeaders[channel].SamplesPerDataRecord + sample], 3); } } } recordCountWrote += recordCount; }
private void openFiles(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".bdf"; dlg.Multiselect = true; dlg.Filter = "BDF Files (*.bdf) | *.bdf"; bool? result = dlg.ShowDialog(); if (result.HasValue && result.Value) { if (openedFiles == null) openedFiles = new List<BDFFile>(); openedFiles.Clear(); workerList.Clear(); disableButtons(); foreach (string fileName in dlg.FileNames) { BDFFile newFile = new BDFFile(); openedFiles.Add(newFile); ProgressBar progressBar = new ProgressBar(); progressBar.Width = Double.NaN; //progressBar.Height = 25.0; progressBar.Minimum = 0; bindProgressBarWithBDFFile(progressBar, ProgressBar.MaximumProperty, "Size", newFile); bindProgressBarWithBDFFile(progressBar, ProgressBar.ValueProperty, "Read", newFile); BackgroundWorker bw = new BackgroundWorker(); workerList.Add(bw); bw.DoWork += (obj, args) => { App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Add(progressBar); })); try { newFile.readFromFile(fileName); } catch (Exception ex) { // } App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Remove(progressBar); })); }; bw.RunWorkerCompleted += (obj, args) => { tryEnableButtons(); }; bw.RunWorkerAsync(); } } }
public void patchEmpty(BDFFile file, int recordCount) { if (recordCount < 0) { throw new BDFPatchException("Begin of patching piece belows sooner than end of file"); } if (header == null) { patchHeader(file.Header); } patchBytes(new byte[samplesPerDataRecord * recordCount * 3]); recordCountWrote += recordCount; }
private void patchAndSaveFile(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".bdf"; dlg.Filter = "BDF Files (*.bdf) | *.bdf"; bool?result = dlg.ShowDialog(); if (result.HasValue && result.Value) { if (openedFiles == null || !openedFiles.Any()) { ; //Not selected files } workerList.Clear(); disableButtons(); BDFFile newFile = new BDFFile(); BackgroundWorker bw = new BackgroundWorker(); workerList.Add(bw); ProgressBar progressBar = new ProgressBar(); progressBar.Width = Double.NaN; progressBar.Height = 25.0; progressBar.Minimum = 0; bindProgressBarWithBDFFile(progressBar, ProgressBar.MaximumProperty, "Size", newFile); bindProgressBarWithBDFFile(progressBar, ProgressBar.ValueProperty, "Wrote", newFile); bw.DoWork += (obj, args) => { newFile.generateFromFiles(openedFiles); App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Add(progressBar); })); newFile.saveToFile(dlg.FileName); App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Remove(progressBar); })); }; bw.RunWorkerCompleted += (obj, args) => { tryEnableButtons(); }; bw.RunWorkerAsync(); } }
public bool tryPatchEmpty(BDFFile file, int recordCount) { bool res; try { patchEmpty(file, recordCount); res = true; } catch (BDFPatchException e) { Console.WriteLine(e.Message); res = false; } return res; }
public bool tryPatchEmpty(BDFFile file, int recordCount) { bool res; try { patchEmpty(file, recordCount); res = true; } catch (BDFPatchException e) { Console.WriteLine(e.Message); res = false; } return(res); }
public BDFHeader readHeader() { BDFFile file = new BDFFile(fileName); BDFHeader header = null; try { header = file.Header; } catch (BDFHeaderReadException e) { Exception ex = e as Exception; Console.WriteLine(); while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } Console.WriteLine(); return null; } return BDFHeader.Copy(header); }
public BDFHeader readHeader() { BDFFile file = new BDFFile(fileName); BDFHeader header = null; try { header = file.Header; } catch (BDFHeaderReadException e) { Exception ex = e as Exception; Console.WriteLine(); while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } Console.WriteLine(); return(null); } return(BDFHeader.Copy(header)); }
public bool readFile() { file = new BDFFile(fileName); return file.tryReadFromFile(fileName); }
public void patchEmpty(BDFFile file, int recordCount) { if (recordCount < 0) throw new BDFPatchException("Begin of patching piece belows sooner than end of file"); if (header == null) { patchHeader(file.Header); } patchBytes(new byte[samplesPerDataRecord * recordCount * 3]); recordCountWrote += recordCount; }
private void openFiles(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".bdf"; dlg.Multiselect = true; dlg.Filter = "BDF Files (*.bdf) | *.bdf"; bool?result = dlg.ShowDialog(); if (result.HasValue && result.Value) { if (openedFiles == null) { openedFiles = new List <BDFFile>(); } openedFiles.Clear(); workerList.Clear(); disableButtons(); foreach (string fileName in dlg.FileNames) { BDFFile newFile = new BDFFile(); openedFiles.Add(newFile); ProgressBar progressBar = new ProgressBar(); progressBar.Width = Double.NaN; //progressBar.Height = 25.0; progressBar.Minimum = 0; bindProgressBarWithBDFFile(progressBar, ProgressBar.MaximumProperty, "Size", newFile); bindProgressBarWithBDFFile(progressBar, ProgressBar.ValueProperty, "Read", newFile); BackgroundWorker bw = new BackgroundWorker(); workerList.Add(bw); bw.DoWork += (obj, args) => { App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Add(progressBar); })); try { newFile.readFromFile(fileName); } catch (Exception ex) { // } App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Remove(progressBar); })); }; bw.RunWorkerCompleted += (obj, args) => { tryEnableButtons(); }; bw.RunWorkerAsync(); } } }
private void bindProgressBarWithBDFFile(ProgressBar progressBar, DependencyProperty property, string propertyName, BDFFile file) { Binding binding = new Binding(); binding.Source = file; binding.Path = new PropertyPath(propertyName); binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; binding.Mode = BindingMode.OneWay; BindingOperations.SetBinding(progressBar, property, binding); }
public bool readFile() { file = new BDFFile(fileName); return(file.tryReadFromFile(fileName)); }
public void patch(BDFFile file) { patch(file, 0, file.Header.RecordCount); }
private void patchAndSaveFile(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".bdf"; dlg.Filter = "BDF Files (*.bdf) | *.bdf"; bool? result = dlg.ShowDialog(); if (result.HasValue && result.Value) { if (openedFiles == null || !openedFiles.Any()) ;//Not selected files workerList.Clear(); disableButtons(); BDFFile newFile = new BDFFile(); BackgroundWorker bw = new BackgroundWorker(); workerList.Add(bw); ProgressBar progressBar = new ProgressBar(); progressBar.Width = Double.NaN; progressBar.Height = 25.0; progressBar.Minimum = 0; bindProgressBarWithBDFFile(progressBar, ProgressBar.MaximumProperty, "Size", newFile); bindProgressBarWithBDFFile(progressBar, ProgressBar.ValueProperty, "Wrote", newFile); bw.DoWork += (obj, args) => { newFile.generateFromFiles(openedFiles); App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Add(progressBar); })); newFile.saveToFile(dlg.FileName); App.Current.Dispatcher.Invoke(new ThreadStart(delegate { this.stackPanel.Children.Remove(progressBar); })); }; bw.RunWorkerCompleted += (obj, args) => { tryEnableButtons(); }; bw.RunWorkerAsync(); } }