private void CleanUp()
        {
            var sqlUtilities = new SqLiteUtilitiesAlt(this);

            try
            {
                sqlUtilities.OpenConnection();
                sqlUtilities.CreateTable();
                sqlUtilities.CloseConnection();

                using (var fUtilities = new FileUtilities(directory))
                {
                    fUtilities.DeleteFile();

                    fUtilities.CreateFile();

                    fUtilities.CloseFile();
                }
            }
            catch (Exception ex)
            {
                var dlgException = new AlertDialog.Builder(this);
                dlgException.SetMessage("An error has occurred: " + ex.Message);
                dlgException.SetTitle("Error");
                dlgException.SetPositiveButton("OK", (sender, args) => { });
                dlgException.SetCancelable(true);
                dlgException.Create().Show();
                return;
            }

            var dlgAlert = new AlertDialog.Builder(this);

            dlgAlert.SetMessage("Completed test setup");
            dlgAlert.SetTitle("Cleanup and Prepare for Tests Successful");
            dlgAlert.SetPositiveButton("OK", (sender, args) => { });
            dlgAlert.SetCancelable(true);
            dlgAlert.Create().Show();
            return;
        }
Beispiel #2
0
        private void LoadRecords()
        {
            SqLiteUtilitiesAlt utilities;

            utilities = new SqLiteUtilitiesAlt(this.context);
            try
            {
                utilities.OpenConnection();
                if (displayType == SqLiteDisplayType.ShowAll)
                {
                    records = utilities.GetAllRecords();
                }
                else
                {
                    records = utilities.GetRecordsWith1();
                }
                utilities.CloseConnection();
            }
            catch (Exception ex)
            {
                // Bah, it's not production code...
            }
        }
        private void AddRecords()
        {
            SqLiteUtilitiesAlt utilities;
            int maxValue = 999;

            utilities = new SqLiteUtilitiesAlt(this);

            TimeSpan original, alternative;

            try
            {
                utilities.OpenConnection();

                var stopWatch = Stopwatch.StartNew();
                for (int i = 0; i <= maxValue; i++)
                {
                    utilities.AddRecord("test", "person", i, "12345678901234567890123456789012345678901234567890");
                }
                stopWatch.Stop();

                original = stopWatch.Elapsed;

                utilities.CloseConnection();

                var newConnection = new SQLiteConnectionWithLock(new SQLitePlatformAndroid(),
                                                                 new SQLiteConnectionString(Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath, "async.db"), true));

                newConnection.DropTable <Record>();
                newConnection.CreateTable <Record>();

                stopWatch.Restart();

                newConnection.BeginTransaction();

                for (int i = 0; i <= maxValue; i++)
                {
                    newConnection.Insert(new Record()
                    {
                        FirstName = "test",
                        LastName  = "person",
                        Index     = i,
                        Misc      = "12345678901234567890123456789012345678901234567890"
                    });
                }

                newConnection.Commit();

                stopWatch.Stop();
                alternative = stopWatch.Elapsed;
            }
            catch (Exception ex)
            {
                AlertDialog.Builder dlgException = new AlertDialog.Builder(this);
                dlgException.SetMessage("An error has occurred adding records: " + ex.Message);
                dlgException.SetTitle("Error");
                dlgException.SetPositiveButton("OK", (sender, args) => { });
                dlgException.SetCancelable(true);
                dlgException.Create().Show();
                return;
            }

            AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
            dlgAlert.SetMessage(string.Format("All records written to database. Original time: {0}, alternative time: {1}", original, alternative));
            dlgAlert.SetTitle("Success");
            dlgAlert.SetPositiveButton("OK", (sender, args) => { });
            dlgAlert.SetCancelable(true);
            dlgAlert.Create().Show();
            return;
        }