示例#1
0
        internal UserContext()
        {
            if (String.IsNullOrEmpty(AppSettings.TfsServer))
                throw new ArgumentNullException("The TfsServer settings are not specified, please set it in config file");

            if (String.IsNullOrEmpty(AppSettings.DefaultProjectName))
                throw new ArgumentNullException("The DefaultProjectName settings is empty, please set it in the config file");

            // Connect to TFS
            _users = new List<string>();

            NetworkCredential credentials = new NetworkCredential("login", "password", "domain");
            TfsCollection = new TfsTeamProjectCollection(new Uri(AppSettings.TfsServer), credentials);

            ICredentials creadentials = TfsCollection.Credentials;

            //TfsCollection.Authenticate();
            WorkItemStore = new WorkItemStore(TfsCollection);
            VersionControlServer = TfsCollection.GetService<VersionControlServer>();

            // Get the current username, and load their settings
            Name = TfsCollection.AuthorizedIdentity.DisplayName;
            Id = TfsCollection.AuthorizedIdentity.TeamFoundationId;

            Settings = new UserSettings(Id);
            Settings.Name = Name;

            // Set the current project and the view settings
            if (String.IsNullOrEmpty(Settings.ProjectName) || !WorkItemStore.Projects.Contains(Settings.ProjectName))
            {
                ChangeCurrentProject(AppSettings.DefaultProjectName);
            }
            else
            {
                _projectName = Settings.ProjectName;
                CurrentProject = new ProjectDetails(WorkItemStore.Projects[_projectName]);
            }

            PopulateProjectNames();
            PopulateUsers();
        }
示例#2
0
        private void ChangeCurrentProject(string projectName)
        {
            if (String.IsNullOrWhiteSpace(projectName))
                throw new ArgumentNullException("The project name was null or empty");

            if (!WorkItemStore.Projects.Contains(projectName))
                throw new InvalidOperationException(string.Format("The project {0} doesn't exist", projectName));

            _projectName = projectName;
            CurrentProject = new ProjectDetails(WorkItemStore.Projects[projectName]);

            Settings.ProjectName = projectName;
            Settings.IterationName = CurrentProject.Iterations[0].Name;
            Settings.IterationPath = CurrentProject.Iterations[0].Path;
        }