private void getVideoSources(object source, ElapsedEventArgs e) { if (isRunning) { return; } isRunning = true; FilterInfoCollection VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); bool changed = false; lock (_locker) { List <VideoDeviceDTO> exists = new List <VideoDeviceDTO>(); foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices) { var vsd = new VideoDeviceDTO() { Name = VideoCaptureDevice.Name, DisplayName = VideoCaptureDevice.Name, Id = VideoCaptureDevice.MonikerString, Type = SourceType.USB_CAMERA }; exists.Add(vsd); } foreach (VideoDeviceDTO videoCaptureDevice in exists) { var found = _videoSourceList.FirstOrDefault(v => v.Name == videoCaptureDevice.Name); if (found == null) { var vsd = new VideoDeviceDTO() { Name = videoCaptureDevice.Name, DisplayName = videoCaptureDevice.Name, Id = videoCaptureDevice.Id, Type = SourceType.USB_CAMERA }; _videoSourceList.Add(vsd); changed = true; } } foreach (VideoDeviceDTO device in _videoSourceList.ToList()) { if (device.Type != SourceType.USB_CAMERA) { continue; } if (!exists.Any(d => d.Name == device.Name)) { _videoSourceList.Remove(device); changed = true; } } } isRunning = false; if (changed) { SourcesChanged?.Invoke(_videoSourceList, null); } }
public void RemoveVehicleVideoSource(VideoDeviceDTO vdd) { lock (_locker) { var vname = _videoSourceList.FirstOrDefault(v => v.VehicleId == vdd.VehicleId); if (vname != null) { _videoSourceList.Remove(vname); SourcesChanged?.Invoke(_videoSourceList, null); } } }
public void ClearVehicleVideoSource() { lock (_locker) { var vsList = _videoSourceList.Where(v => v.Type == SourceType.VEHICLE).ToList(); foreach (var videoSource in vsList) { _videoSourceList.Remove(videoSource); } if (vsList.Count > 0) { SourcesChanged?.Invoke(_videoSourceList, null); } } }
public void AddOrUpdateVehicleVideoSource(VideoDeviceDTO vdd) { bool changed = false; lock (_locker) { var vs = _videoSourceList.FirstOrDefault(v => v.VehicleId == vdd.VehicleId); if (vs == null) { if (!string.IsNullOrEmpty(vdd.Name)) { _videoSourceList.Add(vdd); changed = true; } } else { if (string.IsNullOrEmpty(vdd.Name)) { _videoSourceList.Remove(vs); changed = true; } else if (vs.Name != vdd.Name) { vs.Id = VideoDeviceDTO.GenerateId(vdd.Id, vdd.Name); vs.Name = vdd.Name; vs.DisplayName = vdd.DisplayName; changed = true; } } } if (changed) { SourcesChanged?.Invoke(_videoSourceList, null); } }
private void ServiceThread() { var endpoint = new IPEndPoint(IPAddress.Any, 0); var checklist = new List <Socket>(); udp.Client.Blocking = false; while (running) { checklist.Add(udp.Client); Socket.Select(checklist, null, null, 1000000); // 1 sec if (checklist.Count == 0) { continue; } var packet = Encoding.UTF8.GetString(udp.Receive(ref endpoint)); if (!packet.StartsWith("quack!")) { continue; } var lines = new List <string>(); foreach (var x in packet.Split('\n')) { if (x.Trim().Length > 0) { lines.Add(x); } } var cmd = lines[0].Split('!')[1]; if (cmd == "packages-changed") { var dist = lines[1].Split('/')[1]; var pkgs = new List <Tuple <string, uint?, string> >(); for (int i = 2; i < lines.Count; i++) { var s = lines[i].Split(':'); pkgs.Add(new Tuple <string, uint?, string>(s[0], Convert.ToUInt32(s[1]), null)); } PackagesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, dist, pkgs)); } else if (cmd == "packages-available") { string distro = null; var pkgs = new List <Tuple <string, uint?, string> >(); for (int i = 1; i < lines.Count; i++) { if (lines[i].StartsWith("distro/")) { distro = lines[i].Split('/')[1]; continue; } var s = lines[i].Split(':'); uint? rev = null; string group = null; if (s[1] != "virtual") { rev = Convert.ToUInt32(s[1]); } if (s.Length > 2 && s[2].Length > 0) { group = s[2]; } pkgs.Add(new Tuple <string, uint?, string>(s[0], rev, group)); } AvailablePackagesAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, distro, pkgs)); } else if (cmd.StartsWith("dists-")) { var dists = new List <string>(); for (int i = 1; i < lines.Count; i++) { dists.Add(lines[i]); } var e = new ServiceMessageEventArgs(packet, dists); if (cmd == "dists-changed") { DistributionsChanged?.Invoke(this, e); } else { AvailableDistributionsAccepted?.Invoke(this, e); } } else if (cmd == "text") { string text = ""; for (int i = 1; i < lines.Count; i++) { text += lines[i] + "\n"; } if (text.Length > 0) { text = text.Remove(text.Length - 1); TextAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, text)); } } else if (cmd == "wd") { WorkingDirectory = lines[1]; } else if (cmd == "index-changed") { IndexChanged?.Invoke(this, new ServiceMessageEventArgs(packet)); } else if (cmd == "action-update") { ActionProgressUpdated?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], Convert.ToInt32(lines[2]), Convert.ToInt32(lines[3]))); } else if (cmd == "action-complete") { ActionComplete?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], 0, 0)); } else if (cmd == "sources-changed") { List <string> sources = new List <string>(); for (int x = 1; x < lines.Count; x++) { sources.Add(lines[x]); } SourcesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, null, sources)); } } udp.Close(); }