Ejemplo n.º 1
0
        public void ImportDependenciesFromCsvFile(string csvFile)
        {
            try
            {
                this.RaiseDependenciesModelAboutToChange();

                var engine = new FileHelperEngine <CsvDependency>();

                var records = engine.ReadFile(csvFile);

                if (engine.GetFileHeader() != engine.HeaderText.Trim())
                {
                    throw new Exception(string.Format("[CSV] Column headers: '{0}' from file '{1}' do not match the expected ones: '{2}'", engine.HeaderText.Trim(), csvFile, engine.GetFileHeader()));
                }

                var            theModel = new Dictionary <int, DependencyItem>();
                DependencyItem tempItem;

                foreach (var csvDependency in records)
                {
                    tempItem = new DependencyItem(
                        csvDependency.Id,
                        csvDependency.Title,
                        csvDependency.Comment,
                        csvDependency.SuccessorIds ?? new List <int>(),
                        csvDependency.Tags ?? new List <string>());

                    tempItem.State = csvDependency.Status;

                    theModel.Add(csvDependency.Id, tempItem);
                    this.Logger.Debug(string.Format(@"[CSV] Got: {0}", tempItem.ToString()));
                }

                this.DependenciesModel = theModel;
                this.RaiseDependenciesModelChanged();
            }
            catch (Exception ex)
            {
                this.Logger.Error(string.Format(@"{0}{1}{2}", ex.Message, Environment.NewLine, ex.StackTrace));
                this.RaiseDependenciesModelCouldNotBeChanged();
                throw;
            }
        }
Ejemplo n.º 2
0
        private void PopulateDependenciesWithLinkQuery(Dictionary <int, DependencyItem> dependenciesModel, Query query, QueryDefinition queryDef)
        {
            var queryResults = query.RunLinkQuery();

            int successorsCount = 0;

            DependencyItem tempItem;

            // Populate the model (parent id's and successors) from the query
            foreach (WorkItemLinkInfo workItemInfo in queryResults)
            {
                if (workItemInfo.SourceId == 0) // parent
                {
                    if (!dependenciesModel.ContainsKey(workItemInfo.TargetId))
                    {
                        tempItem = new DependencyItem(workItemInfo.TargetId);
                        dependenciesModel.Add(workItemInfo.TargetId, tempItem);
                        this.Logger.Debug(string.Format(@"[TFS] Got PARENT: {0}", tempItem.ToString()));
                    }
                }
                else // child
                {
                    // ToDo: Make this also work with Predecessors queries
                    if (workItemInfo.LinkTypeId == 3) // successor
                    {
                        // Get the parent
                        dependenciesModel.TryGetValue(workItemInfo.SourceId, out var dependencyItem);
                        if (dependencyItem != null)
                        {
                            dependencyItem.Successors.Add(workItemInfo.TargetId);
                            successorsCount++;
                        }
                        else
                        {
                            this.Logger.Debug(string.Format(@"[TFS] Could not get PARENT: {0} for SUCCESSOR: {1}", workItemInfo.SourceId, workItemInfo.TargetId));
                        }
                    }
                }
            }

            if (successorsCount == 0)
            {
                throw new Exception(string.Format("[TFS] The query '{0}' does not return any successors", queryDef.Name));
            }

            var successorsThatAreNotParents = new List <DependencyItem>();

            // Add Title and Tags to items in the DependenciesModel
            foreach (KeyValuePair <int, DependencyItem> entry in dependenciesModel)
            {
                if (entry.Value.Title == null)
                {
                    var workItem = this.WorkItemStore.GetWorkItem(entry.Key);
                    entry.Value.Title   = workItem.Title;
                    entry.Value.State   = workItem.State;
                    entry.Value.Comment = Path.GetFileName(workItem.IterationPath);

                    entry.Value.Tags.AddRange(TfsHelper.GetTags(workItem));
                }

                foreach (var successor in entry.Value.Successors)
                {
                    // If successors are not parents, retrieve them from TFS and add them
                    if (!dependenciesModel.ContainsKey(successor))
                    {
                        var workItem       = this.WorkItemStore.GetWorkItem(successor);
                        var dependencyItem = new DependencyItem(successor)
                        {
                            Title = workItem.Title, State = workItem.State, Comment = Path.GetFileName(workItem.IterationPath)
                        };
                        dependencyItem.Tags.AddRange(TfsHelper.GetTags(workItem));

                        successorsThatAreNotParents.Add(dependencyItem);
                    }
                }
            }

            // Add successors That Are Not Parents to the DependenciesModel
            foreach (var successor in successorsThatAreNotParents)
            {
                if (!dependenciesModel.ContainsKey(successor.Id))
                {
                    dependenciesModel.Add(successor.Id, successor);
                    this.Logger.Debug(string.Format(@"[TFS] Got SUCCESSOR: {0}", successor.ToString()));
                }
            }
        }