public void Delete()
        {
            var m = new ServiceManager <AsyncCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <AsyncCompletedEventArgs> operationCompleted)
            {
                MessageOperationParam param        = new MessageOperationParam();
                param.MessageId                    = Message.GlobalId;
                param.Operation                    = MessageOperationType.Delete;
                client1.MessageOperationCompleted -= operationCompleted;
                client1.MessageOperationCompleted += operationCompleted;
                client1.MessageOperationAsync(ApplicationState.Current.SessionData.Token, param);
            });

            m.OperationCompleted += (s, a) =>
            {
                FaultException <BAServiceException> faultEx = a.Error as FaultException <BAServiceException>;
                if (a.Error != null && (faultEx == null || faultEx.Detail.ErrorCode != ErrorCode.ObjectNotFound))
                {
                    onOperationCompleted(true);
                    BAMessageBox.ShowError(ApplicationStrings.MessageViewModel_ErrDeleteMessage);
                }
                else
                {
                    ApplicationState.Current.Cache.Messages.Remove(Message.GlobalId);
                    //ApplicationState.Current.ProfileInfo.Messages.Remove(Message);
                    onOperationCompleted(false);
                }
            };

            if (!m.Run())
            {
                onOperationCompleted(true);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
        public void LoadMore()
        {
            var m = new ServiceManager <GetTrainingDayCommentsCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetTrainingDayCommentsCompletedEventArgs> operationCompleted)
            {
                client1.GetTrainingDayCommentsAsync(ApplicationState.Current.SessionData.Token, day, new PartialRetrievingInfo()
                {
                    PageIndex = result.PageIndex + 1
                });
                client1.GetTrainingDayCommentsCompleted -= operationCompleted;
                client1.GetTrainingDayCommentsCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    onBlogCommentsLoaded();
                    BAMessageBox.ShowError(ApplicationStrings.BlogViewModel_LoadComments_ErrorMsg);
                    return;
                }
                else
                {
                    result = a.Result.Result;
                    fillComments(a);
                }
                onBlogCommentsLoaded();
            };

            if (!m.Run())
            {
                onBlogCommentsLoaded();
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #3
0
 private void btnResetAll_Click(object sender, EventArgs e)
 {
     if (BAMessageBox.AskYesNo(Strings.QResetAllOptions) == MessageBoxResult.Yes)
     {
         //TODO: maybe clear cache should be under another button
         try
         {
             PicturesCache.Instance.Cache.Flush();
             TranslationsCache.Instance.Cache.Flush();
             UserContext.Current.Settings.Reset();
             fillSettings();
             File.Delete(Constants.AvalonLayoutFile);
             MainWindow.Instance.SaveSizeAndLocation = false;
             BAMessageBox.ShowInfo(Strings.OptionsWindow_MsgApplyResetLayoutSettings);
         }
         catch (Exception)
         {
             BAMessageBox.ShowError(Strings.OptionsWindow_ErrResetLayoutSettings);
         }
     }
 }
 private void btnStart_Click(object sender, RoutedEventArgs e)
 {
     if (!TimerHasBeenStarted && !isGPSReady() && BAMessageBox.Ask(ApplicationStrings.GPSTrackerPage_InfoGpsNotReady) == MessageBoxResult.Cancel)
     {
         return;
     }
     //if (!TimerHasBeenStarted && viewModel.Entry.HasCoordinates && BAMessageBox.Ask("This entry already contains gps coordinates. Do you want to overwrite them??") == MessageBoxResult.Cancel)
     //{
     //    return;
     //}
     if (IsPause)
     {
         timer.Start();
     }
     else
     {
         timer.Stop();
     }
     startTimer(IsPause);
     TimerHasBeenStarted = true;
 }
Exemple #5
0
        private void btnUseInToday_Click(object sender, RoutedEventArgs e)
        {
            buttonPressed = true;
            var button = (RoundButton)sender;
            InGroup <TrainingPlanEntryViewModel> group = (InGroup <TrainingPlanEntryViewModel>)button.Tag;
            TrainingPlanDay planDay     = (TrainingPlanDay)group.Tag;
            var             workoutPlan = planDay.TrainingPlan;

            if (!workoutPlan.IsFavorite && !workoutPlan.IsMine)
            {
                BAMessageBox.ShowInfo(ApplicationStrings.WorkoutPlanViewControl_ErrMustAddPlanToFavorites);
                return;
            }

            if (BAMessageBox.Ask(ApplicationStrings.WorkoutPlanViewControl_btnUseInToday_QUsePlanInCalendar) == MessageBoxResult.Cancel)
            {
                return;
            }

            fillStrengthTrainingEntryWithPlan(planDay);
        }
        private void retrieveTrainingDay(DateTime date, UserDTO user)
        {
            progressBar.ShowProgress(true, ApplicationStrings.FeaturedPage_RetrievingTrainingDay);
            var m = new ServiceManager <GetTrainingDayCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetTrainingDayCompletedEventArgs> operationCompleted)
            {
                WorkoutDayGetOperation param = new WorkoutDayGetOperation();
                param.WorkoutDateTime        = date;
                param.UserId = user.GlobalId;
                client1.GetTrainingDayAsync(ApplicationState.Current.SessionData.Token, param, new RetrievingInfo());
                client1.GetTrainingDayCompleted -= operationCompleted;
                client1.GetTrainingDayCompleted += operationCompleted;
            });

            m.OperationCompleted += (s1, a1) =>
            {
                progressBar.ShowProgress(false);
                if (a1.Error != null || a1.Result.Result == null)
                {
                    BAMessageBox.ShowError(ApplicationStrings.FeaturedPage_ErrCannotRetrieveTrainingDay);
                    return;
                }
                SelectedTrainingDay = a1.Result.Result;
                ApplicationState.Current.CurrentBrowsingTrainingDays = new TrainingDaysHolder(user);
                ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays.Add(date, new TrainingDayInfo(SelectedTrainingDay));
                ApplicationState.Current.CurrentBrowsingTrainingDays.RetrievedMonths.Add(date.MonthDate());
                this.Navigate("/Pages/TrainingDayEntrySelectorPage.xaml");
            };
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #7
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            bool restartRequired = false;

            foreach (ImageSourceListItem <IOptionsControl> tabPage in xtraTabControl1.Items)
            {
                IOptionsControl optionsControl = tabPage.Value;
                optionsControl.Save();
                if (optionsControl.RestartRequired)
                {
                    restartRequired = true;
                }
            }

            UserContext.Current.Settings.GuiState.Save();
            if (restartRequired)
            {
                BAMessageBox.ShowInfo(Strings.OptionsRestartRequiredMsg);
            }
            DialogResult = true;
            Close();
        }
        public bool Validate(A6WEntryDTO entry)
        {
            //A6WDay day = A6WManager.Weeks[entry.DayNumber - 1];
            A6WDay day = entry.Day;

            if (day.RepetitionNumber < txtSet1.Value)
            {
                BAMessageBox.ShowError(A6WEntryStrings.ErrorSetTooManyRepetitions, 1, entry.Day.DayNumber, day.RepetitionNumber);
                return(false);
            }
            if (day.RepetitionNumber < txtSet2.Value)
            {
                BAMessageBox.ShowError(A6WEntryStrings.ErrorSetTooManyRepetitions, 2, entry.Day.DayNumber, day.RepetitionNumber);
                return(false);
            }
            if (day.RepetitionNumber < txtSet3.Value)
            {
                BAMessageBox.ShowError(A6WEntryStrings.ErrorSetTooManyRepetitions, 3, entry.Day.DayNumber, day.RepetitionNumber);
                return(false);
            }
            return(true);
        }
        private void mnuRefresh_Click(object sender, EventArgs e)
        {
            progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressRetrieveProfile);
            ((MyProfileViewModel)DataContext).RefreshMessages();
            var m = new ServiceManager <GetProfileInformationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetProfileInformationCompletedEventArgs> operationCompleted)
            {
                GetProfileInformationCriteria criteria = new GetProfileInformationCriteria();
                client1.GetProfileInformationAsync(ApplicationState.Current.SessionData.Token, criteria);
                client1.GetProfileInformationCompleted -= operationCompleted;
                client1.GetProfileInformationCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                progressBar.ShowProgress(false);
                if (a.Result.Result != null)
                {
                    ApplicationState.Current.ProfileInfo = a.Result.Result;
                    DataContext = new MyProfileViewModel(ApplicationState.Current.ProfileInfo);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.MyProfileControl_CantRetrieveProfileInfo_ErrMsg);
                }
            };

            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #10
0
        private void mnuPinToStart_Click(object sender, RoutedEventArgs e)
        {
            var       tag  = (HubTile)((MenuItem)sender).Tag;
            var       type = getEntryType(tag.Tag);
            ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("EntryType=" + type.Name));

            if (Tile != null)
            {
                BAMessageBox.ShowInfo(ApplicationStrings.TrainingDaySelectorControl_ErrSecondaryLiveTileExists);
                return;
            }
            StandardTileData tileData = new StandardTileData
            {
                Title               = tag.Title,
                BackgroundImage     = getImageUri(type),
                BackBackgroundImage = new Uri("/WP7TileImage.png", UriKind.RelativeOrAbsolute),
                BackTitle           = "BodyArchitect"
            };

            Uri tileUri = new Uri("/Pages/MainPage.xaml?EntryType=" + type.Name, UriKind.Relative);

            ShellTile.Create(tileUri, tileData);
        }
Exemple #11
0
        protected void CopyEntryToToday()
        {
            //copy only if selected entry is not today entry
            if (ApplicationState.Current.CurrentBrowsingTrainingDays.IsMine && ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate != DateTime.Now.Date)
            {
                //var origEntry = ApplicationState.Current.TrainingDay.TrainingDay.GetEntry(EntryType);
                var origEntry = Entry;
                var entry     = origEntry.Copy(true);

                if (!EnsureRemoveEntryTypeFromToday(EntryType))
                {//cancel overwrite
                    return;
                }
                PrepareCopiedEntry(origEntry, entry);


                ApplicationState.Current.TrainingDay.TrainingDay.Objects.Add(entry);
                entry.TrainingDay = ApplicationState.Current.TrainingDay.TrainingDay;
                ApplicationState.Current.CurrentEntryId = new LocalObjectKey(entry);
                show(true);
                BAMessageBox.ShowInfo(ApplicationStrings.EntryObjectPageBase_CopyEntryToTodayCompleted);
            }
        }
        void checkCrashState()
        {
            if (ApplicationState.Current == null)
            {
                return;
            }
            bool crash = ApplicationState.Current.Crash;

            ApplicationState.Current.Crash = false;

            if (ApplicationState.Current.TrainingDay != null && crash)
            {
                if (BAMessageBox.Ask(ApplicationStrings.TrainingDaySelectorControl_QCrashSaverRestoreEntry) ==
                    MessageBoxResult.OK)
                {
                    LocalObjectKey id           = ApplicationState.Current.CurrentEntryId;
                    Object         currentEntry = ApplicationState.Current.TrainingDay.TrainingDay.GetEntry(id);
                    TrainingDaySelectorControl.GoToPage(currentEntry, this);
                    return;
                }
            }
            ApplicationState.Current.ResetCurrents();
        }
        public void LoadMore()
        {
            var m = new ServiceManager <GetCommentsCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetCommentsCompletedEventArgs> operationCompleted)
            {
                client1.GetCommentsAsync(ApplicationState.Current.SessionData.Token, entry.GlobalId, new PartialRetrievingInfo()
                {
                    PageIndex = result.PageIndex + 1
                });
                client1.GetCommentsCompleted -= operationCompleted;
                client1.GetCommentsCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    onCommentsLoaded();
                    BAMessageBox.ShowError(ApplicationStrings.VotesControl_ErrRetrieveRatings);
                    return;
                }
                else
                {
                    result = a.Result.Result;
                    foreach (var item in a.Result.Result.Items)
                    {
                        Comments.Add(new VoteViewModel(item));
                    }
                }
                onCommentsLoaded();
            };

            if (!m.Run())
            {
                onCommentsLoaded();
                BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
            }
        }
        void enusureRssFeed()
        {
            var feed = loadTips();

            if (feed != null && feed.Language == ApplicationState.CurrentServiceLanguage)
            {
                filterFeed(feed);
                return;
            }
            if (ApplicationState.Current.IsOffline)
            {
                PageTitle.Text = "";
                htmlBlock.Text = ApplicationStrings.OfflineModeFeatureNotRetrieved;
                return;
            }
            WebClient client = new WebClient();

            progressBar.ShowProgress(true, ApplicationStrings.TipsPage_ProgressRetrieveTips);
            client.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    progressBar.ShowProgress(false);
                    BAMessageBox.ShowError(ApplicationStrings.ErrCannotRetrieveTips);
                    return;
                }

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Ignore;

                feed = SyndicationFeed.Load(XmlReader.Create(e.Result, settings));
                saveTips(feed);
                filterFeed(feed);
                progressBar.ShowProgress(false);
            };
            client.OpenReadAsync(new Uri(getFeedUrl(), UriKind.Absolute));
        }
        public bool ValidateControl()
        {
            var incorrectSets = SerieValidator.GetIncorrectSets(StrengthTrainingEntry);

            if (incorrectSets.Count > 0)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("usrStrengthTraining_MsgIncorrectSetsValidation".TranslateStrength());
                foreach (var incorrectSet in incorrectSets.GroupBy(x => x.StrengthTrainingItem.Exercise))
                {
                    builder.Append(incorrectSet.Key.GetLocalizedName() + ": ");
                    foreach (var serieDto in incorrectSet)
                    {
                        builder.Append(serieDto.GetDisplayText(WorkoutPlanOperationHelper.SetDisplayMode.Medium) + ", ");
                    }
                    builder.AppendLine();
                }
                if (BAMessageBox.AskWarningYesNo(builder.ToString()) == MessageBoxResult.No)
                {
                    return(false);
                }
            }
            return(true);
        }
        public override void UpdateEntryObject(EntryObjectDTO entryDto)
        {
            A6WDay?day = a6wControl.GetSelectedA6wDay();

            if (day == null)
            {
                return;
            }
            A6WEntryDTO entry = (A6WEntryDTO)entryDto;

            entry.Day       = day.Value;
            entry.Completed = rbCompleted.IsChecked.Value;
            entry.Comment   = txtComment.Text;
            usrReportStatus1.Save(entry);
            if (entry.Status == EntryObjectStatus.Planned)
            {
                entry.Completed = false;
            }
            else
            {
                if (!entry.Completed)
                {
                    usrA6WPartialCompleted1.Save(entry);
                }
                else
                {
                    entry.Set1 = entry.Set2 = entry.Set3 = null;
                }
            }

            if (entry.Day.DayNumber == A6WManager.LastDay.DayNumber && entry.MyTraining.TrainingEnd == TrainingEnd.NotEnded)
            {
                entry.MyTraining.Complete();
                BAMessageBox.ShowInfo(EnumLocalizer.Default.GetUIString("BodyArchitect.Client.Module.A6W:A6WEntryStrings:TrainingCompletedText"));
            }
        }
Exemple #17
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            CreateProfileWindow dlg = new CreateProfileWindow();

            if (dlg.ShowDialog() == true)
            {
                loggedSessionData = dlg.CreatedSessionData;
                if (loggedSessionData != null)
                {//we allow to login without activation
                    UserContext.CreateUserContext(loggedSessionData);
                    if (LoginSuccessful != null)
                    {
                        LoginSuccessful(this, EventArgs.Empty);
                    }
                    Close();
                }
                else
                {
                    //lblSendActivationEmail.Visible = true;//TODO:Finish?

                    BAMessageBox.ShowInfo(EnumLocalizer.Default.GetStringsString("ErrorMustActivateProfile"));
                }
            }
        }
Exemple #18
0
 public void BreakTraining()
 {
     if (BAMessageBox.AskYesNo(EnumLocalizer.Default.GetStringsString("Question_MyTrainingsViewModel_BreakTraining_AreYouSure")) == MessageBoxResult.No)
     {
         return;
     }
     PleaseWait.Run(delegate(MethodParameters param1)
     {
         try
         {
             var param        = new MyTrainingOperationParam();
             param.Operation  = MyTrainingOperationType.Stop;
             param.MyTraining = SelectedMyTraining.MyTraining;
             param.MyTraining.EntryObjects = new List <EntryObjectDTO>();//we clear this collection to have a smaller request (we need defacto only GlobalId here)
             var myTraining = ServiceManager.MyTrainingOperation(param);
             myTrainingsCache.Update(myTraining);
         }
         catch (Exception ex)
         {
             param1.CloseProgressWindow();
             parentView.SynchronizationContext.Send((x) => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("Exception_MyTrainingsViewModel_BreakTraining"), ErrorWindow.EMailReport), null);
         }
     });
 }
Exemple #19
0
        protected override bool ValidateBeforeSave()
        {
            var incorrectSets = SerieValidator.GetIncorrectSets(Entry);

            if (incorrectSets.Count > 0)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(ApplicationStrings.StrengthTraining_MsgIncorrectSetsValidation);
                foreach (var incorrectSet in incorrectSets.GroupBy(x => x.StrengthTrainingItem.Exercise))
                {
                    builder.Append(incorrectSet.Key.DisplayExercise + ": ");
                    foreach (var serieDto in incorrectSet)
                    {
                        builder.Append(serieDto.GetDisplayText() + ", ");
                    }
                    builder.AppendLine();
                }
                if (BAMessageBox.Ask(builder.ToString()) == MessageBoxResult.Cancel)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #20
0
 private void lsItems_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count > 0)
     {
         _viewModel.SelectedItem = (StrengthTrainingItemViewModel)e.AddedItems[0];
         if (_viewModel.SelectedItem.Exercise != ExerciseDTO.Deleted)
         {
             if (_viewModel.SelectedItem.Exercise.ExerciseType == ExerciseType.Cardio)
             {
                 this.Navigate("/Pages/CardioStrengthTrainingItemPage.xaml");
             }
             else
             {
                 this.Navigate("/Pages/StrengthWorkoutItemPage.xaml");
             }
             return;
         }
         else
         {
             BAMessageBox.ShowError(ApplicationStrings.StrengthWorkoutPage_ErrCannotViewDeletedExercise);
         }
     }
     lsItems.SelectedIndex = -1;
 }
Exemple #21
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);
            }
        }
Exemple #22
0
        private void doLogin(bool automaticLogin)
        {
            string username  = txtUserName.Text;
            string password  = txtPassword.Password;
            bool   autoLogin = chkAutologin.IsChecked.Value;

            RunAsynchronousOperation(delegate(OperationContext context)
            {
                try
                {
                    var sessionData = UserContext.Current.Login(username, password, autoLogin, automaticLogin);
                    if (sessionData == null)
                    {
                        this.Dispatcher.Invoke(new Action(delegate
                        {
                            BAMessageBox.ShowError(EnumLocalizer.Default.GetStringsString("ErrorAuthenticationWrongCredentials"));
                        }));

                        return;
                    }
                    loggedSessionData = sessionData;

                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        if (LoginSuccessful != null)
                        {
                            LoginSuccessful(this, EventArgs.Empty);
                            foreach (var module in PluginsManager.Instance.Modules)
                            {
                                module.AfterUserLogin();
                            }
                            Close();

                            showUpdateInfoWindow();
                        }
                        else
                        {
                            DialogResult = true;
                            Close();
                        }
                    }));

                    //ThreadSafeClose(true);
                }
                catch (SecurityAccessDeniedException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("SecurityAccessDeniedException_LoginWindow_InvalidAPIKey"), ErrorWindow.EMailReport), Dispatcher);
                }
                catch (ProfileIsNotActivatedException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(delegate
                    {
                        //lblSendActivationEmail.Visible = true;//TODO:Finish
                        ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorProfileNotActivated"), ErrorWindow.MessageBox);
                    }, Dispatcher);
                }
                catch (ProfileDeletedException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorCannotLoginToDeletedProfile"), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (EndpointNotFoundException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorConnectionProblem"), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (TimeoutException ex)
                {
                    TasksManager.SetException(ex);

                    UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorConnectionProblem"), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (MaintenanceException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorMaintenanceMode"), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (DatabaseVersionException ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorOldVersionOfBodyArchitect"), ErrorWindow.MessageBox), Dispatcher);
                }
                catch (Exception ex)
                {
                    TasksManager.SetException(ex);
                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetStringsString("ErrorUnhandledException"), ErrorWindow.MessageBox), Dispatcher);
                }
            }, AsyncOperationStateChange);
        }
Exemple #23
0
        private void saveProfile(string hash, WriteableBitmap _bitmap)
        {
            var m = new ServiceManager <UpdateProfileCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <UpdateProfileCompletedEventArgs> operationCompleted)
            {
                ProfileUpdateData data       = new ProfileUpdateData();
                var copyProfile              = ApplicationState.Current.SessionData.Profile.Copy();
                copyProfile.AboutInformation = viewModel.Profile.AboutInformation;
                copyProfile.Birthday         = viewModel.Profile.Birthday.Value;
                copyProfile.Gender           = viewModel.Profile.User.Gender;
                copyProfile.CountryId        = viewModel.Profile.User.CountryId;
                copyProfile.Settings         = viewModel.Profile.Settings;
                if (!string.IsNullOrEmpty(viewModel.Password1))
                {
                    copyProfile.Password = viewModel.Password1.ToSHA1Hash();
                }
                copyProfile.Privacy = viewModel.Profile.User.Privacy;
                copyProfile.Picture = viewModel.Profile.User.Picture;


                data.Profile = copyProfile;
                data.Wymiary = viewModel.Profile.Wymiary;

                if (picture != null)
                {
                    if (copyProfile.Picture == null)
                    {
                        copyProfile.Picture = new PictureInfoDTO();
                    }

                    copyProfile.Picture.PictureIdk__BackingField = PictureId;
                    copyProfile.Picture.Hashk__BackingField      = hash;
                    copyProfile.Picture.SessionIdk__BackingField = ApplicationState.Current.SessionData.Token.SessionId;
                }
                ApplicationState.Current.EditProfileInfo.User.Picture = copyProfile.Picture;
                data.Profile = copyProfile;
                data.Wymiary = ApplicationState.Current.ProfileInfo.Wymiary;

                client1.UpdateProfileAsync(ApplicationState.Current.SessionData.Token, data);
                client1.UpdateProfileCompleted -= operationCompleted;
                client1.UpdateProfileCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    BugSenseHandler.Instance.SendExceptionAsync(a.Error);
                    progressBar.ShowProgress(false);
                    ApplicationBar.EnableApplicationBar(true);
                    BAMessageBox.ShowError(ApplicationStrings.ErrSaveProfile);
                    return;
                }
                else
                {
                    if (_bitmap != null)
                    {
                        PicturesCache.Instance.Remove(PictureId);
                        PictureCacheItem item = new PictureCacheItem(_bitmap, PictureId, hash);
                        PicturesCache.Instance.AddToCache(item);
                        PicturesCache.Instance.Notify(a.Result.Result.Picture);
                    }
                    ApplicationState.Current.ProfileInfo         = ApplicationState.Current.EditProfileInfo;
                    ApplicationState.Current.SessionData.Profile = a.Result.Result;

                    if (!string.IsNullOrEmpty(viewModel.Password1))
                    {//store new password
                        Settings.Password = viewModel.Password1;
                    }

                    Dispatcher.BeginInvoke(delegate
                    {
                        if (NavigationService.CanGoBack)
                        {
                            NavigationService.GoBack();
                        }
                    });
                }
            };
            progressBar.ShowProgress(true, ApplicationStrings.ProfilePage_ProgressSave);
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #24
0
 public void Delete()
 {
     if (SelectedReminder != null && SelectedReminder.Type == ReminderType.Custom && BAMessageBox.AskYesNo("RemindersViewModel_Delete_DeleteReminder".TranslateInstructor(), SelectedReminder.Name) == MessageBoxResult.Yes)
     {
         PleaseWait.Run(delegate
         {
             try
             {
                 var param            = new ReminderOperationParam();
                 param.ReminderItemId = SelectedReminder.GlobalId;
                 param.Operation      = ReminderOperationType.Delete;
                 ServiceManager.ReminderOperation(param);
                 ReminderItemsReposidory.Instance.Remove(SelectedReminder.GlobalId);
                 parentView.SynchronizationContext.Send((x) => NotifyOfPropertyChange(() => Reminders), null);
             }
             catch (Exception ex)
             {
                 parentView.SynchronizationContext.Send((x) => ExceptionHandler.Default.Process(ex, "RemindersViewModel_Delete_CannotRemoveReminder".TranslateInstructor(), ErrorWindow.EMailReport), null);
             }
         });
     }
 }
Exemple #25
0
        private void createProfile()
        {
            if (viewModel.Country == null)
            {
                BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrSelectCountry);
                return;
            }
            creating = true;
            updateGui();
            progressBar.ShowProgress(true, ApplicationStrings.CreateProfilePage_ProgressCreateAccount);
            ExtensionMethods.BindFocusedTextBox();
            IsHitTestVisible = false;



            var m = new ServiceManager <CreateProfileCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <CreateProfileCompletedEventArgs> operationCompleted)
            {
                var profile                 = new ProfileDTO();
                profile.Birthday            = viewModel.Birthday;
                profile.Gender              = viewModel.IsMale ? Gender.Male : Gender.Female;
                profile.CountryId           = viewModel.Country.GeoId;
                profile.UserName            = viewModel.Username;
                profile.Email               = viewModel.Email;
                profile.Settings            = new ProfileSettingsDTO();
                profile.Settings.LengthType = (Service.V2.Model.LengthType)lpLengthType.SelectedIndex;
                profile.Settings.WeightType = (Service.V2.Model.WeightType)lpWeightType.SelectedIndex;
                profile.Privacy             = new ProfilePrivacyDTO();
                profile.Password            = viewModel.Password.ToSHA1Hash();

                client1.CreateProfileAsync(Settings.GetClientInformation(), profile);
                client1.CreateProfileCompleted -= operationCompleted;
                client1.CreateProfileCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, y) =>
            {
                try
                {
                    if (cancel)
                    {
                        progressBar.ShowProgress(false);
                        IsHitTestVisible = true;
                        creating         = false;
                        updateGui();
                        return;
                    }
                    if (y.Error != null)
                    {
                        progressBar.ShowProgress(false);
                        IsHitTestVisible = true;
                        creating         = false;
                        updateGui();
                        FaultException <ValidationFault>    faultEx = y.Error as FaultException <ValidationFault>;
                        FaultException <BAServiceException> baEx    = y.Error as FaultException <BAServiceException>;

                        if (faultEx != null)
                        {
                            BAMessageBox.ShowError(faultEx.Detail.Details[0].Key + ":" + faultEx.Detail.Details[0].Message);
                            return;
                        }
                        if (baEx != null && baEx.Detail.ErrorCode == ErrorCode.UniqueException)
                        {
                            BAMessageBox.ShowWarning(ApplicationStrings.ErrUsernameOrEmailNotUnique);
                            return;
                        }
                        BugSenseHandler.Instance.SendExceptionAsync(y.Error);
                        BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrCreateAccount);
                        return;
                    }
                    else
                    {
                        if (Settings.LiveTileEnabled && Settings.InitialAsk)
                        {
                            try
                            {
                                pushNotification.RegisterDevice(y.Result.Result.Profile.GlobalId);
                            }
                            catch
                            {
                            }
                        }
                        ApplicationState.Current             = new ApplicationState();
                        ApplicationState.Current.SessionData = y.Result.Result;
                        //ApplicationState.Current.MyDays = new TrainingDaysHolder(ApplicationState.Current.SessionData.Profile);
                        ApplicationState.Current.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();

                        ApplicationState.Current.TempUserName = viewModel.Username;
                        ApplicationState.Current.TempPassword = viewModel.Password.ToSHA1Hash();

                        Settings.UserName = viewModel.Username;
                        Settings.Password = viewModel.Password;
                        ApplicationState.Current.SessionData.Token.Language = ApplicationState.CurrentServiceLanguage;

                        ApplicationState.Current.Cache.Messages.Load();

                        getProfileInformation();
                    }
                }
                catch (Exception)
                {
                    progressBar.ShowProgress(false);
                    IsHitTestVisible = true;
                    creating         = false;
                    updateGui();
                    BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrCreateAccount);
                }
            };

            if (!m.Run(true))
            {
                IsHitTestVisible = true;
                creating         = false;
                updateGui();
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #26
0
 private void rbtnNew_Click(object sender, RoutedEventArgs e)
 {
     BAMessageBox.ShowInfo(InstructorStrings.ChampionshipsView_CreateNew_Message);
 }
        void login()
        {
            progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressAuthentication);
            ClientInformation info = Settings.GetClientInformation();



            var m = new ServiceManager <LoginCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <LoginCompletedEventArgs> operationCompleted)
            {
                client1.LoginAsync(info, ApplicationState.Current.TempUserName, ApplicationState.Current.TempPassword, new object());

                client1.LoginCompleted -= operationCompleted;
                client1.LoginCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    progressBar.ShowProgress(false);
                    //hlOfflineMode.IsEnabled = true;
                    BuildApplicationBar();
                    BAMessageBox.ShowError(ApplicationStrings.ErrDuringLogin);
                    return;
                }
                else if (a.Result != null)
                {
                    progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressRetrieveProfile);
                    var state = new ApplicationState();
                    state.SessionData  = a.Result.Result;
                    state.TempUserName = ApplicationState.Current.TempUserName;
                    state.TempPassword = ApplicationState.Current.TempPassword;
                    state.SessionData.Token.Language = ApplicationState.CurrentServiceLanguage;
                    state.Cache  = ApplicationState.Current.Cache.Copy();
                    state.MyDays = ApplicationState.Current.MyDays;


                    var m1 = new ServiceManager <GetProfileInformationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetProfileInformationCompletedEventArgs> operationCompleted)
                    {
                        client1.GetProfileInformationAsync(state.SessionData.Token, new GetProfileInformationCriteria());

                        client1.GetProfileInformationCompleted -= operationCompleted;
                        client1.GetProfileInformationCompleted += operationCompleted;
                    });
                    m1.OperationCompleted += (s1, a1) =>
                    {
                        if (a.Error != null)
                        {
                            //hlOfflineMode.IsEnabled = true;
                            BuildApplicationBar();
                            progressBar.ShowProgress(false);
                            BAMessageBox.ShowError(ApplicationStrings.ErrCantRetrieveProfileInfo);
                            return;
                        }
                        else if (a1.Result != null)
                        {
                            state.ProfileInfo = a1.Result.Result;
                            state.ProfileInfo.FavoriteUsers.Sort(delegate(UserSearchDTO u1, UserSearchDTO u2)
                            {
                                return(u1.UserName.CompareTo(u2.UserName));
                            });
                            state.ProfileInfo.Friends.Sort(delegate(UserSearchDTO u1, UserSearchDTO u2)
                            {
                                return(u1.UserName.CompareTo(u2.UserName));
                            });
                            state.CurrentBrowsingTrainingDays = null;
                            state.IsOffline          = false;
                            ApplicationState.Current = state;
                            ApplicationState.Current.Cache.ClearAfterLogin();
                            Fill(ApplicationState.Current.ProfileInfo);
                            progressBar.ShowProgress(false);
                            //hlOfflineMode.IsEnabled = true;
                            BuildApplicationBar();
                            ((MyProfileViewModel)DataContext).RefreshMessages();
                        }
                    };
                    m1.Run(true);
                }
                else
                {
                    //hlOfflineMode.IsEnabled = true;
                    BuildApplicationBar();
                    progressBar.ShowProgress(false);
                    BAMessageBox.ShowError(ApplicationStrings.ErrUserOrPasswordNotValid);
                }
            };

            if (!m.Run(true))
            {
                BuildApplicationBar();
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Exemple #28
0
        private void uploadPictureAndSaveProfile()
        {
            var m = new ServiceManager <AsyncCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <AsyncCompletedEventArgs> operationCompleted)
            {
                using (OperationContextScope ocs = new OperationContextScope(client1.InnerChannel))
                {
                    var ggg        = (IBodyArchitectAccessService)client1;
                    PictureDTO dto = new PictureDTO();

                    WriteableBitmap _bitmap = new WriteableBitmap(picture);
                    var extImage            = _bitmap.ToImage();
                    var st = (MemoryStream)extImage.ToStream();
                    st.Seek(0, SeekOrigin.Begin);
                    dto.ImageStream = st.ToArray();
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("SessionId", "http://MYBASERVICE.TK/", ApplicationState.Current.SessionData.Token.SessionId));
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("PictureId", "http://MYBASERVICE.TK/", PictureId));
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Hash", "http://MYBASERVICE.TK/", "test"));
                    ApplicationState.AddCustomHeaders();

                    ggg.BeginUploadImage(dto, delegate(IAsyncResult aRes)
                    {
                        var proxy   = (IBodyArchitectAccessService)aRes.AsyncState;
                        string hash = null;
                        using (OperationContextScope o = new OperationContextScope(((BodyArchitectAccessServiceClient)proxy).InnerChannel))
                        {
                            try
                            {
                                proxy.EndUploadImage(aRes);
                            }
                            catch (Exception ex)
                            {
                                BugSenseHandler.Instance.SendExceptionAsync(ex);
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressBar.ShowProgress(false);
                                    ApplicationBar.EnableApplicationBar(true);
                                    BAMessageBox.ShowError(ApplicationStrings.ErrUploadPhoto);
                                });

                                return;
                            }

                            hash = OperationContext.Current.IncomingMessageHeaders.GetHeader <string>("Hash", "http://MYBASERVICE.TK/");
                        }

                        saveProfile(hash, _bitmap);
                    }, client1);
                }
            });

            progressBar.ShowProgress(true, ApplicationStrings.ProfilePage_ProgressUploadPhoto);
            ApplicationBar.EnableApplicationBar(false);
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
 private void deleteSelectedItem()
 {
     if (SelectedItem != null && !SelectedItem.IsSystem && UIHelper.EnsurePremiumLicence() && BAMessageBox.AskYesNo(EnumLocalizer.Default.GetGUIString("MyPlacesView_QDeleteMyPlace"), SelectedItem.Name) == MessageBoxResult.Yes)
     {
         PleaseWait.Run(delegate(MethodParameters param)
         {
             try
             {
                 var param1       = new MyPlaceOperationParam();
                 param1.Operation = MyPlaceOperationType.Delete;
                 param1.MyPlaceId = SelectedItem.GlobalId;
                 ServiceManager.MyPlaceOperation(param1);
                 _myPlacesCache.Remove(SelectedItem.GlobalId);
                 UIHelper.BeginInvoke(() => NotifyOfPropertyChange(() => Items), Dispatcher);
             }
             catch (DeleteConstraintException ex)
             {
                 param.CloseProgressWindow();
                 UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetGUIString("MyPlacesView_ErrDeleteMyPlace_IsInUse"), ErrorWindow.MessageBox), null);
             }
             catch (Exception ex)
             {
                 param.CloseProgressWindow();
                 UIHelper.BeginInvoke(() => ExceptionHandler.Default.Process(ex, EnumLocalizer.Default.GetGUIString("MyPlacesView_ErrDeleteMyPlace"), ErrorWindow.EMailReport), null);
             }
         });
     }
 }
Exemple #30
0
        void changeAccountType(AccountType accountType)
        {
            if (ApplicationState.Current.ProfileInfo.Licence.AccountType > accountType)
            {
                int accountDiff = accountType - ApplicationState.Current.ProfileInfo.Licence.AccountType;
                int kara        = Math.Abs(accountDiff) * ApplicationState.Current.ProfileInfo.Licence.Payments.Kara;
                if (BAMessageBox.Ask(string.Format(ApplicationStrings.AccountTypePage_QChangeAccountToLower, kara)) == MessageBoxResult.Cancel)
                {
                    return;
                }
            }
            else
            {
                if (BAMessageBox.Ask(string.Format(ApplicationStrings.AccountTypePage_QChangeAccountToHigher)) == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            progressBar.ShowProgress(true, ApplicationStrings.AccountTypePage_ChangingAccountType);
            updateButtons(false);
            var m = new ServiceManager <AsyncCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <AsyncCompletedEventArgs> operationCompleted)
            {
                var param         = new ProfileOperationParam();
                param.Operation   = ProfileOperation.AccountType;
                param.ProfileId   = ApplicationState.Current.SessionData.Profile.GlobalId;
                param.AccountType = accountType;

                client1.ProfileOperationAsync(ApplicationState.Current.SessionData.Token, param);
                client1.ProfileOperationCompleted -= operationCompleted;
                client1.ProfileOperationCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                FaultException <BAServiceException> serviceEx = a.Error as FaultException <BAServiceException>;
                if (serviceEx != null && serviceEx.Detail.ErrorCode == ErrorCode.ConsistencyException)
                {
                    updateButtons(true);
                    BAMessageBox.ShowError(ApplicationStrings.AccountTypePage_ErrNotEnoughPoints);
                    return;
                }
                if (a.Error != null)
                {
                    BugSenseHandler.Instance.SendExceptionAsync(a.Error);
                    updateButtons(true);
                    progressBar.ShowProgress(false);

                    BAMessageBox.ShowError(ApplicationStrings.AccountTypePage_ErrCannotChangeAccountType);
                    return;
                }


                refreshProfileInfo();
            };

            if (!m.Run())
            {
                updateButtons(true);
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }