/Microsoft.Build/Microsoft.Build/Microsoft/Build/Execution/BuildSubmission.cs
C# | 203 lines | 186 code | 17 blank | 0 comment | 14 complexity | e1c60dc45d22814ecaa049dd994e9b77 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
- namespace Microsoft.Build.Execution
- {
- using Microsoft.Build.BackEnd;
- using Microsoft.Build.BackEnd.Logging;
- using Microsoft.Build.Shared;
- using System;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Threading;
-
- public class BuildSubmission
- {
- private Microsoft.Build.Execution.BuildResult buildResult;
- private BuildSubmissionCompleteCallback completionCallback;
- private ManualResetEvent completionEvent;
- private int completionInvoked;
- private bool legacyThreadingSemantics;
- private bool loggingCompleted;
-
- internal BuildSubmission(Microsoft.Build.Execution.BuildManager buildManager, int submissionId, Microsoft.Build.Execution.BuildRequestData requestData, bool legacyThreadingSemantics)
- {
- ErrorUtilities.VerifyThrowArgumentNull(buildManager, "buildManager");
- ErrorUtilities.VerifyThrowArgumentNull(requestData, "requestData");
- this.BuildManager = buildManager;
- this.SubmissionId = submissionId;
- this.BuildRequestData = requestData;
- this.completionEvent = new ManualResetEvent(false);
- this.loggingCompleted = false;
- this.completionInvoked = 0;
- this.legacyThreadingSemantics = legacyThreadingSemantics;
- }
-
- private void CheckForCompletion()
- {
- WaitCallback callBack = null;
- if (((this.BuildResult != null) && this.loggingCompleted) && (Interlocked.Exchange(ref this.completionInvoked, 1) != 1))
- {
- this.completionEvent.Set();
- if (this.completionCallback != null)
- {
- if (callBack == null)
- {
- callBack = delegate (object state) {
- this.completionCallback(this);
- };
- }
- ThreadPool.QueueUserWorkItem(callBack);
- }
- }
- }
-
- internal void CompleteLogging(bool waitForLoggingThread)
- {
- if (waitForLoggingThread)
- {
- ((LoggingService) ((IBuildComponentHost) this.BuildManager).LoggingService).WaitForThreadToProcessEvents();
- }
- this.loggingCompleted = true;
- this.CheckForCompletion();
- }
-
- internal void CompleteResults(Microsoft.Build.Execution.BuildResult result)
- {
- ErrorUtilities.VerifyThrowArgumentNull(result, "result");
- ErrorUtilities.VerifyThrow(result.ConfigurationId == this.BuildRequest.ConfigurationId, "BuildResult doesn't match BuildRequest configuration");
- if (this.BuildResult == null)
- {
- this.BuildResult = result;
- }
- this.CheckForCompletion();
- }
-
- public Microsoft.Build.Execution.BuildResult Execute()
- {
- this.ExecuteAsync(null, null, this.legacyThreadingSemantics);
- if (this.legacyThreadingSemantics)
- {
- RequestBuilder.WaitWithBuilderThreadStart(new System.Threading.WaitHandle[] { this.WaitHandle }, false, ((IBuildComponentHost) this.BuildManager).LegacyThreadingData);
- }
- else
- {
- this.WaitHandle.WaitOneNoMessagePump();
- }
- return this.BuildResult;
- }
-
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- public void ExecuteAsync(BuildSubmissionCompleteCallback callback, object context)
- {
- this.ExecuteAsync(callback, context, false);
- }
-
- private void ExecuteAsync(BuildSubmissionCompleteCallback callback, object context, bool allowMainThreadBuild)
- {
- ErrorUtilities.VerifyThrowInvalidOperation(!this.IsCompleted, "SubmissionAlreadyComplete");
- this.completionCallback = callback;
- this.AsyncContext = context;
- this.BuildManager.ExecuteSubmission(this, allowMainThreadBuild);
- }
-
- public object AsyncContext
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<AsyncContext>k__BackingField;
- }
- [CompilerGenerated]
- private set
- {
- this.<AsyncContext>k__BackingField = value;
- }
- }
-
- public Microsoft.Build.Execution.BuildManager BuildManager
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<BuildManager>k__BackingField;
- }
- [CompilerGenerated]
- private set
- {
- this.<BuildManager>k__BackingField = value;
- }
- }
-
- internal Microsoft.Build.BackEnd.BuildRequest BuildRequest
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<BuildRequest>k__BackingField;
- }
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- set
- {
- this.<BuildRequest>k__BackingField = value;
- }
- }
-
- internal Microsoft.Build.Execution.BuildRequestData BuildRequestData
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<BuildRequestData>k__BackingField;
- }
- [CompilerGenerated]
- private set
- {
- this.<BuildRequestData>k__BackingField = value;
- }
- }
-
- public Microsoft.Build.Execution.BuildResult BuildResult
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.buildResult;
- }
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- set
- {
- this.buildResult = value;
- }
- }
-
- public bool IsCompleted
- {
- get
- {
- return this.WaitHandle.WaitOneNoMessagePump(new TimeSpan(0L));
- }
- }
-
- public int SubmissionId
- {
- [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.<SubmissionId>k__BackingField;
- }
- [CompilerGenerated]
- private set
- {
- this.<SubmissionId>k__BackingField = value;
- }
- }
-
- public System.Threading.WaitHandle WaitHandle
- {
- [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
- get
- {
- return this.completionEvent;
- }
- }
- }
- }
-