public ServicesRepository()
		{
			_mobileService = new MobileServiceClient("YOUR URL HERE", "YOUR APP SECRET HERE");
			_categoryTable = _mobileService.GetSyncTable<Category>();
			_serviceTypeTable = _mobileService.GetSyncTable<ServiceType>();
			_productTable = _mobileService.GetSyncTable<Product>();
			_productInfoTable = _mobileService.GetSyncTable<ProductInformation>();
			InitLocalStore();
		}
Esempio n. 2
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();
        }
Esempio n. 3
0
        protected override async void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

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

            CurrentPlatform.Init ();

            // Create the Mobile Service Client instance, using the provided
            // Mobile Service URL and key
            client = new MobileServiceClient (applicationURL, applicationKey);
            await InitLocalStoreAsync();

            // Get the Mobile Service sync 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
            OnRefreshItemsSelected ();
        }
Esempio n. 4
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. 5
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> ();
		}
        protected override async void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

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

            CurrentPlatform.Init ();

            // Create the Mobile Service Client instance, using the provided
            // Mobile Service URL
            client = new MobileServiceClient(applicationURL);
            await InitLocalStoreAsync();

            // Set the current instance of TodoActivity.
            instance = this;

            // Make sure the GCM client is set up correctly.
            GcmClient.CheckDevice(this);
            GcmClient.CheckManifest(this);

            // Get the Mobile Service sync 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 App backend.
            //OnRefreshItemsSelected ();
        }
        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 QSTodoService ()
        {
            CurrentPlatform.Init ();
            SQLitePCL.CurrentPlatform.Init(); 

            // Initialize the Mobile Service client with the Mobile App URL, Gateway URL and key
            client = new MobileServiceClient (applicationURL);

            // Create an MSTable instance to allow us to work with the TodoItem table
            todoTable = client.GetSyncTable <ToDoItem> ();
        }
        private QSTodoService ()
        {
            CurrentPlatform.Init ();
            SQLitePCL.Batteries.Init(); 

            // Initialize the client with the mobile app backend URL.
            client = new MobileServiceClient (applicationURL);

            // Create an MSTable instance to allow us to work with the TodoItem table
            todoTable = client.GetSyncTable <ToDoItem> ();
        }
Esempio n. 10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            global::Xamarin.Forms.Forms.Init (this, bundle);

            CurrentPlatform.Init();

            MobileService = new MobileServiceClient(
                "https://qutbraingearapp.azure-mobile.net/",
                "dqTWRsEygjexEvHVQYjzrneKfvTKBU73"
            );

            // 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(path);
            store.DefineTable<Module>();
            store.DefineTable<QA>();
            store.DefineTable<Comment>();
            store.DefineTable<Skills>();

            // Uses the default conflict handler, which fails on conflict
            MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler ()).Wait ();
            QUTBrainGearDB.MobileService = MobileService;

            QUTBrainGearDB.ModuleTable = MobileService.GetSyncTable <Module> ();
            QUTBrainGearDB.QATable = MobileService.GetSyncTable <QA> ();
            QUTBrainGearDB.CommentTable = MobileService.GetSyncTable <Comment> ();
            QUTBrainGearDB.SkillsTable = MobileService.GetSyncTable <Skills> ();

            QUTBrainGearDB.SyncAsync ();

            LoadApplication (new App());
        }
Esempio n. 11
0
        public SensorModel()
        {
            // initialize mobile services and SQLLite store
            Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
#if __IOS__
            SQLitePCL.CurrentPlatform.Init();
#endif

            // initialize the client with your app url and key
            client = new MobileServiceClient(applicationURL, applicationKey);
            // create sync table instance
            sensorDataTable = client.GetSyncTable<SensorDataItem>();
        }
        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. 13
0
        private TodoItemManager()
        {
            this.client = new MobileServiceClient(Constants.ApplicationURL);

            var store = new MobileServiceSQLiteStore("localstore.db");
            store.DefineTable<TodoItem>();

            //Initializes the SyncContext using the default IMobileServiceSyncHandler.
            this.client.SyncContext.InitializeAsync(store);

            this.todoTable = client.GetSyncTable<TodoItem>();

        }
		/// <summary>
		/// Initializes the backend service and connects with Azure
		/// </summary>
		/// <returns></returns>
		public static async Task InitAsync()
		{
			if (_IsInitialized)
				return;

			// Create the mobile client
			_MobileService = new MobileServiceClient("http://YOUR-MOBILE-SERVICE-URL");

			// Setup the local SQLite database
			var store = new MobileServiceSQLiteStore("mynotestore.db");
			store.DefineTable<Note>();
			await _MobileService.SyncContext.InitializeAsync(store);

			// Get tables for local database
			_NoteTable = _MobileService.GetSyncTable<Note>();		

			// Set initialized flag to avoid double initialisation
			_IsInitialized = true;
		}
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			Xamarin.Forms.Forms.Init (this, bundle);

			#region Azure stuff
			CurrentPlatform.Init ();

			Client = new MobileServiceClient (
				Constants.Url, 
				Constants.Key);		


			#region Azure Sync stuff
			// http://azure.microsoft.com/en-us/documentation/articles/mobile-services-xamarin-android-get-started-offline-data/
			// new code to initialize the SQLite store
			string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "test1.db");

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

			var store = new MobileServiceSQLiteStore(path);
			store.DefineTable<TodoItem>();

			Client.SyncContext.InitializeAsync(store).Wait();
			#endregion


			todoTable = Client.GetSyncTable<TodoItem>(); 
			todoItemManager = new TodoItemManager(Client, todoTable);

			App.SetTodoItemManager (todoItemManager);
			#endregion region

			#region Text to Speech stuff
			App.SetTextToSpeech (new Speech ());
			#endregion

			SetPage (App.GetMainPage ());
		}
        protected override async void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

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

            CurrentPlatform.Init ();

            // Create the Mobile Service Client instance, using the provided
            // Mobile Service URL and key
			client = new MobileServiceClient (AppConstant.applicationURL, AppConstant.applicationKey);
            await InitLocalStoreAsync();

			user = new MobileServiceUser(Intent.GetStringExtra("UserID"));
			user.MobileServiceAuthenticationToken = Intent.GetStringExtra("UserToken");

			client.CurrentUser = user;

			// Set the current instance of TodoActivity.
			instance = this;

			// Make sure the GCM client is set up correctly.
			GcmClient.CheckDevice(this);
			GcmClient.CheckManifest(this);

			// Register the app for push notifications.
			GcmClient.Register(this, ToDoBroadcastReceiver.senderIDs);

            // Get the Mobile Service sync 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
            OnRefreshItemsSelected ();
        }
        public async Task Initialize()
        {
            if (Client?.SyncContext?.IsInitialized ?? false)
                return;


            var appUrl = "https://ilovecoffee.azurewebsites.net";

#if AUTH      
            Client = new MobileServiceClient(appUrl, new AuthHandler());

            if (!string.IsNullOrWhiteSpace (Settings.AuthToken) && !string.IsNullOrWhiteSpace (Settings.UserId)) {
                Client.CurrentUser = new MobileServiceUser (Settings.UserId);
                Client.CurrentUser.MobileServiceAuthenticationToken = Settings.AuthToken;
            }
#else
            //Create our client

            Client = new MobileServiceClient(appUrl);

#endif

            //InitialzeDatabase for path
            var path = "syncstore.db";
            path = Path.Combine(MobileServiceClient.DefaultDatabasePath, path);

            //setup our local sqlite store and intialize our table
            var store = new MobileServiceSQLiteStore(path);

            //Define table
            store.DefineTable<CupOfCoffee>();


            //Initialize SyncContext
            await Client.SyncContext.InitializeAsync(store);

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

            
        }
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			Forms.Init ();
			// create a new window instance based on the screen size
			window = new UIWindow (UIScreen.MainScreen.Bounds);


			#region Azure stuff
			CurrentPlatform.Init ();
			SQLitePCL.CurrentPlatform.Init();

			Client = new MobileServiceClient (
				Constants.Url, 
				Constants.Key);	

			#region Azure Sync stuff
			// http://azure.microsoft.com/en-us/documentation/articles/mobile-services-xamarin-android-get-started-offline-data/
			// new code to initialize the SQLite store
			InitializeStoreAsync().Wait();
			#endregion

			todoTable = Client.GetSyncTable<TodoItem>(); 
			todoItemManager = new TodoItemManager(Client, todoTable);

			App.SetTodoItemManager (todoItemManager);
			#endregion region

			#region Text to Speech stuff
			App.SetTextToSpeech (new Speech ());
			#endregion region

			// If you have defined a view, add it here:
			// window.RootViewController  = navigationController;
			window.RootViewController = App.GetMainPage ().CreateViewController ();

			// make the window visible
			window.MakeKeyAndVisible ();

			return true;
		}
        public TodoItemManager()
        {
            client = new MobileServiceClient(
                Constants.ApplicationURL,
                Constants.GatewayURL,
                //Constants.ApplicationKey, new LoggingHandler(false));
                Constants.ApplicationKey, null);

           // var store = new TodoItemSQLiteStore("localstore.db", false, false, false);
            var store = new MobileServiceSQLiteStore("localstore.db");
            store.DefineTable<TodoItem>();

            // FILES: Initialize file sync
            this.client.InitializeFileSyncContext(new TodoItemFileSyncHandler(this), store);

            //Initializes the SyncContext using the default IMobileServiceSyncHandler.
            this.client.SyncContext.InitializeAsync(store);

            this.todoTable = client.GetSyncTable<TodoItem>();

            eventSubscription = this.client.EventManager.Subscribe<IMobileServiceEvent>(GeneralEventHandler);
        }
        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);

            _progressBar.Visibility = ViewStates.Gone;

            CurrentPlatform.Init();

            // Create the Mobile Service Client instance, using the provided
            // Mobile Service URL
            client = new MobileServiceClient(applicationURL);
            await InitLocalStoreAsync();

            // Get the Mobile Service sync table instance to use
            toDoTable = client.GetSyncTable<ImageQualityError>();
            
            // 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
            OnRefreshItemsSelected();

            instance = this;

            // Make sure the GCM client is set up correctly.
            GcmClient.CheckDevice(this);
            GcmClient.CheckManifest(this);

            // Register the app for push notifications.
            GcmClient.Register(this, ToDoBroadcastReceiver.senderIDs);
        }
Esempio n. 21
0
 public static void SetupSyncTableReferences(MobileServiceClient azureServiceClient)
 {
     IMobileServiceSyncTable<TodoItem> todoTable = azureServiceClient.GetSyncTable<TodoItem>();
 }
Esempio n. 22
0
		public async void connectMaster (int flag)
		{
			try {
				client = new MobileServiceClient (applicationURL,applicationKey);

				path = System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), "local.db");

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



				var store = new MobileServiceSQLiteStore (path);
				store.DefineTable<PanelItem> ();
				store.DefineTable<PanelMasterItem> ();
				store.DefineTable<OutlookMailItem> ();
				await client.SyncContext.InitializeAsync (store);

				panelItemStoreTable = client.GetSyncTable<PanelItem> ();
				panelMasterItemStoreTable = client.GetSyncTable<PanelMasterItem> ();
				outlookMasterStoreTable = client.GetSyncTable<OutlookMailItem>();
				await SyncAsync (flag);


			} catch {
				CreateAndShowDialog ("Cannot connect to internet", "Connection Problem");
				progressBar.Visibility = ViewStates.Gone;
			}
		}