Example #1
0
 // Code to execute when the application is activated (brought to foreground)
 // This code will not execute when the application is first launched
 private void Application_Activated(object sender, ActivatedEventArgs e)
 {
     if (!e.IsApplicationInstancePreserved)
     {
         setCorrectLanguage();
         ThreadPool.QueueUserWorkItem(delegate
         {
             Decoders.AddDecoder <BmpDecoder>();
             Decoders.AddDecoder <PngDecoder>();
             Decoders.AddDecoder <GifDecoder>();
             Decoders.AddDecoder <JpegDecoder>();
         });
         ApplicationState.Current = ApplicationState.LoadState();
         PagesState.Current       = PagesState.LoadState();
         PicturesCache.Load();
     }
 }
Example #2
0
        async public Task LoginImplementation(string username, string password)
        {
            if (!progressBar.IsOperationStarted)
            {//we should perform login
                showProgress(true);
                IsLogining = true;
                var btnLogin = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
                btnLogin.IsEnabled       = true;
                ApplicationState.Current = null;

                progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressAuthentication);

                try
                {
                    currentOperation = new OperationToken();
                    var sessionData = await BAService.LoginAsync(txtUserName.Text, password.ToSHA1Hash());

                    if (sessionData == null)
                    {
                        Settings.UserName = null;
                        Settings.Password = null;
                        IsLogining        = false;
                        showProgress(false);
                        BAMessageBox.ShowError(ApplicationStrings.ErrUserOrPasswordNotValid);
                        return;
                    }
                    if (currentOperation != null && currentOperation.Cancelled)
                    {
                        IsLogining = false;
                        return;
                    }


                    progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressRetrieveProfile);
                    btnLogin.IsEnabled = true;

                    if (Settings.LiveTileEnabled && Settings.InitialAsk)
                    {
                        try
                        {
                            pushNotification.RegisterDevice(sessionData.Profile.GlobalId);
                        }
                        catch
                        {
                        }
                    }

                    var state = ApplicationState.LoadState();
                    if (state == null)
                    {
                        state = new ApplicationState();
                    }
                    else if (state.TempUserName != username)
                    {
                        //if we log as a different user, we should't use cache
                        ApplicationState.ClearOffline();
                        state = new ApplicationState();
                    }

                    state.IsOffline                       = false;
                    ApplicationState.Current              = state;
                    ApplicationState.Current.SessionData  = sessionData;
                    ApplicationState.Current.TempUserName = username;
                    ApplicationState.Current.TempPassword = password.ToSHA1Hash();
                    ApplicationState.Current.SessionData.Token.Language = ApplicationState.CurrentServiceLanguage;

                    Settings.UserName = username;
                    Settings.Password = password;

                    try
                    {
                        await getProfileInformation();
                    }
                    catch (Exception)
                    {
                        showProgress(false);
                        IsLogining = false;
                        BAMessageBox.ShowError(ApplicationStrings.ErrCantRetrieveProfileInfo);
                    }
                }
                //catch (NetworkException)
                //{
                //    IsLogining = false;
                //    showProgress(false);
                //    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                //}
                catch (DatabaseVersionException)
                {
                    IsLogining = false;
                    showProgress(false);
                    BAMessageBox.ShowError(ApplicationStrings.ErrOldApplicationVersion);
                }
                catch (Exception ex)
                {
                    showProgress(false);
                    IsLogining = false;
                    goToOffline(true);
                }
            }
            else
            {
                if (currentOperation != null)
                {
                    currentOperation.Cancel();
                    currentOperation = null;
                }
                showProgress(false);
            }
        }