2012-02-10 22 views
7

¿Hay alguna manera de obtener la última versión del conjunto de cambios mediante programación en general?Obtenga el último número de cheque (último ID del conjunto de cambios)

Es bastante fácil conseguir Identificación del conjunto de cambios de cierto archivo:

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://my.tfs.com/DefaultCollection")); 
     tfs.EnsureAuthenticated(); 
     var vcs = tfs.GetService<VersionControlServer>(); 

y luego llamar GetItems o QueryHistory, pero me gustaría saber cuál fue el último número de registro.

Respuesta

9

Puede hacerlo de esta manera:

var latestChangesetId = 
    vcs.QueryHistory(
     "$/", 
     VersionSpec.Latest, 
     0, 
     RecursionType.Full, 
     String.Empty, 
     VersionSpec.Latest, 
     VersionSpec.Latest, 
     1, 
     false, 
     true) 
     .Cast<Changeset>() 
     .Single() 
     .ChangesetId; 
+5

Parece VersionControlServer también tiene un método GetLatestChangesetId. Es mucho más corto :-) – tbaskan

+0

podemos pasar el nombre de usuario y pwd para la siguiente conexión tfs 'var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection (new Uri (tfsServer)); tfs.Connect (ConnectOptions.None); ' bcoz después de implementar mis páginas web en el servidor IIS. No puedo obtener los detalles de tfs, pero para el servidor local puedo obtener los detalles de tfs para las mismas páginas web. obtengo menos de Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: No tiene autorización para acceder a http: // tfsserver: 8080/tfs/mycollection. en Microsoft.TeamFoundation.Client.TfsConnection.ThrowAuthorizationException (Exception e) – picnic4u

+0

@ picnic4u probablemente sea la mejor pregunta sobre eso. – DaveShaw

0

utilizo siguiente comando tf para este

/// <summary> 
    /// Return last check-in History of a file 
    /// </summary> 
    /// <param name="filename">filename for which history is required</param> 
    /// <returns>TFS history command</returns> 
    private string GetTfsHistoryCommand(string filename) 
    { 
     //tfs history command (return only one recent record stopafter:1) 
     return string.Format("history /stopafter:1 {0} /noprompt", filename); // return recent one row 
    } 

después de la ejecución que analizar la salida de este comando para obtener el número de cambios

using (StreamReader Output = ExecuteTfsCommand(GetTfsHistoryCommand(fullFilePath))) 
     { 
      string line; 
      bool foundChangeSetLine = false; 
      Int64 latestChangeSet; 
      while ((line = Output.ReadLine()) != null) 
      { 
       if (foundChangeSetLine) 
       { 
        if (Int64.TryParse(line.Split(' ').First().ToString(), out latestChangeSet)) 
        { 
         return latestChangeSet; // this is the lastest changeset number of input file 
        } 
       } 
       if (line.Contains("-----"))  // output stream contains history records after "------" row 
        foundChangeSetLine = true; 
      } 
     } 

Esto cómo ejecutar el comando

/// <summary> 
    /// Executes TFS commands by setting up TFS environment 
    /// </summary> 
    /// <param name="commands">TFS commands to be executed in sequence</param> 
    /// <returns>Output stream for the commands</returns> 
    private StreamReader ExecuteTfsCommand(string command) 
    { 
     logger.Info(string.Format("\n Executing TFS command: {0}",command)); 
     Process process = new Process(); 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.FileName = _tFPath; 
     process.StartInfo.UseShellExecute = false; 
     process.StartInfo.RedirectStandardOutput = true; 
     process.StartInfo.RedirectStandardInput = true; 
     process.StartInfo.Arguments = command; 
     process.StartInfo.RedirectStandardError = true; 
     process.Start(); 
     process.WaitForExit();            // wait until process finishes 
     // log the error if there's any 
     StreamReader errorReader = process.StandardError; 
     if(errorReader.ReadToEnd()!="") 
      logger.Error(string.Format(" \n Error in TF process execution ", errorReader.ReadToEnd())); 
     return process.StandardOutput; 
    } 

No es una manera eficiente, pero sigue siendo una solución, esto funciona en TFS 2008, espero que esto ayude.

1

Uso VersionControlServer.GetLatestChangesetId para obtener la última Identificación del conjunto de cambios, como se ha mencionado por el usuario tbaskan en los comentarios.

(TFS En el SDK Java Es VersionControlClient.getLatestChangesetId)

Cuestiones relacionadas