Exemple #1
0
        public Wallboard()
        {
            InitializeComponent();
            teamFoundationServer.Authenticate();

            VersionControlServer s = (VersionControlServer)teamFoundationServer.GetService(typeof(VersionControlServer));
        }
Exemple #2
0
 public ChangesetInfo(string tfsServer, KnownFileTypes knownFileTypes)
 {
     if (string.IsNullOrWhiteSpace(tfsServer))
     {
         throw new ArgumentNullException("tfsServer", "tfsServer is required");
     }
     _tfs            = Server.GetTfsServer(tfsServer);
     _versionControl = _tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
     _workItemStore  = (WorkItemStore)_tfs.GetService(typeof(WorkItemStore));
     this.Downloader = new WorkItemFileManager(knownFileTypes);
 }
        static void Main(string[] args)
        {
            // Let the user choose a TFS Server.
            Console.Write("Please enter a valid TFS Server or URI: ");
            String tfsServer = Console.ReadLine();

            tfsServer = tfsServer.Trim();

            // Connect to the TeamFoundationServer.
            Console.WriteLine();
            Console.Write("Connecting to Team Foundation Server {0}...", tfsServer);
            TeamFoundationServer tfs =
                TeamFoundationServerFactory.GetServer(tfsServer);

            // Connect to the WorkItemStore.
            Console.WriteLine();
            Console.Write("Reading from the Work Item Store...");
            WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            // Display the details about the TeamFoundationServer.
            Console.WriteLine("\n");
            Console.WriteLine("Team Foundation Server details");
            Console.WriteLine("Server Name: " + tfs.Name);
            Console.WriteLine("Uri: " + tfs.Uri);
            Console.WriteLine("AuthenticatedUserDisplayName: " + tfs.AuthenticatedUserDisplayName);
            Console.WriteLine("AuthenticatedUserName: "******"WorkItemStore:");

            //  List the Projects in the WorkItemStore.
            Console.WriteLine("  Projects.Count: " + workItemStore.Projects.Count);
            foreach (Project pr in workItemStore.Projects)
            {
                Console.WriteLine("    " + pr.Name);
            }
        }
        public VersionControlServer GetVersionControlServer(string url)
        {
            ICredentials         creds = GetCredentials(url);
            TeamFoundationServer tfs   = TeamFoundationServerFactory.GetServer(url, creds);

            return(tfs.GetService(typeof(VersionControlServer)) as VersionControlServer);
        }
Exemple #5
0
        internal static Identity ResolveUser(VSTSConnection vstsConn, string userName)
        {
            Debug.Assert(vstsConn != null, "Null vstsConn handle");
            Debug.Assert(userName != null, "Null userName param");
            if (m_gss == null)
            {
                TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(vstsConn.bisUri);
                m_gss = (IGroupSecurityService)tfs.GetService(typeof(IGroupSecurityService));
            }

            // Get the user identity
            Identity userIdentity = null;

            try
            {
                userIdentity = m_gss.ReadIdentityFromSource(SearchFactor.AccountName, userName);
            }
            catch (Exception ex)
            {
                // if there is some Active Directory issue, currently GSS throws GroupSecuritySubsystemException
                // bug#57749 plans to give specific exception for this..
                // we are handling Exception here as the bug 57749 lists this exception as well
                // as one of the possible exception that can be thrown
                // for this exception assume that the user cannot be resolved
                Logger.Write(LogSource.WorkItemTracking, TraceLevel.Warning, "Could not resolve user {0} because of {1}",
                             userName, ex.Message);
            }
            return(userIdentity);
        }
    public bool Execute()
    {
        // set up support for logging
        TaskLoggingHelper loggingHelper = new TaskLoggingHelper(this);

        // Log Variables
        loggingHelper.LogMessageFromText("Custom Task QueueBuild Starting", MessageImportance.High);
        loggingHelper.LogMessageFromText("tfsServer = " + tfsServer, MessageImportance.High);
        loggingHelper.LogMessageFromText("teamProject = " + teamProject, MessageImportance.High);
        loggingHelper.LogMessageFromText("buildDefinition = " + buildDefinition, MessageImportance.High);
        // Get the team foundation server
        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer);
        // Get the IBuildServer
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        // Get the build definition for which a build is to be queued
        IBuildDefinition buildDef = buildServer.GetBuildDefinition(teamProject, buildDefinition);
        // Create variable for queuedBuild and queue the build
        var queuedBuild = buildServer.QueueBuild(buildDef);

        loggingHelper.LogMessageFromText("Waiting for newly queued build from Team Project : " + teamProject + " : and Build Definition : " + buildDefinition + " : to complete", MessageImportance.High);
        loggingHelper.LogMessageFromText("Pinging queuedBuild : " + queuedBuild + " : every 5 seconds to confirm when build is complete", MessageImportance.High);
        // Wait for the completion of newly queued build - Will ping build every 5 seconds to confirm completion for a max of 5 hours
        queuedBuild.WaitForBuildCompletion(TimeSpan.FromSeconds(5), TimeSpan.FromHours(5));
        loggingHelper.LogMessageFromText("Queued Build : " + queuedBuild.Build.BuildNumber + " has now completed", MessageImportance.High);
        loggingHelper.LogMessageFromText("Returning to original build", MessageImportance.High);
        return(true);
    }
        internal WorkItemThingy(string srvr, string query)
        {
            _server = TeamFoundationServerFactory.GetServer(srvr);
            //_query = query;

            _store = _server.GetService(typeof(WorkItemStore)) as WorkItemStore;
        }
Exemple #8
0
        public void Workspace_GetViaInfo()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // does info.GetWorkspace talk to the server and get the
            // mapped paths or no? ANSWER: NO IT DOESN'T
            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.AreEqual(null, serverItem2);
            w1.Delete();
        }
        /// <summary>
        /// Tries the TFS mode.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>the number of checkedout files</returns>
        internal static int TryTFSMode(System.IO.FileInfo input)
        {
            try
            {
                var tfs       = new TeamFoundationServer(Properties.Settings.Default.TFSServer, new NetworkCredential(Properties.Settings.Default.TFSLogin, Properties.Settings.Default.TFSPassword));
                var version   = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
                var workspace = version.GetWorkspace(Properties.Settings.Default.TFSWorkspace, version.AuthorizedUser);
                int ans       = workspace.PendEdit(input.FullName);
                return(ans);
            }
            catch (Exception)
            {
                Console.WriteLine(
                    string.Format(
                        @"
/!\The file {0} is read only
please make sure the TFS app settings are OK

Stack trace:

",
                        input.FullName));
                throw;
            }
        }
Exemple #10
0
        public void FixtureSetUp()
        {
            tfsUrl = Environment.GetEnvironmentVariable("TFS_URL");
            if (String.IsNullOrEmpty(tfsUrl))
            {
                Console.WriteLine("Warning: Environment variable TFS_URL not set.");
                Console.WriteLine("					Some tests cannot be executed without TFS_URL.");
                return;
            }

            string username = Environment.GetEnvironmentVariable("TFS_USERNAME");

            if (String.IsNullOrEmpty(username))
            {
                Console.WriteLine("Warning: No TFS user credentials specified.");
                return;
            }

            credentials = new NetworkCredential(username,
                                                Environment.GetEnvironmentVariable("TFS_PASSWORD"),
                                                Environment.GetEnvironmentVariable("TFS_DOMAIN"));

            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            versionControlServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            workspace = versionControlServer.CreateWorkspace("WorkspaceTest",
                                                             Environment.GetEnvironmentVariable("TFS_USERNAME"));
        }
Exemple #11
0
        private T GetService <T>()
        {
            #region Tracing
#line hidden
            if (ChangesetWatcher.m_TraceSwitch.TraceVerbose)
            {
                Trace.TraceInformation(
                    "Getting service '{0}' from server '{1}'.",
                    typeof(T),
                    Settings.Default.TeamFoundationServerUrl
                    );
            }
#line default
            #endregion

            TeamFoundationServer server = TeamFoundationServerFactory.GetServer(Settings.Default.TeamFoundationServerUrl);
            T service = (T)server.GetService(typeof(T));

            #region Tracing
#line hidden
            if (ChangesetWatcher.m_TraceSwitch.TraceVerbose)
            {
                Trace.TraceInformation(
                    "Service '{0}' successfully retrieved from server '{1}'.",
                    typeof(T),
                    Settings.Default.TeamFoundationServerUrl
                    );
            }
#line default
            #endregion

            return(service);
        }
Exemple #12
0
        public void Workspace_Get()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            Workspace w2 = vcs.GetWorkspace("CreateDelete1_Workspace");

            Assert.AreEqual("My Comment", w2.Comment);

            w1.Delete();
        }
Exemple #13
0
        public void Workspace_RefreshMappings2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            WorkingFolder[] folders    = new WorkingFolder[1];
            string          serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));

            folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory);

            Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace",
                                               Environment.GetEnvironmentVariable("TFS_USERNAME"),
                                               "My Comment", folders, Environment.MachineName);

            //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME"));

            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory);
            Workspace     w2   = info.GetWorkspace(tfs);

            // this will talk to the server and get the mapped paths
            // BUT it will fail because we don't pass a full path like in RefreshMappings1
            w2.RefreshMappings();

            string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt");

            Assert.IsNull(serverItem2);
            w1.Delete();
        }
Exemple #14
0
        // This method returns proxy interface by the given namespace and proxy type
        internal static object GetProxy(
            string teamSystemName,      // BIS namespace
            Type proxyType)             // Type of proxy to return
        {
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(teamSystemName);

            return(tfs.GetService(proxyType));
        }
 protected override T GetService <T>()
 {
     if (_server == null)
     {
         EnsureAuthenticated();
     }
     return((T)_server.GetService(typeof(T)));
 }
Exemple #16
0
        private void initializeTfsClient()
        {
            TeamFoundationServer tfsServer = TeamFoundationServerFactory.GetServer(
                ConfigurationService.ServerUrl);

            m_tfsClient = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));
            m_analysisServiceContainer.AddService(typeof(VersionControlServer), m_tfsClient);
        }
        /// <summary>
        /// Perform the adapter-specific initialization
        /// </summary>
        public virtual void InitializeClient(MigrationSource migrationSource)
        {
            m_migrationSource = migrationSource;
            TeamFoundationServer tfsServer = TeamFoundationServerFactory.GetServer(migrationSource.ServerUrl);

            m_tfsClient = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));
            m_tfsClient.NonFatalError += new ExceptionEventHandler(NonFatalError);
        }
        private void initializeTfsClient()
        {
            TeamFoundationServer tfsServer = TeamFoundationServerFactory.GetServer(
                m_configurationService.ServerUrl);

            m_tfsClient = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));
            m_tfsClient.NonFatalError += new ExceptionEventHandler(NonFatalError);
        }
Exemple #19
0
 private void SetWorkItemType()
 {
     _tfs = new TeamFoundationServer(_settings.TeamServer);
     _tfs.EnsureAuthenticated();
     _wis = _tfs.GetService(typeof(WorkItemStore)) as WorkItemStore;
     SelectedWorkItemType = _wis.Projects[_settings.TeamProject]
                            .WorkItemTypes[_settings.WorkItemType];
 }
        /// <summary>
        /// Perform the adapter-specific initialization
        /// </summary>
        public virtual void InitializeClient(MigrationSource migrationSource)
        {
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(migrationSource.ServerUrl);

            tfs.Authenticate();

            m_workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            m_projectName = migrationSource.SourceIdentifier;
        }
Exemple #21
0
        private WorkItemStore GetWorkItemStore(string serverUrl)
        {
            Trace.TraceInformation("Connecting to '{0}'", serverUrl);
            TeamFoundationServer tfs = new TeamFoundationServer(serverUrl);
            WorkItemStore        wi  = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            Trace.TraceInformation("Connected to '{0}'", serverUrl);

            return(wi);
        }
Exemple #22
0
        public override bool Execute()
        {
            Server    = ""; //TODO: Fill the TFS Server
            Root      = @"$/DotNetNuke/src/DotNetNuke_CS/";
            Committer = ""; //TODO: Fill the committer username.

#pragma warning disable 612,618
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(Server);
#pragma warning restore 612,618
            var vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            string              path                = Root;
            VersionSpec         version             = VersionSpec.Latest;
            const int           deletionId          = 0;
            const RecursionType recursion           = RecursionType.Full;
            string              user                = null;
            VersionSpec         versionFrom         = null;
            VersionSpec         versionTo           = null;
            const int           maxCount            = 100;
            const bool          includeChanges      = true;
            const bool          slotMode            = true;
            const bool          includeDownloadInfo = true;

            IEnumerable enumerable =
                vcs.QueryHistory(path,
                                 version,
                                 deletionId,
                                 recursion,
                                 user,
                                 versionFrom,
                                 versionTo,
                                 maxCount,
                                 includeChanges,
                                 slotMode,
                                 includeDownloadInfo);


            var c = new List <Changeset>();

            foreach (var i in enumerable)
            {
                var cs = (i as Changeset);
                if (cs != null && cs.Committer != Committer)
                {
                    foreach (var change in cs.Changes)
                    {
                        if (!change.Item.ServerItem.Contains("Professional"))
                        {
                            c.Add(cs);
                        }
                    }
                }
            }
            return(true);
        }
Exemple #23
0
        /// <summary>
        /// Internal helper method to get the service
        /// </summary>
        /// <typeparam name="T">Type of service to retrieve</typeparam>
        /// <param name="credentials">Credentials to use when connecting the service</param>
        /// <returns></returns>
        private static T GetService <T>(ICredentials credentials)
        {
            TempCredentials creds = new TempCredentials(credentials);
            string          teamFoundationServerUrl = Settings.Default.TeamFoundationServerUrl;

            TraceHelper.TraceVerbose(Constants.CommonSwitch, "Connecting to server {0} To get service {1} ", teamFoundationServerUrl, typeof(T).ToString());
            TeamFoundationServer server = TeamFoundationServerFactory.GetServer(teamFoundationServerUrl, creds);
            T service = (T)server.GetService(typeof(T));

            return(service);
        }
Exemple #24
0
        public void ConnectToTfsServer(string hostname, string teamCollection, string projectName, string buildDefinitionName = null)
        {
            _hostname = hostname;

            _isWebServer = _hostname.Contains("://");
            try
            {
                string url;
                if (_isWebServer)
                {
                    _hostname  = _hostname.TrimEnd('\\', '/');
                    url        = _hostname + "/" + teamCollection;
                    _urlPrefix = hostname + "/" + teamCollection + "/" + projectName + "/_build#buildUri=";
                }
                else
                {
                    url        = "http://" + _hostname + ":8080/tfs/" + teamCollection;
                    _urlPrefix = "http://" + hostname + ":8080/tfs/Build/Build.aspx?artifactMoniker=";
                }

                // Get a connection to the desired Team Foundation Server
                _tfServer = TeamFoundationServerFactory.GetServer(url, new UICredentialsProvider());

                // Get a reference to a build service
                _buildServer = _tfServer.GetService <IBuildServer>();

                // Retrieve a list of build definitions
                var buildDefs = _buildServer.QueryBuildDefinitions(projectName);

                if (buildDefs.Length != 0)
                {
                    if (string.IsNullOrWhiteSpace(buildDefinitionName))
                    {
                        _buildDefinition = buildDefs[0];
                    }
                    else
                    {
                        foreach (var buildDefinition in buildDefs)
                        {
                            if (string.Compare(buildDefinition.Name, buildDefinitionName, true) == 0)
                            {
                                _buildDefinition = buildDefinition;
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
        public void GetService_VersionControlServer()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            Assert.IsNotNull(vcs);
        }
Exemple #26
0
        private static WorkItemType GetWorkItemType(string serverName, string teamProjectName, string witName)
        {
            string serverUrl = string.Format("http://{0}:8080", serverName);

            TeamFoundationServer tfsServer = TeamFoundationServerFactory.GetServer(serverUrl);
            WorkItemStore        wis       = (WorkItemStore)tfsServer.GetService(typeof(WorkItemStore));

            Project project = wis.Projects[teamProjectName];

            Debug.Assert(project != null);

            return(project.WorkItemTypes[witName]);
        }
Exemple #27
0
    private int GetLatestChangeSet(string url, string project)
    {
        project = string.Format(@"$/{0}", project);

        var server  = new TeamFoundationServer(new Uri(url));
        var version = server.GetService <VersionControlServer>();

        var workspace = version.QueryWorkspaces(null, WindowsIdentity.GetCurrent().Name, System.Environment.MachineName).First();
        var folder    = workspace.Folders.First(f => f.ServerItem == project);

        return(workspace.GetLocalVersions(new[] { new ItemSpec(folder.LocalItem, RecursionType.Full) }, false)
               .SelectMany(lv => lv.Select(l => l.Version)).Max());
    }
        static public WorkItemCollection QueryWorkItems(string server, string projectname)
        {
            TeamFoundationServer tfs           = TeamFoundationServerFactory.GetServer(server);
            WorkItemStore        workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
            Project p         = workItemStore.Projects[projectname];
            string  wiqlQuery = "Select * from Issue where [System.TeamProject] = '" + projectname + "'";

            wiqlQuery += " and [System.State] <> 'Deleted'";
            wiqlQuery += " order by ID";
            WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);

            return(witCollection);
        }
        private void PopulateProjects()
        {
            TeamProjectDropDown.Items.Clear();
            TeamFoundationServer    tfs = TeamFoundationServerFactory.GetServer(lblServerUri.Text);
            ICommonStructureService projectCollection =
                (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));

            foreach (ProjectInfo projectInfo in projectCollection.ListProjects())
            {
                TeamProjectDropDown.Items.Add(projectInfo.Name);
            }
            TeamProjectDropDown.Enabled = true;
        }
Exemple #30
0
        private void BuildStoreWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TeamFoundationServer server = new TeamFoundationServer(_teamFoundationServerUri, CredentialCache.DefaultCredentials);

            server.EnsureAuthenticated();

            while (!this.CancellationPending)
            {
                BuildStore  store  = (BuildStore)server.GetService(typeof(BuildStore));
                BuildData[] builds = store.GetListOfBuilds(_teamProjectName, _teamBuildTypeName);
                this.ReportProgress(0, builds);
                Thread.Sleep(30000);
            }
        }