protected override IList <PowerThreadView> BuildViews(PowerThreadContext context)
        {
            var items = new List <PowerThreadView>()
            {
                new PowerThreadView(ViewIds[0], "view1", "/views/view1.cshtml")
                , new PowerThreadView(ViewIds[1], "view2", "/views/view2.cshtml")
                , new PowerThreadView(ViewIds[2], "view3", "/views/view3.cshtml")
            };

            return(items);
        }
        protected override IList <PowerThreadForm> BuildForms(
            PowerThreadContext context)
        {
            var items = new List <PowerThreadForm>()
            {
                new PowerThreadForm(FormIds[0], "form1", "_testdata/forms/form1.cshtml")
                , new PowerThreadForm(FormIds[1], "form2", "_testdata/forms/form2.cshtml")
                , new PowerThreadForm(FormIds[2], "form3", "_testdata/forms/form3.cshtml")
            };

            return(items);
        }
        protected override IList <PowerThreadNode> BuildNodes(
            PowerThreadContext context)
        {
            var items = new List <PowerThreadNode>()
            {
                new PowerThreadNode(NodeIds[0], "node1")
                , new PowerThreadNode(NodeIds[1], "node2")
                , new PowerThreadNode(NodeIds[2], "node3")
            };

            return(items);
        }
        protected override PowerThreadStateMachine BuildStateMachine(PowerThreadContext context)
        {
            var nodes = context.PowerThread.Nodes;

            PowerThreadStateMachine result = new PowerThreadStateMachine();

            result.Transmissions = new List <Transmission> {
                new Transmission(PowerThreadDefaultNodes.DefaultStartNode, nodes[0]),
                new Transmission(nodes[0], nodes[1]),
                new Transmission(nodes[1], nodes[2]),
                new Transmission(nodes[2], PowerThreadDefaultNodes.DefaultEndNode)
            };

            return(result);
        }
Beispiel #5
0
        private PowerThreadNode GetNextNode(PowerThreadContext context, PowerThreadNode fromNode)
        {
            var transmission = Transmissions.FirstOrDefault(p => p.FromNode.ObjectId == fromNode.ObjectId);

            if (transmission == null)
            {
                return(PowerThreadDefaultNodes.DefaultEndNode);
            }

            foreach (var item in transmission.ConditionBranches)
            {
                if (item.Condition.IsSatisified(context))
                {
                    return(item.ToNode);
                }
            }

            //
            return(PowerThreadDefaultNodes.MissFoundNode);
        }
Beispiel #6
0
        private void LoadFormData(
            PowerThreadContext context
            , PowerThreadForm form
            )
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            var json = string.Format("{{Content:\"my content of {0}\"}}", form.Name);

            form.BindingViewModel.Data =
                JsonConvert.DeserializeObject <ExpandoObject>(json);
        }
Beispiel #7
0
        public void Next(PowerThreadContext context, PowerThreadNode fromNode)
        {
            if (context.IsCurrentNode(fromNode) == false)
            {
                throw new InvalidThreadActionException("Not actived thread node!");
            }

            if (fromNode.Equals(PowerThreadDefaultNodes.DefaultEndNode))
            {
                throw new InvalidTransmissionSinceThreadAlreadyEnd();
            }

            var toNode = GetNextNode(context, fromNode);

            if (toNode != null)
            {
                context.PowerThread.SetCurrentNode(toNode);
                if (!IsEndNode(toNode))
                {
                    toNode.LoadNode();
                }

                if (toNode.IsEnd)
                {
                    context.PowerThread.SetState(PowerThreadState.End);
                }
                else if (IsUnfound(toNode))
                {
                    context.PowerThread.SetState(PowerThreadState.ErrorMissFoundNode);
                }
                else
                {
                    context.PowerThread.SetState(PowerThreadState.Processing);
                }
            }
            else
            {
                // 如果找不到下一个节点, 也认为其结束。
                context.PowerThread.SetState(PowerThreadState.End);
            }
        }
        public override void PatchNodes(PowerThreadContext context)
        {
            var forms = context.PowerThread.Forms;
            var views = context.PowerThread.Views;
            var nodes = context.PowerThread.Nodes;

            foreach (var node in nodes)
            {
                node.SetContext(context);
            }

            nodes[0].RegisterDefaultForm(forms[0]);
            nodes[1].RegisterDefaultForm(forms[1]);
            nodes[2].RegisterDefaultForm(forms[2]);

            nodes[0].RegisterDefaultView(views[0]);
            nodes[1].RegisterDefaultView(views[1]);
            nodes[2].RegisterDefaultView(views[2]);

            // rebuild state machine
            context.PowerThread.StateMachine = BuildStateMachine(context);
        }
Beispiel #9
0
        private void PersistData(
            PowerThreadContext context
            , PowerThreadForm form
            , PowerThreadEntity formData)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            if (formData == null)
            {
                throw new ArgumentNullException(nameof(formData));
            }

            throw new NotImplementedException();
        }
 protected abstract IList <PowerThreadRole> BuildRoles(PowerThreadContext context);
 protected abstract IList <PowerThreadNode> BuildNodes(PowerThreadContext context);
 protected abstract IList <PowerThreadView> BuildViews(PowerThreadContext context);
 protected abstract IList <PowerThreadForm> BuildForms(PowerThreadContext context);
 public abstract void PatchNodes(PowerThreadContext context);
Beispiel #15
0
 public void SetContext(PowerThreadContext context)
 {
     this.context = context;
 }
Beispiel #16
0
 public void TerminateThread(PowerThreadContext context, PowerThreadNode fromNode)
 {
     context.PowerThread.SetState(PowerThreadState.Terminated);
 }
Beispiel #17
0
 public override bool IsSatisified(PowerThreadContext context)
 {
     // TODO:  test from context variables;
     return(base.IsSatisified(context));
 }
 protected abstract PowerThreadStateMachine BuildStateMachine(PowerThreadContext context);
 protected override IList <PowerThreadRole> BuildRoles(
     PowerThreadContext context)
 {
     return(new List <PowerThreadRole>());
 }
 protected abstract IList <PowerVariable> BuildVariables(PowerThreadContext context);
Beispiel #21
0
 public virtual bool IsSatisified(PowerThreadContext context)
 {
     return(true);
 }