예제 #1
0
        public NewCameraKey GenerateUniqueCameraKey()
        {
            int count = 0;

            while (count < 5)
            {
                count++;
                // Camera Key must be exactly 12 characters.
                string randomCameraKey = StringGenerator.GenerateRandomString(12, 12);

                // Ensure Key does not exist in database (return value is -1).
                if (_dbQueryService.GetCameraIdFromKey(randomCameraKey) == -1)
                {
                    // Persist new camera key to database.

                    DatabaseCamera emptyCamera = new DatabaseCamera();
                    emptyCamera.CameraKey = randomCameraKey;
                    bool success = _dbQueryService.PersistNewCamera(emptyCamera);

                    if (success)
                    {
                        return(new NewCameraKey(randomCameraKey));
                    }

                    return(null);
                }
            }

            return(null);
        }
예제 #2
0
        public List <AlertSummary> GetAllActiveAlertsForCameraKey(string cameraKey)
        {
            int cameraId = _dbQueryService.GetCameraIdFromKey(cameraKey);
            List <DatabaseAlert> dbAlerts  = _dbQueryService.GetAlertsByCameraId(cameraId);
            List <AlertSummary>  alertList = new List <AlertSummary>();

            foreach (var dbAlert in dbAlerts)
            {
                if (dbAlert.DisabledUntil.GetValueOrDefault(DateTime.MinValue) < DateTime.Now &&
                    (dbAlert.StartTime.IsNullOrEmpty() || dbAlert.StartTime.ToDateTime() < DateTime.Now) &&
                    (dbAlert.EndTime.IsNullOrEmpty() || dbAlert.EndTime.ToDateTime() > DateTime.Now))
                {
                    AlertSummary alertSummary = new AlertSummary(dbAlert);
                    alertSummary.NeedsImage = DoesAlertNeedsFrameImage(dbAlert);
                    alertList.Add(alertSummary);
                }
            }

            return(alertList);
        }