示例#1
0
        public void TestGetTrainingDay_Last_FriendsOnly()
        {
            setPrivacy(Privacy.FriendsOnly);

            var profile1 = (ProfileDTO)profiles[1].Tag;
            var profile2 = (ProfileDTO)profiles[2].Tag;

            WorkoutDayGetOperation op = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Last;
            op.UserId          = profiles[0].GlobalId;
            op.WorkoutDateTime = trainingDays[2].TrainingDate;
            TrainingDayDTO day  = null;
            SessionData    data = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.AreEqual(trainingDays[trainingDays.Count - 1].TrainingDate, day.TrainingDate);

            data = CreateNewSession(profile2, ClientInformation);
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.IsNull(day);
        }
        async protected virtual Task MergeTrainingDayFromDb(SynchronizationItemViewModel item)
        {
            WorkoutDayGetOperation data = new WorkoutDayGetOperation();

            data.WorkoutDateTime = item.DayInfo.TrainingDay.TrainingDate;
            data.CustomerId      = item.DayInfo.TrainingDay.CustomerId;
            data.Operation       = GetOperation.Current;
            var trainingDay = await BAService.GetTrainingDayAsync(data, new RetrievingInfo());

            await MergeResult(trainingDay, item);

            //var m = new ServiceManager<GetTrainingDayCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler<GetTrainingDayCompletedEventArgs> operationCompleted)
            //{
            //    client1.GetTrainingDayCompleted -= operationCompleted;
            //    client1.GetTrainingDayCompleted += operationCompleted;
            //    WorkoutDayGetOperation data = new WorkoutDayGetOperation();
            //    data.WorkoutDateTime = item.DayInfo.TrainingDay.TrainingDate;
            //    data.CustomerId = item.DayInfo.TrainingDay.CustomerId;
            //    data.Operation = GetOperation.Current;
            //    client1.GetTrainingDayAsync(ApplicationState.Current.SessionData.Token, data, new RetrievingInfo());

            //});


            //m.OperationCompleted += (s, a) =>
            //                            {
            //                                await MergeResult(a.Result, item);

            //                            };
            //if (!m.Run())
            //{
            //    IsBusy = false;
            //    item.State = MergeState.Error;
            //}
        }
        public void TestGetTrainingDay_Current_Private()
        {
            setPrivacy(Privacy.Private);

            var profile1 = (ProfileDTO)profiles[1].Tag;
            var profile2 = (ProfileDTO)profiles[2].Tag;

            WorkoutDayGetOperation op = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Last;
            op.UserId          = profiles[0].Id;
            op.WorkoutDateTime = trainingDays[2].TrainingDate;
            TrainingDayDTO day  = null;
            SessionData    data = SecurityManager.CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.IsNull(day);

            data = SecurityManager.CreateNewSession(profile2, ClientInformation);
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.IsNull(day);
        }
示例#4
0
 public static TrainingDayDTO GetTrainingDay(WorkoutDayGetOperation operation)
 {
     return(exceptionHandling(delegate
     {
         return Instance.GetTrainingDay(Token, operation, new RetrievingInfo());
     }));
 }
示例#5
0
        private void fillTrainingDayFromDate()
        {
            DateTime date  = TrainingDayPageContext.DateTime.Value;
            var      param = new WorkoutDayGetOperation();

            param.WorkoutDateTime = date;
            param.CustomerId      = Customer != null?Customer.GlobalId:(Guid?)null;
            param.UserId          = User != null ? User.GlobalId : (Guid?)null;
            IsInProgress          = true;
            ParentWindow.RunAsynchronousOperation(delegate(OperationContext context)
            {
                //first check the cache and retrieve only when there is no this day in the cache
                var cache   = TrainingDaysReposidory.GetCache(param.CustomerId, param.UserId);
                var tempDay = cache.GetByDate(date);
                if (tempDay == null)
                {
                    tempDay = ServiceManager.GetTrainingDay(param);
                    cache.Add(tempDay);
                }
                UIHelper.BeginInvoke(() =>
                {
                    TrainingDayPageContext.Day = tempDay;
                    populateFromContext();
                    rebuildMainTabs();
                    IsInProgress = false;
                }, Dispatcher);
            });
        }
示例#6
0
        public TrainingDayDTO GetTrainingDay(Token token, WorkoutDayGetOperation operationParams, RetrievingInfo retrievingInfo)
        {
            var securityInfo           = SecurityManager.EnsureAuthentication(token);
            TrainingDayService service = new TrainingDayService(Session, securityInfo, Configuration, PushNotificationService, EMailService);

            return(service.GetTrainingDay(operationParams, retrievingInfo));
        }
示例#7
0
        static async public Task <TrainingDayDTO> GetTrainingDayAsync(WorkoutDayGetOperation param, RetrievingInfo retrievingInfo)
        {
            var test = exceptionHandling((client) =>
            {
                return(Task <TrainingDayDTO> .Factory.FromAsync(client.BeginGetTrainingDay, client.EndGetTrainingDay, ApplicationState.Current.SessionData.Token, param, retrievingInfo, null));
            });

            return(await test);
        }
示例#8
0
        void mnuRefresh_Click(object sender, EventArgs e)
        {
            var m = new ServiceManager <GetTrainingDayCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetTrainingDayCompletedEventArgs> operationCompleted)
            {
                client1.GetTrainingDayCompleted -= operationCompleted;
                client1.GetTrainingDayCompleted += operationCompleted;
                WorkoutDayGetOperation data      = new WorkoutDayGetOperation();
                data.WorkoutDateTime             = ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate;
                data.UserId     = ApplicationState.Current.TrainingDay.TrainingDay.ProfileId;
                data.CustomerId = ApplicationState.Current.TrainingDay.TrainingDay.CustomerId;
                data.Operation  = GetOperation.Current;
                client1.GetTrainingDayAsync(ApplicationState.Current.SessionData.Token, data, new RetrievingInfo());
            });


            m.OperationCompleted += (s, a) =>
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.TrainingDay == null || IsClosing)
                {
                    return;
                }
                if (a.Error != null)
                {
                    BAMessageBox.ShowError(ApplicationStrings.EntryObjectPageBase_ErrDuringRefresh);
                }
                else
                {
                    OfflineModeManager manager = new OfflineModeManager(ApplicationState.Current.MyDays, ApplicationState.Current.SessionData.Profile.GlobalId);
                    manager.MergeNew(a.Result.Result, ApplicationState.Current, false, delegate
                    {
                        return(BAMessageBox.Ask(ApplicationStrings.EntryObjectPageBase_QResfreshMerge) == MessageBoxResult.OK);
                    });

                    show(true);
                }
            };
            progressBar.ShowProgress(true, ApplicationStrings.EntryObjectPageBase_ProgressRefresh);
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
示例#9
0
        public void Paste()
        {
            if (Clipboard.ContainsData(Constants.ClipboardFormat) && SelectedDate.HasValue && !IsSelectedDateFuture)
            {
                if (SelectedTrainingDay == null)
                {
                    var day = (TrainingDayDTO)Clipboard.GetData(Constants.ClipboardFormat);
                    PleaseWait.Run(delegate
                    {
                        try
                        {
                            if (day.Id != Constants.UnsavedObjectId)
                            {
                                //user select Cut operation so we should only move this one time (not many time like with Copy operation)
                                WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                                operation.UserId          = User.Id;
                                operation.Operation       = GetOperation.Current;
                                operation.WorkoutDateTime = day.TrainingDate;
                                day = ServiceManager.GetTrainingDay(operation);
                                ParentWindow.SynchronizationContext.Send(delegate
                                {
                                    Clipboard.Clear();
                                }, null);
                            }

                            day.ChangeDate(SelectedDate.Value);
                            ServiceManager.SaveTrainingDay(day);
                            fillImplementation(day.TrainingDate, User, null);
                            //this.Fill(User, day.TrainingDate);
                        }
                        catch (OldDataException ex)
                        {
                            ExceptionHandler.Default.Process(ex,
                                                             ApplicationStrings.ErrorOldTrainingDay,
                                                             ErrorWindow.MessageBox);
                        }
                        catch (Exception ex)
                        {
                            ExceptionHandler.Default.Process(ex,
                                                             ApplicationStrings.ErrorMoveTrainingDay,
                                                             ErrorWindow.EMailReport);
                        }
                    });
                }
                else
                {
                    FMMessageBox.ShowError(ApplicationStrings.ErrorCannotPaste);
                }
            }
        }
示例#10
0
        public void ForCustomer_GetTrainingDay_Current_AnotherProfile()
        {
            setPrivacy(Privacy.Public);
            var                    profile1 = (ProfileDTO)profiles[1].Tag;
            SessionData            data     = CreateNewSession(profile1, ClientInformation);
            WorkoutDayGetOperation op       = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Current;
            op.UserId          = profiles[0].GlobalId;
            op.CustomerId      = customers[0].GlobalId;
            op.WorkoutDateTime = customersTrainingDays[0].TrainingDate;
            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
        }
示例#11
0
        public void TestGetTrainingDay_Bug_ReturnOnlyOneEntry()
        {
            var                    profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData            data     = CreateNewSession(profile1, ClientInformation);
            WorkoutDayGetOperation op       = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Current;
            op.WorkoutDateTime = DateTime.Now.AddDays(1);
            TrainingDayDTO day = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.AreEqual(2, day.Objects.Count);
        }
示例#12
0
        private void previousNextEntry(TrainingDayDTO currentDay, GetOperation operationType, string limitMessage)
        {
            CancelEventArgs e = new CancelEventArgs();

            onTrainingDayChanging(e);
            if (e.Cancel)
            {
                return;
            }
            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();

            operation.Operation = operationType;
            operation.UserId    = User.GlobalId;
            if (Customer != null)
            {
                operation.CustomerId = Customer.GlobalId;
            }
            operation.WorkoutDateTime = currentDay.TrainingDate;
            ParentWindow.RunAsynchronousOperation(delegate(OperationContext context)
            {
                var day = ServiceManager.GetTrainingDay(operation);
                context.CancellatioToken.ThrowIfCancellationRequested();
                UIHelper.BeginInvoke(new Action(delegate
                {
                    if (day != null)
                    {
                        if (day.TrainingDate.IsFuture() && !UIHelper.EnsurePremiumLicence())
                        {
                            return;
                        }
                        DateTime oldDate           = CurrentDay.TrainingDate;
                        TrainingDayPageContext.Day = day;
                        Fill();
                        //populateFromContext();
                        //Fill(day, User, Customer, EntryObjectBuilder);
                        onTrainingDayChanged(new TrainingDayChangedEventArgs(oldDate, CurrentDay.TrainingDate));
                    }
                    else
                    {
                        BAMessageBox.ShowInfo(limitMessage);//ApplicationStrings.InfoNextEntryLimit);
                    }
                }), Dispatcher);
            }, delegate(OperationContext ctx)
            {
                CanNext = CanPrevious = ctx.State != OperationState.Started;
            });
        }
示例#13
0
        public void GoToTheFirstEntry()
        {
            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();

            operation.UserId    = User.Id;
            operation.Operation = GetOperation.First;
            TrainingDayDTO day = ServiceManager.GetTrainingDay(operation);

            if (day != null)
            {
                SetActiveMonth(day.TrainingDate);
            }
            else
            {
                FMMessageBox.ShowInfo(ApplicationStrings.InfoNoTrainingDayEntires);
            }
        }
        public void TestGetTrainingDay_Current_NotExists()
        {
            var                    profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData            data     = SecurityManager.CreateNewSession(profile1, ClientInformation);
            WorkoutDayGetOperation op       = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Current;
            op.UserId          = profile1.Id;
            op.WorkoutDateTime = DateTime.Now.AddDays(-41);
            TrainingDayDTO day = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.IsNull(day);
        }
        public void TestGetTrainingDay_Last_Myself()
        {
            var                    profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData            data     = SecurityManager.CreateNewSession(profile1, ClientInformation);
            WorkoutDayGetOperation op       = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Last;
            op.UserId          = profile1.Id;
            op.WorkoutDateTime = trainingDays[2].TrainingDate;
            TrainingDayDTO day = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.AreEqual(trainingDays[trainingDays.Count - 1].TrainingDate, day.TrainingDate);
        }
        public void GoToTheFirstEntry()
        {
            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();

            operation.UserId    = User.GlobalId;
            operation.Operation = GetOperation.First;
            TrainingDayDTO day = ServiceManager.GetTrainingDay(operation);

            if (day != null)
            {
                entriesViewer.CalendarControl.DisplayDate = day.TrainingDate;
            }
            else
            {
                BAMessageBox.ShowInfo("InfoNoTrainingDayEntires".TranslateStrings());
            }
        }
示例#17
0
        public void ForCustomer_GetTrainingDay_Next()
        {
            var                    profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData            data     = CreateNewSession(profile1, ClientInformation);
            WorkoutDayGetOperation op       = new WorkoutDayGetOperation();

            op.Operation       = GetOperation.Next;
            op.UserId          = profile1.GlobalId;
            op.CustomerId      = customers[0].GlobalId;
            op.WorkoutDateTime = customersTrainingDays[0].TrainingDate;
            TrainingDayDTO day = null;

            RunServiceMethod(delegate(InternalBodyArchitectService Service)
            {
                day = Service.GetTrainingDay(data.Token, op, new RetrievingInfo());
            });
            Assert.AreEqual(customersTrainingDays[1].TrainingDate, day.TrainingDate);
        }
示例#18
0
        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);
                }
            }
        }
示例#19
0
        public void Copy()
        {
            var day = SelectedTrainingDay;

            if (day != null)
            {
                PleaseWait.Run(delegate
                {
                    WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                    operation.UserId          = User.Id;
                    operation.Operation       = GetOperation.Current;
                    operation.WorkoutDateTime = day.TrainingDate;
                    day = ServiceManager.GetTrainingDay(operation);
                    day = day.Copy();
                });
                if (day.Objects.Count == 0)
                {
                    FMMessageBox.ShowError(ApplicationStrings.ErrorCannotCopyTrainingDayFixedEntries);
                    return;
                }
                Clipboard.SetData(Constants.ClipboardFormat, day);
            }
        }
示例#20
0
        //private void previousNextEntry(TrainingDayDTO currentDay,string limitMessage)
        //{
        //    if (currentDay != null)
        //    {
        //        CurrentDay = currentDay;
        //        Fill(day);
        //    }
        //    else
        //    {
        //        FMMessageBox.ShowInfo(limitMessage);
        //    }
        //}

        private void previousNextEntry(TrainingDayDTO currentDay, GetOperation operationType, string limitMessage)
        {
            CancelEventArgs e = new CancelEventArgs();

            onTrainingDayChanging(e);
            if (e.Cancel)
            {
                return;
            }
            ParentWindow.RunAsynchronousOperation(delegate(OperationContext context)
            {
                WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                operation.Operation       = operationType;
                operation.UserId          = User.Id;
                operation.WorkoutDateTime = currentDay.TrainingDate;
                var day = ServiceManager.GetTrainingDay(operation);
                context.CancellatioToken.ThrowIfCancellationRequested();
                ParentWindow.SynchronizationContext.Send(delegate
                {
                    if (day != null)
                    {
                        DateTime oldDate = CurrentDay.TrainingDate;
                        CurrentDay       = day;
                        Fill(day, User);
                        onTrainingDayChanged(new TrainingDayChangedEventArgs(oldDate, CurrentDay.TrainingDate));
                    }
                    else
                    {
                        FMMessageBox.ShowInfo(limitMessage);//ApplicationStrings.InfoNextEntryLimit);
                    }
                }, null);
            }, delegate(OperationContext ctx)
            {
                tsbNext.Enabled = tsbPrevious.Enabled = ctx.State != OperationState.Started;
            });
        }
 public TrainingDayDTO GetTrainingDay(Token token, WorkoutDayGetOperation operationParams, RetrievingInfo retrievingInfo)
 {
     return(exceptionHandling(token, () => InternalService.GetTrainingDay(token, operationParams, retrievingInfo)));
 }
示例#22
0
        private void monthCalendar1_DayDragDrop(object sender, DayDragDropEventArgs e)
        {
            try
            {
                TrainingDayDTO day = (TrainingDayDTO)e.Data.GetData(typeof(TrainingDayDTO));
                if ((e.KeyState & 8) == 8)
                {
                    //using (var scope = new TransactionScope())
                    //{
                    //    day = TrainingDay.GetById(day.Id);
                    //    var newDay = day.Copy();
                    //    if (newDay.Objects.Count == 0)
                    //    {
                    //        FMMessageBox.ShowError(ApplicationStrings.ErrorCannotCopyTrainingDayFixedEntries);
                    //        return;
                    //    }

                    //    newDay.ChangeDate(e.Date);
                    //    newDay.Save();
                    //    scope.VoteCommit();
                    //}
                    if (day.Id != Constants.UnsavedObjectId)
                    {//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                        WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                        operation.UserId          = User.Id;
                        operation.Operation       = GetOperation.Current;
                        operation.WorkoutDateTime = day.TrainingDate;
                        day = ServiceManager.GetTrainingDay(operation);
                    }
                    day = day.Copy();
                    day.ChangeDate(e.Date);
                    ServiceManager.SaveTrainingDay(day);
                    this.Fill(User, e.Date);
                }
                else if (FMMessageBox.AskYesNo(ApplicationStrings.QMoveTrainingDay) == DialogResult.Yes)
                {
                    if (day.CanMove)
                    {
                        //using (var scope = new TransactionScope())
                        //{
                        //    day = TrainingDay.GetById(day.Id);
                        //    day.ChangeDate(e.Date);
                        //    day.Save();
                        //    scope.VoteCommit();
                        //}
                        if (day.Id != Constants.UnsavedObjectId)
                        {//user select Cut operation so we should only move this one time (not many time like with Copy operation)
                            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();
                            operation.UserId          = User.Id;
                            operation.Operation       = GetOperation.Current;
                            operation.WorkoutDateTime = day.TrainingDate;
                            day = ServiceManager.GetTrainingDay(operation);
                        }
                        day.ChangeDate(e.Date);
                        ServiceManager.SaveTrainingDay(day);
                        this.Fill(User, e.Date);
                    }
                    else
                    {
                        FMMessageBox.ShowError(ApplicationStrings.ErrorCannotMoveTrainingDayFixedEntries);
                    }
                }
            }
            catch (OldDataException ex)
            {
                ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorOldTrainingDay, ErrorWindow.MessageBox);
            }
            catch (Exception ex)
            {
                ExceptionHandler.Default.Process(ex, ApplicationStrings.ErrorMoveTrainingDay, ErrorWindow.EMailReport);
            }
        }
示例#23
0
 public TrainingDayDTO GetTrainingDay(Token token, WorkoutDayGetOperation operationParams, RetrievingInfo retrievingInfo)
 {
     throw new NotImplementedException();
 }