Beispiel #1
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            var task = result as Task <string>;

            if (task.IsFaulted)
            {
                throw task.Exception.InnerException;
            }
            if (task.IsCanceled || context.IsCancellationRequested)
            {
                context.MarkCanceled();
                return;
            }

            try
            {
                if (Text != null && Text.Expression != null)
                {
                    try
                    {
                        Text.Set(context, task.Result);
                    }
                    catch (InvalidOperationException)
                    {
                        Text.Set(context, TypeDescriptor.GetConverter(Text.ArgumentType).ConvertFrom(task.Result));
                    }
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
        }
Beispiel #2
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <T> task = (Task <T>)result;

            if (task == null)
            {
                this.OutputResult(context, default(T));
            }
            try
            {
                if (task.IsFaulted)
                {
                    throw task.Exception.InnerException ?? task.Exception;
                }
                if (task.IsCanceled || context.IsCancellationRequested)
                {
                    context.MarkCanceled();
                }
                else
                {
                    this.OutputResult(context, task.Result);
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
            catch
            {
                if (!this.ContinueOnError.Get(context))
                {
                    throw;
                }
            }
        }
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            var task = result as Task <HttpResponseMessage>;

            if (task.IsFaulted)
            {
                throw task.Exception.InnerException;
            }
            if (task.IsCanceled || context.IsCancellationRequested)
            {
                context.MarkCanceled();
                return;
            }

            try
            {
                var response         = task.Result;
                var requestSuccesful = response.StatusCode == HttpStatusCode.OK;
                var output           = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                HTTPResponseStatus.Set(context, response.StatusCode);
                HTTPResponseBody.Set(context, output);
                HTTPResponseHeaders.Set(context, response.Headers);
                RequestSuccesful.Set(context, requestSuccesful);

                try
                {
                    APIResponse deserializedAPIResponse = JsonConvert.DeserializeObject <APIResponse>(output);
                    APIResponse.Set(context, deserializedAPIResponse);
                }
                catch (Exception)
                {
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
            finally
            {
                if (task.Result != null)
                {
                    task.Result.Dispose();
                }
            }
        }
Beispiel #4
0
 //<snippet10>
 protected override void Cancel(AsyncCodeActivityContext context)
 {
     // Implement any cleanup as a result of the asynchronous work
     // being canceled, and then call MarkCanceled.
     if (context.IsCancellationRequested)
     {
         context.MarkCanceled();
     }
 }
    protected override void Cancel(AsyncCodeActivityContext context)
    {
        var cts = (CancellationTokenSource)context.UserState;

        cts.Cancel();
        if (context.IsCancellationRequested)
        {
            context.MarkCanceled();
        }
    }
Beispiel #6
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <object> task = (Task <object>)result;

            try
            {
                if (task.IsFaulted)
                {
                    throw task.Exception.InnerException;
                }
                if (task.IsCanceled || context.IsCancellationRequested)
                {
                    context.MarkCanceled();
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
        }
Beispiel #7
0
 protected sealed override void EndExecute(AsyncCodeActivityContext context, IAsyncResult asyncResult)
 {
     try
     {
         AsyncFactory.ToEnd(asyncResult);
         PostExecute(context);
     }
     catch (OperationCanceledException) when(context.IsCancellationRequested)
     {
         context.MarkCanceled();
     }
 }
Beispiel #8
0
 protected sealed override void EndExecute(AsyncCodeActivityContext context, IAsyncResult asyncResult)
 {
     try
     {
         AsyncFactory.ToEnd(asyncResult);
         PostExecute(context, (context.UserState as Tuple <TState, CancellationTokenSource>).Item1);
     }
     catch (OperationCanceledException) when(context.IsCancellationRequested)
     {
         context.MarkCanceled();
     }
 }
        protected override string EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            var task = result as Task<string>;

            if (task.IsFaulted) throw task.Exception.InnerException;
            if (task.IsCanceled || context.IsCancellationRequested)
            {
                context.MarkCanceled();
                return string.Empty;
            }

            return task.Result;
        }
        /// <summary>
        /// Cancels the execution of the activity.
        /// </summary>
        /// <param name="context"></param>
        /// <remarks>
        /// This method cancels all registered runnin cancelable tasks before marking the
        /// activity canceled.
        /// </remarks>
        protected override void Cancel(AsyncCodeActivityContext context)
        {
            string id = String.Format("{0}_{1}", context.WorkflowInstanceId.ToString(), context.ActivityInstanceId);

            if (cancelableTasks.ContainsKey(id))
            {
                cancelableTasks[id].Cancel();
            }

            // This is absolutely important here:
            context.MarkCanceled();

            base.Cancel(context);
        }
        protected override T EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            var task = result as Task <T>;

            if (task.IsFaulted)
            {
                throw task.Exception.InnerException;
            }
            if (task.IsCanceled || context.IsCancellationRequested)
            {
                context.MarkCanceled();
            }

            return(task.Result);
        }
Beispiel #12
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <IEnumerable <string> > task = (Task <IEnumerable <string> >)result;

            try
            {
                if (task.IsFaulted)
                {
                    throw task.Exception.InnerException;
                }
                if (task.IsCanceled || context.IsCancellationRequested)
                {
                    context.MarkCanceled();
                }
                else
                {
                    Attachments.Set(context, task.Result);
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
        }
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <List <MailMessage> > task = (Task <List <MailMessage> >)result;

            try
            {
                if (task.IsFaulted)
                {
                    throw task.Exception.InnerException;
                }
                if (task.IsCanceled || context.IsCancellationRequested)
                {
                    context.MarkCanceled();
                }
                else
                {
                    Messages.Set(context, task.Result);
                }
            }
            catch (OperationCanceledException)
            {
                context.MarkCanceled();
            }
        }
Beispiel #14
0
        protected override void Cancel(AsyncCodeActivityContext context)
        {
            BatchCleaningAsyncResult result =
                context.UserState as BatchCleaningAsyncResult;

            context.MarkCanceled();

            if (result != null)
            {
                result.Canceled = true;
                if (result.RunningThread.IsAlive)
                {
                    result.RunningThread.Abort();
                }
            }
            base.Cancel(context);
        }
Beispiel #15
0
        protected override void Cancel(AsyncCodeActivityContext context)
        {
            CommandContext userState = context.UserState as CommandContext;

            if (userState != null && userState.Process != null)
            {
                userState.Process.Kill();

                if (File.Exists(userState.LogFile))
                {
                    File.Delete(userState.LogFile);
                }
            }

            if (context.IsCancellationRequested)
            {
                context.MarkCanceled();
            }
        }
Beispiel #16
0
 protected sealed override T EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
 {
     try
     {
         return(AsyncFactory <T> .ToEnd(result));
     }
     catch (OperationCanceledException)
     {
         if (context.IsCancellationRequested)
         {
             context.MarkCanceled();
         }
         else
         {
             throw;
         }
         return(default(T));    // or throw?
     }
 }
Beispiel #17
0
        protected override void Cancel(AsyncCodeActivityContext context)
        {
            CommandContext userState = context.UserState as CommandContext;

            if (userState != null && userState.Process != null)
            {
                // Kill the AxBuild process
                int processId = userState.Process.Id;
                userState.Process.Kill();

                // Find all Ax32Serv.exe sub-processes of the AxBuild
                using (var mos = new ManagementObjectSearcher(string.Format("SELECT ProcessId, Name FROM Win32_Process WHERE ParentProcessId = {0}", processId)))
                {
                    foreach (var obj in mos.Get())
                    {
                        string processName = (string)obj.Properties["Name"].Value;
                        if (processName == "Ax32Serv.exe")
                        {
                            UInt32 pid = (UInt32)obj.Properties["ProcessId"].Value;
                            if (pid != 0)
                            {
                                Process subProcess = Process.GetProcessById(Convert.ToInt32(pid));
                                if (!subProcess.HasExited)
                                {
                                    subProcess.Kill();
                                }
                            }
                        }
                    }
                }

                if (File.Exists(userState.LogFile))
                {
                    File.Delete(userState.LogFile);
                }
            }

            if (context.IsCancellationRequested)
            {
                context.MarkCanceled();
            }
        }
Beispiel #18
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <T> task = (Task <T>)result;

            if (task.IsFaulted)
            {
                ExceptionDispatchInfo.Capture(task.Exception.InnerException).Throw();
            }
            if (task.IsCanceled)
            {
                context.MarkCanceled();
            }

            if (!_tokenDisposed)
            {
                _cancellationTokenSource?.Dispose();

                _tokenDisposed = true;
            }
        }
        public void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Task <Action <AsyncCodeActivityContext> > task = (Task <Action <AsyncCodeActivityContext> >)result;

            if (task.IsFaulted)
            {
                ExceptionDispatchInfo.Capture(task.Exception.InnerException).Throw();
            }
            if (task.IsCanceled || context.IsCancellationRequested)
            {
                context.MarkCanceled();
            }

            task.Result?.Invoke(context);

            if (!_tokenDisposed)
            {
                _cancellationTokenSource?.Dispose();

                _tokenDisposed = true;
            }
        }