public ReportScreenMasterViewModel(ITimeEntryService timeEntryService, IBusyService busyService, IConnectivityService connectivityService, ITimeEntryTypeRepository timeEntryTypeRepository, ITimeEntryRepository timeEntryRepository, IAppSettings appSettings) { _timeEntryService = timeEntryService; _busyService = busyService; _connectivityService = connectivityService; _timeEntryTypeRepository = timeEntryTypeRepository; _timeEntryRepository = timeEntryRepository; _appSettings = appSettings; Search = new DelegateCommand <object>(ExecuteSearch); _busyService.ShowBusy(_reportscreenKey); LoadPredefinedSearchItems(); SelectedPredefinedSearch = PredefinedSearchItems[1]; EditTimeEntryCommand = new DelegateCommand <object>(EditTimeEntry); SaveCommand = new DelegateCommand <object>(SaveCommandExecute); try { TimeEntryTypes = _timeEntryTypeRepository.GetGlobal(); } catch (Exception ex) { Logger.Error(ex); } TaskCommands.SaveTaskCompleted.RegisterCommand(new DelegateCommand(Reload)); TaskCommands.SaveTaskCancelled.RegisterCommand(new DelegateCommand(Reload)); ApplicationCommands.ConnectivityChanged.RegisterCommand(new DelegateCommand <object>(ConnectivityChangedExecute)); }
private void SaveCommandExecute(object item) { _busyService.ShowBusy(_reportscreenKey); var list = new List <TimeEntry>(); foreach (var gridRowItemViewModel in GridRows.Where(x => x.HasChanges)) { var timeEntry = gridRowItemViewModel.TimeEntry; timeEntry.IsSynced = false; timeEntry.Billable = gridRowItemViewModel.EditableBillable; timeEntry.TimeEntryType = gridRowItemViewModel.EditableType; list.Add(timeEntry); TaskCommands.SaveTaskCompleted.Execute(timeEntry); } _timeEntryRepository.AddOrUpdateRange(list); ApplicationCommands.StartSync.Execute(null); _busyService.HideBusy(_reportscreenKey); }
public DayOverviewViewModel(ITimeEntryService timeEntryService, IBusyService busyService) { _timeEntryService = timeEntryService; _busyService = busyService; _busyService.ShowBusy(_dayoverviewKey); TimeEntries = new List <DataOverviewItemViewModel>(); PreviousDateCommand = new DelegateCommand <object>(a => StartDate = StartDate.AddDays(-1)); NextDayCommand = new DelegateCommand <object>(a => StartDate = StartDate.AddDays(1)); TodayCommand = new DelegateCommand <object>(a => StartDate = GetNuetralKindDateTimeToday()); EditTaskCommand = new DelegateCommand <object>(EditTaskExecute); _saveCommandCompletedCommand = new DelegateCommand <object>(SaveTaskCompleted); TaskCommands.SaveTaskCompleted.RegisterCommand(_saveCommandCompletedCommand); OverviewCommands.GoToDaySubMenu.RegisterCommand(new DelegateCommand <object>(ChangeDate)); VisiblePeriodStart = StartDate.AddHours(6); VisiblePeriodEnd = EndDate.AddHours(-6); StartDate = GetNuetralKindDateTimeToday(); }
private async void LoadTimeEntries() { // Is being invoked twice when date is selected in bound datepicker if (IsBusy) { return; } IsBusy = true; _busyService.ShowBusy(_dayoverviewKey); IEnumerable <DataOverviewItemViewModel> timeEntries = new List <DataOverviewItemViewModel>(); try { //enddate tasks are also included var timeEntriesDtos = await _timeEntryService.GetTimeEntriesByDateIgnoreEmptyTimeEntries(StartDate, StartDate); timeEntries = timeEntriesDtos.Select(timeEntry => new DataOverviewItemViewModel(timeEntry)); } catch (Exception ex) { if (!_isShowingTextbox) { _isShowingTextbox = true; var result = MessageBox.Show("Error loading timeentries", "Error", MessageBoxButton.OK); _isShowingTextbox = result == MessageBoxResult.None; } Logger.Error(ex); } TimeEntries = timeEntries.OrderBy(x => x.TimeEntry.Guid).ToList(); await Task.Run(() => ThreadUtils.WaitForUIRendering()); IsBusy = false; _busyService.HideBusy(_dayoverviewKey); }
private async void DoSync() { if (!_connectivityService.IsOnline) { ApplicationCommands.SyncCompleted.Execute(null); return; } if (SyncInProgress || !_connectivityService.IsOnline) { return; } SyncInProgress = true; ApplicationCommands.SyncStarted.Execute(ShouldDisplayProgress); try { if (ForceResync) { _busyService.ShowBusy(_syncKey); await Task.Run(() => { SyncProgressChanged(20, "Synchronizing companies"); SynchronizeCompanies().Wait(); SyncProgressChanged(30, "Synchronizing projects"); SynchronizeProjects().Wait(); SyncProgressChanged(20, "Synchronizing tasks"); SynchronizeTasks().Wait(); SyncProgressChanged(5, "Synchronizing time entry types"); SynchronizeTimeEntryTypes().Wait(); SyncProgressChanged(10, "Synchronizing local time entries"); SynchronizeTimeEntries().Wait(); SyncProgressChanged(20, "Synchronizing user statistics"); UserSession.UserStatistics = UserService.GetPerformanceInfo(UserSession); AppSettings.MinTimeEntryDate = UserService.GetTimeEntryMinStartDate(UserSession); }); } else { SyncProgressChanged(20, "Synchronizing companies"); await SynchronizeCompanies(); SyncProgressChanged(30, "Synchronizing projects"); await SynchronizeProjects(); SyncProgressChanged(20, "Synchronizing tasks"); await SynchronizeTasks(); SyncProgressChanged(5, "Synchronizing time entry types"); await SynchronizeTimeEntryTypes(); SyncProgressChanged(10, "Synchronizing local time entries"); await SynchronizeTimeEntries(); SyncProgressChanged(20, "Synchronizing user statistics"); UserSession.UserStatistics = UserService.GetPerformanceInfo(UserSession); AppSettings.MinTimeEntryDate = UserService.GetTimeEntryMinStartDate(UserSession); } SyncProgressChanged(10, "Synchronizing history list"); var numOfDaysBack = UserSession.UserPreferences.StatisticsNumOfDaysBack; var startTime = DateTime.Now.Date.AddDays(-numOfDaysBack); var endTime = DateTime.Now; var lastXDaysTimeEntries = await TimeEntryService.GetTimeEntriesByDate(startTime, endTime); var unsyncedTimeEntries = _timeEntryRepository.GetUnsyncedTimeEntries(); lastXDaysTimeEntries.AddRange(unsyncedTimeEntries.Where(x => !x.HasSyncError)); UserSession.UserStatistics.LastXDaysTimeEntries = lastXDaysTimeEntries; AppSettings.LastSyncDate = DateTime.Now; AppSettings.Save(); SyncProgressChanged(0, "Synchronization complete"); SyncInProgress = false; ForceResync = false; ApplicationCommands.SyncCompleted.Execute(null); } catch (NotFoundByGuidException notFoundByGuidException) { Logger.Error(notFoundByGuidException); SyncInProgress = false; _resyncCommand.Execute(null); } catch (MissingHieracleDataException missingHieracleDataException) { Logger.Error(missingHieracleDataException); if (!ForceResync) { SyncInProgress = false; _resyncCommand.Execute(null); } else { OnSyncFailed("Unknown Synchronization failure. Contact support"); } } catch (Exception ex) { if (ex is AggregateException) { var aggregateException = ex as AggregateException; foreach (var e in aggregateException.Flatten().InnerExceptions) { HandleSyncError(e); } } else { HandleSyncError(ex); } OnSyncFailed("Synchronization failed due to a connectivity error. The application will retry in " + AppSettings.SyncInterval.Minutes + " minutes."); } _busyService.HideBusy(_syncKey); }