/// <summary> /// Initialize to run a specific batch of the current task. /// </summary> bool ITaskExecutionHost.InitializeForBatch(TaskLoggingContext loggingContext, ItemBucket batchBucket, IDictionary<string, string> taskIdentityParameters) { ErrorUtilities.VerifyThrowArgumentNull(loggingContext, "loggingContext"); ErrorUtilities.VerifyThrowArgumentNull(batchBucket, "batchBucket"); _taskLoggingContext = loggingContext; _batchBucket = batchBucket; if (_taskFactoryWrapper == null) { return false; } // If the task assembly is loaded into a separate AppDomain using LoadFrom, then we have a problem // to solve - when the task class Type is marshalled back into our AppDomain, it's not just transferred // here. Instead, NDP will try to Load (not LoadFrom!) the task assembly into our AppDomain, and since // we originally used LoadFrom, it will fail miserably not knowing where to find it. // We need to temporarily subscribe to the AppDomain.AssemblyResolve event to fix it. if (null == _resolver) { _resolver = new TaskEngineAssemblyResolver(); _resolver.Initialize(_taskFactoryWrapper.TaskFactoryLoadedType.Assembly.AssemblyFile); _resolver.InstallHandler(); } // We instantiate a new task object for each batch _taskInstance = InstantiateTask(taskIdentityParameters); if (_taskInstance == null) { return false; } _taskInstance.BuildEngine = _buildEngine; _taskInstance.HostObject = _taskHost; return true; }
/// <summary> /// Constructor /// </summary> public TaskHostTask(IElementLocation taskLocation, TaskLoggingContext taskLoggingContext, IBuildComponentHost buildComponentHost, IDictionary<string, string> taskHostParameters, LoadedType taskType, AppDomainSetup appDomainSetup) { ErrorUtilities.VerifyThrowInternalNull(taskType, "taskType"); _taskLocation = taskLocation; _taskLoggingContext = taskLoggingContext; _buildComponentHost = buildComponentHost; _taskType = taskType; _appDomainSetup = appDomainSetup; _taskHostParameters = taskHostParameters; _packetFactory = new NodePacketFactory(); (this as INodePacketFactory).RegisterPacketHandler(NodePacketType.LogMessage, LogMessagePacket.FactoryForDeserialization, this); (this as INodePacketFactory).RegisterPacketHandler(NodePacketType.TaskHostTaskComplete, TaskHostTaskComplete.FactoryForDeserialization, this); (this as INodePacketFactory).RegisterPacketHandler(NodePacketType.NodeShutdown, NodeShutdown.FactoryForDeserialization, this); _packetReceivedEvent = new AutoResetEvent(false); _receivedPackets = new Queue<INodePacket>(); _taskHostLock = new Object(); _setParameters = new Dictionary<string, object>(); }