public void AddWebcam(Webcam webcam)
 {
     lock (this)
     {
         webcams.Add(webcam);
     }
 }
 public bool RemoveWebcam(Webcam webcam)
 {
     lock (this)
     {
         if (webcams.Contains(webcam))
         {
             webcams.Remove(webcam);
             return true;
         }
         else
             return false;
     }
 }
        private void AcceptWebcamConnections()
        {
            System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    while (_listening)
                    {
                        try
                        {
                            Webcam w = new Webcam(_webcamListener.AcceptTcpClient(), _view.BasePath);

                            w.Connected += OnConnect;
                            w.Disconnected += OnDisconnect;
                            w.MotionDetected += OnMotionDetect;
                            w.Recorded += (source) => _view.Status = "Webcam " + source.Name + " started recording";
                            w.MotionStopped += (source) =>
                                {
                                    source.StopRecording();
                                    _view.Status = "Webcam " + source.Name + " stopped recording";
                                };
                        }
                        catch (SocketException ex)
                        {
                            _view.Status = ex.Message;
                        }
                    }
                });
        }
        private void OnMotionDetect(Webcam source)
        {
            if (source.FirstAlarm)
                _view.Status = "Webcam " + source.Name + " detected motion";

            if (_view.AllowVideoRecord)
                source.StartRecording();
            if (_view.AllowSoundAlarm)
                source.Alarm();
        }
        private void OnDisconnect(Webcam source)
        {
            rwl.EnterWriteLock();
            _webcams.Remove(source);
            rwl.ExitWriteLock();

            _view.RemovedWebcam = source.Name;
            _view.Status = "Webcam " + source.Name + " has disconnected";
            source.Disconnected -= OnDisconnect;
            source.Dispose();
        }
        private void OnConnect(Webcam source)
        {
            rwl.EnterWriteLock();
            _webcams.Add(source);
            rwl.ExitWriteLock();

            source.AddClient(this);
            _view.AddedWebcam = source.Name;
            _view.Status = "Webcam " + source.Name + " is now connected";
        }