public string Commit(string serverItemPath, string changedContent, string commitComment) { TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.FuncTestCollection)); var vcs = collection.GetService <VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.FuncTestsProject); ItemSet itemSet = vcs.GetItems(tp.ServerItem, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File); Item item = itemSet.Items.FirstOrDefault(x => x.ServerItem == serverItemPath); string localItem = _workspace.GetLocalItemForServerItem(item.ServerItem); int changesetId = _workspace.PendEdit(localItem); using (var file = File.OpenWrite(localItem)) { var changes = new UTF8Encoding(true).GetBytes(changedContent); file.Seek(0, SeekOrigin.End); file.Write(changes, 0, changes.Length); } PendingChange[] pendingChanges = _workspace.GetPendingChanges().Where(x => x.ChangeType == ChangeType.Edit).ToArray(); int changeset = _workspace.CheckIn(pendingChanges, ConfigHelper.Instance.Login, commitComment, null, null, null); Changeset latestChangeset = vcs.GetChangeset(changeset); collection.Dispose(); return(latestChangeset.ChangesetId.ToString(CultureInfo.InvariantCulture)); }
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)); }
public void Disconnect() { _projectCollection?.Dispose(); _configurationServer?.Dispose(); ClearBranchPaths(); IsConnected = false; }
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); }
protected virtual void Dispose(bool disposing) { if (disposing) { _collection.Dispose(); } }
public static bool CollectionExists(Uri collectionUri, ICredentials credentials, out bool isAuthorized) { TfsTeamProjectCollection collection = null; try { collection = new TfsTeamProjectCollection(collectionUri, credentials); collection.EnsureAuthenticated(); isAuthorized = true; return true; } catch (TeamFoundationServerUnauthorizedException) { isAuthorized = false; return true; } catch { isAuthorized = false; return false; } finally { collection.Dispose(); collection = null; } }
public void Dispose() { _buildServer = null; _tfsCollection?.Dispose(); _buildDefinitions = null; GC.Collect(); }
/// <summary> /// Cierra la conexión /// </summary> public void Close() { if (tfsTeamProject != null) { tfsTeamProject.Dispose(); tfsTeamProject = null; } }
public void Disconnect() { if (collection != null) { collection.Disconnect(); collection.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { m_tpc.Dispose(); } base.Dispose(disposing); }
private void btnConnectTfs_Click(object sender, EventArgs e) { _projectDict.Clear(); Uri tfsUri = new Uri(tbTfsUri.Text); if (null != _tfsServer) { _tfsServer.Dispose(); } _tfsServer = new TfsTeamProjectCollection(tfsUri); WorkItemStore workstore = _tfsServer.GetService <WorkItemStore>(); foreach (Project project in workstore.Projects) { _projectDict.Add(project.Name, project); listBoxProjects.Items.Add(project.Name); } }
public void Dispose() { _buildServer = null; _tfsCollection?.Dispose(); _buildDefinitions = null; _buildDefinitions2015 = null; _connection = null; _buildClient = null; GC.Collect(); }
public void Dispose() { _connection.Dispose(); _projectHttpClient.Dispose(); _workItemTrackingHttpClient.Dispose(); _gitHttpClient.Dispose(); _processHttpClient.Dispose(); _buildHttpClient.Dispose(); _httpClient.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposing == true) { //someone want the deterministic release of all resources //Let us release all the managed resources _TfsTeamProjectCollection.Dispose(); } else { // Do nothing, no one asked a dispose, the object went out of // scope and finalized is called so lets next round of GC // release these resources } // Release the unmanaged resource in any case as they will not be // released by GC _TfsTeamProjectCollection.Dispose(); }
public void Dispose() { _buildServer = null; if (_tfsCollection != null) { _tfsCollection.Dispose(); } _buildDefinition = null; GC.Collect(); }
public void Dispose() { if (this.IsDisposed) { return; } _teamProjectCollection.Dispose(); this.IsDisposed = true; }
public void Disconnect() { if (!IsAuthenticated) { return; } _tfs.Disconnect(); _tfs.Dispose(); _tfs = null; }
protected virtual void Dispose(bool disposing) { if (!disposed && disposing && teamProjectCollection != null) { build.Save(); teamProjectCollection.Dispose(); teamProjectCollection = null; build = null; } disposed = true; }
public void Dispose() { _buildServer = null; if (_tfsCollection != null) { _tfsCollection.Dispose(); } _buildDefinitions = null; _buildDefinitions2017 = null; _connection = null; _buildClient = null; GC.Collect(); }
public void Close() { if (m_Connection != null) { m_Connection.Close(); m_Connection = null; } if (projectCollection != null) { projectCollection.Dispose(); projectCollection = null; } }
public void ClearFileContent() { TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.FuncTestCollection)); var vcs = collection.GetService <VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.FuncTestsProject); ItemSet itemSet = vcs.GetItems(tp.ServerItem, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File); Item item = itemSet.Items.FirstOrDefault(x => x.ServerItem == string.Concat("$/", ConfigHelper.Instance.FuncTestsProject + "/testFile.txt")); string localItem = _workspace.GetLocalItemForServerItem(item.ServerItem); _workspace.PendEdit(localItem); using (var file = File.Open(localItem, FileMode.Truncate)) { } PendingChange[] pendingChanges = _workspace.GetPendingChanges().Where(x => x.ChangeType == ChangeType.Edit).ToArray(); _workspace.CheckIn(pendingChanges, ConfigHelper.Instance.Login, string.Empty, null, null, null); collection.Dispose(); }
public string GetLatestRevision() { TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.TestCollection)); var vcs = collection.GetService<VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.TestCollectionProject); var maxChangeset = vcs.QueryHistory( tp.ServerItem, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, Int32.MaxValue, true, true).Cast<Changeset>().Max(x => x.ChangesetId); collection.Dispose(); return maxChangeset.ToString(); }
public string GetLatestRevision() { var collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.TestCollection)); var vcs = collection.GetService <VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.TestCollectionProject); var maxChangeset = vcs.QueryHistory( tp.ServerItem, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, Int32.MaxValue, true, true).Cast <Changeset>().Max(x => x.ChangesetId); collection.Dispose(); return(maxChangeset.ToString(CultureInfo.InvariantCulture)); }
//Connecting to TFS servers public int connectToTFS(string serverPath) { if (serverPath == null) { throw new Exception("serverPath can not be null!"); } if (tpc != null) { tpc.Dispose(); } try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; tpc = new TfsTeamProjectCollection(new Uri(serverPath)); workItemStore = tpc.GetService <WorkItemStore>(); return(1); } catch { return(0); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> void IDisposable.Dispose() { m_tfsTeamProjectCollection.Dispose(); }
private void button_save_Click(object sender, EventArgs e) { try { ////http://social.technet.microsoft.com/wiki/contents/articles/3280.tfs-2010-api-create-workitems-bugs.aspx TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(this.textbox_tfsUrl.Text)); WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); WorkItemTypeCollection workItemTypes = workItemStore.Projects[this.textbox_defaultProject.Text].WorkItemTypes; WorkItemType workItemType = workItemTypes[combobox_workItemType.Text]; // Assign values to each mandatory field var workItem = new WorkItem(workItemType); workItem.Title = textbox_title.Text; workItem.Description = textbox_description.Text; var fieldAssignTo = "System.AssignedTo"; if (combobox_AssignTo.SelectedItem != null && workItem.Fields.Contains(fieldAssignTo)) { workItem.Fields[fieldAssignTo].Value = combobox_AssignTo.Text; } var fieldSeverity="Microsoft.VSTS.Common.Severity"; if (combobox_severity.SelectedItem != null && workItem.Fields.Contains(fieldSeverity)) { workItem.Fields[fieldSeverity].Value = combobox_severity.Text; } var fieldPriority = "Microsoft.VSTS.Common.Priority"; if (workItem.Fields.Contains(fieldPriority)) { workItem.Fields[fieldPriority].Value = textbox_Priority.Text; } if (combobox_AreaPath.SelectedItem != null) { workItem.AreaPath = combobox_AreaPath.Text; } if (combobox_IterationPath.SelectedItem != null) { workItem.IterationPath = combobox_IterationPath.Text; } var fieldState = "System.State"; if (combobox_state.SelectedItem != null && workItem.Fields.Contains(fieldState)) { workItem.Fields[fieldState].Value = combobox_state.Text; } var fieldReason = "System.Reason"; if (combobox_reason.SelectedItem != null && workItem.Fields.Contains(fieldReason)) { workItem.Fields["System.Reason"].Value = combobox_reason.Text; } string fieldSystenInfo = "Microsoft.VSTS.TCM.SystemInfo"; if (workItem.Fields.Contains(fieldSystenInfo)) { if (workItem.Fields[fieldSystenInfo].FieldDefinition.FieldType == FieldType.Html) { workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text.Replace(Environment.NewLine,"<br/>"); } else { workItem.Fields[fieldSystenInfo].Value = textbox_SystemInfo.Text; } } string fieldsReproStreps = "Microsoft.VSTS.TCM.ReproSteps"; if (workItem.Fields.Contains(fieldsReproStreps)) { workItem.Fields[fieldsReproStreps].Value = textbox_ReproStep.Text; if (string.IsNullOrEmpty(textbox_ReproStep.Text)) { workItem.Fields[fieldsReproStreps].Value = workItem.Description; } } // add image string tempFile = Path.Combine(Environment.CurrentDirectory, this.Filename); File.WriteAllBytes(tempFile, this.ImageData); workItem.Attachments.Add(new Attachment(tempFile)); // Link the failed test case to the Bug // workItem.Links.Add(new RelatedLink(testcaseID)); // Check for validation errors before saving the Bug ArrayList validationErrors = workItem.Validate(); if (validationErrors.Count == 0) { workItem.Save(); if (this.TFSInfo == null) { this.TFSInfo = new TFSInfo(); } this.TFSInfo.ID = workItem.Id.ToString(); this.TFSInfo.Title = workItem.Title; this.TFSInfo.Description = workItem.Description; // http://stackoverflow.com/questions/6466441/how-to-map-a-tfs-item-url-to-something-viewable var testManagementService = tfs.GetService<ILinking>(); this.TFSInfo.WebDetailUrl = testManagementService.GetArtifactUrlExternal(workItem.Uri.ToString()); var myService = tfs.GetService<TswaClientHyperlinkService>(); this.TFSInfo.WebEditUrl = myService.GetWorkItemEditorUrl(workItem.Id).ToString(); if (checkbox_description_addImage.Checked) { if (workItem.Fields["System.Description"].FieldDefinition.FieldType == FieldType.Html) { workItem.Description += string.Format("<br/><a href=\"{0}\"><img src=\"{0}\" /></a>", workItem.Attachments[0].Uri.ToString()); } else { workItem.Description += System.Environment.NewLine + workItem.Attachments[0].Uri.ToString(); } } if (checkbox_reproStep_AddImage.Checked && (workItem.Fields.Contains(fieldsReproStreps))) { if (workItem.Fields[fieldsReproStreps].FieldDefinition.FieldType == FieldType.Html) { workItem.Fields[fieldsReproStreps].Value += string.Format("<br/><a href=\"{0}\"><img src=\"{0}\" /></a>", workItem.Attachments[0].Uri.ToString()); } else { workItem.Fields[fieldsReproStreps].Value += System.Environment.NewLine + workItem.Attachments[0].Uri.ToString(); } } workItem.Save(); this.SetLastValue(); DialogResult = DialogResult.OK; } else { string errrorMsg = "Validation Error in field\n"; foreach (Field field in validationErrors) { errrorMsg += field.Name + "\n"; } MessageBox.Show(errrorMsg); } tfs.Dispose(); // delete temps images System.IO.File.Delete(tempFile); } catch (Exception eError) { MessageBox.Show(eError.ToString()); } }
protected override void OnCheckConnection(PluginProfileErrorCollection errors, TfsPluginProfile settings) { settings.ValidateStartRevision(errors); settings.ValidateUri(errors); if (!errors.Any()) { TfsTeamProjectCollection collection = null; try { TfsConnectionParameters parameters = TfsConnectionHelper.GetTfsConnectionParameters(settings); switch (parameters.SegmentsCount) { case UriTfsProjectCollection: { collection = new TfsTeamProjectCollection(parameters.TfsCollectionUri, parameters.Credential); collection.EnsureAuthenticated(); collection.Connect(ConnectOptions.None); var vcs = collection.GetService <VersionControlServer>(); CheckChangeset(settings, vcs); break; } case UriTfsTeamProject: { collection = new TfsTeamProjectCollection(parameters.TfsCollectionUri, parameters.Credential); collection.EnsureAuthenticated(); collection.Connect(ConnectOptions.None); var vcs = collection.GetService <VersionControlServer>(); TeamProject teamProject = vcs.GetTeamProject(parameters.TeamProjectName); CheckChangeset(settings, vcs, teamProject); break; } default: errors.Add(new PluginProfileError { FieldName = "Uri", Message = "Could not connect to server." }); break; } } catch (TeamFoundationServerUnauthorizedException e) { errors.Add( new PluginProfileError { Status = PluginProfileErrorStatus.WrongCredentialsError, FieldName = "Login", Message = "Authorization failed.", AdditionalInfo = e.Message }); errors.Add( new PluginProfileError { Status = PluginProfileErrorStatus.WrongCredentialsError, FieldName = "Password", Message = "Authorization failed.", AdditionalInfo = e.Message }); } catch (ResourceAccessException e) { errors.Add(new PluginProfileError { AdditionalInfo = e.Message, FieldName = "Uri", Message = "Resource access denied", Status = PluginProfileErrorStatus.Error }); } catch (ChangesetNotFoundException e) { errors.Add(new PluginProfileError { AdditionalInfo = e.Message, FieldName = "StartRevision", Message = "There’s no such revision.", Status = PluginProfileErrorStatus.UnexistedRevisionWarning }); } catch (TeamFoundationServiceUnavailableException e) { errors.Add(new PluginProfileError { AdditionalInfo = e.Message, FieldName = "Uri", Message = "Could not connect to server.", }); } finally { if (collection != null) { collection.Dispose(); } } } }
protected override void OnExit(ExitEventArgs e) { base.OnExit(e); _tfs.Dispose(); }
public string Commit(string serverItemPath, string changedContent, string commitComment) { TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.FuncTestCollection)); var vcs = collection.GetService<VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.FuncTestsProject); ItemSet itemSet = vcs.GetItems(tp.ServerItem, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File); Item item = itemSet.Items.FirstOrDefault(x => x.ServerItem == serverItemPath); string localItem = _workspace.GetLocalItemForServerItem(item.ServerItem); int changesetId = _workspace.PendEdit(localItem); using (var file = File.OpenWrite(localItem)) { var changes = new UTF8Encoding(true).GetBytes(changedContent); file.Seek(0, SeekOrigin.End); file.Write(changes, 0, changes.Length); } PendingChange[] pendingChanges = _workspace.GetPendingChanges().Where(x => x.ChangeType == ChangeType.Edit).ToArray(); int changeset = _workspace.CheckIn(pendingChanges, ConfigHelper.Instance.Login, commitComment, null, null, null); Changeset latestChangeset = vcs.GetChangeset(changeset); collection.Dispose(); return latestChangeset.ChangesetId.ToString(CultureInfo.InvariantCulture); }
public void ClearFileContent() { TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.FuncTestCollection)); var vcs = collection.GetService<VersionControlServer>(); TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.FuncTestsProject); ItemSet itemSet = vcs.GetItems(tp.ServerItem, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File); Item item = itemSet.Items.FirstOrDefault(x => x.ServerItem == string.Concat("$/", ConfigHelper.Instance.FuncTestsProject + "/testFile.txt")); string localItem = _workspace.GetLocalItemForServerItem(item.ServerItem); _workspace.PendEdit(localItem); using (var file = File.Open(localItem, FileMode.Truncate)) { } PendingChange[] pendingChanges = _workspace.GetPendingChanges().Where(x => x.ChangeType == ChangeType.Edit).ToArray(); _workspace.CheckIn(pendingChanges, ConfigHelper.Instance.Login, string.Empty, null, null, null); collection.Dispose(); }
protected override void OnDispose() { _projectCollection?.Dispose(); _projectCollection = null; }
public void DisposeTfs() { _tfsCollection.Dispose(); }
public void Dispose() { teamProjectCollection.Dispose(); }
/// <summary> /// Dispose le projet. /// </summary> public void Dispose() { _projectCollection.Dispose(); }