public async Task <IActionResult> GetWorkItemComments(int id) { var uriLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_Uri"); Uri accountUri = new Uri(uriLookup.Lvalue); var tokenLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AccessToken"); String personalAccessToken = tokenLookup.Lvalue; // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { // Get the specified work item WorkItemComments comments = witClient.GetCommentsAsync(id).Result; return(Ok(comments)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { throw vssex; } throw aex; } }
public async Task <IActionResult> GetWorkItem(int id) { var uriLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_Uri"); Uri accountUri = new Uri(uriLookup.Lvalue); //new Uri("https://dev.azure.com/inser13"); var tokenLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AccessToken"); String personalAccessToken = tokenLookup.Lvalue; //"4b6dsojsubb7bzkowrm6krz5f7gjubfirckbvu5kn5nzmwdljkyq"; // See https://www.visualstudio.com/docs/integrate/get-started/authentication/pats // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { // Get the specified work item WorkItem workitem = witClient.GetWorkItemAsync(id).Result; return(Ok(workitem)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { throw vssex; } throw aex; } }
static private async Task ShowWorkItemDetails(VssConnection connection, int workItemId) { //Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { //Get the apecified work item WorkItem workitem = await witClient.GetWorkItemAsync(workItemId); //Output the work item´s field values foreach (var field in workitem.Fields) { Console.WriteLine(" {0}: {1}", field.Key, field.Value); } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
static private async Task ShowWorkItemDetails(VssConnection connection, int workItemId) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { WorkItem workitem = await witClient.GetWorkItemAsync(workItemId); foreach (var field in workitem.Fields) { Console.WriteLine("{0}:{1}", field.Key, field.Value); } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } for (int i = 1; i <= 10; i++) { Console.WriteLine("\nTabla de multiplicar del {0}", i); Console.WriteLine("------------------------------"); for (int j = 1; j <= 10; j++) { Console.WriteLine("{0} * {1} = {2}", i, j, (i * j)); } } Console.ReadKey(); }
static private async Task AddOrUpdateApplicationDetail(VssConnection connection, SqlConnection con) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { Wiql wiql = new Wiql(); wiql.Query = "SELECT QUERY"; WorkItemQueryResult tasks = await witClient.QueryByWiqlAsync(wiql); IEnumerable <WorkItemReference> tasksRefs; tasksRefs = tasks.WorkItems.OrderBy(x => x.Id); List <WorkItem> tasksList = witClient.GetWorkItemsAsync(tasksRefs.Select(wir => wir.Id)).Result; } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
/// <summary>Determines if the message code is a specific value.</summary> /// <param name="source">The source.</param> /// <param name="messageCode">The expected message code.</param> /// <returns><see langword="true"/> if the error has the given message code.</returns> public static bool IsMessageCode(this VssServiceException source, string messageCode) { var message = source.Message; if (String.IsNullOrEmpty(message)) { return(false); } return(String.Compare(source.GetMessageCode(), messageCode, true) == 0); }
/// <summary>Determines if the message code is one of several specific values.</summary> /// <param name="source">The source.</param> /// <param name="messageCodes">The expected message codes.</param> /// <returns><see langword="true"/> if the message code is in the provided list.</returns> public static bool IsMessageCode(this VssServiceException source, params string[] messageCodes) { var message = source.Message; if (String.IsNullOrEmpty(message)) { return(false); } var actualCode = source.GetMessageCode(); return(messageCodes.Contains(actualCode, StringComparer.OrdinalIgnoreCase)); }
static void Main(string[] args) { Uri accountUri = new Uri(Helper.ThisIsMyVSTS); String personalAccessToken = Helper.ThisIsMyPAT; var workItemIds = new List <int>(); workItemIds.Add(1744); // this is a random list of work item ids in the tpc workItemIds.Add(1665); workItemIds.Add(29); // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { foreach (var wID in workItemIds) { Console.WriteLine("*****************************"); Console.WriteLine("*****************************"); Console.WriteLine("*** WORK ITEM: {0} *******", wID); Console.WriteLine("*****************************"); Console.WriteLine("*****************************"); // Get the specified work item WorkItem workitem = witClient.GetWorkItemAsync(wID).Result; // Output the work item's field values foreach (var field in workitem.Fields) { Console.WriteLine(" {0}: {1}", field.Key, field.Value); } Console.WriteLine(); Console.WriteLine(); } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
public async Task <IActionResult> GetWorkItemsByTag(string tag) { var uriLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_Uri"); Uri accountUri = new Uri(uriLookup.Lvalue); var tokenLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AccessToken"); String personalAccessToken = tokenLookup.Lvalue; // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); //create a wiql object and build our query Wiql wiql = new Wiql() { Query = "Select [System.Id], [System.Title], [System.State] From WorkItems " + "Where [State] <> 'Closed' AND [State] <> 'Removed' AND [System.Tags] Contains '" + tag + "' " + "order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" }; try { //execute the query to get the list of work items in the results WorkItemQueryResult workItemQueryResult = witClient.QueryByWiqlAsync(wiql).Result; List <WorkItem> workItemList = new List <WorkItem>(); foreach (WorkItemReference wi in workItemQueryResult.WorkItems) { workItemList.Add(witClient.GetWorkItemAsync(wi.Id).Result); } return(Ok(workItemList)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { throw vssex; } throw aex; } }
static private async Task ShowWorkItemDetails(VssConnection connection, int workItemId) { var witClient = connection.GetClient <BuildHttpClient>(); try { var workitem = await witClient.GetBuildAsync(new Guid("7cc85a15-7f9c-4e84-b42e-68d1452c3afa"), 151); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
public async Task <Stream> GetArtifact(int buildId, string artifactName) { var witClient = Connection.GetClient <BuildHttpClient>( ); try { return(await witClient.GetArtifactContentZipAsync(ProjectId.ToString(), buildId, artifactName)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } throw; } }
public async Task <TeamProject> GetCurrentProject() { var witClient = Connection.GetClient <ProjectHttpClient>(); try { return(await witClient.GetProject(ProjectId.ToString())); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } throw; } }
public async Task <IPagedList <Build> > GetProjectBuilds() { var witClient = Connection.GetClient <BuildHttpClient>(); try { return(await witClient.GetBuildsAsync2(ProjectId.ToString())); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } throw; } }
public WorkItem GetWorkItem(int WorkItemId) { try { // Get the specified work item WorkItem workitem = _witClient.GetWorkItemAsync(WorkItemId).GetAwaiter().GetResult(); return(workitem); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { _log.LogInformation(vssex.Message); } } return(null); }
/// <summary>Gets the error code from the message, if any.</summary> /// <param name="source">The source.</param> /// <returns>The message code, if any.</returns> public static string GetMessageCode(this VssServiceException source) { if (String.IsNullOrEmpty(source.Message)) { return(""); } var index = source.Message.IndexOf(':'); if (index < 0) { index = source.Message.IndexOf(' '); } if (index < 0) { return(""); } return(source.Message.Left(index)); }
private static async Task UpdateWorkItemAsync(int workItemId, string user, WorkItemTrackingHttpClient witClient, int i) { try { var patchDocument = new JsonPatchDocument(); patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AssignedTo", Value = user }); patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.ChangedBy", Value = user }); patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.History", Value = "This comment was added during the sync #" + i.ToString() }); await witClient.UpdateWorkItemAsync(patchDocument, workItemId, bypassRules : true); //var workItem = await witClient.GetWorkItemAsync(workItemId); //Console.WriteLine("Retrieved work item revision #{0}", workItem.Rev); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
static void Main(string[] args) { if (args.Length == 3) { Uri accountUri = new Uri(args[0]); // Account URL, for example: https://fabrikam.visualstudio.com String personalAccessToken = args[1]; // See https://www.visualstudio.com/docs/integrate/get-started/authentication/pats int workItemId = int.Parse(args[2]); // ID of a work item, for example: 12 // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { // Get the specified work item WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result; // Output the work item's field values foreach (var field in workitem.Fields) { Console.WriteLine(" {0}: {1}", field.Key, field.Value); } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } } else { Console.WriteLine("Usage: ConsoleApp {accountUri} {personalAccessToken} {workItemId}"); } }
public Exception Unwrap(IDictionary <String, Type> typeMapping) { Exception innerException = null; if (InnerException != null) { innerException = InnerException.Unwrap(typeMapping); UnwrappedInnerException = innerException; } Exception exception = null; // if they have bothered to map type, use that first. if (!String.IsNullOrEmpty(TypeKey)) { Type type; if (typeMapping != null && typeMapping.TryGetValue(TypeKey, out type) || baseTranslatedExceptions.TryGetValue(TypeKey, out type)) { try { this.Type = type; exception = Activator.CreateInstance(this.Type, Message, innerException) as Exception; } catch (Exception) { // do nothing } } } if (exception == null) { //no standard mapping, fallback to exception = UnWrap(innerException); } if (exception is VssException) { ((VssException)exception).EventId = this.EventId; ((VssException)exception).ErrorCode = this.ErrorCode; } if (exception == null && !String.IsNullOrEmpty(Message)) { // NOTE: We can get exceptions that we can't create, IE. SqlException, AzureExceptions. // This is not a failure, we will just wrap the exception in a VssServiceException // since the type is not available. exception = new VssServiceException(Message, innerException); } if (exception == null && !string.IsNullOrEmpty(TypeName)) { Debug.Assert(false, string.Format("Server exception cannot be resolved. Type name: {0}", TypeName)); } if (exception != null && !string.IsNullOrEmpty(HelpLink)) { exception.HelpLink = HelpLink; } if (exception != null && !string.IsNullOrEmpty(this.StackTrace)) { FieldInfo stackTraceField = typeof(Exception).GetTypeInfo().GetDeclaredField("_stackTraceString"); if (stackTraceField != null && !stackTraceField.Attributes.HasFlag(FieldAttributes.Public) && !stackTraceField.Attributes.HasFlag(FieldAttributes.Static)) { stackTraceField.SetValue(exception, this.StackTrace); } } if (exception != null && exception.GetType() == this.Type) { TryUnWrapCustomProperties(exception); } return(exception); }
public static async Task CreateTask(VssConnection connection) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { JsonPatchDocument patchDocument = new JsonPatchDocument(); // título da solicitação patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "titulo" } ); // descrição da solicitação patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.c474834f-4b08-42ac-aaa3-1bcf80e3ae66", Value = "descricao" } ); // razão social do cliente patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.ClienteLista", Value = "XCLIENTE DE TESTE - NÃO APAGAR" } ); // responsável pelo cadastro patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.Contato", Value = "PAULO" } ); // protocolo patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.ProtocoloManager", Value = "999999" } ); // sistema/produto //https://dev.azure.com/gruposym/_apis/projects?api-version=5.1 patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.Produto", Value = "NEFRODATA ACD" } ); //prioridade patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/Custom.Prioridade", Value = "2 - Médio" } ); WorkItem workitem = await witClient.CreateWorkItemAsync(patchDocument, "Nefrodata", "Erro"); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
/// <summary>Determines if this is a warning or not.</summary> /// <param name="source">The source.</param> /// <returns><see langword="true"/> if it is a warning.</returns> public static bool IsWarning(this VssServiceException source) { return(source?.LogLevel == System.Diagnostics.EventLogEntryType.Warning); }
public async Task <IActionResult> GetWorkItems() { CurrentUser cUser = new CurrentUser(HttpContext, _configuration); var uriLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_Uri"); Uri accountUri = new Uri(uriLookup.Lvalue); var tokenLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AccessToken"); String personalAccessToken = tokenLookup.Lvalue; //var iterationLookup = await lookupRepo.GetLookupConfigByName("DevOps_IterationPath"); //string IterationPath = iterationLookup.Lvalue; var areaLookup = await lookupRepo.GetLookupConfigByName(0, "Y", "DevOps_AreaPath"); string AreaPath = null; if (areaLookup != null) { AreaPath = areaLookup.Lvalue; } // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); //create a wiql object and build our query Wiql wiql = new Wiql() { Query = "Select [System.Id], [System.Title], [System.State] From WorkItems " + "Where [System.Tags] contains '" + cUser.Email + "' " + "and [System.AreaPath] = '" + AreaPath + "' " + "order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" }; try { //execute the query to get the list of work items in the results WorkItemQueryResult workItemQueryResult = witClient.QueryByWiqlAsync(wiql).Result; List <WorkItem> workItemList = new List <WorkItem>(); foreach (WorkItemReference wi in workItemQueryResult.WorkItems) { workItemList.Add(witClient.GetWorkItemAsync(wi.Id, null, null, WorkItemExpand.Relations).Result); //string[] splitString = wi.Url.ToString().Split('/'); //Guid attachmentId = new Guid(splitString[7].ToString()); //Stream attachmentStream = witClient.GetAttachmentContentAsync(attachmentId).Result; //using (FileStream writeStream = new FileStream(fileFullPath, FileMode.Create, FileAccess.ReadWrite)) //{ // attachmentStream.CopyTo(writeStream); //} } return(Ok(workItemList)); } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { throw vssex; } throw aex; } }
static public async Task ShowWorkItemDetails(VssConnection connection, int workItemId, List <WorkitemDto> all) { WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { WorkItem workitem = await witClient.GetWorkItemAsync(workItemId); object a = new object(); object b = new object(); object c = new object(); var getall = 0; foreach (var field in workitem.Fields) { if (field.Key == "System.WorkItemType") { a = field.Value; getall++; } if (field.Key == "System.Title") { b = field.Value; getall++; } if (field.Key == "System.CreatedDate") { c = field.Value; getall++; } if (getall == 3) { int?total = 0; if (all.Count == 0) { total = 1; } else { total = all[0].ID + 1; } all.Add(new WorkitemDto() { ID = total ?? 1, Tipo = a.ToString(), Titulo = b.ToString(), DataCriacao = Convert.ToDateTime(c.ToString()) }); DBInsert(all[all.Count - 1]); getall++; } Console.WriteLine(" {0}: {1}", field.Key, field.Value); } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } }
public override void Given() { HandledErrorCodes = new[] { _errorCode }; Input = new VssServiceException($"TF{_errorCode}: This is a sample exception"); base.Given(); }
public override void Given() { HandledErrorCodes = new int[] {}; Input = new VssServiceException("TFabcd: This is a sample exception"); base.Given(); }
static void Main(string[] args) { loadConfiguration(); if (args.Length <= 2) { //Uri accountUri = new Uri(args[0]); // Account URL, for example: https://fabrikam.visualstudio.com //String personalAccessToken = args[1]; // See https://www.visualstudio.com/docs/integrate/get-started/authentication/pats int workItemId = int.Parse(args[0]); // ID of a work item, for example: 12 if (args.Length == 2 && args[1] == "create") { create = true; } // Create a connection to the account VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken)); // Get an instance of the work item tracking client WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>(); try { // Get the specified work item WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result; //// Output the work item's field values //foreach (var field in workitem.Fields) //{ // Console.WriteLine(" {0}: {1}", field.Key, field.Value); //} //if (workitem.Relations != null) //{ // foreach (WorkItemRelation wrel in workitem.Relations) // { // Console.WriteLine("{0} - {1}", wrel.Title, wrel.Url); // } //} //foreach (KeyValuePair<string, object> obj in workitem.Links.Links) //{ // ReferenceLink rlink = (ReferenceLink)obj.Value; // Console.WriteLine("{0} - {1}", obj.Key, rlink.Href); //} //Console.WriteLine("-------------------------------------------------------"); GetWorkItemFullyExpanded(connection, workItemId); Console.WriteLine(" WorkItem.URL = {0}", workitem.Url); //CreateAndLinkToWorkItem(connection, workItemId, workitem.Url); /*WorkItem wi1 = CreateTask(connection, Convert.ToString(workitem.Fields["System.Title"]), workitem.Url, Convert.ToString(workitem.Fields["Microsoft.VSTS.Common.Priority"]), * taskNameConv[1], DateTime.Now, false, "", "", ""); * * WorkItem wi2 = CreateTask(connection, Convert.ToString(workitem.Fields["System.Title"]), workitem.Url, Convert.ToString(workitem.Fields["Microsoft.VSTS.Common.Priority"]), * taskNameConv[2], DateTime.Now, false, "", wi1.Url, "");*/ if (create) { Console.WriteLine("-------------------------------------------------------"); Console.WriteLine("Creating child task..."); WorkItem prevItem = null; for (int ix = 0; ix < (taskNameConv.Length / 3); ix++) { string titleStr = Convert.ToString(workitem.Fields["System.Title"]); titleStr = String.Format("{0} - {1} {2}", taskNameConv[ix, 1], workItemId, titleStr); WorkItem wi = CreateTask(connection, titleStr, workitem.Url, Convert.ToString(workitem.Fields["Microsoft.VSTS.Common.Priority"]), taskNameConv[ix, 0], DateTime.Now, taskNameConv[ix, 1] == "6", "", (prevItem != null) ? prevItem.Url : null, taskNameConv[ix, 2]); prevItem = wi; } } } catch (AggregateException aex) { VssServiceException vssex = aex.InnerException as VssServiceException; if (vssex != null) { Console.WriteLine(vssex.Message); } } } else { Console.WriteLine("Usage: ConsoleApp {accountUri} {personalAccessToken} {workItemId}"); } }