private void OnClose(object sender, EventArgs e) { if (_exporter != null) { _exporter.Cancel(); _exporter.EndExport(); _exporter.Close(); } VideoOS.Platform.SDK.Environment.RemoveAllServers(); Close(); }
/// <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; }