我使用TFS API,现在我需要向用户显示有关Workspace.CheckIn方法结果的消息。
public int? CheckInPendingChanges(PendingChange[] pendingChanges, string comments)
{
using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConstTfsServerUri)))
{
if (pc == null) return null;
WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(ConstDefaultFlowsTfsPath);
Workspace workspace = workspaceInfo?.GetWorkspace(pc);
try
{
int? result = workspace?.CheckIn(pendingChanges, comments);
return result;
}
catch (CheckinException exception)
{
UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(exception.Message, "Check in exception has happened", MessageBoxButton.OK, MessageBoxImage.Error));
return null;
}
catch (VersionControlException exception)
{
UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(exception.Message, "Version Control Exception has happened", MessageBoxButton.OK, MessageBoxImage.Error));
return null;
}
}
}
但是我还没有找到有关它的全面信息。我刚刚发现它应该在成功的情况下返回变更集的ID。另外,我发现这篇文章: https://blogs.msdn.microsoft.com/buckh/2006/09/18/vc-api-checkin-may-return-0/ 它解释了CheckIn返回" 0"如果您的文件没有更改,TFS撤消它。 但是如果它返回-1并且为空则意味着什么呢?
答案 0 :(得分:0)
检查Workspace.CheckIn Method的备注:
每次登记都是原子操作。签入所有更改,或者都没有。如果签入成功,则此方法返回正变更集编号。如果签入的挂起更改集为空,则服务器会尝试检入工作空间中的所有更改。但是,如果编辑或添加工作空间中的任何挂起更改,则此操作无效,因为内容不会上载到服务器。
答案 1 :(得分:0)
根据从不同来源收集的信息,我向用户显示不同的消息:
public int? CheckInPendingChanges(PendingChange[] pendingChanges, string comments)
{
using (TfsTeamProjectCollection pc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConstTfsServerUri)))
{
if (pc == null) return null;
WorkspaceInfo workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(ConstDefaultFlowsTfsPath);
Workspace workspace = workspaceInfo?.GetWorkspace(pc);
try
{
int? result = workspace?.CheckIn(pendingChanges, comments);
return result;
}
catch (CheckinException exception)
{
UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(exception.Message, "Check in exception has happened", MessageBoxButton.OK, MessageBoxImage.Error));
return null;
}
catch (VersionControlException exception)
{
UIHelper.Instance.RunOnUiThread(() => MessageBox.Show(exception.Message, "Version Control Exception has happened", MessageBoxButton.OK, MessageBoxImage.Error));
return null;
}
}
}
1)如果结果为null或否定 - 我认为它是异常:
if (result < 0||result == null)
{
MessageBox.Show("Check in has failed due to internal Error", "Error", MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
2)如果结果为0,我认为它已经执行了撤销:
if (0 == result)
{
MessageBox.Show("The version control server automatically undoed the pending changes due to attempt to check in files that haven’t changed.", "No changes have been detected in your check in", MessageBoxButton.OK,
MessageBoxImage.Information);
ChangeSourceControlOperation(SourceControlOperations.Undo, currentVm);
}
3)。如果结果是肯定的,我认为这是TFS的成功结果:
if (result > 0)
{
//TODO: show changeset id or what ever
}
如果我错了,请纠正我。