コード例 #1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            INotificationCallback callBack = context.GetExtension <INotificationCallback>();

            if (callBack != null)
            {
                callBack.SendClientNotification(new ComponentProcessMessage().CreateServerMessage(
                                                    Batch.Get(context).Id,
                                                    Group.Get(context).Id, new Guid(),
                                                    "Group Started"));
            }
            Thread thread = new Thread(DoProcess)
            {
                IsBackground = true
            };
            var result = new AsyncGroupResult(callback, state)
            {
                ComponentList = ComponentList.Get(context),
                GroupNode     = GroupNode.Get(context),
                Batch         = Batch.Get(context),
                Group         = Group.Get(context),
                RunningThread = thread,
                GroupCallback = context.GetExtension <INotificationCallback>()
            };

            context.UserState = result;

            thread.Start(result);
            return(result);
        }
コード例 #2
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            INotificationCallback callBack = context.GetExtension <INotificationCallback>();

            if (callBack != null)
            {
            }
            Thread thread = new Thread(DoProcess)
            {
                IsBackground = true
            };
            var startNode = ComponentParameters.Get(context)[0].FindStartupNode(ComponentParameters.Get(context));

            Workflow.Activities.AsyncNodeResult result = new Workflow.Activities.AsyncNodeResult(callback, state)
            {
                ComponentList = ComponentParameters.Get(context),
                StartNode     = startNode,
                Batch         = Batch.Get(context),
                Job           = (ProcessJob)(Batch.Get(context)).Groups[0].Jobs[0],
                Group         = Batch.Get(context).Groups[0],
                JobCallback   = context.GetExtension <INotificationCallback>(),
                RunningThread = thread,
            };
            context.UserState = result;

            thread.Start(result);
            return(result);
        }
コード例 #3
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            AsyncNodeResult endResult = result as AsyncNodeResult;

            if (endResult.Exception != null)
            {
                INotificationCallback callBack = context.GetExtension <INotificationCallback>();
                if (callBack != null)
                {
                    callBack.SendClientNotification(new ComponentProcessMessage().CreateErrorMessage(
                                                        Batch.Get(context).Id,
                                                        Group.Get(context).Id,
                                                        Job.Get(context).Id,
                                                        endResult.Exception.Message));
                }
                log4net.ILog log4Net = context.GetExtension <log4net.ILog>();
                if (log4Net != null)
                {
                    log4Net.Fatal(new ComponentProcessMessage().CreateErrorMessage(
                                      Batch.Get(context).Id,
                                      Group.Get(context).Id,
                                      Job.Get(context).Id,
                                      endResult.Exception.Message));
                }
            }
            else
            {
                INotificationCallback callBack = context.GetExtension <INotificationCallback>();
                if (callBack != null)
                {
                    callBack.SendClientNotification(new ComponentProcessMessage().CreateServerMessage(
                                                        Batch.Get(context).Id,
                                                        Group.Get(context).Id,
                                                        Job.Get(context).Id,
                                                        "Job Ended"));
                }
            }


            if (endResult != null && endResult.NextNode != null)
            {
                NextParameter.Set(context, endResult.NextNode);
                endResult.Dispose();
            }

            if (endResult.Exception != null && !context.IsCancellationRequested)
            {
                //throw new ApplicationException("Error generating reports. See inner for details", endResult.Exception);
            }
        }
コード例 #4
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            DataTable    dataTable        = null;
            string       connString       = null;
            SecureString connSecureString = null;
            string       provName         = null;
            string       tableName        = null;

            string[]           columnNames        = null;
            DatabaseConnection existingConnection = null;
            long             affectedRecords      = 0;
            IExecutorRuntime executorRuntime      = null;
            var continueOnError = ContinueOnError.Get(context);

            try
            {
                existingConnection = DbConnection = ExistingDbConnection.Get(context);
                connString         = ConnectionString.Get(context);
                provName           = ProviderName.Get(context);
                tableName          = TableName.Get(context);
                dataTable          = DataTable.Get(context);
                columnNames        = ColumnNames.Get(context);
                executorRuntime    = context.GetExtension <IExecutorRuntime>();
                connSecureString   = ConnectionSecureString.Get(context);
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                affectedRecords = await Task.Run(() =>
                {
                    DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString != null ? connString : new NetworkCredential("", connSecureString).Password, provName);
                    if (DbConnection == null)
                    {
                        return(0);
                    }
                    if (executorRuntime != null && executorRuntime.HasFeature(ExecutorFeatureKeys.LogMessage))
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames, executorRuntime));
                    }
                    else
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames));
                    }
                });
            }
            catch (Exception ex)
            {
                HandleException(ex, continueOnError);
            }
            finally
            {
                if (existingConnection == null)
                {
                    DbConnection?.Dispose();
                }
            }

            return(asyncCodeActivityContext =>
            {
                AffectedRecords.Set(asyncCodeActivityContext, affectedRecords);
            });
        }
コード例 #5
0
 /// <summary>
 /// Executes the user code to retrieve the task.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 Task ExecuteInternalAsync(AsyncCodeActivityContext context)
 {
     // search local, for an executor scope, or default to the extension
     return(ExecuteAsync(context,
                         Executor ??
                         context.GetProperty <AsyncTaskExecutorHandle>()?.Executor ??
                         context.GetExtension <AsyncTaskExtension>().Executor));
 }
コード例 #6
0
        protected override void EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            AsyncGroupResult endResult = result as AsyncGroupResult;

            if (endResult != null)
            {
                NextNode.Set(context, endResult.NextNode);
                endResult.Dispose();
            }

            if (endResult.Exception != null)
            {
                INotificationCallback callBack = context.GetExtension <INotificationCallback>();
                callBack.SendClientNotification(new ComponentProcessMessage().CreateErrorMessage(
                                                    Batch.Get(context).Id,
                                                    Group.Get(context).Id,
                                                    new Guid(),
                                                    endResult.Exception.Message));
            }
            else
            {
                INotificationCallback callBack = context.GetExtension <INotificationCallback>();
                if (callBack != null)
                {
                    callBack.SendClientNotification(new ComponentProcessMessage().CreateServerMessage(
                                                        Batch.Get(context).Id,
                                                        Group.Get(context).Id,
                                                        new Guid(),
                                                        "Group Ended"));
                }
            }



            if (endResult.Exception != null && !context.IsCancellationRequested)
            {
                throw new ApplicationException("Error generating reports. See inner for details", endResult.Exception);
            }
        }
コード例 #7
0
ファイル: ExecuteQuery.cs プロジェクト: theresadower/graywulf
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext activityContext, AsyncCallback callback, object state)
        {
            QueryPartitionBase querypartition = QueryPartition.Get(activityContext);

            using (Context context = querypartition.Query.CreateContext(this, activityContext, ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                querypartition.PrepareExecuteQuery(context, activityContext.GetExtension <IScheduler>());
            }

            Guid   workflowInstanceGuid = activityContext.WorkflowInstanceId;
            string activityInstanceId   = activityContext.ActivityInstanceId;

            return(EnqueueAsync(_ => OnAsyncExecute(workflowInstanceGuid, activityInstanceId, querypartition), callback, state));
        }
コード例 #8
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            TestTraceListenerExtension listenerExtension = context.GetExtension <TestTraceListenerExtension>();

            UserTrace.Trace(listenerExtension, context.WorkflowInstanceId, AsyncOperationBlockEntered);

            AsyncWorkState asyncWorkState = new AsyncWorkState()
            {
                InstanceID        = context.WorkflowInstanceId,
                Duration          = this.Duration.Get(context),
                ListenerExtension = listenerExtension
            };

            return(new AsyncOperationBlockActivityAsyncResult(asyncWorkState, callback, state));
        }
コード例 #9
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext activityContext, AsyncCallback callback, object state)
        {
            var    query = Query.Get(activityContext);
            var    tableReference = TableReference.Get(activityContext);
            string connectionString, sql;

            using (Context context = query.CreateContext(this, activityContext, ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
            {
                query.InitializeQueryObject(context, activityContext.GetExtension <IScheduler>(), false);
                query.PrepareComputeTableStatistics(context, tableReference, out connectionString, out sql);
            }

            Guid   workflowInstanceGuid = activityContext.WorkflowInstanceId;
            string activityInstanceId   = activityContext.ActivityInstanceId;

            return(EnqueueAsync(_ => OnAsyncExecute(workflowInstanceGuid, activityInstanceId, query, tableReference, connectionString, sql), callback, state));
        }
コード例 #10
0
ファイル: ShellExec.cs プロジェクト: markjulmar/BioWorkflow
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            string fn = Filename.Get(context);

            if (string.IsNullOrWhiteSpace(fn))
            {
                throw new ArgumentNullException("Filename", "Missing filename to execute.");
            }

            string     args = Arguments.Get(context);
            TextWriter tw   = context.GetExtension <TextWriter>() ?? Console.Out;

            Func <int> exec = () =>
            {
                ProcessStartInfo psi = new ProcessStartInfo(fn)
                {
                    CreateNoWindow         = true,
                    ErrorDialog            = false,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = this.UseShellExec,
                };

                if (!string.IsNullOrEmpty(args))
                {
                    psi.Arguments = args;
                }

                _process = Process.Start(psi);
                _process.OutputDataReceived += (sender, eventArgs) => tw.WriteLine(eventArgs.Data);
                _process.ErrorDataReceived  += (sender, eventArgs) => tw.WriteLine(eventArgs.Data);
                _process.WaitForExit();

                int rc = _process.ExitCode;
                _process = null;
                return(rc);
            };

            context.UserState = exec;
            return(exec.BeginInvoke(callback, state));
        }
コード例 #11
0
ファイル: ReadLine.cs プロジェクト: markjulmar/BioWorkflow
        /// <summary>
        /// When implemented in a derived class and using the specified execution context, callback method, and user state, enqueues an asynchronous activity in a run-time workflow.
        /// </summary>
        /// <returns>
        /// An object.
        /// </returns>
        /// <param name="context">Information that defines the execution environment for the <see cref="T:System.Activities.AsyncCodeActivity"/>.</param><param name="callback">The method to be called after the asynchronous activity and completion notification have occurred.</param><param name="state">An object that saves variable information for an instance of an asynchronous activity.</param>
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            TextReader textReader = context.GetExtension <TextReader>() ?? Console.In;

            if (textReader == null)
            {
                throw new Exception("Missing TextReader extension for ReadLine activity.");
            }

            var           tcs  = new TaskCompletionSource <string>(state);
            Task <string> task = textReader.ReadLineAsync();

            task.ContinueWith(tr =>
            {
                // Copy the Task.Result into the Task WF sees.
                if (tr.IsFaulted)
                {
                    tcs.TrySetException(tr.Exception.InnerExceptions);
                }
                else if (tr.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(tr.Result);
                }

                // Invoke the callback so WF sees it.
                if (callback != null)
                {
                    callback(tcs.Task);
                }
            });

            return(tcs.Task);
        }