public SynchronizationItemViewModel(TrainingDayInfo dayInfo, GPSTrackerEntryDTO entry, GPSPointsBag bag, SynchronizationViewModel parent) { this.parent = parent; DayInfo = dayInfo; ItemType = ItemType.GPSCoordinates; GPSBag = bag; GPSEntry = entry; }
public static bool DeleteTrainingDay(TrainingDayDTO day, TrainingDayInfo dayInfo = null) { bool res = false; if (day != null && UIHelper.EnsurePremiumLicence()) { if (BAMessageBox.AskYesNo(Strings.QRemoveTrainingDay, day.TrainingDate.ToShortDateString()) == MessageBoxResult.Yes) { if (dayInfo != null) { dayInfo.IsProcessing = true; } PleaseWait.Run(delegate(MethodParameters par) { try { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; ServiceManager.DeleteTrainingDay(param); Guid?customerId = day.CustomerId; Guid?userId = day.ProfileId; var cache = TrainingDaysReposidory.GetCache(customerId, userId); cache.Remove(day.TrainingDate); res = true; } catch (TrainingIntegrationException te) { res = false; par.CloseProgressWindow(); ExceptionHandler.Default.Process(te, Strings.ErrorCannotDeleteTrainingDayPartOfTraining, ErrorWindow.MessageBox); } catch (Exception te) { res = false; par.CloseProgressWindow(); ExceptionHandler.Default.Process(te, Strings.ErrorRemoveTrainingDay, ErrorWindow.MessageBox); } finally { if (dayInfo != null) { dayInfo.IsProcessing = false; } } }); } } return(res); }
public TrainingDayInfo SetTrainingDay(TrainingDayDTO day) { TrainingDayInfo info; if (TrainingDays.ContainsKey(day.TrainingDate)) { info = TrainingDays[day.TrainingDate]; info.TrainingDay = day; } else { info = new TrainingDayInfo(day); TrainingDays.Add(day.TrainingDate, info); } return(info); }
//checks if this entry is already saved (to the server or local only) public bool IsSaved(EntryObjectDTO entry) { bool isAlreadySavedInLocal = false; if (entry.IsNew) { isAlreadySavedInLocal = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays.ContainsKey(entry.TrainingDay.TrainingDate); if (isAlreadySavedInLocal) { TrainingDayInfo dayInfo = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[entry.TrainingDay.TrainingDate]; var entrySavedInLocal = dayInfo.TrainingDay.Objects.Where(x => x.InstanceId == entry.InstanceId).SingleOrDefault(); isAlreadySavedInLocal = entrySavedInLocal != null; } } bool emptyEntry = entry.IsNew && !isAlreadySavedInLocal; return(!emptyEntry); }
async protected Task applySave(SaveTrainingDayResult result, SynchronizationItemViewModel item) { var newDay = result.TrainingDay; var customerId = item.DayInfo.TrainingDay.CustomerId; var holder = appState.GetTrainingDayHolder(customerId); TrainingDayInfo newInfo = null; if (newDay != null) { var oldInfo = holder.TrainingDays[newDay.TrainingDate]; newDay.FillInstaneId(oldInfo.TrainingDay, true); //oldInfo.TrainingDay.GlobalId = newDay.GlobalId; //find all gps tracker entries and set correct globalid (we need this in uploading gps coordinates) //foreach (var gpsEntry in newDay.Objects.OfType<GPSTrackerEntryDTO>()) //{ // var oldEntry=oldInfo.TrainingDay.Objects.OfType<GPSTrackerEntryDTO>().Where(x => x.Exercise.GlobalId == gpsEntry.Exercise.GlobalId && x.StartDateTime==gpsEntry.StartDateTime && x.EndDateTime==gpsEntry.EndDateTime ).FirstOrDefault(); // if (oldEntry != null) // { // oldEntry.GlobalId = gpsEntry.GlobalId; // gpsEntry.InstanceId = oldEntry.InstanceId; // } //} //now check if gps entry has been removed on the server and if yes remove also gps coordinates uploading foreach (var source in Items.Where(x => x.DayInfo == oldInfo && x.ItemType == ItemType.GPSCoordinates).ToList()) { var oldEntry = newDay.Objects.OfType <GPSTrackerEntryDTO>().Where(x => (source.GPSEntry.GlobalId != Guid.Empty && x.GlobalId == source.GPSEntry.GlobalId) || (x.Exercise.GlobalId == source.GPSEntry.Exercise.GlobalId && x.StartDateTime == source.GPSEntry.StartDateTime && x.EndDateTime == source.GPSEntry.EndDateTime)).FirstOrDefault(); if (oldEntry == null) { source.GPSEntry = null; } } newInfo = holder.SetTrainingDay(newDay); newInfo.IsModified = false; } else { holder.TrainingDays.Remove(item.DayInfo.TrainingDay.TrainingDate); } item.DayInfo.IsConflict = false; item.DayInfo = newInfo; item.State = MergeState.Finished; Items.Remove(item); }
public SynchronizationItemViewModel(TrainingDayInfo dayInfo, SynchronizationViewModel parent) { this.parent = parent; DayInfo = dayInfo; ItemType = ItemType.TrainingDay; }
public CalendarItem(DateTime calendarItemDate, TrainingDayInfo trainingDay) { Item = trainingDay; CalendarItemDate = calendarItemDate; }
public bool RetrievedDays(DateTime startMonth, int months, IEnumerable <TrainingDayDTO> days, TrainingDaysHolder current) { bool withoutProblems = true; foreach (TrainingDayDTO dayDto in days) { if (current.TrainingDays.ContainsKey(dayDto.TrainingDate)) { var dayInfo = current.TrainingDays[dayDto.TrainingDate]; if (!dayInfo.IsModified) { current.TrainingDays[dayDto.TrainingDate] = new TrainingDayInfo(dayDto); } //else if (dayInfo.OriginalVersion != dayDto.Version) //{ // int version = dayDto.Version; // dayDto.Version = dayInfo.OriginalVersion; // dayInfo.TrainingDay.GlobalId = dayDto.GlobalId; // //version is changed but we must check if the content is different. If not we can merge // if (dayDto.IsModified(dayInfo.TrainingDay)) // {//still problem with InstanceId in child objects // dayInfo.IsConflict = true; // withoutProblems = false; // } // else // { // state.TrainingDays[dayDto.TrainingDate].TrainingDay.Version = version; // state.TrainingDays[dayDto.TrainingDate].TrainingDay.GlobalId = dayDto.GlobalId; // } //} else { //int version = dayDto.Version; //dayDto.Version = dayInfo.OriginalVersion; dayInfo.TrainingDay.GlobalId = dayDto.GlobalId; //version is changed but we must check if the content is different. If not we can merge if (dayDto.IsModified(dayInfo.TrainingDay)) {//still problem with InstanceId in child objects dayInfo.IsConflict = true; withoutProblems = false; } else { setVersion(current.TrainingDays[dayDto.TrainingDate].TrainingDay, dayDto); current.TrainingDays[dayDto.TrainingDate].TrainingDay.GlobalId = dayDto.GlobalId; } } } else { TrainingDayInfo info = new TrainingDayInfo(dayDto); current.TrainingDays.Add(dayDto.TrainingDate, info); } } for (int i = 0; i < months; i++) { DateTime tempDate = startMonth.AddMonths(i); if (!current.RetrievedMonths.Contains(tempDate)) { current.RetrievedMonths.Add(tempDate); } } return(withoutProblems); }
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(); }
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); }