protected override void DoWork() { var projects = AsyncHelper.RunSync(() => _projectRepository.GetAll().ToListAsync()); foreach (var project in projects) { var utcNow = Clock.Now.ToUniversalTime(); var asanaBaseToken = new AsanaTaskInput() { Token = project.AsanaToken, ProjectId = project.AsanaProjectId, }; var asanaTasks = AsyncHelper.RunSync(() => _asanaManager.GetAllTasksInProject(asanaBaseToken)); var getWorkItemsInput = new GetWorkItemsInput() { Organization = project.DevOpsOrganization, Project = project.DevOpsProjectTitle, Token = project.DevOpsToken, Version = "6.0" }; var result = AsyncHelper.RunSync(() => _devOpsManager.GetProjectWorkItems(getWorkItemsInput)); AsyncHelper.RunSync(() => UpsertAsanaTasks(asanaTasks, project)); AsyncHelper.RunSync(() => UpsertDevOpsTasks(result, project)); } }
public async Task <AsanaTaskDetail> GetAllTasksInProject(AsanaTaskInput input) { var httpClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"projects/{input.ProjectId}/tasks?opt_fields=resource_type,name,approval_status,completed,completed_at,completed_by,created_at,html_notes,memberships,modified_at,assignee,parent,tags,notes "); httpClient.BaseAddress = new Uri("https://app.asana.com/api/1.0/"); // to do: get uri from appsettings httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {input.Token}"); var response = await httpClient.SendAsync(request); if (response.StatusCode == HttpStatusCode.BadRequest) { throw new UserFriendlyException("an error occurred"); } var stringData = await response.Content.ReadAsStringAsync(); var asanaTasksDetails = JsonConvert.DeserializeObject <AsanaTaskDetail>(stringData); return(asanaTasksDetails != null ? asanaTasksDetails : new AsanaTaskDetail()); }
public async Task <List <KeyValuePair <string, string> > > GetAllTasksInProject(AsanaTaskInput input) { var result = await _asanaManager.GetAllTasksInProject(input); var list = new List <KeyValuePair <string, string> >(); result.data.ForEach(a => { list.Add(new KeyValuePair <string, string>(a.gid, a.name)); }); return(list); }