SQLite based implementation of IMobileServiceLocalStore
Inheritance: Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceLocalStore
Esempio n. 1
0
      public async Task Init()
      {
          

        if (MobileService.SyncContext.IsInitialized)    
          return;

        var path = "syncstore.db";
        var store = new MobileServiceSQLiteStore(path);
        store.DefineTable<Order>();
        store.DefineTable<Account>();
        store.DefineTable<Contact>();

        try
        {
          await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

        }
        catch(Exception ex)
        {
          Debug.WriteLine(@"Sync Failed: {0}", ex.Message);
       
        }
        

        orderTable = MobileService.GetSyncTable<Order>();

        accountTable = MobileService.GetSyncTable<Account>();

        contactTable = MobileService.GetSyncTable<Contact>();
      }
		public async Task InitializeStoreAsync()
		{
			string path = "syncstore.db";
			var store = new MobileServiceSQLiteStore(path);
			store.DefineTable<TodoItem>();
			await Client.SyncContext.InitializeAsync(store);
		}
        public async Task InitializeAsync()
        {
            if (IsInitialized)
                return;

            //Get our current client, only ever need one
            var client = ServiceLocator.Instance.Resolve<IAzureClient>()?.Client;

            /*
            if (!string.IsNullOrWhiteSpace(CrossSettings.Current.AuthToken) && !string.IsNullOrWhiteSpace(Settings.Current.UserId))
            {
                client.CurrentUser = new MobileServiceUser(CrossSettings.Current.UserId);
                client.CurrentUser.MobileServiceAuthenticationToken = CrossSettings.Current.AuthToken;
            }*/

            var path = $"beerdrinkin.db";
            //setup our local sqlite store and intialize our table
            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<Beer>();
            store.DefineTable<CheckIn>();
            store.DefineTable<Brewery>();

            await client.SyncContext.InitializeAsync((IMobileServiceLocalStore) store, new MobileServiceSyncHandler()).ConfigureAwait(false);

            IsInitialized = true;
        }
Esempio n. 4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ToDo.TodoItemManager"/> class.
		/// </summary>
		public TodoItemManager ()
		{
			// Create the service client and make sure to use the native network stack via ModernHttpClient's NativeMessageHandler.
			this.client = new MobileServiceClient (Constants.ApplicationURL, Constants.GatewayURL, new CustomMessageHandler ());

			// This is where we want to store our local data.
			this.store = new MobileServiceSQLiteStore (((App)App.Current).databaseFolderAndName);

			// Create the tables.
			this.store.DefineTable<TodoItem> ();

			// Initializes the SyncContext using a specific IMobileServiceSyncHandler which handles sync errors.
			this.client.SyncContext.InitializeAsync (store, new SyncHandler ());

			// The ToDo items should be synced.
			this.todoTable = client.GetSyncTable<TodoItem> ();

			// Uncomment to clear all local data to have a fresh start. Then comment out again.
			//this.todoTable.PurgeAsync();


			// Create a Sqlite-Net connection to the SAME DB that is also used for syncing.
			// Everything that gets inserted via this connection will not be synced.
			// Azure Mobile always syncs everything, so we have to either use an alternative database or use  another API to acces the same DB.
			this.sqliteNetConn = new SQLiteAsyncConnection (((App)App.Current).databaseFolderAndName);
			this.sqliteNetConn.CreateTableAsync<ConfigItem> ();
		}
Esempio n. 5
0
        public async Task Initialize()
        {
            if (isInitialized)
                return;

            var time = Xamarin.Insights.TrackTime("InitializeTime");
            time.Start();
            

            var handler = new AuthHandler();
            //Create our client
            MobileService = new MobileServiceClient("https://mycoffeeapp.azurewebsites.net", handler);
            handler.Client = MobileService;

            if (!string.IsNullOrWhiteSpace (Settings.AuthToken) && !string.IsNullOrWhiteSpace (Settings.UserId)) {
                MobileService.CurrentUser = new MobileServiceUser (Settings.UserId);
                MobileService.CurrentUser.MobileServiceAuthenticationToken = Settings.AuthToken;
            }
            
            const string path = "syncstore.db";
            //setup our local sqlite store and intialize our table
            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<CupOfCoffee>();

            await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            //Get our sync table that will call out to azure
            coffeeTable = MobileService.GetSyncTable<CupOfCoffee>();

            isInitialized = true;
            time.Stop();
        }
        private async Task InitLocalStoreAsync()
        {
            // new code to initialize the SQLite store
            string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), localDbFilename);

            if (!File.Exists(path))
            {
                File.Create(path).Dispose();
            }

            var store = new MobileServiceSQLiteStore(localDbFilename);

            BeaconActivity beaconact = new BeaconActivity();
            GuiSettingsActivity guisettingsact = new GuiSettingsActivity();
           
            store.DefineTable<Beacon>();
            store.DefineTable<GuiSettings>();
            store.DefineTable<Location>();
            store.DefineTable<Map>();
            store.DefineTable<Prompt>();
            store.DefineTable<PromptStep>();
            store.DefineTable<Reminder>();
            store.DefineTable<Settings>();
            store.DefineTable<UserSettings>();
            store.DefineTable<Users>();
            store.DefineTable<UserMaps>();


            // Uses the default conflict handler, which fails on conflict
            // To use a different conflict handler, pass a parameter to InitializeAsync. For more details, see http://go.microsoft.com/fwlink/?LinkId=521416
            await client.SyncContext.InitializeAsync(store);
        }
Esempio n. 7
0
 private static async void OnLoad(object sender, EventArgs eventArgs)
 {
     const string path = "bd.sqlite";
     var store = new MobileServiceSQLiteStore(path);
     store.DefineTable<TodoItem>();
     await Program.TableClient.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
 }
Esempio n. 8
0
        public async Task Initialize()
        {
            if (isInitialized)
                return;

            var time = Xamarin.Insights.TrackTime("InitializeTime");
            time.Start();
            
            //Create our client
            MobileService = new MobileServiceClient("https://mycoffeeapp.azurewebsites.net");

            const string path = "syncstore.db";
            //setup our local sqlite store and intialize our table
            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<CupOfCoffee>();

            await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            //Get our sync table that will call out to azure
            coffeeTable = MobileService.GetSyncTable<CupOfCoffee>();

            isInitialized = true;
            time.Stop();
        }
Esempio n. 9
0
        public async Task InitializeAsync()
        {
            if (IsInitialized)
                return;

            //Get our current client, only ever need one
            var client = ServiceLocator.Instance.Resolve<IAzureClient>()?.Client;

            if (!string.IsNullOrWhiteSpace(Settings.Current.AuthToken) &&
                !string.IsNullOrWhiteSpace(Settings.Current.AzureMobileUserId))
            {
                client.CurrentUser = new MobileServiceUser(Settings.Current.AzureMobileUserId)
                {
                    MobileServiceAuthenticationToken = Settings.Current.AuthToken
                };
            }

            var path = $"syncstore{Settings.Current.DatabaseId}.db";
            //setup our local sqlite store and intialize our table
            store = new MobileServiceSQLiteStore(path);

            store.DefineTable<UserProfile>();
            store.DefineTable<TripPoint>();
            store.DefineTable<Photo>();
            store.DefineTable<Trip>();
            store.DefineTable<POI>();
            store.DefineTable<IOTHubData>();

            await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()).ConfigureAwait(false);

            IsInitialized = true;
        }
Esempio n. 10
0
//==============================================================================================
/// <summary>
/// Initialize the Data Store asynchronously
/// </summary>
/// <returns></returns>
//==============================================================================================
        public async Task InitializeAsync()
        {
          // Create the two sides of the service


            try
            {
             

                CloudService = new MobileServiceClient(this.ConfigurationSettings.PaasUri);
                LocalCacheService = new MobileServiceSQLiteStore(this.ConfigurationSettings.LocalCache);

                // Define the table structure
                ((MobileServiceSQLiteStore)LocalCacheService).DefineTable<Organization>();

                // Initialize the local store
                await CloudService.SyncContext.InitializeAsync(LocalCacheService);
            }
            catch (Exception ex)
            {

                int g = 8;
            }


         
        }
 public async Task InitializeAsync()
 {
     string path = "localstore.db";
     var store = new MobileServiceSQLiteStore(path);
     store.DefineTable<ToDoItem>();
     await client.SyncContext.InitializeAsync(store, new SyncHandler(client));
 }
		public async Task InitializeAsync()
		{
			var store = new MobileServiceSQLiteStore("localdata.db");
			store.DefineTable<PolicyHistory> ();
			await this.MobileService.SyncContext.InitializeAsync(store);

			phTable = this.MobileService.GetSyncTable<PolicyHistory>();
		}
		private TodoItemManager()
		{
			this.client = new MobileServiceClient(Constants.ApplicationURL);
			var store = new MobileServiceSQLiteStore("localstore.db");
			store.DefineTable<TodoItem>();
			this.client.SyncContext.InitializeAsync(store);
			this.todoTable = client.GetSyncTable<TodoItem>();
		}
        protected override async void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Activity_To_Do);

            progressBar = FindViewById<ProgressBar> (Resource.Id.loadingProgressBar);

            // Initialize the progress bar
            progressBar.Visibility = ViewStates.Gone;

            // Create ProgressFilter to handle busy state
            var progressHandler = new ProgressHandler ();
            progressHandler.BusyStateChange += (busy) => {
                if (progressBar != null) 
                    progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
            };

            try {
                CurrentPlatform.Init ();
                // Create the Mobile Service Client instance, using the provided
                // Mobile Service URL and key
                client = new MobileServiceClient (
                    applicationURL,
                    applicationKey, progressHandler);

                string path = 
                    Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "localstore.db");
                
                if (!File.Exists(path))
                {
                    File.Create(path).Dispose();
                }
                var store = new MobileServiceSQLiteStore(path);
                store.DefineTable<ToDoItem>();
                await client.SyncContext.InitializeAsync(store, new SyncHandler(this));

                // Get the Mobile Service Table instance to use
                toDoTable = client.GetSyncTable <ToDoItem> ();

                textNewToDo = FindViewById<EditText> (Resource.Id.textNewToDo);

                // Create an adapter to bind the items with the view
                adapter = new ToDoItemAdapter (this, Resource.Layout.Row_List_To_Do);
                var listViewToDo = FindViewById<ListView> (Resource.Id.listViewToDo);
                listViewToDo.Adapter = adapter;

                // Load the items from the Mobile Service
                await RefreshItemsFromTableAsync ();

            } catch (Java.Net.MalformedURLException) {
                CreateAndShowDialog (new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
            } catch (Exception e) {
                CreateAndShowDialog (e, "Error");
            }
        }
 private async Task ExecuteAndClearStore(Func<IMobileServiceSyncTable<DerivedDataEntity>, Task> test)
 {
     using (var store = new MobileServiceSQLiteStore("test.sqlite"))
     {
         var table = await GetTableAsync(store);
         await test(table);
     }
     File.Delete("test.sqlite");
 }
        public async Task InitializeStoreAsync()
        {
            var store = new MobileServiceSQLiteStore(localDbPath);
            store.DefineTable<ToDoItem>();

            // Uses the default conflict handler, which fails on conflict
            // To use a different conflict handler, pass a parameter to InitializeAsync. For more details, see http://go.microsoft.com/fwlink/?LinkId=521416
            await client.SyncContext.InitializeAsync(store);
        }
    public async Task Init()
    {
      initialized = true;
      string path = "syncstore.db";
      var store = new MobileServiceSQLiteStore(path);
      store.DefineTable<TripExpense>();
      await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

      expenseTable = MobileService.GetSyncTable<TripExpense>();
    }
 private async Task InitLocalStoreAsync()
 {
     if (!App.MobileService.SyncContext.IsInitialized)
     {
         var store = new MobileServiceSQLiteStore("localstore.db");
         store.DefineTable<Vehicle>();
         await App.MobileService.SyncContext.InitializeAsync(store);
     }
     await SyncAsync();
 }
Esempio n. 19
0
        public async Task InitializeStore()
        {
            initialized = true;
            const string path = "syncstore.db";
            var store = new MobileServiceSQLiteStore(path);
            //store.DefineTable<Monkey>();
            await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            //monkeyTable = MobileService.GetSyncTable<Monkey>();
        }
        public async Task InitializeAsync()
        {
            this.MobileService = 
                new MobileServiceClient(MobileUrl, new LoggingHandler());

            var store = new MobileServiceSQLiteStore("local.db");
            store.DefineTable<Job>();

            await MobileService.SyncContext.InitializeAsync(store, StoreTrackingOptions.NotifyLocalAndServerOperations);
            jobTable = MobileService.GetSyncTable<Job>();
        }
Esempio n. 21
0
 public AzureDataService()
 {
     this.client = new MobileServiceClient(App.ApplicationURL);
     var store = new MobileServiceSQLiteStore("gomonkeystore.db");
     store.DefineTable<Monkey>(); 
     this.monkeyTable = this.client.GetSyncTable<Monkey>();
     this.client.InitializeFileSyncContext(new ImagesFileSyncHandler<Monkey>(monkeyTable), store);
     this.client.SyncContext.InitializeAsync(store, StoreTrackingOptions.AllNotifications);
     var dispose = this.client.EventManager.Subscribe<Microsoft.WindowsAzure.MobileServices.Eventing.IMobileServiceEvent>((e) => {
         System.Diagnostics.Debug.WriteLine("Event Handled: " + e.Name);
     });
 }
Esempio n. 22
0
 public async Task InitStoreAsync()
 {
     if (!client.SyncContext.IsInitialized)
     {
         var store = new MobileServiceSQLiteStore(syncStorePath);
         store.DefineTable<SensorDataItem>();
         await client.SyncContext.InitializeAsync(
             store, 
             new ConflictHandler(client, ConflictResolutionPolicy.KeepLocal)
          );
     }
 }
Esempio n. 23
0
		public async Task Init()
		{
			initialized = true;
			const string path = "syncstore.db";
			var store = new MobileServiceSQLiteStore(path);
			store.DefineTable<Store>();
			store.DefineTable<Feedback> ();
			await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

			storeTable = MobileService.GetSyncTable<Store>();
			feedbackTable = MobileService.GetSyncTable<Feedback> ();
		}
Esempio n. 24
0
        /// <summary>
        /// Initialize the Data Store asynchronously
        /// </summary>
        /// <returns></returns>
        private async Task InitializeAsync()
        {
            // Create the two sides of the service
            CloudService = new MobileServiceClient(DataStore.clouduri);
            LocalCacheService = new MobileServiceSQLiteStore(localcache);

            // Define the table structure
            ((MobileServiceSQLiteStore)LocalCacheService).DefineTable<TodoItem>();

            // Initialize the local store
            await CloudService.SyncContext.InitializeAsync(LocalCacheService);
        }
		/// <summary>
		/// Initialize the local database and sync the data
		/// </summary>
		private async void InitLocalStore()
		{
			if (!_mobileService.SyncContext.IsInitialized)
			{
				var store = new MobileServiceSQLiteStore("pocketguide.db");
				store.DefineTable<Category>();
				store.DefineTable<ServiceType>();
				store.DefineTable<Product>();
				store.DefineTable<ProductInformation>();
				await _mobileService.SyncContext.InitializeAsync(store);
			}
		}
Esempio n. 26
0
        private async Task Initialize()
        {
            if (!App.MobileService.SyncContext.IsInitialized)
            {
                var store = new MobileServiceSQLiteStore("localdb8.db");
                store.DefineTable<MobileOrder>();
                store.DefineTable<MobileCustomer>();

                await App.MobileService.SyncContext.InitializeAsync(store);
            }

            await RefreshOrderList();
        }
        private async Task<IMobileServiceSyncTable<DerivedDataEntity>> GetTableAsync(MobileServiceSQLiteStore store)
        {
            store.DefineTable<DerivedDataEntity>();
            MobileServiceClient client = null;
#if WIN_APPS
            client = new MobileServiceClient((string)ApplicationData.Current.LocalSettings.Values["MobileAppUrl"]);
#else
            client = new MobileServiceClient(ConfigurationManager.AppSettings["MobileAppUrl"]);
#endif
            client.InitializeExpressFileSyncContext(store);
            await client.SyncContext.InitializeAsync(store);
            return client.GetSyncTable<DerivedDataEntity>();
        }
Esempio n. 28
0
        public async Task InitializeAsync()
        {
            this.MobileService = AppService.CreateMobileServiceClient(
                MobileAppURL,
                "");
            // 3. initialize local store

            var store = new MobileServiceSQLiteStore("local-db-" + MobileAppName);
            store.DefineTable<Job>();

            await MobileService.SyncContext.InitializeAsync(store);

            jobTable = MobileService.GetSyncTable<Job>();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode != NavigationMode.New) // only handle initial launch 
                return; 

            if (!App.MobileService.SyncContext.IsInitialized)
            {
                var store = new MobileServiceSQLiteStore("localsync.db");
                store.DefineTable<TodoItem>();
                await App.MobileService.SyncContext.InitializeAsync(store, new SyncHandler(App.MobileService));
            }

            await RefreshTodoItems();
        }
Esempio n. 30
0
        public async Task InitializeAsync()
        {
            this.MobileService = AppService.CreateMobileServiceClient(
                "https://fetechnician-code.azurewebsites.net/",
                "OtFsjAFDBBMENsPCBQFJmItwjvAfaX77");
            // 3. initialize local store

            var store = new MobileServiceSQLiteStore("local-db-fabrikam80");
            store.DefineTable<Job>();

            await MobileService.SyncContext.InitializeAsync(store);

            jobTable = MobileService.GetSyncTable<Job>();
        }
Esempio n. 31
0
        /*****************************************************************
         * INITIALIZE METHOD - CONNECTS TO THE DATABASE
         ****************************************************************/

        public async Task Intialize()
        {
            if (isInitialised)
            {
                return;
            }

            //Create our client
            MobileService = new MobileServiceClient("https://ssds00164997.azurewebsites.net");

            const string path = "Person.db";
            //setup our local sqlite store and intialize our table
            var store = new Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore(path);

            store.DefineTable <Person>();
            await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            //Get our sync table that will call out to azure
            personTable = MobileService.GetSyncTable <Person>();

            isInitialised = true;
        }
        /// <summary>
        /// Defines a table to use for offline sync
        /// </summary>
        /// <param name="store">The offline store.</param>
        /// <typeparam name="T">The model type of the table</typeparam>
        public static void DefineTable <T>(this MobileServiceSQLiteStore store)
        {
            var settings = new MobileServiceJsonSerializerSettings();

            DefineTable <T>(store, settings);
        }