Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
         }
     }
 }