Example #1
0
 private static long CountMilliseconds(ExecutingAction method)
 {
     var stopwatch = new Stopwatch();
     stopwatch.Start();
     method();
     stopwatch.Stop();
     return stopwatch.ElapsedMilliseconds;
 }
Example #2
0
 public virtual void Restore(IActivityStorage storage)
 {
     if (!CanInduceIdle)
     {
         return;
     }
     _onComplete = storage.GetCallback(ON_COMPLETE);
     _token      = storage.GetToken(TOKEN);
 }
        public override void Execute(object parameter)
        {
            if (IsExecuting)
            {
                return;
            }

            ExecutingAction.BeginInvoke(parameter, ExecutionCompleted, null);
            IsExecuting = true;
        }
 public void SetCallback(String name, ExecutingAction callback)
 {
     if (IsLoading)
     {
         throw new InvalidOperationException("Set in loading mode");
     }
     if (callback == null)
     {
         return;
     }
     _expando.Set(name, CallbackItem.CreateFrom(callback));
 }
Example #5
0
        public override async ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            _onComplete = onComplete;
            _token      = token;
            // boundary events
            foreach (var ev in Parent.FindAll <BoundaryEvent>(ev => ev.AttachedToRef == Id))
            {
                await ev.ExecuteAsync(context, Parent.NewToken(), EventComplete);
            }

            // loop here
            await ExecuteBody(context);
        }
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            _onComplete = onComplete;
            var startNode = States.Find(s => s.IsStart);

            if (startNode == null)
            {
                throw new WorkflowException("Flowchart. Start node not found");
            }
            _currentState = startNode.Id;
            context.Schedule(startNode, OnNextState, token);
            return(ValueTask.CompletedTask);
        }
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     _onComplete = onComplete;
     _token      = token;
     NextState   = null;
     if (Trigger != null)
     {
         context.Schedule(Trigger, OnTriggerComplete, token);
     }
     else
     {
         return(ContinueExecute(context));
     }
     return(ValueTask.CompletedTask);
 }
Example #8
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            _onComplete = onComplete;
            _token      = token;
            var eventDef = EventDefinition;

            if (eventDef != null)
            {
                context.AddEvent(eventDef.CreateEvent(Id), this, OnTrigger);
            }
            else
            {
                SetComplete(context);
            }
            return(ValueTask.CompletedTask);
        }
Example #9
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     _onComplete = onComplete;
     if (Branches == null || Branches.Count == 0)
     {
         if (onComplete != null)
         {
             return(onComplete(context, this));
         }
         return(ValueTask.CompletedTask);
     }
     foreach (var br in Branches)
     {
         context.Schedule(br, OnBranchComplete, token);
     }
     return(ValueTask.CompletedTask);
 }
Example #10
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     _onComplete = onComplete;
     NextState   = null;
     if (Entry != null)
     {
         context.Schedule(Entry, OnEntryComplete, token);
     }
     else if (ScheduleTransitions(context))
     {
         return(ValueTask.CompletedTask);
     }
     else
     {
         return(ScheduleExit(context, Next));
     }
     return(ValueTask.CompletedTask);
 }
Example #11
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            _onComplete = onComplete;
            _token      = token;
            if (Activities == null || Activities.Count == 0)
            {
                if (onComplete != null)
                {
                    return(onComplete(context, this));
                }
                return(ValueTask.CompletedTask);
            }
            _next = 0;
            var first = Activities[_next++];

            context.Schedule(first, OnChildComplete, token);
            return(ValueTask.CompletedTask);
        }
Example #12
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            if (Nodes == null)
            {
                if (onComplete != null)
                {
                    return(onComplete(context, this));
                }
                return(ValueTask.CompletedTask);
            }
            var start = Nodes.Find(n => n.IsStart);

            if (start == null)
            {
                throw new WorkflowException($"Flowchart (Ref={Id}. Start node not found");
            }
            context.Schedule(start, onComplete, token);
            return(ValueTask.CompletedTask);
        }
Example #13
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var node = Parent.FindNode(Next);

            if (node != null)
            {
                context.Schedule(node, onComplete, token);
            }
            return(ValueTask.CompletedTask);
        }
Example #14
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            context.Execute(Id, nameof(Script));

            Parent.KillToken(token);
            if (onComplete != null)
            {
                return(onComplete(context, this));
            }
            return(ValueTask.CompletedTask);
        }
Example #15
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var val = context.Evaluate <Object>(Id, nameof(Expression));

            Console.WriteLine(val);
            if (onComplete != null)
            {
                return(onComplete(context, this));
            }
            return(ValueTask.CompletedTask);
        }
Example #16
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     throw new NotImplementedException();
 }
Example #17
0
 public abstract ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete);
Example #18
0
        public override async ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var prms   = new ExpandoObject();
            var result = await _dbContext.ExecuteAndLoadAsync <ExpandoObject, ExpandoObject>(DataSource, Procedure, prms);

            // TODO result
            if (onComplete != null)
            {
                await onComplete(context, this);
            }
        }
 public void Restore(IActivityStorage storage)
 {
     _onComplete = storage.GetCallback(ON_COMPLETE);
     _token      = storage.GetToken(TOKEN);
 }
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     _onComplete = onComplete;
     context.Schedule(Activity, OnChildComplete, token);
     return(ValueTask.CompletedTask);
 }
Example #21
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            context.Execute(Id, nameof(Script));

            if (Children == null)
            {
                return(onComplete(context, this));
            }

            foreach (var flow in Outgoing)
            {
                var flowElem = Parent.FindElement <SequenceFlow>(flow.Text);
                if (flowElem.SourceRef != Id)
                {
                    throw new WorkflowException($"BPMN. Invalid SequenceFlow (Id={Id}. SourceRef does not match");
                }
                // generate new token for every outogoing flow!
                context.Schedule(flowElem, onComplete, Parent.NewToken());
            }
            return(ValueTask.CompletedTask);
        }
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     return(onComplete.Invoke(context, this));
 }
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            SequenceFlow flowToExecute = FindFlowToExecute(context);

            if (flowToExecute != null)
            {
                context.Schedule(flowToExecute, null, token);
            }
            if (onComplete != null)
            {
                return(onComplete(context, this));
            }
            return(ValueTask.CompletedTask);
        }
Example #24
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     NextState = Next;
     if (onComplete != null)
     {
         return(onComplete(context, this));
     }
     return(ValueTask.CompletedTask);
 }
Example #25
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     context.Schedule(Entry, onComplete, token);
     return(ValueTask.CompletedTask);
 }
Example #26
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var cond     = context.Evaluate <Boolean>(Id, nameof(Condition));
            var nextNode = Parent.FindNode(cond ? Then : Else);

            if (nextNode == null)
            {
                nextNode = Parent.FindNode(Next);
            }
            if (nextNode != null)
            {
                context.Schedule(nextNode, onComplete, token);
            }
            return(ValueTask.CompletedTask);
        }
Example #27
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var cond = context.Evaluate <Boolean>(Id, nameof(Condition));

            if (cond)
            {
                if (Then != null)
                {
                    context.Schedule(Then, onComplete, token);
                }
                else if (onComplete != null)
                {
                    return(onComplete(context, this));
                }
            }
            else
            {
                if (Else != null)
                {
                    context.Schedule(Else, onComplete, token);
                }
                else if (onComplete != null)
                {
                    return(onComplete(context, this));
                }
            }
            return(ValueTask.CompletedTask);
        }
Example #28
0
 public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
 {
     _onComplete = onComplete;
     context.SetBookmark(Bookmark, this, OnBookmarkComplete);
     return(ValueTask.CompletedTask);
 }
Example #29
0
        public override ValueTask ExecuteAsync(IExecutionContext context, IToken token, ExecutingAction onComplete)
        {
            var parts = Children.OfType <Participant>();

            if (parts == null)
            {
                throw new WorkflowException("No participants in the Collaboration");
            }
            if (parts.Count() != 1)
            {
                throw new WorkflowException("Collaboration has multiply participants. Yet not implemented");
            }
            return(parts.First().ExecuteAsync(context, token, onComplete));
        }
 public void Restore(IActivityStorage storage)
 {
     _currentState = storage.Get <String>(CURRENT_STATE);
     _onComplete   = storage.GetCallback(ON_COMPLETE);
     _token        = storage.GetToken(TOKEN);
 }