public async Task SyncWebToMobileAsync(string userId)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                MessagingUtils.SendOfflineMessage();
                return;
            }

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            try
            {
                Logger.Track(EvolveLoggerKeys.SyncWebToMobile);

                var ssoClient = DependencyService.Get <ISSOClient>();
                await ssoClient.LogoutAsync();

                // login with the new user Id obtained via the QR code scan
                var account = await ssoClient.LoginAnonymouslyAsync(userId);

                if (account != null)
                {
                    Settings.Current.UserIdentifier = account.User.Email;

                    MessagingService.Current.SendMessage(MessageKeys.LoggedIn);
                    Logger.Track(EvolveLoggerKeys.LoginSuccess);

                    Settings.Current.FirstRun = false;
                }

                try
                {
                    var storeManager = DependencyService.Get <IStoreManager>();
                    await storeManager.SyncAllAsync(Settings.Current.IsLoggedIn);

                    Settings.Current.LastSync      = DateTime.UtcNow;
                    Settings.Current.HasSyncedData = true;
                }
                catch (Exception ex)
                {
                    //if sync doesn't work don't worry it is alright we can recover later
                    Logger.Report(ex);
                }
            }
            catch (Exception ex)
            {
                Logger.Report(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #2
0
        async Task ExecuteSyncCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (!CrossConnectivity.Current.IsConnected)
            {
                MessagingUtils.SendOfflineMessage();
                return;
            }

            Logger.Track(EvolveLoggerKeys.ManualSync);

            SyncText = "Syncing...";
            IsBusy   = true;

            try
            {
#if DEBUG
                await Task.Delay(1000);
#endif

                Settings.HasSyncedData = true;
                Settings.LastSync      = DateTime.UtcNow;
                OnPropertyChanged("LastSyncDisplay");

                await StoreManager.SyncAllAsync(Settings.Current.IsLoggedIn);

                if (!Settings.Current.IsLoggedIn && FeatureFlags.LoginEnabled)
                {
                    MessagingService.Current.SendMessage(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title   = $"{EventInfo.EventName} Data Synced",
                        Message = "You now have the latest conference data, however to sync your favorites and feedback you must sign in.",
                        Cancel  = "OK"
                    });
                }
            }
            catch (Exception ex)
            {
                ex.Data["method"] = "ExecuteSyncCommandAsync";
                MessagingUtils.SendAlert("Unable to sync", "Uh oh, something went wrong with the sync, please try again. \n\n Debug:" + ex.Message);
                Logger.Report(ex);
            }
            finally
            {
                SyncText = defaultSyncText;
                IsBusy   = false;
            }
        }
예제 #3
0
        public async Task FinishHack()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                MessagingUtils.SendAlert("Offline", "You are currently offline. Please go online in order to unlock this Mini-Hack.");
                return;
            }

            if (!Settings.Current.IsLoggedIn)
            {
                queued = true;
                MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                return;
            }

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            queued = false;

            try
            {
                Logger.Track(EvolveLoggerKeys.FinishMiniHack, "Name", Hack.Name);

                var mobileClient = DataStore.Azure.StoreManager.MobileService;
                if (mobileClient == null)
                {
                    return;
                }

                var body = JsonConvert.SerializeObject(Hack.Id);
                await mobileClient.InvokeApiAsync("CompleteMiniHack", body, HttpMethod.Post, null);

                Hack.IsCompleted = true;
                Settings.Current.FinishHack(Hack.Id);
            }
            catch (Exception ex)
            {
                Logger.Report(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #4
0
        async Task ExecuteGetSyncCodeAsync()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                MessagingUtils.SendOfflineMessage();
                return;
            }

            if (IsBusy)
            {
                return;
            }

            IsBusy        = true;
            SyncCodeError = false;
            try
            {
                Logger.Track(EvolveLoggerKeys.GetSyncCode);

                var mobileClient = DataStore.Azure.StoreManager.MobileService;
                if (mobileClient == null)
                {
                    return;
                }

                var code   = new MobileToWebSync();
                var result = await mobileClient.InvokeApiAsync <MobileToWebSync, MobileToWebSync>("MobileToWebSync", code, HttpMethod.Post, null);

                if (result == null)
                {
                    SyncCodeError = true;
                    return;
                }

                SyncCode      = result.TempCode;
                ResultVisible = true;
            }
            catch (Exception ex)
            {
                SyncCodeError = true;
                Logger.Report(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #5
0
        void ExecuteLoginCommand()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                MessagingUtils.SendOfflineMessage();
                return;
            }


            if (IsBusy)
            {
                return;
            }


            if (Settings.IsLoggedIn)
            {
                MessagingService.Current.SendMessage <MessagingServiceQuestion>(MessageKeys.Question, new MessagingServiceQuestion
                {
                    Title       = "Logout?",
                    Question    = "Are you sure you want to logout? You can only save favorites and leave feedback when logged in.",
                    Positive    = "Yes, Logout",
                    Negative    = "Cancel",
                    OnCompleted = async(result) =>
                    {
                        if (!result)
                        {
                            return;
                        }

                        await Logout();
                    }
                });

                return;
            }

            Logger.TrackPage(AppPage.Login.ToString(), "Settings");
            MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
        }