protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state) { if (context == null) { throw new ArgumentNullException("context"); } Runspace runspace = null; Pipeline pipeline = null; PipelineInvokerAsyncResult pipelineInvokerAsyncResult = null; var script = this.ResolveScript( this.BuildWorkspace.Get(context), this.Script.Get(context), this.Arguments.Get(context)); context.Track(new System.Activities.Tracking.CustomTrackingRecord(string.Format(CultureInfo.CurrentCulture, "Script resolved to {0}", script))); //context.TrackBuildMessage(string.Format(CultureInfo.CurrentCulture, "Script resolved to {0}", script), BuildMessageImportance.Low); try { runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); pipeline = runspace.CreatePipeline(script); context.UserState = pipeline; pipelineInvokerAsyncResult = new PipelineInvokerAsyncResult(pipeline, callback, state); return(pipelineInvokerAsyncResult); } finally { if (runspace != null) { runspace.Dispose(); } if (pipeline != null) { pipeline.Dispose(); } if (pipelineInvokerAsyncResult != null) { pipelineInvokerAsyncResult.Dispose(); } } }
protected override void EndExecute( AsyncCodeActivityContext context, IAsyncResult result) { List <SalesOrderDetail> orderDetail = ((Func <Int32, List <SalesOrderDetail> >) context.UserState).EndInvoke(result); if (orderDetail != null) { OrderDetail.Set(context, orderDetail); //add custom tracking CustomTrackingRecord trackRec = new CustomTrackingRecord("QueryResults"); trackRec.Data.Add("Count", orderDetail.Count); context.Track(trackRec); } }