Пример #1
0
        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;
        }
Пример #2
0
        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;
        }
Пример #3
0
        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();
                }
            }
        }
Пример #4
0
 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;
 }
Пример #5
0
        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();
            }
        }
Пример #6
0
 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;
 }
Пример #7
0
        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);
        }
Пример #8
0
 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);
 }
Пример #9
0
        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));
        }
Пример #10
0
 public bool readFile()
 {
     file = new BDFFile(fileName);
     return file.tryReadFromFile(fileName);
 }
Пример #11
0
 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;
 }
Пример #12
0
        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();
                }
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
 public bool readFile()
 {
     file = new BDFFile(fileName);
     return(file.tryReadFromFile(fileName));
 }
Пример #15
0
 public void patch(BDFFile file)
 {
     patch(file, 0, file.Header.RecordCount);
 }
Пример #16
0
 public void patch(BDFFile file)
 {
     patch(file, 0, file.Header.RecordCount);
 }
Пример #17
0
        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();

            }
        }
Пример #18
0
 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);
 }