/// <summary> /// Update progress 10 times a second /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowProgress(object sender, EventArgs e) { if (_wavExporter != null) { int progress = _wavExporter.Progress; int lastError = _wavExporter.LastError; string lastErrorString = _wavExporter.LastErrorString; if (progress >= 0) { progressBar.Value = progress; if (progress == 100) { _timer.Stop(); labelError.Text = "Completed"; _wavExporter.EndExport(); _wavExporter = null; buttonCancel.Enabled = false; } } if (lastError > 0) { progressBar.Value = 0; labelError.Text = lastErrorString + " ( " + lastError + " )"; if (_wavExporter != null) { _wavExporter.EndExport(); _wavExporter = null; buttonCancel.Enabled = false; } } } }
/// <summary> /// Now start the export /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonExport_Click(object sender, EventArgs e) { List <Item> audioSources = new List <Item>(); String destPath = _path; if (dateTimePickerStart.Value > dateTimePickerEnd.Value) { MessageBox.Show("Start time need to be lower than end time"); return; } if (string.IsNullOrWhiteSpace(textBoxAudioFileName.Text)) { MessageBox.Show("Please enter a filename for the WAV file.", "Enter Filename"); return; } destPath = Path.Combine(_path, "Exported Audios\\"); _wavExporter = new WAVExporter() { FileName = textBoxAudioFileName.Text, Codec = (String)comboBoxCodec.SelectedItem, AudioSampleRate = Int32.Parse(comboBoxAudioSampleRates.SelectedItem.ToString()), Path = destPath, AudioList = _audioList, }; _wavExporter.Init(); bool isStarted = _wavExporter.StartExport(dateTimePickerStart.Value.ToUniversalTime(), dateTimePickerEnd.Value.ToUniversalTime()); try { if (isStarted) { _timer.Tick += ShowProgress; _timer.Start(); buttonExport.Enabled = false; buttonCancel.Enabled = true; } else { int lastError = _wavExporter.LastError; string lastErrorString = _wavExporter.LastErrorString; labelError.Text = lastErrorString + " ( " + lastError + " )"; _wavExporter.EndExport(); } } catch (Exception ex) { EnvironmentManager.Instance.ExceptionDialog("Start Export", ex); } }
private void _buttonExport_Click(object sender, RoutedEventArgs e) { if (_audioList.Count == 0) { UpdateStatus("Please Select audio device before export"); return; } if (_datePickerStart.Value.CompareTo(_datePickerEnd.Value) >= 0) { UpdateStatus("Start time has to be smaller than end time"); return; } if (string.IsNullOrWhiteSpace(_textBoxFileName.Text)) { UpdateStatus("Please give it a export file name"); return; } if (_buttonSelectDestination.Content.ToString() == "Select Destination") { UpdateStatus("Please specify a export destination"); return; } var wavExporter = new WAVExporter() { FileName = _textBoxFileName.Text, Codec = _comboBoxCodec.SelectedItem.ToString(), AudioSampleRate = Int32.Parse(_comboBoxSampleRates.SelectedItem.ToString()), AudioList = _audioList, Path = _selectedPath }; if (!string.IsNullOrWhiteSpace(_textBoxExportName.Text)) { wavExporter.ExportName = _textBoxExportName.Text; } _exportJobsQueue.Enqueue(new ExportJob() { Exporter = wavExporter, StartTime = _datePickerStart.Value.ToUniversalTime(), EndTime = _datePickerEnd.Value.ToUniversalTime() }); //We have different threads accessing the same UpdateProgress, however, since the export jobs in SC are executed sequentially, the progressbar will not show concurret updates Progress <int> progressIndicator = new Progress <int>(UpdateProgress); var cts = new CancellationTokenSource(); _ctsQueue.Enqueue(cts); Task.Factory.StartNew(() => ExportFromQueueAsync(progressIndicator, cts.Token), cts.Token); }
private void BuildCodecList() { comboBoxCodec.Items.Clear(); WAVExporter tempExporter = new WAVExporter(); tempExporter.Init(); string[] codecList = tempExporter.CodecList; tempExporter.Close(); foreach (string name in codecList) { comboBoxCodec.Items.Add(name); } comboBoxCodec.SelectedIndex = 0; }