/// <summary> /// Executes the Activity /// </summary> /// <param name="context"></param> protected override void Execute(NativeActivityContext context) { // // We must enter a NoPersist zone because it looks like we're idle while our // Task is executing but, we aren't really // NoPersistHandle noPersistHandle = NoPersistHandle.Get(context); noPersistHandle.Enter(context); // // Set a bookmark that we will resume when our Task is done // m_Bookmark = context.CreateBookmark(BookmarkResumptionCallback); this.Bookmark.Set(context, m_Bookmark); m_BookmarkResumptionHelper = context.GetExtension <BookmarkResumptionHelper>(); // // Prepare to execute // PrepareToExecute(context); // // Start a Task to do the actual execution of our activity // CancellationTokenSource tokenSource = new CancellationTokenSource(); m_Task = Task.Factory.StartNew(ExecuteNonblocking, tokenSource.Token); m_Task.ContinueWith(TaskCompletionCallback); }
protected override void Execute(NativeActivityContext context) { // setup a no persist zone (don't want to be persisted while querying or mapping values) NoPersistHandle noPersistHandle = this.noPersistHandle.Get(context); noPersistHandle.Enter(context); // configure the helper object to access the database dbHelper = new DbHelper(); dbHelper.ConnectionString = this.ConnectionString.Get(context); dbHelper.ProviderName = this.ProviderName.Get(context); dbHelper.ConfigName = this.ConfigName.Get(context); dbHelper.Sql = this.Sql.Get(context); dbHelper.CommandType = this.CommandType; dbHelper.Parameters = this.parameters; dbHelper.Init(context); // retrieve the data this.reader = dbHelper.ExecuteReader(); // map the results if (this.Mapper != null) { // direct execution (invoke the Mapper function in a single pulse) DirectMapping(context); } else // execute in multiple pulses (each pulse invokes the MapperAction ActivityFunc) { // initialize results list this.Result.Set(context, new List <TResult>()); // map a record InternalMapRecord(context); } }
protected override void Execute(NativeActivityContext context) { var noPersistHandle = NoPersistHandle.Get(context); noPersistHandle.Enter(context); var bookmark = context.CreateBookmark(BookmarkResumptionCallback); this.Bookmark.Set(context, bookmark); BookmarkResumptionHelper helper = context.GetExtension <BookmarkResumptionHelper>(); Action <IAsyncResult> resumeBookmarkAction = (result) => { helper.ResumeBookmark(bookmark, result); }; IAsyncResult asyncResult = this.BeginExecute(context, AsyncCompletionCallback, resumeBookmarkAction); if (asyncResult.CompletedSynchronously) { noPersistHandle.Exit(context); context.RemoveBookmark(bookmark); EndExecute(context, asyncResult); } }
private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value) { var noPersistHandle = NoPersistHandle.Get(context); if (m_Task.IsFaulted) { // // The task had a problem // Console.WriteLine("Exception from ExecuteNonBlocking task:"); Exception ex = m_Task.Exception; while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } // // If there was an exception exit the no persist handle and rethrow. // if (m_Task.Exception != null) { noPersistHandle.Exit(context); throw m_Task.Exception; } } AfterExecute(context); noPersistHandle.Exit(context); }
private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value) { NoPersistHandle noPersistHandle = this.NoPersistHandle.Get(context); noPersistHandle.Exit(context); System.IAsyncResult result = value as System.IAsyncResult; this.EndExecute(context, result); }
protected override void Execute(NativeActivityContext context) { if (this.Body != null) { NoPersistHandle handle = this.noPersistHandle.Get(context); handle.Enter(context); context.ScheduleActivity(this.Body); } }
private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value) { var noPersistHandle = NoPersistHandle.Get(context); noPersistHandle.Exit(context); // unnecessary since it's not multiple resume: // context.RemoveBookmark(bookmark); IAsyncResult asyncResult = value as IAsyncResult; this.EndExecute(context, asyncResult); }
protected override void Execute(NativeActivityContext context) { TestTraceListenerExtension listenerExtension = context.GetExtension <TestTraceListenerExtension>(); NoPersistHandle handle = _noPersistHandle.Get(context); handle.Enter(context); UserTrace.Trace(listenerExtension, context.WorkflowInstanceId, NoPersistenceBlockEntered); // Schedule all of the Sequence's Activities base.Execute(context); UserTrace.Trace(listenerExtension, context.WorkflowInstanceId, NoPersistenceBlockExited); }
protected override void Execute(NativeActivityContext context) { string bookmarkName = BookmarkName.Get(context); NoPersistHandle noPersistHandleToEnter = noPersistHandle.Get(context); noPersistHandleToEnter.Enter(context); Bookmark bookmark = context.CreateBookmark(bookmarkName, (NativeActivityContext _callbackContext, Bookmark _bookmark, object _state) => { NoPersistHandle noPersistHandleToExit = noPersistHandle.Get(_callbackContext); noPersistHandleToExit.Exit(_callbackContext); }); this.bookmark.Set(context, bookmark); }
protected override void Execute(NativeActivityContext context) { // enter a no persist scope NoPersistHandle noPersistHandle = this.noPersistHandle.Get(context); noPersistHandle.Enter(context); // get the connection string string connectionString = this.ConnectionString.Get(context); // create the connection context this.efContext = new ObjectContext(connectionString); // use NorthwindEntities as the container name for this example until the default container feature is in this.efContext.DefaultContainerName = this.ContainerName.Get(context); // set the object context in the execution properties (to make it an ambient object context) context.Properties.Add(ObjectContextPropertyName, efContext); // schedule the body activity context.ScheduleActivity(this.Body, new CompletionCallback(OnBodyComplete)); }
protected override void Execute(NativeActivityContext context) { NoPersistHandle noPersistHandle = this.NoPersistHandle.Get(context); noPersistHandle.Enter(context); Bookmark bookmark = context.CreateBookmark(new BookmarkCallback(this.BookmarkResumptionCallback)); this.Bookmark.Set(context, bookmark); BookmarkResumptionHelper helper = context.GetExtension <BookmarkResumptionHelper>(); System.Action <System.IAsyncResult> state = delegate(System.IAsyncResult result) { helper.ResumeBookmark(bookmark, result); }; System.IAsyncResult asyncResult = this.BeginExecute(context, new System.AsyncCallback(this.AsyncCompletionCallback), state); if (asyncResult.CompletedSynchronously) { noPersistHandle.Exit(context); context.RemoveBookmark(bookmark); this.EndExecute(context, asyncResult); } }
protected override void OnInitialize(HandleInitializationContext context) { this.noPersistHandle = context.CreateAndInitializeHandle <NoPersistHandle>(); this.bookmarkScopeHandle = context.CreateAndInitializeHandle <BookmarkScopeHandle>(); }
protected override void Execute(NativeActivityContext context) { Message inMessage = null; try { inMessage = this.Message.Get(context); object[] outObjects; if (this.parameters == null || this.parameters.Count == 0) { outObjects = Constants.EmptyArray; } else { outObjects = new object[this.parameters.Count]; } // The formatter would be null if there is no parameters to Deserialize in message contracts if (this.Formatter != null) { this.Formatter.DeserializeRequest(inMessage, outObjects); } else { Fx.Assert(this.parameters == null, "There shouldn't be any parameters to be deserialized"); } if (this.parameters != null) { for (int i = 0; i < this.parameters.Count; i++) { OutArgument outArgument = this.parameters[i]; Fx.Assert(outArgument != null, "Parameter cannot be null"); object obj = outObjects[i]; if (obj == null) { obj = ProxyOperationRuntime.GetDefaultParameterValue(outArgument.ArgumentType); } outArgument.Set(context, obj); } } } finally { if (this.CloseMessage && inMessage != null) { inMessage.Close(); } this.Message.Set(context, null); bool useNoPersistHandle = UseNoPersistHandle(context); if (useNoPersistHandle) { NoPersistHandle handle = (this.NoPersistHandle == null) ? null : this.NoPersistHandle.Get(context); if (handle != null) { handle.Exit(context); } } } }