PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. namespace Microsoft.Build.Execution
  2. {
  3. using Microsoft.Build.BackEnd;
  4. using Microsoft.Build.BackEnd.Logging;
  5. using Microsoft.Build.Shared;
  6. using System;
  7. using System.Runtime;
  8. using System.Runtime.CompilerServices;
  9. using System.Threading;
  10. public class BuildSubmission
  11. {
  12. private Microsoft.Build.Execution.BuildResult buildResult;
  13. private BuildSubmissionCompleteCallback completionCallback;
  14. private ManualResetEvent completionEvent;
  15. private int completionInvoked;
  16. private bool legacyThreadingSemantics;
  17. private bool loggingCompleted;
  18. internal BuildSubmission(Microsoft.Build.Execution.BuildManager buildManager, int submissionId, Microsoft.Build.Execution.BuildRequestData requestData, bool legacyThreadingSemantics)
  19. {
  20. ErrorUtilities.VerifyThrowArgumentNull(buildManager, "buildManager");
  21. ErrorUtilities.VerifyThrowArgumentNull(requestData, "requestData");
  22. this.BuildManager = buildManager;
  23. this.SubmissionId = submissionId;
  24. this.BuildRequestData = requestData;
  25. this.completionEvent = new ManualResetEvent(false);
  26. this.loggingCompleted = false;
  27. this.completionInvoked = 0;
  28. this.legacyThreadingSemantics = legacyThreadingSemantics;
  29. }
  30. private void CheckForCompletion()
  31. {
  32. WaitCallback callBack = null;
  33. if (((this.BuildResult != null) && this.loggingCompleted) && (Interlocked.Exchange(ref this.completionInvoked, 1) != 1))
  34. {
  35. this.completionEvent.Set();
  36. if (this.completionCallback != null)
  37. {
  38. if (callBack == null)
  39. {
  40. callBack = delegate (object state) {
  41. this.completionCallback(this);
  42. };
  43. }
  44. ThreadPool.QueueUserWorkItem(callBack);
  45. }
  46. }
  47. }
  48. internal void CompleteLogging(bool waitForLoggingThread)
  49. {
  50. if (waitForLoggingThread)
  51. {
  52. ((LoggingService) ((IBuildComponentHost) this.BuildManager).LoggingService).WaitForThreadToProcessEvents();
  53. }
  54. this.loggingCompleted = true;
  55. this.CheckForCompletion();
  56. }
  57. internal void CompleteResults(Microsoft.Build.Execution.BuildResult result)
  58. {
  59. ErrorUtilities.VerifyThrowArgumentNull(result, "result");
  60. ErrorUtilities.VerifyThrow(result.ConfigurationId == this.BuildRequest.ConfigurationId, "BuildResult doesn't match BuildRequest configuration");
  61. if (this.BuildResult == null)
  62. {
  63. this.BuildResult = result;
  64. }
  65. this.CheckForCompletion();
  66. }
  67. public Microsoft.Build.Execution.BuildResult Execute()
  68. {
  69. this.ExecuteAsync(null, null, this.legacyThreadingSemantics);
  70. if (this.legacyThreadingSemantics)
  71. {
  72. RequestBuilder.WaitWithBuilderThreadStart(new System.Threading.WaitHandle[] { this.WaitHandle }, false, ((IBuildComponentHost) this.BuildManager).LegacyThreadingData);
  73. }
  74. else
  75. {
  76. this.WaitHandle.WaitOneNoMessagePump();
  77. }
  78. return this.BuildResult;
  79. }
  80. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  81. public void ExecuteAsync(BuildSubmissionCompleteCallback callback, object context)
  82. {
  83. this.ExecuteAsync(callback, context, false);
  84. }
  85. private void ExecuteAsync(BuildSubmissionCompleteCallback callback, object context, bool allowMainThreadBuild)
  86. {
  87. ErrorUtilities.VerifyThrowInvalidOperation(!this.IsCompleted, "SubmissionAlreadyComplete");
  88. this.completionCallback = callback;
  89. this.AsyncContext = context;
  90. this.BuildManager.ExecuteSubmission(this, allowMainThreadBuild);
  91. }
  92. public object AsyncContext
  93. {
  94. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  95. get
  96. {
  97. return this.<AsyncContext>k__BackingField;
  98. }
  99. [CompilerGenerated]
  100. private set
  101. {
  102. this.<AsyncContext>k__BackingField = value;
  103. }
  104. }
  105. public Microsoft.Build.Execution.BuildManager BuildManager
  106. {
  107. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  108. get
  109. {
  110. return this.<BuildManager>k__BackingField;
  111. }
  112. [CompilerGenerated]
  113. private set
  114. {
  115. this.<BuildManager>k__BackingField = value;
  116. }
  117. }
  118. internal Microsoft.Build.BackEnd.BuildRequest BuildRequest
  119. {
  120. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  121. get
  122. {
  123. return this.<BuildRequest>k__BackingField;
  124. }
  125. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  126. set
  127. {
  128. this.<BuildRequest>k__BackingField = value;
  129. }
  130. }
  131. internal Microsoft.Build.Execution.BuildRequestData BuildRequestData
  132. {
  133. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  134. get
  135. {
  136. return this.<BuildRequestData>k__BackingField;
  137. }
  138. [CompilerGenerated]
  139. private set
  140. {
  141. this.<BuildRequestData>k__BackingField = value;
  142. }
  143. }
  144. public Microsoft.Build.Execution.BuildResult BuildResult
  145. {
  146. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  147. get
  148. {
  149. return this.buildResult;
  150. }
  151. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  152. set
  153. {
  154. this.buildResult = value;
  155. }
  156. }
  157. public bool IsCompleted
  158. {
  159. get
  160. {
  161. return this.WaitHandle.WaitOneNoMessagePump(new TimeSpan(0L));
  162. }
  163. }
  164. public int SubmissionId
  165. {
  166. [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  167. get
  168. {
  169. return this.<SubmissionId>k__BackingField;
  170. }
  171. [CompilerGenerated]
  172. private set
  173. {
  174. this.<SubmissionId>k__BackingField = value;
  175. }
  176. }
  177. public System.Threading.WaitHandle WaitHandle
  178. {
  179. [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  180. get
  181. {
  182. return this.completionEvent;
  183. }
  184. }
  185. }
  186. }