예제 #1
0
        //This blocking version is called by Android from the
        //background service.
        public void Sync(SyncParams syncParams)
        {
            _isSyncRunning = true;
            try
            {
                if (syncParams.SendAuth)
                    ZumeroClient.Sync(SyncController.DatabasePath, null, syncParams.URL, syncParams.DBFile, syncParams.Scheme, syncParams.User, syncParams.Password);
                else
                    ZumeroClient.Sync(SyncController.DatabasePath, null, syncParams.URL, syncParams.DBFile, null, null, null);
                _isSyncRunning = false;
                SyncController.Instance.NotifySyncCompleted(syncParams);
            }
            catch (Exception e)
            {
                if (e is ZumeroException)
                {
                    //if you need to react to a certain result, you can check
                    //the result of the sync like this:

                    //ZumeroException ze = (ZumeroException)e;
                    //
                    //if (ze.ErrorCode == (int)ZumeroResult.AuthenticationFailed)
                    //...

                    //The error code could also be a SQLite error code
                    //
                    //if (ze.ErrorCode == (int)SQLite3.Result.Error)
                    //...
                }
                _isSyncRunning = false;
                SyncController.Instance.NotifySyncFailed(e);
            }
        }
예제 #2
0
 public static SyncParams LoadSavedSyncParams()
 {
     SyncParams param = null;
     SQLiteConnection db = new SQLiteConnection(SyncController.DatabasePath);
     db.CreateTable<SyncParams>();
     if (db.Table<SyncParams>().Count() != 0)
         param = db.Table<SyncParams>().First();
     else
         param = new SyncParams();
     db.Close();
     return param;
 }
예제 #3
0
		private SyncController ()
		{
			CrossConnectivity.Current.ConnectivityChanged += (object sender, ConnectivityChangedEventArgs e) => { TrySync (); };

			_syncParams = SyncParams.LoadSavedSyncParams();

			Device.StartTimer (TimeSpan.FromMinutes(10), () =>
				{
					TrySync ();
					return true;
				});
		}
 public void StartBackgroundSync(SyncParams p)
 {
     if (SyncActivity == null)
     {
         SyncController.Instance.NotifySyncFailed(new Exception("SyncActivity is null."));
         return;
     }
     Intent syncIntent = new Intent(SyncActivity, typeof(AndroidBackgroundSyncService));
     syncIntent.PutExtra("url", p.URL);
     syncIntent.PutExtra("dbfile", p.DBFile);
     syncIntent.PutExtra("sendAuth", p.SendAuth);
     syncIntent.PutExtra("scheme", p.Scheme);
     syncIntent.PutExtra("user", p.User);
     syncIntent.PutExtra("password", p.Password);
     //Starting a service can take a while, do that in a background
     //thread as well.
     Task.Run(() =>
     {
         SyncActivity.StartService(syncIntent);
     });
 }
        protected override void OnHandleIntent(Intent i)
        {
            Log.Debug(Class.Name, "OnHandleIntent starting");
            SyncParams p = new SyncParams();

            p.URL = i.GetStringExtra("url");
            p.DBFile = i.GetStringExtra("dbfile");
            p.SendAuth = i.GetBooleanExtra("sendAuth", false);
            p.Scheme = i.GetStringExtra("scheme");
            p.User = i.GetStringExtra("user");
            p.Password = i.GetStringExtra("password");

            //Call the BaseSyncService in the portable Core.
            //Since we're already in the background, call the blocking version
            //of sync.
            new BaseSyncService().Sync(p);
            Log.Debug(Class.Name, "OnHandleIntent ending");
            this.StopSelf();
        }
예제 #6
0
 private void syncCompleted(object sender, SyncParams e)
 {
     ((CorflowMobile.App)Xamarin.Forms.Application.Current).ShowLoginPage();
 }
예제 #7
0
        public void NotifySyncCompleted(SyncParams p)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                if (!ZagDebugSchemaVersionCheck.VerifySchema())
                    ((CorflowMobile.App)Xamarin.Forms.Application.Current).MainPage.DisplayAlert("Database Schema Changed", "The schema for the database has been changed since this application was generated.  This may cause failures if columns have been removed.  You may want to use Zumero Application Generator to recreate this app, based on the new schema.", "Ok");

                _syncParams.SaveSyncParam();
                _syncInProgress = false;
                _syncNeeded = false;

                if (_userNotified)
                {
                    notifyUserOnline();
                    _userNotified = false;
                }

                if (OnSyncCompleted != null)
                    OnSyncCompleted(this, p);
            });
        }
예제 #8
0
 //This default version is used on iOS and WinPhone
 public void StartBackgroundSync(SyncParams syncParams)
 {
     Task.Run(() => { Sync(syncParams); });
 }