public int?EnsureClasification(string fullName, WebModel.TreeStructureGroup structureGroup = WebModel.TreeStructureGroup.Iterations) { if (string.IsNullOrWhiteSpace(fullName)) { Logger.Log(LogLevel.Error, "Empty value provided for node name/path."); throw new ArgumentException("fullName"); } var path = fullName.Split('/'); var name = path.Last(); var parent = string.Join("/", path.Take(path.Length - 1)); if (!string.IsNullOrEmpty(parent)) { EnsureClasification(parent, structureGroup); } var cache = structureGroup == WebModel.TreeStructureGroup.Iterations ? IterationCache : AreaCache; lock (cache) { if (cache.TryGetValue(fullName, out int id)) { return(id); } WebModel.WorkItemClassificationNode node = null; try { node = WiClient.CreateOrUpdateClassificationNodeAsync( new WebModel.WorkItemClassificationNode() { Name = name, }, Settings.Project, structureGroup, parent).Result; } catch (Exception ex) { Logger.Log(ex, $"Error while adding {(structureGroup == WebModel.TreeStructureGroup.Iterations ? "iteration" : "area")} '{fullName}' to Azure DevOps/TFS.", LogLevel.Critical); } if (node != null) { Logger.Log(LogLevel.Debug, $"{(structureGroup == WebModel.TreeStructureGroup.Iterations ? "Iteration" : "Area")} '{fullName}' added to Azure DevOps/TFS."); cache.Add(fullName, node.Id); Store.RefreshCache(); return(node.Id); } } return(null); }
private async Task <(Dictionary <string, int>, int)> CreateClasificationCacheAsync(string project, WebModel.TreeStructureGroup structureGroup) { try { Logger.Log(LogLevel.Info, $"Building {(structureGroup == WebModel.TreeStructureGroup.Iterations ? "iteration" : "area")} cache..."); WebModel.WorkItemClassificationNode all = await WiClient.GetClassificationNodeAsync(project, structureGroup, null, 1000); var clasificationCache = new Dictionary <string, int>(); if (all.Children != null && all.Children.Any()) { foreach (var iteration in all.Children) { CreateClasificationCacheRec(iteration, clasificationCache, ""); } } return(clasificationCache, all.Id); } catch (Exception ex) { Logger.Log(ex, $"Error while building {(structureGroup == WebModel.TreeStructureGroup.Iterations ? "iteration" : "area")} cache."); return(null, -1); } }