Пример #1
0
        public List <WorkItemDto> GetIncompleteItemsByUserIdList(int serverId, int employeeId, List <int> employeeIdList)
        {
            TeamServer         server           = null;
            List <WorkItem>    workItems        = null;
            List <WorkItemDto> workItemsDtoList = new List <WorkItemDto>();
            UserServerInfo     userServerInfo   = null;

            try
            {
                using (TeamServerRepository teamServerRepository = new TeamServerRepository())
                {
                    server = teamServerRepository.GetById(serverId);
                    if (server == null)
                    {
                        throw new Exception(string.Format("Invalid Server Id : {0}", serverId));
                    }
                }
                UserInfo userInfo = null;
                using (UserInfoRepository userInfoRepository = new UserInfoRepository())
                {
                    userInfo = userInfoRepository.Find(x => x.EmployeeId == employeeId);
                    if (userInfo == null)
                    {
                        throw new Exception(string.Format("User with Employee ID {0} Not Found", employeeId));
                    }
                }
                List <string> serverUserIdList = new List <string>();
                using (UserServerInfoRepository userServerInfoRepository = new UserServerInfoRepository())
                {
                    userServerInfo = userServerInfoRepository.FindLocal(x => x.EmployeeId == employeeId && x.TfsId == serverId);
                    if (userServerInfo == null)
                    {
                        throw new Exception(string.Format("User with employee id : {0} is not registered with server id : {1}", employeeId, serverId));
                    }

                    string test = userServerInfoRepository.Filter(x => employeeIdList.Contains(x.EmployeeId))
                                  .Select(x => x.UserId).Aggregate((current, next) => "'" + current + "' OR ");

                    string credentialHash = userServerInfo.CredentialHash;
                    string url            = server.Url;
                    string query          = "Select * From WorkItems " +
                                            "Where [System.AssignedTo] = @me " +
                                            "AND ([System.State] = 'To Do' OR [System.State] = 'In Progress')"
                                            + "Order By [State] Asc, [Changed Date] Desc";

                    workItems = _teamServerManagementService.GetWorkItemByQuery(query, url, credentialHash);
                }
                foreach (WorkItem workItem in workItems)
                {
                    workItemsDtoList.Add(workItem.ToDto());
                }
                return(workItemsDtoList);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
        }
Пример #2
0
        public WorkItemDto GetWorkItemById(int taskId, int serverId, string userId)
        {
            TeamServer     server         = null;
            UserServerInfo userServerInfo = null;

            try
            {
                using (TeamServerRepository teamServerRepository = new TeamServerRepository())
                {
                    server = teamServerRepository.GetById(serverId);
                    if (server == null)
                    {
                        throw new Exception(string.Format("Invalid Server Id : {0}", serverId));
                    }
                }
                UserInfo userInfo = null;
                using (UserInfoRepository userInfoRepository = new UserInfoRepository())
                {
                    userInfo = userInfoRepository.Find(x => x.UserId != null && x.UserId.ToUpper() == userId.ToUpper());
                    if (userInfo == null)
                    {
                        throw new Exception(string.Format("User with ID {0} Not Found", userId));
                    }
                }

                using (UserServerInfoRepository userServerInfoRepository = new UserServerInfoRepository())
                {
                    userServerInfo = userServerInfoRepository.FindLocal(
                        x => x.UserId != null &&
                        x.UserId.ToUpper() == userId.ToUpper() &&
                        x.TfsId == serverId);
                    if (userServerInfo == null)
                    {
                        throw new Exception(string.Format("User : {0} is not registered with server id : {1}", userId, serverId));
                    }
                    string   credentialHash = userServerInfo.CredentialHash;
                    string   url            = server.Url;
                    WorkItem workItem       = _teamServerManagementService.GetWorkItemById(taskId, url, credentialHash);
                    if (workItem != null)
                    {
                        return(workItem.ToEntity(serverId).ToDto(workItem.Id));
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
        }
Пример #3
0
        public List <WorkItemDto> GetUserIncompleteSyncedTasks(int serverId, string userId)
        {
            TeamServer         server           = null;
            List <WorkItemDto> workItemsDtoList = new List <WorkItemDto>();
            UserServerInfo     userServerInfo   = null;

            try
            {
                using (TeamServerRepository teamServerRepository = new TeamServerRepository())
                {
                    server = teamServerRepository.GetById(serverId);
                    if (server == null)
                    {
                        throw new Exception(string.Format("Invalid Server Id : {0}", serverId));
                    }
                }

                UserInfo userInfo = null;
                using (UserInfoRepository userInfoRepository = new UserInfoRepository())
                {
                    userInfo = userInfoRepository.Find(x => x.UserId == userId);
                    if (userInfo == null)
                    {
                        throw new Exception(string.Format("User with ID {0} Not Found", userId));
                    }
                }

                using (UserServerInfoRepository userServerInfoRepository = new UserServerInfoRepository())
                {
                    userServerInfo = userServerInfoRepository.FindLocal(
                        x => x.UserId == userId &&
                        x.TfsId == serverId
                        );
                    if (userServerInfo == null)
                    {
                        throw new Exception(string.Format("User with id : {0} is not registered with server id : {1}", userId, serverId));
                    }
                }

                string credentialHash = userServerInfo.CredentialHash;
                string url            = server.Url;

                WeekInfo currentWeek = null;
                using (WeekInfoRepository weekInfoRepository = new WeekInfoRepository())
                {
                    currentWeek = weekInfoRepository.GetCurrentWeekInfo();
                    if (currentWeek == null)
                    {
                        throw new Exception("Current Week is not registered.");
                    }
                }
                List <WorkItem> tfsWorkItems = _teamServerManagementService.GetUserIncompleteItems(url, credentialHash);
                using (WorkItemRepository workItemRepository = new WorkItemRepository())
                {
                    foreach (WorkItem item in tfsWorkItems)
                    {
                        // Add new items.
                        UserWorkItem existingWorkItem = workItemRepository.Find(x => x.UserId == userId &&
                                                                                x.WeekId == currentWeek.Id &&
                                                                                x.TaskId == item.Id);
                        if (existingWorkItem == null)
                        {
                            UserWorkItem newWorkItem = item.ToEntity(userServerInfo.TfsId);
                            newWorkItem.UserId     = userId;
                            newWorkItem.AssignedTo = userInfo.FirstName + " " + userInfo.LastName;
                            newWorkItem.WeekId     = currentWeek.Id;
                            int newWorkItemId = workItemRepository.Insert(newWorkItem);

                            workItemsDtoList.Add(newWorkItem.ToDto(newWorkItemId));
                        }
                        else
                        {
                            existingWorkItem.Title       = item.Title;
                            existingWorkItem.Status      = item.State;
                            existingWorkItem.Sprint      = item.IterationPath;
                            existingWorkItem.Project     = item.AreaPath;
                            existingWorkItem.Description = item.Description;

                            workItemRepository.Update(existingWorkItem);
                            workItemsDtoList.Add(existingWorkItem.ToDto(existingWorkItem.Id));
                        }
                    }
                }

                return(workItemsDtoList);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                throw;
            }
        }