Exemplo n.º 1
0
        public static Flow Create()
        {
            var scheme = new FlowScheme("Flow2. Uses fork-join node", "MicroFlow.Meta.Test.Flow2");

            scheme.DefaultFaultHandlerType        = typeof(MyFaultHandler);
            scheme.DefaultCancellationHandlerType = typeof(MyCancellationHandler);

            scheme
            .AddProperty <IWriter>("Writer")
            .AddProperty <int>("A")
            .AddProperty <int>("B")
            .AddProperty <int>("C");

            var first = new ActivityInfo(typeof(DelayedIncrementActivity))
                        .WithDescription("First work")
                        .AddPropertyBinding(new PropertyBindingInfo("X", "A"));

            var second = new ActivityInfo(typeof(DelayedIncrementActivity))
                         .WithDescription("Second work")
                         .AddPropertyBinding(new PropertyBindingInfo("X", "B"));

            var third = new ActivityInfo(typeof(DelayedIncrementActivity))
                        .WithDescription("First work")
                        .AddPropertyBinding(new PropertyBindingInfo("X", "C"));

            var forkJoin = new ForkJoinInfo()
                           .WithDescription("My fork join node")
                           .AddForks(first, second, third);

            var sum = new ActivityInfo(typeof(SumActivity))
                      .WithDescription("Sum action")
                      .AddPropertyBinding(new PropertyBindingInfo("A", PropertyBindingKind.ActivityResult)
            {
                Activity = first
            })
                      .AddPropertyBinding(new PropertyBindingInfo("B", PropertyBindingKind.ActivityResult)
            {
                Activity = second
            })
                      .AddPropertyBinding(new PropertyBindingInfo("C", PropertyBindingKind.ActivityResult)
            {
                Activity = third
            });

            scheme.AddNodes(forkJoin, sum);
            scheme.IntialNode = forkJoin;
            forkJoin.ConnectTo(sum);

            scheme.AddService(ServiceInfo.Singleton <IWriter>("Writer"));

            return(scheme.EmitFlow());
        }
Exemplo n.º 2
0
        public static Flow Create()
        {
            var scheme = new FlowScheme("Flow3. Uses block and variable", "MicroFlow.Meta.Test.Flow3");

            scheme.DefaultFaultHandlerType        = typeof(MyFaultHandler);
            scheme.DefaultCancellationHandlerType = typeof(MyCancellationHandler);

            scheme
            .AddProperty <IReader>("Reader")
            .AddProperty <IWriter>("Writer");

            var var = new VariableInfo(typeof(int), "var");

            var activity = new ActivityInfo(typeof(ReadIntActivity))
                           .WithDescription("Input number")
                           .AddVariableBinding(new VariableBindingInfo(var, VariableBindingKind.ActivityResult));

            var block = new BlockInfo()
                        .WithDescription("MyBlock")
                        .AddNode(activity);

            var outputActivity = new ActivityInfo(typeof(WriteMessageActivity))
                                 .WithDescription("Output activity")
                                 .AddPropertyBinding(new PropertyBindingInfo("Message", "() => $\"Echo: {var.CurrentValue}\""));

            scheme.AddNodes(block, outputActivity);
            scheme.AddVariable(var);

            scheme.IntialNode = block;
            block.ConnectTo(outputActivity);

            scheme
            .AddService(ServiceInfo.Singleton <IReader>("Reader"))
            .AddService(ServiceInfo.Singleton <IWriter>("Writer"));

            return(scheme.EmitFlow());
        }
Exemplo n.º 3
0
        public static Flow Create()
        {
            var scheme = new FlowScheme("Flow1. Uses condition node", "MicroFlow.Meta.Test.Flow1");

            scheme.DefaultFaultHandlerType        = typeof(MyFaultHandler);
            scheme.DefaultCancellationHandlerType = typeof(MyCancellationHandler);

            var inputFirst = new ActivityInfo(typeof(ReadIntActivity))
            {
                Description = "Read first number",
                Result      = new VariableInfo(typeof(int), "first")
            };

            var inputSecond = new ActivityInfo(typeof(ReadIntActivity))
            {
                Description = "Read second number",
                Result      = new VariableInfo(typeof(int), "second")
            };

            var condition = new ConditionInfo("() => first.Get() > second.Get()")
            {
                Description = "If first number > second number"
            };

            var outputWhenTrue = new ActivityInfo(typeof(WriteMessageActivity))
            {
                Description = "Output: first > second"
            };

            outputWhenTrue.AddPropertyBinding(new PropertyBindingInfo("Message", PropertyBindingKind.Expression)
            {
                BindingExpression = "() => $\"{first.Get()} > {second.Get()}\""
            });

            var outputWhenFalse = new ActivityInfo(typeof(WriteMessageActivity))
            {
                Description = "Output: first <= second"
            };

            outputWhenFalse.AddPropertyBinding(new PropertyBindingInfo("Message", PropertyBindingKind.Expression)
            {
                BindingExpression = "() => $\"{first.Get()} <= {second.Get()}\""
            });

            scheme.IntialNode = inputFirst;

            inputFirst.PointsTo  = inputSecond;
            inputSecond.PointsTo = condition;

            condition.WhenTrue  = outputWhenTrue;
            condition.WhenFalse = outputWhenFalse;

            scheme.AddNodes(inputFirst, inputSecond, condition, outputWhenTrue, outputWhenFalse);

            scheme.AddProperty(new FlowPropertyInfo(typeof(IReader), "Reader"));
            scheme.AddProperty(new FlowPropertyInfo(typeof(IWriter), "Writer"));

            scheme.AddService(
                new ServiceInfo(typeof(IReader), lifetimeKind: LifetimeKind.Singleton, instanceExpression: "Reader"));

            scheme.AddService(
                new ServiceInfo(typeof(IWriter), lifetimeKind: LifetimeKind.Singleton, instanceExpression: "Writer"));

            return(scheme.EmitFlow());
        }