本文整理汇总了C#中TfsTeamProjectCollection类的典型用法代码示例。如果您正苦于以下问题:C# TfsTeamProjectCollection类的具体用法?C# TfsTeamProjectCollection怎么用?C# TfsTeamProjectCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TfsTeamProjectCollection类属于命名空间,在下文中一共展示了TfsTeamProjectCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareLocal
/// <summary>
/// Compares changesets
/// </summary>
/// <param name="localPath"></param>
/// <param name="sourceChangesetId">Source changeset Id</param>
/// <param name="serverUrl">Server Uri</param>
/// <param name="srcPath">Source item path</param>
public static void CompareLocal(string localPath, string sourceChangesetId, string serverUri, string srcPath)
{
if (String.IsNullOrWhiteSpace(sourceChangesetId))
throw new ArgumentException("'sourceChangesetId' is null or empty.");
if (String.IsNullOrWhiteSpace(serverUri))
throw new TfsHistorySearchException("'serverUri' is null or empty.");
if (String.IsNullOrWhiteSpace(srcPath))
throw new TfsHistorySearchException("'srcPath' is null or empty.");
if (String.IsNullOrWhiteSpace(localPath))
throw new TfsHistorySearchException("'localPath' is null or empty.");
TfsTeamProjectCollection tc = new TfsTeamProjectCollection(new Uri(serverUri));
VersionControlServer vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;
//VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);
VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.AuthorizedUser);
//VersionSpec targetVersion = VersionSpec.ParseSingleSpec(targetChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);
//Difference.DiffFiles(
Difference.VisualDiffItems(vcs, Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion), Difference.CreateTargetDiffItem(vcs, localPath, null, 0, null));
//Difference.VisualDiffFiles();
//Difference.VisualDiffItems(vcs,
// Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion),
// Difference.CreateTargetDiffItem(vcs, targetPath, targetVersion, 0, targetVersion));
}
示例2: Connect
public override void Connect(string serverUri, string remotePath, string localPath, int fromChangeset, string tfsUsername, string tfsPassword, string tfsDomain)
{
this._serverUri = new Uri(serverUri);
this._remotePath = remotePath;
this._localPath = localPath;
this._startingChangeset = fromChangeset;
try
{
NetworkCredential tfsCredential = new NetworkCredential(tfsUsername, tfsPassword, tfsDomain);
//this._teamFoundationServer = new Microsoft.TeamFoundation.Client.TeamFoundationServer(this._serverUri, tfsCredential);
this._tfsProjectCollection = new TfsTeamProjectCollection(this._serverUri, tfsCredential);
this._versionControlServer = this._tfsProjectCollection.GetService<VersionControlServer>();
}
catch (Exception ex)
{
throw new Exception("Error connecting to TFS", ex);
}
//clear hooked eventhandlers
BeginChangeSet = null;
EndChangeSet = null;
FileAdded = null;
FileEdited = null;
FileDeleted = null;
FileUndeleted = null;
FileBranched = null;
FileRenamed = null;
FolderAdded = null;
FolderDeleted = null;
FolderUndeleted = null;
FolderBranched = null;
FolderRenamed = null;
ChangeSetsFound = null;
}
示例3: GetLastButOneRevision
public string GetLastButOneRevision()
{
var collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.FuncTestCollection));
var vcs = collection.GetService<VersionControlServer>();
TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.FuncTestsProject);
var changesets = vcs.QueryHistory(
tp.ServerItem,
VersionSpec.Latest,
0,
RecursionType.Full,
null,
null,
null,
Int32.MaxValue,
true,
true).Cast<Changeset>().ToArray();
collection.Dispose();
if (changesets.Count() == 1)
return changesets.First().ChangesetId.ToString();
int lastButOneChangeset = changesets.Where(x => x.ChangesetId < changesets.Max(m => m.ChangesetId)).Max(x => x.ChangesetId);
return lastButOneChangeset.ToString(CultureInfo.InvariantCulture);
}
示例4: ConnectToTfsCollection
private TfsTeamProjectCollection ConnectToTfsCollection()
{
var tfsCredentials = GetTfsCredentials();
foreach (var credentials in tfsCredentials)
{
try
{
Logger.InfoFormat("Connecting to TFS {0} using {1} credentials", _config.TfsServerConfig.CollectionUri, credentials);
var tfsServer = new TfsTeamProjectCollection(new Uri(_config.TfsServerConfig.CollectionUri), credentials);
tfsServer.EnsureAuthenticated();
Logger.InfoFormat("Successfully connected to TFS");
return tfsServer;
}
catch (Exception ex)
{
Logger.WarnFormat("TFS connection attempt failed.\n Exception: {0}", ex);
}
}
Logger.ErrorFormat("All TFS connection attempts failed");
throw new Exception("Cannot connect to TFS");
}
示例5: WorkItemQueryServiceModel
public WorkItemQueryServiceModel(ITeamPilgrimServiceModelProvider teamPilgrimServiceModelProvider, ITeamPilgrimVsService teamPilgrimVsService, TfsTeamProjectCollection projectCollection, Project project)
: base(teamPilgrimServiceModelProvider, teamPilgrimVsService)
{
_projectCollection = projectCollection;
_project = project;
QueryItems = new ObservableCollection<WorkItemQueryChildModel>();
NewWorkItemCommand = new RelayCommand<string>(NewWorkItem, CanNewWorkItem);
GoToWorkItemCommand = new RelayCommand(GoToWorkItem, CanGoToWorkItem);
NewQueryDefinitionCommand = new RelayCommand<WorkItemQueryFolderModel>(NewQueryDefinition, CanNewQueryDefinition);
NewQueryFolderCommand = new RelayCommand<WorkItemQueryFolderModel>(NewQueryFolder, CanNewQueryFolder);
OpenQueryDefinitionCommand = new RelayCommand<WorkItemQueryDefinitionModel>(OpenQueryDefinition, CanOpenQueryDefinition);
EditQueryDefinitionCommand = new RelayCommand<WorkItemQueryDefinitionModel>(EditQueryDefinition, CanEditQueryDefinition);
DeleteQueryItemCommand = new RelayCommand<WorkItemQueryChildModel>(DeleteQueryDefinition, CanDeleteQueryDefinition);
OpenSeurityDialogCommand = new RelayCommand<WorkItemQueryChildModel>(OpenSeurityDialog, CanOpenSeurityDialog);
_populateBackgroundWorker = new BackgroundWorker();
_populateBackgroundWorker.DoWork +=PopulateBackgroundWorkerOnDoWork;
_populateBackgroundWorker.RunWorkerAsync();
}
示例6: Close
public void Close(string itemId, string comment)
{
using (var collection = new TfsTeamProjectCollection(locator.Location))
{
var workItemId = int.Parse(itemId);
var workItemStore = new WorkItemStore(collection, WorkItemStoreFlags.BypassRules);
var workItem = workItemStore.GetWorkItem(workItemId);
var workItemDefinition = workItem.Store.Projects[workItem.Project.Name].WorkItemTypes[workItem.Type.Name];
if (workItemDefinition == null)
{
throw new ArgumentException("Could not obtain work item definition to close work item");
}
var definitionDocument = workItemDefinition.Export(false).InnerXml;
var xDocument = XDocument.Parse(definitionDocument);
var graphBuilder = new StateGraphBuilder();
var stateGraph = graphBuilder.BuildStateGraph(xDocument);
var currentStateNode = stateGraph.FindRelative(workItem.State);
var graphWalker = new GraphWalker<string>(currentStateNode);
var shortestWalk = graphWalker.WalkToNode("Closed");
foreach (var step in shortestWalk.Path)
{
workItem.State = step.Value;
workItem.Save();
}
workItem.Fields[CoreField.Description].Value = comment + "<br /><br/>" + workItem.Fields[CoreField.Description].Value;
workItem.Save();
}
}
示例7: GetDropDownloadPath
private static string GetDropDownloadPath(TfsTeamProjectCollection collection, IBuildDetail buildDetail)
{
string droplocation = buildDetail.DropLocation;
if (string.IsNullOrEmpty(droplocation))
{
throw new FailingBuildException(string.Format(CultureInfo.CurrentCulture, "No drop is available for {0}.", buildDetail.BuildNumber));
}
ILocationService locationService = collection.GetService<ILocationService>();
string containersBaseAddress = locationService.LocationForAccessMapping(ServiceInterfaces.FileContainersResource, FrameworkServiceIdentifiers.FileContainers, locationService.DefaultAccessMapping);
droplocation = BuildContainerPath.Combine(droplocation, string.Format(CultureInfo.InvariantCulture, "{0}.zip", buildDetail.BuildNumber));
try
{
long containerId;
string itemPath;
BuildContainerPath.GetContainerIdAndPath(droplocation, out containerId, out itemPath);
string downloadPath = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", containersBaseAddress, containerId, itemPath.TrimStart('/'));
return downloadPath;
}
catch (InvalidPathException)
{
throw new FailingBuildException(string.Format(CultureInfo.CurrentCulture, "No drop is available for {0}.", buildDetail.BuildNumber));
}
}
示例8: GetTestCaseParameters
/// <summary>
/// Get the parameters of the test case
/// </summary>
/// <param name="testCaseId">Test case id (work item id#) displayed into TFS</param>
/// <returns>Returns the test case parameters in datatable format. If there are no parameters then it will return null</returns>
public static DataTable GetTestCaseParameters(int testCaseId)
{
ITestManagementService TestMgrService;
ITestCase TestCase = null;
DataTable TestCaseParameters = null;
NetworkCredential netCred = new NetworkCredential(
Constants.TFS_USER_NAME,
Constants.TFS_USER_PASSWORD);
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(
new Uri(Constants.TFS_URL),
tfsCred);
teamProjectCollection.Authenticate();
TestMgrService = teamProjectCollection.GetService<ITestManagementService>();
TestCase = TestMgrService.GetTeamProject(Constants.TFS_PROJECT_NAME).TestCases.Find(testCaseId);
if (TestCase != null)
{
if (TestCase.Data.Tables.Count > 0)
{
TestCaseParameters = TestCase.Data.Tables[0];
}
}
return TestCaseParameters;
}
示例9: ProcessRecord
protected override void ProcessRecord()
{
using (var collection = new TfsTeamProjectCollection(CollectionUri))
{
var cssService = collection.GetService<ICommonStructureService4>();
var projectInfo = cssService.GetProjectFromName(TeamProject);
var teamService = collection.GetService<TfsTeamService>();
var tfsTeam = teamService.ReadTeam(projectInfo.Uri, Team, null);
if (tfsTeam == null)
{
WriteError(new ErrorRecord(new ArgumentException(string.Format("Team '{0}' not found.", Team)), "", ErrorCategory.InvalidArgument, null));
return;
}
var identityService = collection.GetService<IIdentityManagementService>();
var identity = identityService.ReadIdentity(IdentitySearchFactor.AccountName, Member, MembershipQuery.Direct, ReadIdentityOptions.None);
if (identity == null)
{
WriteError(new ErrorRecord(new ArgumentException(string.Format("Identity '{0}' not found.", Member)), "", ErrorCategory.InvalidArgument, null));
return;
}
identityService.AddMemberToApplicationGroup(tfsTeam.Identity.Descriptor, identity.Descriptor);
WriteVerbose(string.Format("Identity '{0}' added to team '{1}'", Member, Team));
}
}
示例10: MyTfsProjectCollection
public MyTfsProjectCollection(CatalogNode teamProjectCollectionNode, TfsConfigurationServer tfsConfigurationServer, NetworkCredential networkCredential)
{
try
{
Name = teamProjectCollectionNode.Resource.DisplayName;
ServiceDefinition tpcServiceDefinition = teamProjectCollectionNode.Resource.ServiceReferences["Location"];
var configLocationService = tfsConfigurationServer.GetService<ILocationService>();
var tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));
_tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri, new MyCredentials(networkCredential));
_commonStructureService = _tfsTeamProjectCollection.GetService<ICommonStructureService>();
_buildServer = _tfsTeamProjectCollection.GetService<IBuildServer>();
_tswaClientHyperlinkService = _tfsTeamProjectCollection.GetService<TswaClientHyperlinkService>();
CurrentUserHasAccess = true;
}
catch (TeamFoundationServiceUnavailableException ex)
{
_log.Debug("Can't access " + Name + ". This could be because the project collection is currently offline.", ex);
CurrentUserHasAccess = false;
}
catch (TeamFoundationServerUnauthorizedException ex)
{
_log.Debug("Unauthorized access to " + teamProjectCollectionNode, ex);
CurrentUserHasAccess = false;
}
}
示例11: SetConfiguration
public void SetConfiguration(ConfigurationBase newConfiguration)
{
if (timer != null)
{
timer.Change(Timeout.Infinite, Timeout.Infinite);
}
configuration = newConfiguration as TeamFoundationConfiguration;
if (configuration == null)
{
throw new ApplicationException("Configuration can not be null.");
}
var credentialProvider = new PlainCredentialsProvider(configuration.Username, configuration.Password);
var teamProjectCollection = new TfsTeamProjectCollection(new Uri(configuration.CollectionUri), credentialProvider);
buildServer = teamProjectCollection.GetService<IBuildServer>();
if (timer == null)
{
timer = new Timer(Tick, null, 0, configuration.PollInterval);
}
else
{
timer.Change(0, configuration.PollInterval);
}
}
示例12: Main
static void Main(string[] args)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("https://code-inside.visualstudio.com/DefaultCollection"));
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
//Following will get all changesets since 365 days. Note : "DateVersionSpec(DateTime.Now - TimeSpan.FromDays(20))"
System.Collections.IEnumerable history = vcs.QueryHistory("$/Grocerylist",
LatestVersionSpec.Instance,
0,
RecursionType.Full,
null,
new DateVersionSpec(DateTime.Now - TimeSpan.FromDays(365)),
LatestVersionSpec.Instance,
Int32.MaxValue,
true,
false);
foreach (Changeset changeset in history)
{
Console.WriteLine("Changeset Id: " + changeset.ChangesetId);
Console.WriteLine("Owner: " + changeset.Owner);
Console.WriteLine("Date: " + changeset.CreationDate.ToString());
Console.WriteLine("Comment: " + changeset.Comment);
Console.WriteLine("-------------------------------------");
}
Console.ReadLine();
}
示例13: GetProject
/// <summary>
/// Selects the target Team Project containing the migrated test cases.
/// </summary>
/// <param name="serverUrl">URL of TFS Instance</param>
/// <param name="project">Name of Project within the TFS Instance</param>
/// <returns>The Team Project</returns>
private static ITestManagementTeamProject GetProject(string serverUrl, string project)
{
var uri = new System.Uri(serverUrl);
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(uri);
ITestManagementService tms = tfs.GetService<ITestManagementService>();
return tms.GetTeamProject(project);
}
示例14: Main
/// <summary>
/// Main Execution. UI handled in separate method, as this is a procedural utility.
/// </summary>
/// <param name="args">Not used</param>
private static void Main(string[] args)
{
string serverUrl, destProjectName, plansJSONPath, logPath, csvPath;
UIMethod(out serverUrl, out destProjectName, out plansJSONPath, out logPath, out csvPath);
teamCollection = new TfsTeamProjectCollection(new Uri(serverUrl));
workItemStore = new WorkItemStore(teamCollection);
Trace.Listeners.Clear();
TextWriterTraceListener twtl = new TextWriterTraceListener(logPath);
twtl.Name = "TextLogger";
twtl.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;
ConsoleTraceListener ctl = new ConsoleTraceListener(false);
ctl.TraceOutputOptions = TraceOptions.DateTime;
Trace.Listeners.Add(twtl);
Trace.Listeners.Add(ctl);
Trace.AutoFlush = true;
// Get Project
ITestManagementTeamProject newTeamProject = GetProject(serverUrl, destProjectName);
// Get Test Plans in Project
ITestPlanCollection newTestPlans = newTeamProject.TestPlans.Query("Select * From TestPlan");
// Inform user which Collection/Project we'll be working in
Trace.WriteLine("Executing alignment tasks in collection \"" + teamCollection.Name
+ "\",\n\tand Destination Team Project \"" + newTeamProject.TeamProjectName + "\"...");
// Get and print all test case information
GetAllTestPlanInfo(newTestPlans, plansJSONPath, logPath, csvPath);
Console.WriteLine("Alignment completed. Check log file in:\n " + logPath
+ "\nfor missing areas or other errors. Press enter to close.");
Console.ReadLine();
}
示例15: EnsureTfs
private void EnsureTfs(bool allowCache = true)
{
if (_tfs != null)
return;
if (allowCache)
{
var tfsFromCache = HttpRuntime.Cache[CacheKey] as TfsTeamProjectCollection;
if (tfsFromCache != null)
{
_tfs = tfsFromCache;
return;
}
}
lock (_CacheLock)
{
if (allowCache && _tfs != null)
return;
_tfs = new TfsTeamProjectCollection(
new Uri(_principal.TfsUrl), _principal.GetCredentialsProvider());
//new Uri(_principal.TfsUrl), CredentialCache.DefaultCredentials, _principal.GetCredentialsProvider());
HttpRuntime.Cache.Add(
CacheKey,
_tfs,
null,
Cache.NoAbsoluteExpiration,
new TimeSpan(1, 0, 0),
CacheItemPriority.Normal,
null);
}
}