Ejemplo n.º 1
0
        public void TwoEntries_SameType_OneIsNew()
        {
            TrainingDayDTO daySource = new TrainingDayDTO();

            daySource.InstanceId = Guid.NewGuid();
            daySource.GlobalId   = Guid.NewGuid();
            SizeEntryDTO size = new SizeEntryDTO();

            size.ReservationId = Guid.NewGuid();//for testing purposes
            size.InstanceId    = Guid.NewGuid();
            size.GlobalId      = Guid.NewGuid();
            daySource.Objects.Add(size);
            size.TrainingDay = daySource;
            SizeEntryDTO tracker = new SizeEntryDTO();

            tracker.InstanceId    = Guid.NewGuid();
            tracker.ReservationId = Guid.NewGuid();//for testing purposes
            daySource.Objects.Add(tracker);
            tracker.TrainingDay = daySource;

            var dayCopy = daySource.Copy();

            dayCopy.Objects[1].GlobalId   = Guid.NewGuid();
            dayCopy.InstanceId            = Guid.Empty;
            dayCopy.Objects[0].InstanceId = Guid.Empty;
            dayCopy.Objects[1].InstanceId = Guid.Empty;

            dayCopy.FillInstaneId(daySource);

            Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId);
            Assert.AreEqual(size.ReservationId, dayCopy.Objects.Where(x => x.InstanceId == size.InstanceId).SingleOrDefault().ReservationId);
            Assert.AreEqual(tracker.ReservationId, dayCopy.Objects.Where(x => x.InstanceId == tracker.InstanceId).SingleOrDefault().ReservationId);
        }
Ejemplo n.º 2
0
        public void TwoEntries_EachDifferentType()
        {
            TrainingDayDTO daySource = new TrainingDayDTO();

            daySource.InstanceId = Guid.NewGuid();
            SizeEntryDTO size = new SizeEntryDTO();

            size.InstanceId = Guid.NewGuid();
            daySource.Objects.Add(size);
            size.TrainingDay = daySource;
            GPSTrackerEntryDTO tracker = new GPSTrackerEntryDTO();

            tracker.InstanceId = Guid.NewGuid();
            daySource.Objects.Add(tracker);
            tracker.TrainingDay = daySource;

            var dayCopy = daySource.Copy();

            dayCopy.GlobalId              = Guid.NewGuid();
            dayCopy.Objects[0].GlobalId   = Guid.NewGuid();
            dayCopy.Objects[1].GlobalId   = Guid.NewGuid();
            dayCopy.InstanceId            = Guid.Empty;
            dayCopy.Objects[0].InstanceId = Guid.Empty;
            dayCopy.Objects[1].InstanceId = Guid.Empty;

            dayCopy.FillInstaneId(daySource);

            Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId);
            Assert.AreEqual(daySource.Objects.OfType <SizeEntryDTO>().Single().InstanceId, dayCopy.Objects.OfType <SizeEntryDTO>().Single().InstanceId);
            Assert.AreEqual(daySource.Objects.OfType <GPSTrackerEntryDTO>().Single().InstanceId, dayCopy.Objects.OfType <GPSTrackerEntryDTO>().Single().InstanceId);
        }
Ejemplo n.º 3
0
        public void TwoEntries_SameType_FindingByGlobalId()
        {
            TrainingDayDTO daySource = new TrainingDayDTO();

            daySource.GlobalId   = Guid.NewGuid();
            daySource.InstanceId = Guid.NewGuid();
            SizeEntryDTO size = new SizeEntryDTO();

            size.GlobalId   = Guid.NewGuid();
            size.InstanceId = Guid.NewGuid();
            daySource.Objects.Add(size);
            size.TrainingDay = daySource;
            SizeEntryDTO tracker = new SizeEntryDTO();

            tracker.InstanceId = Guid.NewGuid();
            tracker.GlobalId   = Guid.NewGuid();
            daySource.Objects.Add(tracker);
            tracker.TrainingDay = daySource;

            var dayCopy = daySource.Copy();

            dayCopy.InstanceId            = Guid.Empty;
            dayCopy.Objects[0].InstanceId = Guid.Empty;
            dayCopy.Objects[1].InstanceId = Guid.Empty;

            dayCopy.FillInstaneId(daySource);

            Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId);
            Assert.AreEqual(size.InstanceId, dayCopy.Objects.Single(x => x.GlobalId == size.GlobalId).InstanceId);
            Assert.AreEqual(tracker.InstanceId, dayCopy.Objects.Single(x => x.GlobalId == tracker.GlobalId).InstanceId);
        }
Ejemplo n.º 4
0
        async public void SyncOperation_NeedsMerge_ErrorDuringSecondSave()
        {
            ApplicationState state = new ApplicationState();

            ApplicationState.Current  = state;
            state.SessionData         = new SessionData();
            state.SessionData.Profile = new ProfileDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var      holder = state.GetTrainingDayHolder(null);
            DateTime time   = ExtensionMethods.MonthDate(DateTime.UtcNow);
            var      day    = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            };

            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(day)
            {
                IsModified = true
            });


            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.Action = MergeAction.UseServer;
            viewModel.NeedsMergeException       = true;
            viewModel.ErrorInSecondSave         = true;
            viewModel.FromServer                = day.Copy();
            viewModel.FromServer.Comment        = "test";
            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };

            await viewModel.Synchronize();

            Assert.AreEqual(1, viewModel.Maximum);
            Assert.AreEqual(2, viewModel.SaveCount);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.FirstSave);
            Assert.IsTrue(viewModel.SecondSave);
            Assert.IsTrue(viewModel.Items[0].DayInfo.IsModified);
            Assert.IsFalse(viewModel.Items[0].DayInfo.IsConflict);
            Assert.AreEqual(MergeState.Error, viewModel.Items[0].State);
            Assert.IsTrue(viewModel.Merged);
            Assert.IsTrue(viewModel.IsInProgressGood);
            EnqueueTestComplete();
        }
Ejemplo n.º 5
0
        public void Merge_removed_entry_on_server_day_and_old_entry_already_saved()
        {
            var state = new ApplicationState();

            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var currentHolder = new TrainingDaysHolder(new UserSearchDTO()
            {
                GlobalId = Guid.NewGuid()
            });

            state.MyDays.Add(new CacheKey()
            {
                ProfileId = currentHolder.User.GlobalId
            }, currentHolder);
            var days = currentHolder;

            state.CurrentBrowsingTrainingDays = days;
            DateTime time = DateTime.UtcNow.MonthDate();

            days.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            }));
            days.TrainingDays.Add(time.AddDays(2), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(2)
            }));

            var day = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(3)
            };

            day.GlobalId = Guid.NewGuid();
            day.Objects.Add(new StrengthTrainingEntryDTO()
            {
                Comment = "Test"
            });
            day.Objects[0].Version  = 1;
            day.Objects[0].GlobalId = Guid.NewGuid();
            days.TrainingDays.Add(time.AddDays(3), new TrainingDayInfo(day));

            state.TrainingDay = days.TrainingDays[time.AddDays(3)].Copy();
            var serverCopy = day.Copy();

            //on the client we have one entry more (removed entry on server)
            state.TrainingDay.TrainingDay.Objects.Add(new SizeEntryDTO()
            {
                Version = 1, GlobalId = Guid.NewGuid(), Comment = "size"
            });

            OfflineModeManager manager = new OfflineModeManager(state.MyDays, currentHolder.User.GlobalId);

            manager.MergeNew(serverCopy, state, false, delegate
            {
                throw new Exception("We shouldn't be here!");
            });
            Assert.AreEqual(1, state.TrainingDay.TrainingDay.Objects[0].Version);
            Assert.AreEqual(1, state.TrainingDay.TrainingDay.Objects.Count);
            Assert.AreEqual(day.Objects[0].GlobalId, state.TrainingDay.TrainingDay.Objects[0].GlobalId);
            Assert.AreEqual("Test", state.TrainingDay.TrainingDay.Objects[0].Comment);

            Assert.AreEqual(1, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].TrainingDay.Objects[0].Version);
            Assert.AreEqual(1, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].TrainingDay.Objects.Count);
            //should be a different references to the same object (copy)
            Assert.AreNotEqual(state.TrainingDay, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].TrainingDay);

            Assert.AreEqual(false, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].IsModified);
            Assert.AreEqual(false, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].IsConflict);
        }
Ejemplo n.º 6
0
        public void Merge_ContentChanged_day_and_entry_already_saved_answer_false()
        {
            bool?answer = null;
            var  state  = new ApplicationState();

            state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();
            var currentHolder = new TrainingDaysHolder(new UserSearchDTO()
            {
                GlobalId = Guid.NewGuid()
            });

            state.MyDays.Add(new CacheKey()
            {
                ProfileId = currentHolder.User.GlobalId
            }, currentHolder);
            var days = currentHolder;

            state.CurrentBrowsingTrainingDays = days;
            DateTime time = DateTime.UtcNow.MonthDate();

            days.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            }));
            days.TrainingDays.Add(time.AddDays(2), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(2)
            }));

            var day = new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(3)
            };

            day.GlobalId = Guid.NewGuid();
            day.Objects.Add(new StrengthTrainingEntryDTO()
            {
                Comment = "Test"
            });
            day.Objects[0].Version  = 1;
            day.Objects[0].GlobalId = Guid.NewGuid();
            days.TrainingDays.Add(time.AddDays(3), new TrainingDayInfo(day)
            {
                IsModified = true
            });

            state.TrainingDay = days.TrainingDays[time.AddDays(3)].Copy();
            var serverCopy = day.Copy();

            serverCopy.Objects[0].Version = 2;
            serverCopy.Objects[0].Comment = "ggggg";
            OfflineModeManager manager = new OfflineModeManager(state.MyDays, currentHolder.User.GlobalId);

            manager.MergeNew(serverCopy, state, false, delegate(ModificationType m)
            {
                Assert.AreEqual(ModificationType.EntryModified, m);
                answer = false;
                return(answer.Value);
            });
            Assert.AreEqual(2, state.TrainingDay.TrainingDay.Objects[0].Version);
            Assert.AreEqual("Test", state.TrainingDay.TrainingDay.Objects[0].Comment);
            Assert.AreEqual(false, answer);
            Assert.AreEqual(1, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].TrainingDay.Objects[0].Version);
            //should be a different references to the same object (copy)
            Assert.AreNotEqual(state.TrainingDay, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].TrainingDay);

            Assert.AreEqual(true, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].IsModified);
            Assert.AreEqual(false, days.TrainingDays[state.TrainingDay.TrainingDay.TrainingDate].IsConflict);
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        private void monthCalendar1_Drop(object sender, RoutedEventArgs e)
        {
            ExDragEventArgs arg = (ExDragEventArgs)e;

            if (arg.DragEventArgs.Data.GetDataPresent("DateTime"))
            {
                DateTime date       = (DateTime)arg.DragEventArgs.Data.GetData("DateTime");
                DateTime targetDate = (DateTime)arg.DirectTarget.Tag;
                var      result     = entriesViewer.CalendarControl.GetDateInfo(date);
                if (result.Count == 1)
                {
                    var dayInfo = (TrainingDayInfo)result[0];

                    TrainingDayDTO day = getTrainingDay(date);
                    if (targetDate.IsFuture() && !UIHelper.EnsurePremiumLicence())
                    {
                        return;
                    }
                    if (Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        dayInfo.IsProcessing = true;
                        ParentWindow.RunAsynchronousOperation(x =>
                        {
                            //if (day.GlobalId != Constants.UnsavedGlobalId)
                            //{//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);
                            //}
                            try
                            {
                                day = day.Copy();
                                day.ChangeDate(targetDate);
                                var result1 = ServiceManager.SaveTrainingDay(day);
                                if (result1.TrainingDay != null)
                                {
                                    cache.Add(result1.TrainingDay);
                                }
                            }
                            catch (OldDataException ex)
                            {
                                UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorOldTrainingDay".TranslateStrings(), ErrorWindow.MessageBox), Dispatcher);
                            }
                            catch (Exception ex)
                            {
                                UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorMoveTrainingDay".TranslateStrings(), ErrorWindow.EMailReport), Dispatcher);
                            }
                            finally
                            {
                                dayInfo.IsProcessing = false;
                            }
                        });
                    }
                    else if (BAMessageBox.AskYesNo("QMoveTrainingDay".TranslateStrings()) == MessageBoxResult.Yes)
                    {
                        if (day.CanMove)
                        {
                            dayInfo.IsProcessing = true;
                            ParentWindow.RunAsynchronousOperation(x =>
                            {
                                //if (day.GlobalId != Constants.UnsavedGlobalId)
                                //{//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);
                                //}
                                try
                                {
                                    day = day.StandardClone();
                                    day.ChangeDate(targetDate);
                                    var result1 = ServiceManager.SaveTrainingDay(day);
                                    cache.Remove(date);

                                    if (result1.TrainingDay != null)
                                    {
                                        day = result1.TrainingDay;
                                        cache.Add(day);
                                    }
                                }
                                catch (OldDataException ex)
                                {
                                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorOldTrainingDay".TranslateStrings(), ErrorWindow.MessageBox), Dispatcher);
                                }
                                catch (Exception ex)
                                {
                                    UIHelper.Invoke(() => ExceptionHandler.Default.Process(ex, "ErrorMoveTrainingDay".TranslateStrings(), ErrorWindow.EMailReport), Dispatcher);
                                }
                                finally
                                {
                                    dayInfo.IsProcessing = false;
                                }
                            });
                        }
                        else
                        {
                            BAMessageBox.ShowError("ErrorCannotMoveTrainingDayFixedEntries".TranslateStrings());
                        }
                    }
                }
            }
        }