public static BlobService GetInstance() { if (_instance == null) { _instance = new BlobService(); } return(_instance); }
public async Task InitializeAsync() { if (_mobileService != null) { return; } // Inicialización de SQLite local (cache offline) var store = new MobileServiceSQLiteStore("cursoxamarin.db"); store.DefineTable <City>(); _mobileService = new MobileServiceClient(GlobalSettings.CityMobileServiceEndpoint); _cityTable = _mobileService.GetSyncTable <City>(); await _mobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()); if (CrossConnectivity.Current.IsConnected) { try { var cities = await _cityTable.ReadAsync(); var citiesList = new List <City>(cities); //subimos las imagenes offline al blob foreach (var city in citiesList.Where(city => city.OfflineImage != null)) { city.Image = await BlobService.GetInstance().UploadPhotoAsync(city.OfflineImage); city.OfflineImage = null; await _cityTable.UpdateAsync(city); } // Subir cambios a la base de datos remota await _mobileService.SyncContext.PushAsync(); await _cityTable.PullAsync( "allCities", _cityTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Exception: {0}", ex.Message); } } }