/// <summary>
        /// Loads the default settings, from values in the database
        /// </summary>
        public void LoadDefaults()
        {
            var       db = new CaptureDb(ConfigurationManager.ConnectionStrings["LOCALDB"].ConnectionString);
            DataTable dt = db.ReturnMotionSettingDefaults();

            //iterate over the properties in this object, and the properties in the Datatable until a match is found
            foreach (DataRow dr in dt.Rows)
            {
                foreach (PropertyInfo property in typeof(MotionSensorSettings).GetProperties())
                {
                    if (property.Name.Equals(dr["settingTypeName"].ToString()))
                    {
                        if (property.PropertyType.ToString() == "System.Decimal")
                        {
                            property.SetValue(this, dr["value"].ToString().StringToDec());
                        }
                        else if (property.PropertyType.ToString() == "System.Int32")
                        {
                            property.SetValue(this, dr["value"].ToString().StringToInt());
                        }
                        else if (property.PropertyType.ToString() == "System.Boolean")
                        {
                            property.SetValue(this, dr["value"].ToString().StringToBool());
                        }
                    }
                }
            }//foreach datarow
        }
Exemplo n.º 2
0
        protected override void StartSaveTask(long dbId, byte[] template, Guid guid, CancellationToken token)
        {
            Task saveTask = Task.Run(() =>
            {
                Log.Debug("Save task running.");

                CaptureDb capture = (from c in m_Database.Captures
                                     where c.Id == dbId
                                     select c).FirstOrDefault();

                if (capture != null)
                {
                    // Update the template to that supplied
                    capture.GoldTemplate = template;
                    m_Database.SubmitChanges();
                }
                else
                {
                    Log.WarnFormat("Failed to find capture wtih DbId={0}. Not saving template", dbId);
                }
            }, token);

            // Raise the SaveTemplateComplete event in the case where the Task faults.
            saveTask.ContinueWith((Task t) =>
            {
                if (t.IsFaulted)
                {
                    Log.Error("Failed to save template: " + t.Exception.Message, t.Exception);
                    OnSaveTemplateComplete(new SaveTemplateEventArgs(guid, DataRequestResult.TaskFailed));
                }
            });
        }
Exemplo n.º 3
0
        private CaptureInfo GetCapture(ScannerType scannerType, CancellationToken token)
        {
            Log.DebugFormat("GetCapture(scannerType={0}, token={1}) called",
                            scannerType, token);
            CaptureInfo       captureInfo = null;
            DataRequestResult result      = DataRequestResult.None;
            bool isRunning = true;
            int  attempts  = 0;

            while (isRunning)
            {
                // Check if cancellation requested
                token.ThrowIfCancellationRequested();

                // First query the database to get an image file name.
                CaptureDb captureCandidate = GetCaptureFromDatabase(scannerType);

                if (captureCandidate != null)
                {
                    // Try to find an image file using the file name.
                    byte[] imageData;
                    bool   isFound = TryGetImageFromName(captureCandidate.HumanId, out imageData);
                    if (isFound)
                    {
                        // Matching file found.
                        Log.DebugFormat("Matching file found for capture={0}", captureCandidate.HumanId);
                        isRunning   = false;
                        captureInfo = new CaptureInfo(
                            captureCandidate.Id,
                            imageData,
                            captureCandidate.GoldTemplate);
                        result = DataRequestResult.Success;
                    }
                    else
                    {
                        // Give up if the number of attemps exceeds limit.
                        attempts++;
                        if (attempts > MAX_OPEN_FILE_ATTEMPTS)
                        {
                            Log.WarnFormat("Exceeded maximum number of file searches (attempts={0})",
                                           attempts);
                            isRunning = false;
                            result    = DataRequestResult.Failed;
                        }
                    }
                }
                else
                {
                    // Queries are not returning any more candidates, give up immediately.
                    Log.Warn("No candidate filename obtained from the database");
                    result = DataRequestResult.Failed;
                    break;
                }
            }
            IntegrityCheck.AreNotEqual(DataRequestResult.None, result);
            return(captureInfo);
        }
Exemplo n.º 4
0
        public void TestAddCapture()
        {
            ImageSaver imageSaver = new ImageSaver(@"d:\motion", "movement", 0);

            ICaptureDb db = new CaptureDb(ConfigurationManager.ConnectionStrings["LOCALDB"].ConnectionString);

            db.CreateCaptureSession(imageSaver.captureId, imageSaver.SaveDirectory);
            Assert.IsTrue(db.CaptureIdExists(imageSaver.captureId));

            Exception ex = null;

            try
            {
                db.CreateCaptureSession(imageSaver.captureId, imageSaver.SaveDirectory);
            }
            catch (Exception exc)
            {
                ex = exc;
            }

            Assert.IsNotNull(ex);
        }