Ejemplo n.º 1
0
        private async void Sync_SyncQueued(object sender, SyncQueuedEventArgs e)
        {
            try
            {
                SyncResult result = await e.ResultTask;

                foreach (var mainWindow in Windows.OfType <MainAppWindow>())
                {
                    mainWindow.Dispatcher.Run(async delegate
                    {
                        try
                        {
                            var currAccount = mainWindow.GetCurrentAccount();

                            if (e.Account != currAccount || currAccount == null)
                            {
                                return;
                            }

                            if (result.Error != null)
                            {
                                if (result.Error.Equals(SyncResponse.INCORRECT_PASSWORD) || result.Error.Equals(SyncResponse.USERNAME_CHANGED) || result.Error.Equals(SyncResponse.DEVICE_NOT_FOUND))
                                {
                                    mainWindow.ShowPopupUpdateCredentials(currAccount, UpdateCredentialsType.Normal);
                                    return;
                                }

                                else if (result.Error.Equals(SyncResponse.DEVICE_NOT_FOUND) || result.Error.Equals(SyncResponse.NO_DEVICE))
                                {
                                    mainWindow.ShowPopupUpdateCredentials(currAccount, UpdateCredentialsType.NoDevice);
                                    return;
                                }
                            }

                            //if the user bought the in-app purchase, but their account isn't a lifetime account, we'll
                            //make their account a lifetime account
                            if (!currAccount.IsLifetimePremiumAccount && await OwnsInAppPurchaseAsync())
                            {
                                var dontWait = Sync.SetAsPremiumAccount(currAccount);
                            }
                        }

                        catch (Exception ex)
                        {
                            TelemetryExtension.Current?.TrackException(ex);
                        }
                    });
                }
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
Ejemplo n.º 2
0
        private async void Sync_SyncQueued(object sender, SyncQueuedEventArgs e)
        {
            try
            {
                await Dispatcher.RunOrFallbackToCurrentThreadAsync(async delegate
                {
                    try
                    {
                        if (CurrentAccount != null && CurrentAccount.LocalAccountId == e.Account.LocalAccountId)
                        {
                            SyncState = SyncStates.Syncing;

                            _currSyncResultTask = e.ResultTask;

                            SyncResult result;

                            try
                            {
                                result = await e.ResultTask;
                            }

                            catch (OperationCanceledException) { result = null; }

                            // If this is still the task we're considering for intermediate, then we clear intermediate (if another was queued, it wouldn't match task)
                            if (_currSyncResultTask == e.ResultTask)
                            {
                                if (UploadImageProgress > 0 && UploadImageProgress < 1)
                                {
                                    SyncState = SyncStates.UploadingImages;
                                }
                                else
                                {
                                    SyncState = SyncStates.Done;
                                }
                            }
                            else
                            {
                                return;
                            }

                            // Canceled
                            if (result == null)
                            {
                                return;
                            }

                            else if (result.Error != null)
                            {
                                if (result.Error.Equals("Offline."))
                                {
                                    IsOffline = true;
                                    ClearSyncErrors();
                                }

                                else if (result.Error.Equals(PowerPlannerSending.SyncResponse.NO_ACCOUNT))
                                {
                                    IsOffline = false;
                                    SetSyncErrors(new LoggedError[] {
                                        new LoggedError("Online account deleted", "Your online account was deleted and no longer exists.")
                                    });
                                }

                                else
                                {
                                    IsOffline = false;
                                    SetSyncErrors(new LoggedError[] {
                                        new LoggedError("Sync Error", result.Error)
                                    });
                                }

                                if (result.Error.Equals(PowerPlannerSending.SyncResponse.INCORRECT_PASSWORD) || result.Error.Equals(PowerPlannerSending.SyncResponse.USERNAME_CHANGED) || result.Error.Equals(PowerPlannerSending.SyncResponse.DEVICE_NOT_FOUND))
                                {
                                    ShowPopupUpdateCredentials(CurrentAccount);
                                    return;
                                }

                                else if (result.Error.Equals(PowerPlannerSending.SyncResponse.DEVICE_NOT_FOUND) || result.Error.Equals(PowerPlannerSending.SyncResponse.NO_DEVICE))
                                {
                                    ShowPopupUpdateCredentials(CurrentAccount, UpdateCredentialsViewModel.UpdateTypes.NoDevice);
                                }
                            }

                            else if (result.UpdateErrors != null && result.UpdateErrors.Count > 0)
                            {
                                IsOffline = false;
                                SetSyncErrors(result.UpdateErrors.Select(i => new LoggedError("Sync Item Error", i.Name + ": " + i.Message)));
                            }

                            else
                            {
                                // All good!
                                IsOffline = false;
                                ClearSyncErrors();
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        TelemetryExtension.Current?.TrackException(ex);
                    }
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }