Exemple #1
0
        public int?EnsureClasification(string fullName, WebModel.TreeStructureGroup structureGroup = WebModel.TreeStructureGroup.Iterations)
        {
            if (string.IsNullOrWhiteSpace(fullName))
            {
                Logger.Log(LogLevel.Error, "Invalid 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(LogLevel.Error, $"Error while adding {(structureGroup == WebModel.TreeStructureGroup.Iterations ? "iteration" : "area")} {fullName} to Azure DevOps/TFS: {ex.Message}");
                }

                if (node != null)
                {
                    Logger.Log(LogLevel.Info, $"{(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 void CreateClasificationCacheRec(WebModel.WorkItemClassificationNode current, Dictionary <string, int> agg, string parentPath)
        {
            string fullName = !string.IsNullOrWhiteSpace(parentPath) ? parentPath + "/" + current.Name : current.Name;

            agg.Add(fullName, current.Id);
            Logger.Log(LogLevel.Debug, $"{(current.StructureType == WebModel.TreeNodeStructureType.Iteration ? "Iteration" : "Area")} '{fullName}' added to cache");
            if (current.Children != null)
            {
                foreach (var node in current.Children)
                {
                    CreateClasificationCacheRec(node, agg, fullName);
                }
            }
        }