Esempio n. 1
0
        public int AddTeamServer(string name, string url, int port)
        {
            try
            {
                TeamServer server = new TeamServer
                {
                    Name = name,
                    Url  = url.ToLower().Trim(),
                    Port = port
                };

                using (TeamServerRepository repository = new TeamServerRepository())
                {
                    TeamServer ts = repository.Find(x => x.Url == server.Url);
                    if (ts == null)
                    {
                        return(repository.Insert(server));
                    }
                    else
                    {
                        throw new Exception("Server already exists.");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
        }
Esempio n. 2
0
        public List <UserServerDto> GetUserServerList(string userId)
        {
            List <UserServerDto> userServerList = new List <UserServerDto>();
            List <UserServerDto> dtoList        = new List <UserServerDto>();

            try
            {
                using (UserServerInfoRepository repository = new UserServerInfoRepository())
                {
                    System.Linq.IQueryable <UserServerInfo> servers = repository.Filter(x => x.UserId == userId);
                    foreach (UserServerInfo server in servers)
                    {
                        UserServerDto dto = new UserServerDto
                        {
                            TfsId  = server.TfsId,
                            UserId = server.UserId
                        };
                        dtoList.Add(dto);
                    }
                }
                using (TeamServerRepository serverRepository = new TeamServerRepository())
                {
                    foreach (UserServerDto server in dtoList)
                    {
                        TeamServer teamServer = serverRepository.Find(x => x.Id == server.TfsId);
                        if (teamServer != null)
                        {
                            server.ServerName = teamServer.Name;
                            server.ServerUrl  = teamServer.Url;

                            userServerList.Add(server);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Failed to get servers for User-Id " + userId);
                throw;
            }
            return(userServerList);
        }
        public List <WorkItemDto> GetUserCurrentWeekSyncedTasks(string userId, bool includeIncompleteItems = true)
        {
            List <WorkItemDto> currentWeekTasks = new List <WorkItemDto>();
            WeekInfo           currentWeek      = null;

            UserInfo currentUser = null;

            using (UserInfoRepository userInfoRepository = new UserInfoRepository())
            {
                currentUser = userInfoRepository.Find(x => x.UserId == userId);
                if (currentUser == null)
                {
                    throw new Exception(string.Format("User Id {0} not found", userId));
                }
            }

            // Get current week.
            using (WeekInfoRepository repository = new WeekInfoRepository())
            {
                currentWeek = repository.GetCurrentWeekInfo();
                if (currentWeek == null)
                {
                    throw new Exception("Current Week is not registered.");
                }
            }

            // Get servers configured for the user.
            List <UserServerInfo> userServers = new List <UserServerInfo>();

            using (UserServerInfoRepository repository = new UserServerInfoRepository())
            {
                userServers = repository.Filter(x => x.UserId == userId).ToList();
            }

            // Get user incomplete tasks from task repository.
            List <int> currentWeekTaskIdList    = new List <int>();
            List <int> currentWeekMovedTaskList = new List <int>();

            foreach (UserServerInfo server in userServers)
            {
                using (WorkItemRepository workItemRepository = new WorkItemRepository())
                {
                    IQueryable <UserWorkItem> currentWeekSavedTasks = workItemRepository
                                                                      .Filter(x => x.ServerId == server.Id &&
                                                                              x.UserId == userId &&
                                                                              x.State != WorkItemState.Moved &&
                                                                              x.WeekId == currentWeek.Id);

                    IQueryable <UserWorkItem> currentWeekMovedTasks = workItemRepository
                                                                      .Filter(x => x.ServerId == server.Id &&
                                                                              x.UserId == userId &&
                                                                              x.State == WorkItemState.Moved &&
                                                                              x.WeekId == currentWeek.Id);

                    currentWeekTaskIdList    = currentWeekSavedTasks.Select(x => x.TaskId).ToList();
                    currentWeekMovedTaskList = currentWeekSavedTasks.Select(x => x.TaskId).ToList();
                }

                TeamServer teamServer = null;
                using (TeamServerRepository repository = new TeamServerRepository())
                {
                    teamServer = repository.Find(x => x.Id == server.TfsId);
                    if (teamServer == null)
                    {
                        continue;
                    }
                }

                // Get all tasks by id including to do items.
                List <WorkItem> userIncompleteItems = _teamServerManagementService
                                                      .GetWorkItemsByIds(currentWeekTaskIdList, teamServer.Url, server.CredentialHash, includeIncompleteItems);
                using (WorkItemRepository workItemRepository = new WorkItemRepository())
                {
                    foreach (WorkItem item in userIncompleteItems)
                    {
                        // 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(server.TfsId);
                            newWorkItem.UserId     = userId;
                            newWorkItem.AssignedTo = currentUser.FirstName + " " + currentUser.LastName;
                            newWorkItem.WeekId     = currentWeek.Id;
                            int newWorkItemId = workItemRepository.Insert(newWorkItem);

                            currentWeekTasks.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);
                            currentWeekTasks.Add(existingWorkItem.ToDto(existingWorkItem.Id));
                        }
                    }
                }
            }
            return(currentWeekTasks);
        }