/// <summary> /// Update progress 10 times a second /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowProgress(object sender, EventArgs e) { if (_exporter != null) { int progress = _exporter.Progress; int lastError = _exporter.LastError; string lastErrorString = _exporter.LastErrorString; if (progress >= 0) { progressBar.Value = progress; if (progress == 100) { _timer.Stop(); labelError.Text = "Done"; _exporter.EndExport(); _exporter = null; ///*buttonCancel*/.Enabled = false; } } if (lastError > 0) { progressBar.Value = 0; labelError.Text = lastErrorString + " ( " + lastError + " )"; if (_exporter != null) { _exporter.EndExport(); _exporter = null; //buttonCancel.Enabled = false; } } } }
private void OnClose(object sender, EventArgs e) { if (_exporter != null) { _exporter.Cancel(); _exporter.EndExport(); _exporter.Close(); } VideoOS.Platform.SDK.Environment.RemoveAllServers(); Close(); }
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; }