Skip to content

Commit fccee97

Browse files
Merge pull request #9 from ShawnLaMountain/main
Updating Samples to use ThunderDesign.Net-PCL.Threading to version 1.0.10
2 parents 894dcea + 21380be commit fccee97

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

samples/WinForms/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static ContactsBridge Instance
1717
{
1818
get
1919
{
20-
lock (_Locker)
20+
lock (_InstanceLocker)
2121
{
2222
return _Instance ??= new ContactsBridge();
2323
}
@@ -26,7 +26,7 @@ public static ContactsBridge Instance
2626
#endregion
2727

2828
#region variables
29-
protected readonly static object _Locker = new();
29+
private readonly static object _InstanceLocker = new object();
3030
private static ContactsBridge? _Instance = null;
3131
#endregion
3232
}

samples/WinForms/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static SimpleContactsConnection Instance
1515
{
1616
get
1717
{
18-
lock (_Locker)
18+
lock (_InstanceLocker)
1919
{
2020
return _Instance ??= new SimpleContactsConnection();
2121
}
@@ -24,6 +24,7 @@ public static SimpleContactsConnection Instance
2424
#endregion
2525

2626
#region variables
27+
private readonly static object _InstanceLocker = new object();
2728
private const string _DatabaseFilename = "Contacts.db3";
2829
private static SimpleContactsConnection? _Instance = null;
2930
#endregion

samples/WinForms/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static ContactsTable Instance
1717
{
1818
get
1919
{
20-
lock (_Locker)
20+
lock (_InstanceLocker)
2121
{
2222
return _Instance ??= new ContactsTable();
2323
}
@@ -26,6 +26,7 @@ public static ContactsTable Instance
2626
#endregion
2727

2828
#region variables
29+
private readonly static object _InstanceLocker = new object();
2930
private static ContactsTable? _Instance = null;
3031
#endregion
3132

samples/Xamarin/SimpleContacts/SimpleContacts/Database/Bridges/ContactsBridge.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static ContactsBridge Instance
1717
{
1818
get
1919
{
20-
lock (_Locker)
20+
lock (_InstanceLocker)
2121
{
2222
return _Instance ??= new ContactsBridge();
2323
}
@@ -26,7 +26,7 @@ public static ContactsBridge Instance
2626
#endregion
2727

2828
#region variables
29-
protected readonly static object _Locker = new object();
29+
private readonly static object _InstanceLocker = new object();
3030
private static ContactsBridge _Instance = null;
3131
#endregion
3232
}

samples/Xamarin/SimpleContacts/SimpleContacts/Database/Connections/SimpleContactsConnection.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
1-
using ThunderDesign.Net.SQLite.Connections;
1+
using System;
2+
using System.IO;
3+
using ThunderDesign.Net.SQLite.Connections;
4+
using Xamarin.Forms;
25

36
namespace SimpleContacts.Database.Connections
47
{
58
public class SimpleContactsConnection : BaseSQLiteConnection
69
{
710
#region constructors
8-
public SimpleContactsConnection() : base(_DatabaseFilename)
11+
public SimpleContactsConnection() : base(_DatabaseFilename, GetDatabasePath())
912
{
1013
}
1114
#endregion
1215

1316
#region properties
17+
private static string GetDatabasePath()
18+
{
19+
string databasePath = "";
20+
if (Device.RuntimePlatform == Device.iOS)
21+
{
22+
// we need to put in /Library/ on iOS5.1+ to meet Apple's iCloud terms
23+
// (they don't want non-user-generated data in Documents)
24+
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
25+
databasePath = Path.Combine(documentsPath, "..", "Library"); // Library folder instead
26+
}
27+
else if (Device.RuntimePlatform == Device.Android)
28+
{
29+
// Just use whatever directory SpecialPolder.Personal returns
30+
databasePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
31+
}
32+
return databasePath;
33+
}
34+
1435
public static SimpleContactsConnection Instance
1536
{
1637
get
1738
{
18-
lock (_Locker)
39+
lock (_InstanceLocker)
1940
{
2041
return _Instance ??= new SimpleContactsConnection();
2142
}
@@ -24,6 +45,7 @@ public static SimpleContactsConnection Instance
2445
#endregion
2546

2647
#region variables
48+
private readonly static object _InstanceLocker = new object();
2749
private const string _DatabaseFilename = "Contacts.db3";
2850
private static SimpleContactsConnection _Instance = null;
2951
#endregion

samples/Xamarin/SimpleContacts/SimpleContacts/Database/Tables/ContactsTable.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static ContactsTable Instance
1717
{
1818
get
1919
{
20-
lock (_Locker)
20+
lock (_InstanceLocker)
2121
{
2222
return _Instance ??= new ContactsTable();
2323
}
@@ -26,6 +26,7 @@ public static ContactsTable Instance
2626
#endregion
2727

2828
#region variables
29+
private readonly static object _InstanceLocker = new object();
2930
private static ContactsTable _Instance = null;
3031
#endregion
3132
}

samples/Xamarin/SimpleContacts/SimpleContacts/SimpleContacts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Sharpnado.Shadows" Version="1.2.0" />
18+
<PackageReference Include="ThunderDesign.Net-PCL.Threading" Version="1.0.10" />
1819
<PackageReference Include="ThunderDesign.Xamarin.Forms.FloatingActionButton" Version="1.0.0" />
1920
<PackageReference Include="Xamarin.CommunityToolkit" Version="2.0.0" />
2021
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />

0 commit comments

Comments
 (0)