private void Export_Button_Click(object sender, EventArgs e) { try { 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 (textBoxAVIfilename.Text == "") { MessageBox.Show("Please enter a filename for the AVI file.", "Enter Filename"); return; } _exporter = new VideoOS.Platform.Data.AVIExporter() { Filename = textBoxAVIfilename.Text, }; destPath = Path.Combine(_path, "Exported Images\\" + _item.Name); _exporter.Init(); _exporter.Path = destPath; _exporter.CameraList = new List <Item>() { _item }; _exporter.AudioList = audioSources; bool startresult = _exporter.StartExport(dateTimePickerStart.Value.ToUniversalTime(), dateTimePickerEnd.Value.ToUniversalTime()); if (startresult) { _timer.Tick += ShowProgress; _timer.Start(); buttonExport.Enabled = false; buttonCancel.Enabled = true; } else { int lastError = _exporter.LastError; string lastErrorString = _exporter.LastErrorString; //labelError.Text = lastErrorString + " ( " + lastError + " )"; _exporter.EndExport(); } } catch (Exception ex) { EnvironmentManager.Instance.ExceptionDialog("Start Export", ex); } }
/// <summary> /// the thread doing the work /// </summary> private void Run() { EnvironmentManager.Instance.Log(false, "SCExport background thread", "Now starting...", null); while (!_stop) { _currentJob = null; string queueLength = ""; lock (_exportJobs) { queueLength = "Queue: " + _exportJobs.Count; if (_exportJobs.Count > 0) { _currentJob = _exportJobs[0]; _exportJobs.Remove(_currentJob); } } if (_currentJob != null) { ShowStatus(queueLength + " - " + _currentJob, 0); if (_currentJob.AVIexport) { VideoOS.Platform.Data.AVIExporter aviExporter = new VideoOS.Platform.Data.AVIExporter() { Width = 320, Height = 240, Filename = _currentJob.FileName, AutoSplitExportFile = true, MaxAVIFileSize = 512 * 1024 * 1024 }; // 512 MB if (_currentJob.OverlayImage != null) { if (aviExporter.SetOverlayImage(_currentJob.OverlayImage, _currentJob.VerticalOverlayPosition, _currentJob.HorizontalOverlayPosition, _currentJob.ScaleFactor, _currentJob.IgnoreAspect) == false) { ShowStatus("Error: " + aviExporter.LastErrorString, 0); } } _exporter = aviExporter; _exporter.AudioList = new List <Item>(); _exporter.Path = _currentJob.Path; // comment the following if you want to avoid audio from a microphone _not_ connected to the camera. if (_currentJob.Item.HasRelated != HasRelated.No) { List <Item> related = _currentJob.Item.GetRelated(); foreach (Item item in related) { if (item.FQID.Kind == Kind.Microphone) { _exporter.AudioList.Add(item); } } } } else if (_currentJob.MKVexport) { _exporter = new VideoOS.Platform.Data.MKVExporter() { Filename = _currentJob.FileName }; _exporter.AudioList = new List <Item>(); _exporter.Path = _currentJob.Path; // comment the following if you want to avoid audio from a microphone _not_ connected to the camera. if (_currentJob.Item.HasRelated != HasRelated.No) { List <Item> related = _currentJob.Item.GetRelated(); foreach (Item item in related) { if (item.FQID.Kind == Kind.Microphone) { _exporter.AudioList.Add(item); } } } } else { _exporter = new VideoOS.Platform.Data.DBExporter() { Encryption = false }; _exporter.AudioList = new List <Item>(); _exporter.Path = Path.Combine(_currentJob.Path, _currentJob.FileName); ((VideoOS.Platform.Data.DBExporter)_exporter).PreventReExport = _currentJob.PreventReExport; ((VideoOS.Platform.Data.DBExporter)_exporter).SignExport = _currentJob.SignExport; // If there is recorded audio from a microphone on the camera it will be in the export, as the Smart Client will // add audio spurces automatically for DB Exports } _exporter.Init(); _exporter.CameraList = new List <Item>() { _currentJob.Item }; bool started = _exporter.StartExport(_currentJob.StartTime, _currentJob.EndTime); if (started) { while (_exporter.Progress == 0) { Thread.Sleep(100); } // Perhaps consider some cancel mechanism while (_exporter.Progress < 100 && _exporter.Progress > 0) { lock (_exportJobs) { queueLength = "Queue: " + _exportJobs.Count; } ShowStatus(queueLength + " - " + _currentJob, _exporter.Progress); Thread.Sleep(300); } } if (_exporter.LastError != 0) { ShowStatus("Error:" + _exporter.LastErrorString, 0); Thread.Sleep(5000); } _exporter.EndExport(); _exporter.Close(); } ShowStatus(queueLength, 0); Thread.Sleep(2000); } EnvironmentManager.Instance.Log(false, "SCExport background thread", "Now stopping...", null); _thread = null; }
private void buttonExport_Click_1(object sender, EventArgs e) { bool isStarted = false; 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 (checkBoxRelated.Checked) { audioSources = selectedItem.GetRelated(); // Get the defined related Microphones and Speakers for the selected camera if (EnvironmentManager.Instance.MasterSite.ServerId.ServerType == ServerId.EnterpriseServerType) { //Enterprise does not record speaker sound foreach (Item item in audioSources.ToList()) { if (item.FQID.Kind != Kind.Microphone) { audioSources.Remove(item); } } } } if (radioButtonAVI.Checked) { if (textBoxVideoFilename.Text == "") { MessageBox.Show("Please enter a filename for the AVI file.", "Enter Filename"); return; } _exporter = new VideoOS.Platform.Data.AVIExporter() { Filename = textBoxVideoFilename.Text, Codec = (String)comboBoxCodec.SelectedItem, AudioSampleRate = Int32.Parse(comboBoxSampleRate.SelectedItem.ToString()) }; destPath = Path.Combine(_path, "Exported Images\\" + selectedItem.Name); } else if (radioButtonMKV.Checked) { if (textBoxVideoFilename.Text == "") { MessageBox.Show("Please enter a filename for the MKV file.", "Enter Filename"); return; } _exporter = new VideoOS.Platform.Data.MKVExporter() { Filename = textBoxVideoFilename.Text }; destPath = Path.Combine(_path, "Exported Images\\" + selectedItem.Name); } else { if (radioButtonPIC.Checked) { _exporter = new VideoOS.Platform.Data.DBExporter(); } else { if (checkBoxEncrypt.Checked && textBoxEncryptPassword.Text == "") { MessageBox.Show("Please enter password to encrypt with.", "Enter Password"); return; } _exporter = new VideoOS.Platform.Data.DBExporter(true) { Encryption = checkBoxEncrypt.Checked, EncryptionStrength = VideoOS.Platform.Data.EncryptionStrength.AES128, Password = textBoxEncryptPassword.Text, SignExport = checkBoxSign.Checked, PreventReExport = checkBoxReExport.Checked, IncludeBookmarks = checkBoxIncludeBookmark.Checked }; } } _exporter.Init(); _exporter.Path = destPath; _exporter.CameraList = new List <Item>() { selectedItem }; _exporter.AudioList = audioSources; isStarted = _exporter.StartExport(dateTimePickerStart.Value.ToUniversalTime(), dateTimePickerEnd.Value.ToUniversalTime()); try { if (isStarted) { _timer.Tick += ShowProgress; _timer.Start(); buttonExport.Enabled = false; //execute shell cmd //buttonCancel.Enabled = true; } else { int lastError = _exporter.LastError; string lastErrorString = _exporter.LastErrorString; labelError.Text = lastErrorString + " ( " + lastError + " )"; _exporter.EndExport(); } } catch (Exception ex) { EnvironmentManager.Instance.ExceptionDialog("Start Export", ex); } }