From 21380bed583e8119ca3d55ff63c090550d9ab52c Mon Sep 17 00:00:00 2001 From: Shawn LaMountain Date: Mon, 30 Oct 2023 12:26:28 -0400 Subject: [PATCH] Updating Samples to use ThunderDesign.Net-PCL.Threading to version 1.0.10 --- .../Database/Bridges/ContactsBridge.cs | 4 +-- .../Connections/SimpleContactsConnection.cs | 3 +- .../Database/Tables/ContactsTable.cs | 3 +- .../Database/Bridges/ContactsBridge.cs | 4 +-- .../Connections/SimpleContactsConnection.cs | 28 +++++++++++++++++-- .../Database/Tables/ContactsTable.cs | 3 +- .../SimpleContacts/SimpleContacts.csproj | 1 + 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs index 0137147..64f8419 100644 --- a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs +++ b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs @@ -17,7 +17,7 @@ public static ContactsBridge Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new ContactsBridge(); } @@ -26,7 +26,7 @@ public static ContactsBridge Instance #endregion #region variables - protected readonly static object _Locker = new(); + private readonly static object _InstanceLocker = new object(); private static ContactsBridge? _Instance = null; #endregion } diff --git a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs index 135a672..15fe939 100644 --- a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs +++ b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs @@ -15,7 +15,7 @@ public static SimpleContactsConnection Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new SimpleContactsConnection(); } @@ -24,6 +24,7 @@ public static SimpleContactsConnection Instance #endregion #region variables + private readonly static object _InstanceLocker = new object(); private const string _DatabaseFilename = "Contacts.db3"; private static SimpleContactsConnection? _Instance = null; #endregion diff --git a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs index fd271b7..7262b13 100644 --- a/samples/WinForms/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs +++ b/samples/WinForms/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs @@ -17,7 +17,7 @@ public static ContactsTable Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new ContactsTable(); } @@ -26,6 +26,7 @@ public static ContactsTable Instance #endregion #region variables + private readonly static object _InstanceLocker = new object(); private static ContactsTable? _Instance = null; #endregion diff --git a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs index 5921d15..bfd1af4 100644 --- a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs +++ b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs @@ -17,7 +17,7 @@ public static ContactsBridge Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new ContactsBridge(); } @@ -26,7 +26,7 @@ public static ContactsBridge Instance #endregion #region variables - protected readonly static object _Locker = new object(); + private readonly static object _InstanceLocker = new object(); private static ContactsBridge _Instance = null; #endregion } diff --git a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs index fc79ce5..c0d270f 100644 --- a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs +++ b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs @@ -1,21 +1,42 @@ -using ThunderDesign.Net.SQLite.Connections; +using System; +using System.IO; +using ThunderDesign.Net.SQLite.Connections; +using Xamarin.Forms; namespace SimpleContacts.Database.Connections { public class SimpleContactsConnection : BaseSQLiteConnection { #region constructors - public SimpleContactsConnection() : base(_DatabaseFilename) + public SimpleContactsConnection() : base(_DatabaseFilename, GetDatabasePath()) { } #endregion #region properties + private static string GetDatabasePath() + { + string databasePath = ""; + if (Device.RuntimePlatform == Device.iOS) + { + // we need to put in /Library/ on iOS5.1+ to meet Apple's iCloud terms + // (they don't want non-user-generated data in Documents) + string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder + databasePath = Path.Combine(documentsPath, "..", "Library"); // Library folder instead + } + else if (Device.RuntimePlatform == Device.Android) + { + // Just use whatever directory SpecialPolder.Personal returns + databasePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + } + return databasePath; + } + public static SimpleContactsConnection Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new SimpleContactsConnection(); } @@ -24,6 +45,7 @@ public static SimpleContactsConnection Instance #endregion #region variables + private readonly static object _InstanceLocker = new object(); private const string _DatabaseFilename = "Contacts.db3"; private static SimpleContactsConnection _Instance = null; #endregion diff --git a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs index f02499e..0d61445 100644 --- a/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs +++ b/samples/Xamarin/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs @@ -17,7 +17,7 @@ public static ContactsTable Instance { get { - lock (_Locker) + lock (_InstanceLocker) { return _Instance ??= new ContactsTable(); } @@ -26,6 +26,7 @@ public static ContactsTable Instance #endregion #region variables + private readonly static object _InstanceLocker = new object(); private static ContactsTable _Instance = null; #endregion } diff --git a/samples/Xamarin/SimpleContacts/SimpleContacts/SimpleContacts.csproj b/samples/Xamarin/SimpleContacts/SimpleContacts/SimpleContacts.csproj index de2370f..e0cb624 100644 --- a/samples/Xamarin/SimpleContacts/SimpleContacts/SimpleContacts.csproj +++ b/samples/Xamarin/SimpleContacts/SimpleContacts/SimpleContacts.csproj @@ -15,6 +15,7 @@ +