Beispiel #1
0
        public Func <Task> BuildHandler(IServiceProvider serviceProvider, Func <Task> next)
        {
            var channel       = serviceProvider.GetRequiredService <ITextChannel>();
            var parser        = serviceProvider.GetRequiredService <ICommandParser>();
            var handlerLookup = serviceProvider.GetServices <ICommandHandler>().ToDictionary(x => x.Name.ToUpperInvariant());

            return(async() =>
            {
                var loopInstance = new LoopInstance
                {
                    IsRunning = true,
                    Provider = serviceProvider
                };

                while (loopInstance.IsRunning)
                {
                    var commandLine = await channel.ReceiveLineAsync();

                    var info = parser.Parse(commandLine);

                    if (info.IsValid)
                    {
                        if (handlerLookup.TryGetValue(info.Name, out var handler))
                        {
                            await handler.Handle(loopInstance, info);
                        }
                        else
                        {
                            await channel.SendLineAsync($"Unknown command {info.Name}");
                        }
                    }
                    else
                    {
                        await channel.SendLineAsync("Invalid command");
                    }
                }
            });
        }
Beispiel #2
0
        /// <summary>wangmj  初始化一个工作流网实例,将引擎的扩展属性,注入到对应的工作流元素中</summary>
        /// <param name="process"></param>
        /// <param name="kenelExtensions"></param>
        public NetInstance(WorkflowProcess process, Dictionary<String, List<IKernelExtension>> kenelExtensions)
        {
            this.workflowProcess = process;

            //开始节点
            StartNode startNode = workflowProcess.StartNode;
            StartNodeInstance = new StartNodeInstance(startNode);
            List<IKernelExtension> extensionList = kenelExtensions[StartNodeInstance.ExtensionTargetName];
            for (int i = 0; extensionList != null && i < extensionList.Count; i++)
            {
                IKernelExtension extension = extensionList[i];
                StartNodeInstance.registExtension(extension);
            }
            //this.StartNodeInstance = StartNodeInstance; 自身赋值自身没用。
            wfElementInstanceMap.Add(startNode.Id, StartNodeInstance);

            //活动节点activity
            List<Activity> activities = workflowProcess.Activities;
            for (int i = 0; i < activities.Count; i++)
            {
                Activity activity = (Activity)activities[i];
                ActivityInstance activityInstance = new ActivityInstance(activity);
                extensionList = kenelExtensions[activityInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    activityInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(activity.Id, activityInstance);
            }

            //同步器节点
            List<Synchronizer> synchronizers = workflowProcess.Synchronizers;
            for (int i = 0; i < synchronizers.Count; i++)
            {
                Synchronizer synchronizer = (Synchronizer)synchronizers[i];
                SynchronizerInstance synchronizerInstance = new SynchronizerInstance(synchronizer);
                extensionList = kenelExtensions[synchronizerInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    synchronizerInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(synchronizer.Id, synchronizerInstance);
            }

            //结束节点
            List<EndNode> endNodes = workflowProcess.EndNodes;
            //        List<EndNodeInstance> endNodeInstances = netInstance.getEndNodeInstances();
            for (int i = 0; i < endNodes.Count; i++)
            {
                EndNode endNode = endNodes[i];
                EndNodeInstance endNodeInstance = new EndNodeInstance(endNode);
                //            endNodeInstances.add(endNodeInstance);
                extensionList = kenelExtensions[endNodeInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    endNodeInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(endNode.Id, endNodeInstance);
            }

            //转移线
            List<Transition> transitions = workflowProcess.Transitions;
            for (int i = 0; i < transitions.Count; i++)
            {
                Transition transition = (Transition)transitions[i];
                TransitionInstance transitionInstance = new TransitionInstance(transition);

                String fromNodeId = transition.FromNode.Id;
                if (fromNodeId != null)
                {
                    INodeInstance enteringNodeInstance = (INodeInstance)wfElementInstanceMap[fromNodeId];
                    if (enteringNodeInstance != null)
                    {
                        enteringNodeInstance.AddLeavingTransitionInstance(transitionInstance);
                        transitionInstance.EnteringNodeInstance=enteringNodeInstance;
                    }
                }

                String toNodeId = transition.ToNode.Id;
                if (toNodeId != null)
                {
                    INodeInstance leavingNodeInstance = (INodeInstance)wfElementInstanceMap[toNodeId];
                    if (leavingNodeInstance != null)
                    {
                        leavingNodeInstance.AddEnteringTransitionInstance(transitionInstance);
                        transitionInstance.LeavingNodeInstance=leavingNodeInstance;
                    }
                }
                extensionList = kenelExtensions[transitionInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    transitionInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(transitionInstance.Id, transitionInstance);
            }

            //循环线
            List<Loop> loops = workflowProcess.Loops;
            for (int i = 0; i < loops.Count; i++)
            {
                Loop loop = (Loop)loops[i];
                LoopInstance loopInstance = new LoopInstance(loop);

                String fromNodeId = loop.FromNode.Id;
                if (fromNodeId != null)
                {
                    INodeInstance enteringNodeInstance = (INodeInstance)wfElementInstanceMap[fromNodeId];
                    if (enteringNodeInstance != null)
                    {
                        enteringNodeInstance.AddLeavingLoopInstance(loopInstance);
                        loopInstance.EnteringNodeInstance=enteringNodeInstance;
                    }
                }

                String toNodeId = loop.ToNode.Id;
                if (toNodeId != null)
                {
                    INodeInstance leavingNodeInstance = (INodeInstance)wfElementInstanceMap[toNodeId];
                    if (leavingNodeInstance != null)
                    {
                        leavingNodeInstance.AddEnteringLoopInstance(loopInstance);
                        loopInstance.LeavingNodeInstance=leavingNodeInstance;
                    }
                }
                extensionList = kenelExtensions[loopInstance.ExtensionTargetName];
                for (int j = 0; extensionList != null && j < extensionList.Count; j++)
                {
                    IKernelExtension extension = extensionList[j];
                    loopInstance.registExtension(extension);
                }
                wfElementInstanceMap.Add(loopInstance.Id, loopInstance);
            }
        }