예제 #1
0
        public void TestConnectToDatabase()
        {
            // Connect to SQlite.
            SQLiteConnection dbConnection = new SQLiteConnection(
                String.Format("Data Source={0};Version=3;",
                              DATABASE_PATH));

            // Set the LINQ data context to the database connection.
            SimPrintsDb db = new SimPrintsDb(dbConnection);

            // Make a basic query
            // Query for customers from London
            var q = from c in db.Captures
                    where c.ScannerName == "LES"
                    select c;

            foreach (CaptureDb capt in q)
            {
                Console.WriteLine("id = {0}, ScannerName = {1}, FingerNumber = {2}, Pid = {3}",
                                  capt.Id,
                                  capt.ScannerName,
                                  capt.FingerNumber,
                                  capt.Person.Pid);
            }
        }
예제 #2
0
        protected override void StartInitialiseTask(DataControllerConfig config, Guid guid, CancellationToken token)
        {
            // Define and run the task, passing in the token.
            Task initialiseTask = Task.Run(() =>
            {
                Log.Debug("Initialise task running.");
                // Connect to SQlite.
                SQLiteConnection dbConnection = new SQLiteConnection(
                    String.Format(CONNECTION_STRING, SQLITE_DATABASE));

                // Set the LINQ data context to the database connection.
                m_Database = new SimPrintsDb(dbConnection);

                // Obtain image files on local machine, to be matched with database entries.
                m_ImageFiles = GetImageFiles(IMAGES_FILE_PATH);
                if (m_ImageFiles != null &&
                    m_ImageFiles.Count() > 0)
                {
                    m_State = InitialisationResult.Initialised;
                }
                else
                {
                    Log.Error("Failed to get image files.");
                    m_State = InitialisationResult.Error;
                }

                OnInitialisationComplete(
                    new InitialisationCompleteEventArgs(m_State, guid, DataRequestResult.Success));
            }, token);

            // Raise the GetCaptureComplete event in the case where the Task faults.
            initialiseTask.ContinueWith((Task t) =>
            {
                if (t.IsFaulted)
                {
                    Log.Error("Failed initialise controller: " + t.Exception.Message, t.Exception);
                    OnInitialisationComplete(new InitialisationCompleteEventArgs(
                                                 InitialisationResult.Uninitialised, guid, DataRequestResult.TaskFailed));
                }
            });
        }