Exemplo n.º 1
0
 public LiveCameraMonitor()
 {
     new Task(() =>
     {
         while (true)
         {
             Thread.Sleep(1500);
             IPCamera[] lives = null;
             lock (syncRoot)
             {
                 lives = new IPCamera[liveCameras.Count];
                 liveCameras.CopyTo(lives, 0);
             }
             foreach (var camera in lives)
             {
                 try
                 {
                     if (!camera.Player.IsPlaying)
                     {
                         camera.Player.Play(new FileInfo(camera.RecordPath));
                     }
                 }
                 catch (Exception) { }
             }
         }
     }, TaskCreationOptions.LongRunning).Start();
 }
Exemplo n.º 2
0
        public void Add(CameraAddress addr)
        {
            IPCamera camera = null;

            if (!TryGet(addr, out camera))
            {
                liveCameras.Add(new IPCamera(addr, monitor));
            }
        }
Exemplo n.º 3
0
 public void Watch(IPCamera camera)
 {
     if (!IsUnderWatching(camera))
     {
         lock (syncRoot)
         {
             liveCameras.Add(camera);
         }
     }
 }
Exemplo n.º 4
0
 public MediaPlayer(IPCamera camera, string fileName, long startPos, int duration)
 {
     InitializeComponent();
     this.camera = camera;
     this.fileName = fileName;
     this.startPos = startPos;
     this.duration = duration;
     this.Controls.Add(camera.Player);
     context = SynchronizationContext.Current;
 }
Exemplo n.º 5
0
 public MediaPlayer(IPCamera camera, string fileName, long startPos, int duration)
 {
     InitializeComponent();
     this.camera   = camera;
     this.fileName = fileName;
     this.startPos = startPos;
     this.duration = duration;
     this.Controls.Add(camera.Player);
     context = SynchronizationContext.Current;
 }
Exemplo n.º 6
0
 private bool IsUnderWatching(IPCamera camera)
 {
     foreach (var cam in liveCameras)
     {
         if (cam.Address == camera.Address)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public IList <IPCamera> ListCamerasToReplay(string machineAddr, DateTime checkInTime)
        {
            var directoriesToReplay = new List <string>();
            var camerasToReplay     = new List <IPCamera>();
            var directories         = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "video");

            foreach (var dir in directories)
            {
                var split = new DirectoryInfo(dir).Name.Split('.');
                if (split.Length == 2)
                {
                    if (split[1].Equals(machineAddr))
                    {
                        directoriesToReplay.Add(dir);
                    }
                }
            }
            foreach (var dir in directoriesToReplay)
            {
                var fileNamesToLong = Directory.GetFiles(dir)
                                      .Where(f => Path.GetExtension(f).Equals(".avi"))
                                      .Select(f => Convert.ToInt64(Path.GetFileNameWithoutExtension(f)))
                                      .OrderBy(d => d)
                                      .ToArray();
                var idx = Array.BinarySearch <long>(fileNamesToLong, TimeUtil.ToTimestamp(checkInTime));
                if (idx >= 0)
                {
                    var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx]));
                    camerasToReplay.Add(camera);
                    if (!camera.IsRecLongEnoughToPlay(checkInTime))
                    {
                        if (idx != fileNamesToLong.Length - 1)
                        {
                            camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx + 1])));
                        }
                    }
                }
                else
                {
                    idx = ~idx;
                    if (idx != 0)
                    {
                        var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx - 1]));
                        camerasToReplay.Add(camera);
                        if (!camera.IsRecLongEnoughToPlay(checkInTime))
                        {
                            camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx])));
                        }
                    }
                }
            }
            return(camerasToReplay);
        }
Exemplo n.º 8
0
 public bool TryGet(CameraAddress addr, out IPCamera camera)
 {
     camera = null;
     var exists = false;
     foreach (var cam in liveCameras)
     {
         if (cam.Address == addr)
         {
             camera = cam;
             exists = true;
             break;
         }
     }
     return exists;
 }
Exemplo n.º 9
0
        public bool TryGet(CameraAddress addr, out IPCamera camera)
        {
            camera = null;
            var exists = false;

            foreach (var cam in liveCameras)
            {
                if (cam.Address == addr)
                {
                    camera = cam;
                    exists = true;
                    break;
                }
            }
            return(exists);
        }
Exemplo n.º 10
0
 public IList<IPCamera> ListCamerasToReplay(string machineAddr, DateTime checkInTime)
 {
     var directoriesToReplay = new List<string>();
     var camerasToReplay = new List<IPCamera>();
     var directories = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "video");
     foreach(var dir in directories)
     {
         var split = new DirectoryInfo(dir).Name.Split('.');
         if (split.Length == 2)
         {
             if (split[1].Equals(machineAddr)) directoriesToReplay.Add(dir);
         }
     }
     foreach (var dir in directoriesToReplay)
     {
         var fileNamesToLong = Directory.GetFiles(dir)
             .Where(f => Path.GetExtension(f).Equals(".avi"))
             .Select(f => Convert.ToInt64(Path.GetFileNameWithoutExtension(f)))
             .OrderBy(d => d)
             .ToArray();
         var idx = Array.BinarySearch<long>(fileNamesToLong, TimeUtil.ToTimestamp(checkInTime));
         if (idx >= 0)
         {
             var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx]));
             camerasToReplay.Add(camera);
             if (!camera.IsRecLongEnoughToPlay(checkInTime))
             {
                 if (idx != fileNamesToLong.Length - 1) camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx + 1])));
             }
         }
         else
         {
             idx = ~idx;
             if (idx != 0)
             {
                 var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx - 1]));
                 camerasToReplay.Add(camera);
                 if (!camera.IsRecLongEnoughToPlay(checkInTime))
                 {
                     camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx])));
                 }
             }
         }
     }
     return camerasToReplay;
 }
Exemplo n.º 11
0
 private bool IsUnderWatching(IPCamera camera)
 {
     foreach (var cam in liveCameras) if (cam.Address == camera.Address) return true;
     return false;
 }
Exemplo n.º 12
0
 public void Watch(IPCamera camera)
 {
     if (!IsUnderWatching(camera))
     {
         lock (syncRoot)
         {
             liveCameras.Add(camera);
         }
     }
 }
Exemplo n.º 13
0
 public LiveCameraMonitor()
 {
     new Task(() =>
     {
         while (true)
         {
             Thread.Sleep(1500);
             IPCamera[] lives = null;
             lock (syncRoot)
             {
                 lives = new IPCamera[liveCameras.Count];
                 liveCameras.CopyTo(lives, 0);
             }
             foreach (var camera in lives)
             {
                 try
                 {
                     if (!camera.Player.IsPlaying) camera.Player.Play(new FileInfo(camera.RecordPath));
                 }
                 catch (Exception) { }
             }
         }
     }, TaskCreationOptions.LongRunning).Start();
 }