Exemple #1
0
        public async Task <SyncResult> SyncAuthProviders()
        {
            // Current set of providers in the database so we can check if any have been removed.
            List <String>       currentList = (await DataAccessLayer.Current.GetAuthProvidersAsync()).Select(a => a.Name).ToList();
            SyncResult          result      = SyncResult.Failed;
            HttpResponseMessage response;

            try
            {
                response = await WebAPI.GetAuthProviders();

                if (response.IsSuccessStatusCode)
                {
                    var providers = await response.Content.ReadAsAsync <IEnumerable <AuthProvider> >();

                    foreach (AuthProvider ap in providers)
                    {
                        // Add provider to the database and remove from the current list
                        await DataAccessLayer.Current.UpdateOrAddAuthProviderAsync(ap);

                        currentList.Remove(ap.Name);
                    }

                    // If there are any providers remaining in currentList, then they've been removed
                    // from the backend and we need to delete those records from our database.
                    foreach (String s in currentList)
                    {
                        await DataAccessLayer.Current.DeleteAuthProviderAsync(s);
                    }

                    await Configuration.PopulateAuthProvidersFromDB();

                    result = SyncResult.Success;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("SyncAuthProviders failed: " + ex.Message);
            }

            return(result);
        }