Exemple #1
0
        private void AddPreviewBoxes()
        {
            lock (flowPreview.Controls)
            {
                MasterFileList = new List <FilePreview>();
                foreach (Control c in _pnlCameras.Controls)
                {
                    try
                    {
                        if (c is CameraWindow)
                        {
                            var cw = ((CameraWindow)c);
                            List <FilesFile> ffs;
                            lock (cw.FileList)
                            {
                                ffs = cw.FileList.ToList();
                            }
                            foreach (FilesFile ff in ffs)
                            {
                                MasterFileList.Add(new FilePreview(ff.Filename, ff.DurationSeconds, cw.Camobject.name,
                                                                   ff.CreatedDateTicks, 2, cw.Camobject.id, ff.MaxAlarm));
                            }
                        }
                        if (c is VolumeLevel)
                        {
                            var vl = ((VolumeLevel)c);
                            List <FilesFile> ffs;
                            lock (vl.FileList)
                            {
                                ffs = vl.FileList.ToList();
                            }
                            foreach (FilesFile ff in ffs)
                            {
                                MasterFileList.Add(new FilePreview(ff.Filename, ff.DurationSeconds, vl.Micobject.name,
                                                                   ff.CreatedDateTicks, 1, vl.Micobject.id, ff.MaxAlarm));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("", ex);
                    }
                }
                var displayList =
                    MasterFileList.OrderByDescending(p => p.CreatedDateTicks).Where(p => p.ObjectTypeId == 2).Take(Conf.PreviewItems).ToList();
                foreach (FilePreview fp in displayList)
                {
                    FilePreview fp1      = fp;
                    var         filename = Conf.MediaDirectory + "video\\" + Cameras.Single(p => p.id == fp1.ObjectId).directory +
                                           "\\" + fp.Filename;
                    FilePreview fp2   = fp;
                    var         thumb = Conf.MediaDirectory + "video\\" + Cameras.Single(p => p.id == fp2.ObjectId).directory +
                                        "\\thumbs\\" + fp.Filename.Substring(0, fp.Filename.LastIndexOf(".", StringComparison.Ordinal)) + ".jpg";

                    AddPreviewControl(thumb, filename, fp.Duration, (new DateTime(fp.CreatedDateTicks)), false);
                }
            }
        }
 public void LoadPreviews()
 {
     UISync.Execute(ClearPreviewBoxes);
     lock (flowPreview.Controls)
     {
         MasterFileList = new List <FilePreview>();
         foreach (Control c in _pnlCameras.Controls)
         {
             try
             {
                 if (c is CameraWindow)
                 {
                     var cw = ((CameraWindow)c);
                     List <FilesFile> ffs;
                     lock (cw.FileList)
                     {
                         ffs = cw.FileList.ToList();
                     }
                     foreach (FilesFile ff in ffs)
                     {
                         MasterFileList.Add(new FilePreview(ff.Filename, ff.DurationSeconds, cw.Camobject.name,
                                                            ff.CreatedDateTicks, 2, cw.Camobject.id));
                     }
                 }
             }
             catch
             {
             }
         }
         MasterFileList =
             MasterFileList.OrderByDescending(p => p.CreatedDateTicks).Take(Conf.PreviewItems).ToList();
         foreach (FilePreview fp in MasterFileList)
         {
             FilePreview fp1      = fp;
             var         filename = Conf.MediaDirectory + "video\\" + Cameras.Single(p => p.id == fp1.ObjectId).directory +
                                    "\\" + fp.Filename;
             FilePreview fp2   = fp;
             var         thumb = Conf.MediaDirectory + "video\\" + Cameras.Single(p => p.id == fp2.ObjectId).directory +
                                 "\\thumbs\\" + fp.Filename.Substring(0, fp.Filename.LastIndexOf(".")) + ".jpg";
             AddPreviewControl(thumb, filename, fp.Duration, (new DateTime(fp.CreatedDateTicks)), false);
         }
     }
 }
Exemple #3
0
        public void Maximise(object obj, bool minimiseIfMaximised)
        {
            if (obj == null)
            {
                return;
            }
            if (obj is CameraWindow)
            {
                var cameraControl = ((CameraWindow)obj);
                cameraControl.BringToFront();


                try
                {
                    //
                    // by [email protected] / 1. May 2012
                    //
                    // maximise camera by keep it's aspect ratio and center to the main window
                    // cameraControl.RestoreRect is set to Empty if not maximised and can be checked if camera is maximised or normal view
                    //
                    if (cameraControl.RestoreRect.IsEmpty)
                    {
                        var s = "320x240";
                        if (!String.IsNullOrEmpty(cameraControl.Camobject.resolution))
                        {
                            s = cameraControl.Camobject.resolution;
                        }
                        var wh = s.Split('x');

                        cameraControl.RestoreRect = new Rectangle(cameraControl.Location.X, cameraControl.Location.Y,
                                                                  cameraControl.Width, cameraControl.Height);

                        double wFact = Convert.ToDouble(_pnlCameras.Width) / Convert.ToDouble(wh[0]);
                        double hFact = Convert.ToDouble(_pnlCameras.Height) / Convert.ToDouble(wh[1]);
                        if (cameraControl.VolumeControl != null)
                        {
                            hFact = Convert.ToDouble((_pnlCameras.Height - 40)) / Convert.ToDouble(wh[1]);
                        }
                        if (hFact <= wFact)
                        {
                            cameraControl.Width  = Convert.ToInt32(((Convert.ToDouble(_pnlCameras.Width) * hFact) / wFact));
                            cameraControl.Height = _pnlCameras.Height;
                        }
                        else
                        {
                            cameraControl.Width  = _pnlCameras.Width;
                            cameraControl.Height = Convert.ToInt32((Convert.ToDouble(_pnlCameras.Width) * wFact) / hFact);
                        }
                        cameraControl.Location = new Point(((_pnlCameras.Width - cameraControl.Width) / 2),
                                                           ((_pnlCameras.Height - cameraControl.Height) / 2));
                        if (cameraControl.VolumeControl != null)
                        {
                            cameraControl.Height -= 40;
                        }
                    }
                    else
                    {
                        if (minimiseIfMaximised)
                        {
                            Minimize(obj, false);
                        }
                        cameraControl.RestoreRect = Rectangle.Empty;
                    }
                    //
                    // end
                    //
                }
                catch (Exception ex)
                {
                    Log.Error("", ex);
                }
            }

            if (obj is VolumeLevel)
            {
                var vf = ((VolumeLevel)obj);
                vf.BringToFront();
                if (vf.Paired)
                {
                    CameraWindow cw = GetCameraWindow(Cameras.Single(p => p.settings.micpair == vf.Micobject.id).id);
                    if (vf.Width == _pnlCameras.Width)
                    {
                        if (minimiseIfMaximised)
                        {
                            Minimize(cw, false);
                        }
                    }
                    else
                    {
                        Maximise(cw);
                    }
                }
            }

            if (obj is FloorPlanControl)
            {
                var fp = ((FloorPlanControl)obj);
                fp.BringToFront();

                if (fp.RestoreRect.IsEmpty)
                {
                    fp.RestoreRect = new Rectangle(fp.Location.X, fp.Location.Y,
                                                   fp.Width, fp.Height);
                    var wFact = Convert.ToDouble(_pnlCameras.Width) / fp.Width;
                    var hFact = Convert.ToDouble(_pnlCameras.Height) / fp.Height;

                    if (hFact <= wFact)
                    {
                        fp.Width  = (int)(_pnlCameras.Width / wFact * hFact);
                        fp.Height = _pnlCameras.Height;
                    }
                    else
                    {
                        fp.Width  = _pnlCameras.Width;
                        fp.Height = (int)(_pnlCameras.Height / hFact * wFact);
                    }
                    fp.Location = new Point(((_pnlCameras.Width - fp.Width) / 2), ((_pnlCameras.Height - fp.Height) / 2));
                }
                else
                {
                    if (minimiseIfMaximised)
                    {
                        Minimize(obj, false);
                    }
                    fp.RestoreRect = Rectangle.Empty;
                }
            }
        }
Exemple #4
0
        public void Maximise(object obj, bool minimiseIfMaximised)
        {
            if (obj == null)
            {
                return;
            }
            if (InvokeRequired)
            {
                BeginInvoke(new MaximiseDelegate(Maximise), obj, minimiseIfMaximised);
                return;
            }
            var window = obj as CameraWindow;

            if (window != null)
            {
                var cameraControl = window;
                cameraControl.BringToFront();


                try
                {
                    var r = cameraControl.RestoreRect;
                    if (r.IsEmpty)
                    {
                        var s = "320x240";
                        if (!string.IsNullOrEmpty(cameraControl.Camobject.resolution))
                        {
                            s = cameraControl.Camobject.resolution;
                        }
                        var wh = s.Split('x');

                        cameraControl.RestoreRect = new Rectangle(cameraControl.Location.X, cameraControl.Location.Y,
                                                                  cameraControl.Width, cameraControl.Height);

                        double wFact = Convert.ToDouble(_pnlCameras.Width) / Convert.ToDouble(wh[0]);
                        double hFact = Convert.ToDouble(_pnlCameras.Height) / Convert.ToDouble(wh[1]);
                        if (cameraControl.VolumeControl != null)
                        {
                            hFact = Convert.ToDouble((_pnlCameras.Height - 40)) / Convert.ToDouble(wh[1]);
                        }
                        if (hFact <= wFact)
                        {
                            cameraControl.Width  = Convert.ToInt32(((Convert.ToDouble(_pnlCameras.Width) * hFact) / wFact));
                            cameraControl.Height = _pnlCameras.Height;
                        }
                        else
                        {
                            cameraControl.Width  = _pnlCameras.Width;
                            cameraControl.Height = Convert.ToInt32((Convert.ToDouble(_pnlCameras.Height) * wFact) / hFact);
                        }
                        cameraControl.Location = new Point(((_pnlCameras.Width - cameraControl.Width) / 2),
                                                           ((_pnlCameras.Height - cameraControl.Height) / 2));
                        if (cameraControl.VolumeControl != null)
                        {
                            cameraControl.Height -= 40;
                        }
                    }
                    else
                    {
                        if (minimiseIfMaximised)
                        {
                            Minimize(window, false);
                        }
                        cameraControl.RestoreRect = Rectangle.Empty;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex);
                }
            }

            var level = obj as VolumeLevel;

            if (level != null)
            {
                var vf = level;
                vf.BringToFront();
                if (vf.Paired)
                {
                    CameraWindow cw = GetCameraWindow(Cameras.Single(p => p.settings.micpair == vf.Micobject.id).id);
                    if (vf.Width == _pnlCameras.Width)
                    {
                        if (minimiseIfMaximised)
                        {
                            Minimize(cw, false);
                        }
                    }
                    else
                    {
                        Maximise(cw);
                    }
                }
                else
                {
                    var r = vf.RestoreRect;
                    if (r.IsEmpty)
                    {
                        vf.RestoreRect = new Rectangle(vf.Location.X, vf.Location.Y,
                                                       vf.Width, vf.Height);
                        vf.Location = new Point(0, 0);
                        vf.Width    = _pnlCameras.Width;
                        vf.Height   = _pnlCameras.Height;
                    }
                    else
                    {
                        if (minimiseIfMaximised)
                        {
                            Minimize(vf, false);
                        }
                        vf.RestoreRect = Rectangle.Empty;
                    }
                }
            }

            var control = obj as FloorPlanControl;

            if (control != null)
            {
                var fp = control;
                fp.BringToFront();
                var r = fp.RestoreRect;
                if (r.IsEmpty)
                {
                    fp.RestoreRect = new Rectangle(fp.Location.X, fp.Location.Y,
                                                   fp.Width, fp.Height);
                    var wFact = Convert.ToDouble(_pnlCameras.Width) / fp.Width;
                    var hFact = Convert.ToDouble(_pnlCameras.Height) / fp.Height;

                    if (hFact <= wFact)
                    {
                        fp.Width  = (int)(_pnlCameras.Width / wFact * hFact);
                        fp.Height = _pnlCameras.Height;
                    }
                    else
                    {
                        fp.Width  = _pnlCameras.Width;
                        fp.Height = (int)(_pnlCameras.Height / hFact * wFact);
                    }
                    fp.Location = new Point(((_pnlCameras.Width - fp.Width) / 2), ((_pnlCameras.Height - fp.Height) / 2));
                }
                else
                {
                    if (minimiseIfMaximised)
                    {
                        Minimize(control, false);
                    }
                    fp.RestoreRect = Rectangle.Empty;
                }
            }
        }