public void TryAddOrUpdateVideoSource(BcDevices device) { this.TryToRemoveVideoSource(device.Id); string connectionString = VideoServer.GetDeviceConnectionString(device); IReadOnlyDictionary <string, string> deviceOptions = VideoServer.GetDeviceOptions(device); CS.VideoSources.Core.IVideoSource videoSource = VideoServer.CreateVideoSource(device.Type, connectionString, device.Login, device.Password, deviceOptions); if (videoSource != null) { this.VideoSources.Add(device.Id, videoSource); videoSource.VideoSourceError += new CS.VideoSources.Core.VideoSourceErrorEventHandler(this.HandleVideoSourceError); } if (videoSource != null) { return; } this._logger.WarnFormat("Unable to create Video source of type {0} and id {1}", (object)device.Type, (object)device.Id); }
private static void PrepareDirectories(string serviceName) { VideoServer instance = VideoServerContractImpl.Instance; instance.ApplicationFolder = PathExtensions.GetProductAppDataFolder(serviceName); instance.ImageFolder = Path.Combine(instance.ApplicationFolder, "Images"); try { PathExtensions.PrepareDirectory(instance.ApplicationFolder); PathExtensions.PrepareDirectory(Path.Combine(instance.ApplicationFolder, "Faces")); PathExtensions.PrepareDirectory(instance.ImageFolder); PathExtensions.PrepareDirectory(Path.Combine(instance.ApplicationFolder, "Data")); } catch (Exception ex) { instance.Logger.Fatal((object)"Unable to create directory. Service stopped", ex); throw; } }
private void AddOrUpdateVideoSources(IEnumerable <BcDevices> checkDevs) { foreach (BcDevices device in checkDevs) { bool flag = false; string connectionString = VideoServer.GetDeviceConnectionString(device); foreach (KeyValuePair <Guid, CS.VideoSources.Core.IVideoSource> keyValuePair in (IEnumerable <KeyValuePair <Guid, CS.VideoSources.Core.IVideoSource> >) this.VideoSources) { CS.VideoSources.Core.IVideoSource videoSource = keyValuePair.Value; if (!(keyValuePair.Key != device.Id)) { if (!string.Equals(videoSource.ConnectionString, connectionString, StringComparison.InvariantCultureIgnoreCase)) { this.TryAddOrUpdateVideoSource(device); } flag = true; break; } } if (!flag) { this.TryAddOrUpdateVideoSource(device); } CS.VideoSources.Core.IVideoSource processedSource = this.VideoSources[device.Id]; if (device.IsActive && !processedSource.IsRunning) { try { this._logger.InfoFormat("Starting source {0} with connection string {1}", (object)processedSource.GetType(), (object)processedSource.ConnectionString); processedSource.Start(); } catch (Exception ex) { this._logger.Error((object)"Error starting source", ex); this.TryToRemoveVideoSource(device.Id); } } else if (!device.IsActive && processedSource.IsRunning) { this.StopSource(processedSource); } } }
public CommonContracts.VideoFrame GetLastFrameFromDevice(Guid devId, bool deleteFrame) { try { this._performanceLogger.Info((object)string.Format("Request DevId = {0}", (object)devId)); if (!this.VideoSources.ContainsKey(devId)) { return((CommonContracts.VideoFrame)null); } CS.VideoSources.Core.IVideoSource videoSource = this.VideoSources[devId]; if (!videoSource.IsRunning) { return((CommonContracts.VideoFrame)null); } using (CS.VideoSources.Core.VideoFrame currentFrame = videoSource.GetCurrentFrame(deleteFrame)) { if (currentFrame == null) { return((CommonContracts.VideoFrame)null); } this._performanceLogger.Info((object)string.Format("Response DevId = {0} FrameId = {1}", (object)devId, (object)currentFrame.Index)); byte[] frameBytes = VideoServer.GetFrameBytes(currentFrame); return(new CommonContracts.VideoFrame() { Frame = frameBytes, FrameIndex = currentFrame.Index, Date = DateTimeOffset.Now }); } } catch (Exception ex) { this._logger.Error((object)ex); } return((CommonContracts.VideoFrame)null); }