From af43c7a5feb12fed5737b24ba538b0dcd6c8d10a Mon Sep 17 00:00:00 2001 From: Prashant Cholachagudda Date: Wed, 23 May 2018 15:27:23 +0530 Subject: [PATCH] Replace connectivity plugin with Xamarin.Essentials --- MyShop.UWP/project.lock.json | 7 ------- MyShop/MyShop.csproj | 1 - MyShop/Services/AzureDataStore.cs | 14 ++++++-------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/MyShop.UWP/project.lock.json b/MyShop.UWP/project.lock.json index 1d844fb..aa0f566 100644 --- a/MyShop.UWP/project.lock.json +++ b/MyShop.UWP/project.lock.json @@ -902,7 +902,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -2090,7 +2089,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -3334,7 +3332,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -4522,7 +4519,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -5766,7 +5762,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -6954,7 +6949,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", @@ -8198,7 +8192,6 @@ "Refractored.MvvmHelpers": "1.3.0", "SQLitePCLRaw.bundle_green": "1.1.9", "SQLitePCLRaw.core": "1.1.9", - "Xam.Plugin.Connectivity": "3.1.1", "Xam.Plugin.EmbeddedResource": "1.0.1", "Xam.Plugin.ExternalMaps": "4.0.1", "Xam.Plugins.Forms.ImageCircle": "2.0.2", diff --git a/MyShop/MyShop.csproj b/MyShop/MyShop.csproj index 710dd7c..56eab54 100644 --- a/MyShop/MyShop.csproj +++ b/MyShop/MyShop.csproj @@ -19,7 +19,6 @@ - diff --git a/MyShop/Services/AzureDataStore.cs b/MyShop/Services/AzureDataStore.cs index 2933929..8ae6ffd 100644 --- a/MyShop/Services/AzureDataStore.cs +++ b/MyShop/Services/AzureDataStore.cs @@ -2,16 +2,13 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.WindowsAzure.MobileServices; -using System.Linq; using Microsoft.WindowsAzure.MobileServices.SQLiteStore; using Microsoft.WindowsAzure.MobileServices.Sync; using System.Diagnostics; using System; -using Xamarin.Forms; //Comment back in to use azure -using MyShop; -using Plugin.Connectivity; +using Xamarin.Essentials; //[assembly: Dependency(typeof(AzureDataStore))] namespace MyShop @@ -119,8 +116,8 @@ public async Task> GetStoresAsync() public async Task SyncStoresAsync() { try - { - if (!CrossConnectivity.Current.IsConnected || !Settings.NeedsSync) + { + if (!IsInternetAvailable || !Settings.NeedsSync) return; await storeTable.PullAsync("allStores", storeTable.CreateQuery()); @@ -138,10 +135,9 @@ public async Task SyncFeedbacksAsync() try { Settings.NeedSyncFeedback = true; - if (!CrossConnectivity.Current.IsConnected) + if (!IsInternetAvailable) return; - await MobileService.SyncContext.PushAsync(); Settings.NeedSyncFeedback = false; } @@ -151,6 +147,8 @@ public async Task SyncFeedbacksAsync() } } + bool IsInternetAvailable => Connectivity.NetworkAccess == NetworkAccess.Internet; + static readonly AzureDataStore instance = new AzureDataStore(); /// /// Gets the instance of the Azure Web Service