/// <summary> /// Cleans up after running the task. /// </summary> void ITaskExecutionHost.CleanupForTask() { if (_resolver != null) { _resolver.RemoveHandler(); _resolver = null; } _taskFactoryWrapper = null; // We must null this out because it could be a COM object (or any other ref-counted object) which needs to // be released. _taskHost = null; CleanupCancellationToken(); ErrorUtilities.VerifyThrow(_taskInstance == null, "Task Instance should be null"); }
/// <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; }