/Microsoft.Build/Microsoft.Build/Microsoft/Build/BackEnd/Logging/ProjectLoggingContext.cs
C# | 139 lines | 121 code | 18 blank | 0 comment | 17 complexity | d3ec0add2db96bfb3c3ea02c6db0368f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
- namespace Microsoft.Build.BackEnd.Logging
- {
- using Microsoft.Build.BackEnd;
- using Microsoft.Build.Collections;
- using Microsoft.Build.Execution;
- using Microsoft.Build.Framework;
- using Microsoft.Build.Shared;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime;
- using System.Runtime.CompilerServices;
-
- internal class ProjectLoggingContext : BaseLoggingContext
- {
- private Microsoft.Build.BackEnd.Logging.NodeLoggingContext nodeLoggingContext;
- private string projectFullPath;
-
- internal ProjectLoggingContext(Microsoft.Build.BackEnd.Logging.NodeLoggingContext nodeLoggingContext, BuildRequestEntry requestEntry, BuildEventContext parentBuildEventContext) : this(nodeLoggingContext, requestEntry.Request.SubmissionId, requestEntry.Request.ConfigurationId, requestEntry.RequestConfiguration.ProjectFullPath, requestEntry.Request.Targets, requestEntry.RequestConfiguration.ToolsVersion, requestEntry.RequestConfiguration.Project.PropertiesToBuildWith, requestEntry.RequestConfiguration.Project.ItemsToBuildWith, parentBuildEventContext)
- {
- }
-
- internal ProjectLoggingContext(Microsoft.Build.BackEnd.Logging.NodeLoggingContext nodeLoggingContext, BuildRequest request, string projectFullPath, string toolsVersion, BuildEventContext parentBuildEventContext) : this(nodeLoggingContext, request.SubmissionId, request.ConfigurationId, projectFullPath, request.Targets, toolsVersion, null, null, parentBuildEventContext)
- {
- }
-
- private ProjectLoggingContext(Microsoft.Build.BackEnd.Logging.NodeLoggingContext nodeLoggingContext, int submissionId, int configurationId, string projectFullPath, List<string> targets, string toolsVersion, PropertyDictionary<ProjectPropertyInstance> projectProperties, ItemDictionary<ProjectItemInstance> projectItems, BuildEventContext parentBuildEventContext) : base(nodeLoggingContext)
- {
- this.nodeLoggingContext = nodeLoggingContext;
- this.projectFullPath = projectFullPath;
- ProjectPropertyInstanceEnumeratorProxy properties = null;
- ProjectItemInstanceEnumeratorProxy items = null;
- IEnumerable<ProjectPropertyInstance> backingProperties = (projectProperties == null) ? EmptyEnumerable<ProjectPropertyInstance>.Instance : null;
- IEnumerable<ProjectItemInstance> backingItems = (projectItems == null) ? EmptyEnumerable<ProjectItemInstance>.Instance : null;
- string[] propertiesToSerialize = base.LoggingService.PropertiesToSerialize;
- if (!base.LoggingService.OnlyLogCriticalEvents && (!base.LoggingService.RunningOnRemoteNode || base.LoggingService.SerializeAllProperties))
- {
- if (projectProperties != null)
- {
- backingProperties = projectProperties.GetCopyOnReadEnumerable();
- }
- if (projectItems != null)
- {
- backingItems = projectItems.GetCopyOnReadEnumerable();
- }
- properties = new ProjectPropertyInstanceEnumeratorProxy(backingProperties);
- items = new ProjectItemInstanceEnumeratorProxy(backingItems);
- }
- if (((projectProperties != null) && (propertiesToSerialize != null)) && ((propertiesToSerialize.Length > 0) && !base.LoggingService.SerializeAllProperties))
- {
- PropertyDictionary<ProjectPropertyInstance> dictionary = new PropertyDictionary<ProjectPropertyInstance>();
- foreach (string str in propertiesToSerialize)
- {
- ProjectPropertyInstance projectProperty = projectProperties[str];
- if (projectProperty != null)
- {
- dictionary.Set(projectProperty);
- }
- }
- properties = new ProjectPropertyInstanceEnumeratorProxy(dictionary);
- }
- base.BuildEventContext = base.LoggingService.LogProjectStarted(nodeLoggingContext.BuildEventContext, submissionId, configurationId, parentBuildEventContext, projectFullPath, string.Join(";", targets.ToArray()), properties, items);
- base.LoggingService.LogComment(base.BuildEventContext, MessageImportance.Low, "ToolsVersionInEffectForBuild", new object[] { toolsVersion });
- base.IsValid = true;
- }
-
- internal void LogProjectFinished(bool success)
- {
- ErrorUtilities.VerifyThrow(base.IsValid, "invalid");
- base.LoggingService.LogProjectFinished(base.BuildEventContext, this.projectFullPath, success);
- base.IsValid = false;
- }
-
- internal TargetLoggingContext LogTargetBatchStarted(string projectFullPath, ProjectTargetInstance target, string parentTargetName)
- {
- ErrorUtilities.VerifyThrow(base.IsValid, "invalid");
- return new TargetLoggingContext(this, projectFullPath, target, parentTargetName);
- }
-
- internal Microsoft.Build.BackEnd.Logging.NodeLoggingContext NodeLoggingContext
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.nodeLoggingContext;
- }
- }
-
- private class ProjectItemInstanceEnumeratorProxy : IEnumerable<DictionaryEntry>, IEnumerable
- {
- private IEnumerable<ProjectItemInstance> backingItems;
-
- internal ProjectItemInstanceEnumeratorProxy(IEnumerable<ProjectItemInstance> backingItems)
- {
- this.backingItems = backingItems;
- }
-
- public IEnumerator<DictionaryEntry> GetEnumerator()
- {
- foreach (ProjectItemInstance iteratorVariable0 in this.backingItems)
- {
- yield return new DictionaryEntry(iteratorVariable0.ItemType, new ProjectItemInstance.TaskItem(iteratorVariable0));
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- }
-
- private class ProjectPropertyInstanceEnumeratorProxy : IEnumerable<DictionaryEntry>, IEnumerable
- {
- private IEnumerable<ProjectPropertyInstance> backingProperties;
-
- internal ProjectPropertyInstanceEnumeratorProxy(IEnumerable<ProjectPropertyInstance> backingProperties)
- {
- this.backingProperties = backingProperties;
- }
-
- public IEnumerator<DictionaryEntry> GetEnumerator()
- {
- foreach (ProjectPropertyInstance iteratorVariable0 in this.backingProperties)
- {
- yield return new DictionaryEntry(iteratorVariable0.Name, iteratorVariable0.EvaluatedValue);
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.GetEnumerator();
- }
-
- }
- }
- }
-