Ejemplo n.º 1
0
        /// <summary>
        /// Try to update the project data given a project started event. This is useful if the project
        /// was created (e.g. as a parent) before we saw the started event.
        /// <remarks>Does nothing if the data has already been set or the new data is null.</remarks>
        /// </summary>
        /// <param name="args">The <see cref="ProjectStartedEventArgs"/> instance containing the event data.</param>
        public void UpdateProject(Project project, ProjectStartedEventArgs args)
        {
            if (project.Name == null && args != null)
            {
                project.StartTime    = args.Timestamp;
                project.Name         = Intern(Path.GetFileName(args.ProjectFile));
                project.ProjectFile  = Intern(args.ProjectFile);
                project.EntryTargets = string.IsNullOrWhiteSpace(args.TargetNames)
                    ? ImmutableArray <string> .Empty
                    : stringTable.InternList(TextUtilities.SplitSemicolonDelimitedList(args.TargetNames));
                project.TargetsText = args.TargetNames;

                var evaluationId = BuildEventContext.InvalidEvaluationId;
                if (args.BuildEventContext.EvaluationId > BuildEventContext.InvalidEvaluationId)
                {
                    evaluationId = args.BuildEventContext.EvaluationId;
                }
                else if (args.ParentProjectBuildEventContext != null && args.ParentProjectBuildEventContext.EvaluationId > BuildEventContext.InvalidEvaluationId)
                {
                    evaluationId = args.ParentProjectBuildEventContext.EvaluationId;
                }

                project.EvaluationId = evaluationId;
                if (evaluationId != BuildEventContext.InvalidEvaluationId)
                {
                    project.EvaluationText = Intern("id:" + evaluationId);
                }

                project.GlobalProperties = stringTable.InternStringDictionary(args.GlobalProperties) ?? ImmutableDictionary <string, string> .Empty;

                if (args.GlobalProperties != null)
                {
                    AddGlobalProperties(project, project.GlobalProperties);
                }

                if (!string.IsNullOrEmpty(args.TargetNames))
                {
                    AddEntryTargets(project);
                }

                AddProperties(project, args.Properties);
                AddItems(project, args.Items);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try to update the project data given a project started event. This is useful if the project
        /// was created (e.g. as a parent) before we saw the started event.
        /// <remarks>Does nothing if the data has already been set or the new data is null.</remarks>
        /// </summary>
        /// <param name="args">The <see cref="ProjectStartedEventArgs"/> instance containing the event data.</param>
        public void UpdateProject(Project project, ProjectStartedEventArgs args)
        {
            if (project.Name == null && args != null)
            {
                project.StartTime    = args.Timestamp;
                project.Name         = Intern(args.Message);
                project.ProjectFile  = Intern(args.ProjectFile);
                project.EntryTargets = string.IsNullOrWhiteSpace(args.TargetNames)
                    ? ImmutableArray <string> .Empty
                    : stringTable.InternList(TextUtilities.SplitSemicolonDelimitedList(args.TargetNames));

                var internedGlobalProperties = stringTable.InternStringDictionary(args.GlobalProperties) ?? ImmutableDictionary <string, string> .Empty;

                project.GlobalProperties = internedGlobalProperties;

                if (args.GlobalProperties != null)
                {
                    AddGlobalProperties(project, internedGlobalProperties);
                }

                if (args.Properties != null)
                {
                    var properties = project.GetOrCreateNodeWithName <Folder>(Intern("Properties"));
                    AddProperties(properties, args
                                  .Properties
                                  .Cast <DictionaryEntry>()
                                  .OrderBy(d => d.Key)
                                  .Select(d => new KeyValuePair <string, string>(
                                              Intern(Convert.ToString(d.Key)),
                                              Intern(Convert.ToString(d.Value)))));
                }

                if (args.Items != null)
                {
                    RetrieveProjectInstance(project, args);

                    var items = project.GetOrCreateNodeWithName <Folder>("Items");
                    foreach (DictionaryEntry kvp in args.Items)
                    {
                        var itemName  = Intern(Convert.ToString(kvp.Key));
                        var itemGroup = items.GetOrCreateNodeWithName <Folder>(itemName);

                        var item = new Item();

                        var taskItem = kvp.Value as ITaskItem;
                        if (taskItem != null)
                        {
                            item.Text = Intern(taskItem.ItemSpec);
                            foreach (DictionaryEntry metadataName in taskItem.CloneCustomMetadata())
                            {
                                item.AddChild(new Metadata
                                {
                                    Name  = Intern(Convert.ToString(metadataName.Key)),
                                    Value = Intern(Convert.ToString(metadataName.Value))
                                });
                            }

                            itemGroup.AddChild(item);
                        }
                    }
                }
            }
        }