async Task LoadProjects(bool isUserAction = false) { if (!await CheckInternetConnection(false)) { return; } // AddOperation(); await new LoadDataService(isUserAction).LoadWorkspaceProjects(Id, false); await LoadProjectsFromDb(); //RemoveOperation(); if (NavigationEventArgs.NavigationMode != NavigationMode.Back || isUserAction) { var projects = Projects; var dataService = new LoadDataService(isUserAction); foreach (var asanaProject in projects) { await dataService.LoadProjectTasks(Id, asanaProject.id, false); var id = asanaProject.id; var project = Projects.FirstOrDefault(x => x.id == id); if (project != null) { var tasksCount = await SetProjectInfo(project); Dispatcher.RunAsync(() => { project.TasksCount = tasksCount.Item1; project.OverdueTasksCount = tasksCount.Item2; }); } } } }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected override async void OnInvoke(ScheduledTask task) { Debug.WriteLine("OnInvoke"); if (!AsanaStateService.IsSetAuthToken && !AsanaStateService.IsSetApiKey) { Debug.WriteLine("Complete - no auth"); NotifyComplete(); return; } var response = await new AsanaRespository().GetWorkspaces(); if (!AsanaClient.ProcessResponse(response, true)) { Debug.WriteLine("Complete - no connection"); NotifyComplete(); return; } var service = new LoadDataService(false); service.IsBackgroundAgent = true; var projects = await new StorageService().GetProjectsForRefresh(); foreach (var project in projects) { await service.LoadProjectTasks(project.workspaceid, project.id, false); } TileService.UpdateMainTile(); Debug.WriteLine("Complete - OK"); NotifyComplete(); }