Ejemplo n.º 1
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);
        }
 public SynchronizationItemViewModel(TrainingDayInfo dayInfo, GPSTrackerEntryDTO entry, GPSPointsBag bag, SynchronizationViewModel parent)
 {
     this.parent = parent;
     DayInfo     = dayInfo;
     ItemType    = ItemType.GPSCoordinates;
     GPSBag      = bag;
     GPSEntry    = entry;
 }
Ejemplo n.º 3
0
        public GPSTrackerViewModel(GPSTrackerEntryDTO entry)
        {
            this.entry = entry;

            var tdi    = ApplicationState.Current.TrainingDay;
            var gpsBag = tdi.GetGpsCoordinates(entry);

            if (gpsBag != null)
            {
                Points = gpsBag.Points;
            }
            //tdi.SetGpsCoordinates(entry, Points);
        }
Ejemplo n.º 4
0
 public void SetGpsCoordinates(GPSTrackerEntryDTO gpsEntry, IEnumerable <GPSPoint> points, bool isSaved = true)
 {
     if (gpsEntry.IsNew)
     {
         GPSCoordinates[new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId)] = new GPSPointsBag(points, isSaved);
     }
     else
     {
         //first check if there is old element which using InstanceId for this entry. if yes then remove it
         if (GPSCoordinates.ContainsKey(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId)))
         {
             GPSCoordinates.Remove(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId));
         }
         GPSCoordinates[new LocalObjectKey(gpsEntry.GlobalId, KeyType.GlobalId)] = new GPSPointsBag(points, isSaved);
     }
 }
Ejemplo n.º 5
0
        private string getGpsTrackerMessage(GPSTrackerEntryDTO gpsEntry)
        {
            StringBuilder builder = new StringBuilder();
            UIHelper      ui      = new UIHelper();

            builder.AppendLine(gpsEntry.Exercise.Name);
            if (gpsEntry.Distance.HasValue)
            {
                builder.AppendFormat("{2}: {0:0.#} {1}\r\n", gpsEntry.Distance.Value.ToDisplayDistance(), ui.DistanceType, ApplicationStrings.GPSTrackerPage_Distance);
            }
            if (gpsEntry.Duration.HasValue)
            {
                builder.AppendFormat("{1}: {0}\r\n", gpsEntry.Duration.Value.ToDisplayDuration(), ApplicationStrings.GPSTrackerPage_ShortDuration);
            }
            if (gpsEntry.Calories.HasValue)
            {
                builder.AppendFormat("{1}: {0:0} kcal", gpsEntry.Calories.Value, ApplicationStrings.GPSTrackerPage_Calories);
            }
            return(builder.ToString());
        }
Ejemplo n.º 6
0
 public GPSPointsBag GetGpsCoordinates(GPSTrackerEntryDTO gpsEntry)
 {
     return(GPSCoordinates.Where(x => x.Key.Id == gpsEntry.GlobalId || x.Key.Id == gpsEntry.InstanceId).Select(x => x.Value).SingleOrDefault());
 }
Ejemplo n.º 7
0
 public void Fill(GPSTrackerEntryDTO gpsTrackerEntry)
 {
     this.entry = gpsTrackerEntry;
 }
Ejemplo n.º 8
0
        async public void SyncOperation_UploadGPSCoordinates_RemovedGPSTrackerEntry()
        {
            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)
            };
            var tdi = new TrainingDayInfo(day)
            {
                IsModified = true
            };
            //these points should be detected to save
            GPSTrackerEntryDTO gpsEntry = new GPSTrackerEntryDTO();

            gpsEntry.Exercise = new ExerciseLightDTO()
            {
                GlobalId = Guid.NewGuid()
            };
            tdi.TrainingDay.Objects.Add(gpsEntry);
            gpsEntry.TrainingDay = tdi.TrainingDay;
            var points = new List <GPSPoint>();

            points.Add(new GPSPoint(1, 2, 3, 4, 6));
            tdi.GPSCoordinates.Add(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, false));

            holder.TrainingDays.Add(time.AddDays(1), tdi);


            bool eventCompleted = false;

            MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state);

            viewModel.UploadGPSError            = ErrorCode.ObjectNotFound;
            viewModel.RemoveFromServer          = typeof(GPSTrackerEntryDTO);
            viewModel.SynchronizationCompleted += delegate
            {
                eventCompleted = true;
            };
            var items = viewModel.Items.ToArray();
            await viewModel.Synchronize();

            Assert.AreEqual(2, viewModel.Maximum);
            Assert.AreEqual(1, viewModel.SaveCount);
            Assert.AreEqual(0, viewModel.GPSUploadCount);
            Assert.AreEqual(MergeState.Finished, items[0].State);
            Assert.AreEqual(MergeState.Finished, items[1].State);
            Assert.AreNotEqual(Guid.Empty, day.GlobalId);
            Assert.IsTrue(eventCompleted);
            Assert.IsTrue(viewModel.FirstSave);
            Assert.IsFalse(viewModel.Merged);
            Assert.IsTrue(viewModel.IsInProgressGood);
            EnqueueTestComplete();
        }
Ejemplo n.º 9
0
        public void InitialState()
        {
            ApplicationState appState = new ApplicationState();

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

            holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(1)
            })
            {
                IsModified = true
            });
            holder.TrainingDays.Add(time.AddDays(2), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(2)
            }));
            holder.TrainingDays.Add(time.AddDays(3), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(3)
            })
            {
                IsModified = true
            });
            var tdi = new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(4)
            })
            {
                IsModified = true
            };
            //these points should be detected to save
            GPSTrackerEntryDTO gpsEntry = new GPSTrackerEntryDTO();

            tdi.TrainingDay.Objects.Add(gpsEntry);
            gpsEntry.TrainingDay = tdi.TrainingDay;
            var points = new List <GPSPoint>();

            points.Add(new GPSPoint(1, 2, 3, 4, 6));
            tdi.GPSCoordinates.Add(new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, false));

            //these shouldn't be
            var entry1 = new GPSTrackerEntryDTO();

            tdi.TrainingDay.Objects.Add(entry1);
            entry1.TrainingDay = tdi.TrainingDay;
            points             = new List <GPSPoint>();
            points.Add(new GPSPoint(11, 12, 13, 14, 7));
            tdi.GPSCoordinates.Add(new LocalObjectKey(entry1.InstanceId, KeyType.InstanceId), new GPSPointsBag(points, true));

            holder.TrainingDays.Add(time.AddDays(4), tdi);

            holder.TrainingDays.Add(time.AddDays(5), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(5)
            }));
            holder.TrainingDays.Add(time.AddDays(6), new TrainingDayInfo(new TrainingDayDTO()
            {
                TrainingDate = time.AddDays(6)
            }));

            SynchronizationViewModel viewModel = new SynchronizationViewModel(appState);

            Assert.AreEqual(4, viewModel.Items.Count);
            Assert.AreEqual(Visibility.Collapsed, viewModel.ProgressVisibility);
            Assert.AreEqual(holder.TrainingDays[time.AddDays(1)], viewModel.Items[0].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[0].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(3)], viewModel.Items[1].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[1].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)], viewModel.Items[2].DayInfo);
            Assert.AreEqual(ItemType.TrainingDay, viewModel.Items[2].ItemType);

            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)].GPSCoordinates[new LocalObjectKey(gpsEntry.InstanceId, KeyType.InstanceId)], viewModel.Items[3].GPSBag);
            Assert.AreEqual(ItemType.GPSCoordinates, viewModel.Items[3].ItemType);
            Assert.AreEqual(holder.TrainingDays[time.AddDays(4)], viewModel.Items[3].DayInfo);
            Assert.AreEqual(gpsEntry, viewModel.Items[3].GPSEntry);
        }
Ejemplo n.º 10
0
 public void CalculateCaloriesBurned(GPSTrackerEntryDTO gpsEntry, decimal duration, IPerson person)
 {
     gpsEntry.Calories = CalculateCalories(gpsEntry.Exercise.Met, duration, person);
 }