コード例 #1
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static For Loop()
        {
            Variable<int> loopVariable = new Variable<int>();

            return new For()
            {
                Variables = { loopVariable },

                InitAction = new Assign<int>()
                {
                    To = loopVariable,
                    Value = 0,
                },

                IterationAction = new Assign<int>()
                {
                    To = loopVariable,
                    Value = new InArgument<int>(ctx => loopVariable.Get(ctx) + 1)
                },

                // ExpressionServices.Convert is called to convert LINQ expression to a
                // serializable Expression Activity.
                Condition = ExpressionServices.Convert<bool>(ctx => loopVariable.Get(ctx) < 10),
                Body = new WriteLine
                {
                    Text = new InArgument<string>(ctx => "Value of item is: " + loopVariable.Get(ctx).ToString()),
                },
            };
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Sequence CreateWorkflow()
        {
            Variable<int> count = new Variable<int> { Name = "count", Default = totalSteps };
            Variable<int> stepsCounted = new Variable<int> { Name = "stepsCounted" };

            return new Sequence()
            {
                Variables = { count, stepsCounted },
                Activities =
                {
                    new While((env) => count.Get(env) > 0)
                    {
                        Body = new Sequence
                        {
                            Activities =
                            {
                                new EchoPrompt {BookmarkName = echoPromptBookmark },
                                new IncrementStepCount(),
                                new Assign<int>{ To = new OutArgument<int>(count), Value = new InArgument<int>((context) => count.Get(context) - 1)}
                            }
                        }
                    },
                    new GetCurrentStepCount {Result = new OutArgument<int>(stepsCounted )},
                    new WriteLine { Text = new InArgument<string>((context) => "there were " + stepsCounted.Get(context) + " steps in this program")}}
            };
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static void CreateService()
        {
            Variable<string> message = new Variable<string> { Name = "message" };
            Variable<string> echo = new Variable<string> { Name = "echo" };

            Receive receiveString = new Receive
            {
                OperationName = "Echo",
                ServiceContractName = "Echo",
                CanCreateInstance = true,
                //parameters for receive
                Content = new ReceiveParametersContent
                {
                    Parameters =
                    {
                        {"message", new OutArgument<string>(message)}
                    }
                }
            };
            Sequence workflow = new Sequence()
            {
                Variables = { message, echo },
                Activities =
                    {
                        receiveString,
                        new WriteLine
                        {
                            Text = new InArgument<string>(env =>("Message received: " + message.Get(env)))
                        },
                        new Assign<string>
                        {
                            Value = new InArgument<string>(env =>("<echo> " + message.Get(env))),
                            To = new OutArgument<string>(echo)
                        },
                        //parameters for reply
                        new SendReply
                        {
                            Request = receiveString,
                            Content = new SendParametersContent
                            {
                                Parameters =
                                {
                                    { "echo", new InArgument<string>(echo) }
                                },
                            }
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>(env =>("Message sent: " + echo.Get(env)))
                        },
                    },
            };

            service = new WorkflowService
            {
                Name = "Echo",
                Body = workflow
            };
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity GetClientWorkflow()
        {
            Variable<PurchaseOrder> po = new Variable<PurchaseOrder>();
            Variable<OrderStatus> orderStatus = new Variable<OrderStatus>();

            Endpoint clientEndpoint = new Endpoint
            {
                Binding = Constants.Binding,
                AddressUri = new Uri(Constants.ServiceAddress)
            };

            Send submitPO = new Send
            {
                Endpoint = clientEndpoint,
                ServiceContractName = Constants.POContractName,
                OperationName = Constants.SubmitPOName,
                Content = SendContent.Create(new InArgument<PurchaseOrder>(po))
            };

            return new Sequence
            {
                Variables = { po, orderStatus },
                Activities =
                {
                    new WriteLine { Text = "Sending order for 150 widgets." },
                    new Assign<PurchaseOrder> { To = po, Value = new InArgument<PurchaseOrder>( (e) => new PurchaseOrder() { PartName = "Widget", Quantity = 150 } ) },
                    new CorrelationScope
                    {
                        Body = new Sequence
                        {
                            Activities =
                            {
                                submitPO,
                                new ReceiveReply
                                {
                                    Request = submitPO,
                                    Content = ReceiveContent.Create(new OutArgument<int>( (e) => po.Get(e).Id ))
                                }
                            }
                        }
                    },
                    new WriteLine { Text = new InArgument<string>( (e) => string.Format("Got PoId: {0}", po.Get(e).Id) ) },
                    new Assign<OrderStatus> { To = orderStatus, Value = new InArgument<OrderStatus>( (e) => new OrderStatus() { Id = po.Get(e).Id, Confirmed = true }) },
                    new Send
                    {
                        Endpoint = clientEndpoint,
                        ServiceContractName = Constants.POContractName,
                        OperationName = Constants.ConfirmPurchaseOrder,
                        Content = SendContent.Create(new InArgument<OrderStatus>(orderStatus))
                    },
                    new WriteLine { Text = "The order was confirmed." },
                    new WriteLine { Text = "Client completed." }
                }
            };
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static Activity CreateMySequence()
        {
            Variable<int> count = new Variable<int> { Default = 1 };

            return new MySequence
            {
                Variables = { count },
                Activities = {
                    new WriteLine { Text = new InArgument<string>((env) => "Hello from sequence count is " + count.Get(env).ToString())},
                    new Assign<int> { To = count, Value = new InArgument<int>((env) => count.Get(env)+ 1)},
                    new WriteLine { Text = new InArgument<string>((env) => "Hello from sequence count is " + count.Get(env).ToString())}}
            };
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static Activity CreateMyWhile()
        {
            Variable<int> count = new Variable<int> { Default = 1 };

            return new MyWhile
            {
                Variables = { count },
                Condition = new LambdaValue<bool>((env) => count.Get(env) < 3),
                Body = new Sequence
                {
                    Activities = {
                        new WriteLine { Text = new InArgument<string>((env) => "Hello from while loop " + count.Get(env).ToString()) },
                        new Assign<int> { To = count, Value = new InArgument<int>((env) => count.Get(env)+ 1) }}
                }
            };
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity GetServiceWorkflow()
        {
            Variable<string> echoString = new Variable<string>();

            Receive echoRequest = new Receive
            {
                CanCreateInstance = true,
                ServiceContractName = contract,
                OperationName = "Echo",
                Content = new ReceiveParametersContent()
                {
                    Parameters = { { "echoString", new OutArgument<string>(echoString) } }
                }
            };

            return new ReceiveInstanceIdScope
            {
                Variables = { echoString },
                Activities =
                {
                    echoRequest,
                    new WriteLine { Text = new InArgument<string>( (e) => "Received: " + echoString.Get(e) ) },
                    new SendReply
                    {
                        Request = echoRequest,
                        Content = new SendParametersContent()
                        {
                            Parameters = { { "result", new InArgument<string>(echoString) } }
                        }
                    }
                }
            };
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
 private static WorkflowService CreateService()
 {
     Variable<string> message = new Variable<string> { Name = "message" };
     Receive receiveString = new Receive
     {
         OperationName = "Print",
         ServiceContractName = XName.Get("IPrintService", "http://tempuri.org/"),
         Content = new ReceiveParametersContent
         {
             Parameters = 
             {
                 {"message", new OutArgument<string>(message)}
             }
         },
         CanCreateInstance = true
     };
     Sequence workflow = new Sequence()
     {
         Variables = { message },
         Activities =
         {    
             receiveString,    
             new WriteLine                        
             {    
                 Text = new InArgument<string>(env =>("Message received from Client: " + message.Get(env)))   
             },
         },
     };
     return new WorkflowService
     {
         Name = "PrintService",
         Body = workflow
     };
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static void CreateClientWorkflow()
        {
            Variable<string> message = new Variable<string>("message", "Hello!");
            Variable<string> result = new Variable<string> { Name = "result" };

            Endpoint endpoint = new Endpoint
            {
                AddressUri = new Uri(Microsoft.Samples.WorkflowServicesSamples.Common.Constants.ServiceBaseAddress),
                Binding = new BasicHttpBinding(),
            };

            Send requestEcho = new Send
            {
                ServiceContractName = XName.Get("Echo", "http://tempuri.org/"),
                Endpoint = endpoint,
                OperationName = "Echo",
                //parameters for send
                Content = new SendParametersContent
                {
                    Parameters =
                        {
                            { "message", new InArgument<string>(message) }
                        }
                }
            };
            workflow = new CorrelationScope
            {
                Body = new Sequence
                {
                    Variables = { message, result },
                    Activities =
                    {
                        new WriteLine {
                            Text = new InArgument<string>("Client is ready!")
                        },
                        requestEcho,

                        new WriteLine {
                            Text = new InArgument<string>("Message sent: Hello!")
                        },

                        new ReceiveReply
                        {
                            Request = requestEcho,
                            //parameters for the reply
                            Content = new ReceiveParametersContent
                            {
                                Parameters =
                                {
                                    { "echo", new OutArgument<string>(result) }
                                }
                            }
                        },
                        new WriteLine {
                            Text = new InArgument<string>(env => "Message received: "+result.Get(env))
                        }
                    }
                }
            };
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static Activity CreateRulesInterop()
        {
            //Create the variables needed to be passed into the 35 Ruleset
            Variable<int> discountLevel = new Variable<int> { Default = 1 };
            Variable<double> discountPoints = new Variable<double> { Default = 0.0 };
            Variable<string> destination = new Variable<string> { Default = "London" };
            Variable<double> price = new Variable<double> { Default = 1000.0 };
            Variable<double> priceOut = new Variable<double> { Default = 0.0 };

            Sequence result = new Sequence
            {
                Variables = {discountLevel, discountPoints, destination, price, priceOut},
                Activities =
                {
                    new WriteLine { Text = new InArgument<string>(env => string.Format("Price before applying Discount Rules = {0}", price.Get(env).ToString())) },
                    new WriteLine { Text = "Invoking Discount Rules defined in .NET 3.5"},
                    new Interop()
                    {
                        ActivityType = typeof(TravelRuleSet),
                        ActivityProperties =
                        {
                            //These bind to the dependency properties of the 35 custom ruleset
                            { "DiscountLevel", new InArgument<int>(discountLevel) },
                            { "DiscountPoints", new InArgument<double>(discountPoints) },
                            { "Destination", new InArgument<string>(destination) },
                            { "Price", new InArgument<double>(price) },
                            { "PriceOut", new OutArgument<double>(priceOut) }
                        }
                    },
                    new WriteLine {Text = new InArgument<string>(env => string.Format("Price after applying Discount Rules = {0}", priceOut.Get(env).ToString())) }
                }
            };
            return result;
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity CreateWorkflow()
        {
            Variable<string> x = new Variable<string>() { Name = "x" };
            Variable<string> y = new Variable<string>() { Name = "y" };
            Variable<string> z = new Variable<string>() { Name = "z" };

            // Create a workflow with three bookmarks: x, y, z. After all three bookmarks
            // are resumed (in any order), the concatenation of the values provided
            // when the bookmarks were resumed is written to output.
            return new Sequence
            {
                Variables = { x, y, z },
                Activities =
                {
                    new System.Activities.Statements.Parallel
                    {
                        Branches =
                        {
                            new Read<string>() { BookmarkName = "x", Result = x },
                            new Read<string>() { BookmarkName = "y", Result = y },
                            new Read<string>() { BookmarkName = "z", Result = z }
                        }
                    },
                    new WriteLine
                    {
                        Text = new InArgument<string>((ctx) => "x+y+z=" + x.Get(ctx) + y.Get(ctx) + z.Get(ctx))
                    }
                }
            };
        }
コード例 #12
0
        Constraint UnrootedRequestRule()
        {
            DelegateInArgument<SendReply> sendReply = new DelegateInArgument<SendReply>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
            DelegateInArgument<Activity> activityInTree = new DelegateInArgument<Activity>();
            Variable<bool> requestInTree = new Variable<bool> { Default = false };

            return new Constraint<SendReply>
            {
                Body = new ActivityAction<SendReply, ValidationContext>
                {
                    Argument1 = sendReply,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables = { requestInTree },
                        Activities =
                        {
                            new If
                            {
                                Condition = new InArgument<bool>(ctx => sendReply.Get(ctx).Request != null),
                                Then = new Sequence
                                {
                                    Activities = 
                                    {
                                        new ForEach<Activity>
                                        {
                                            Values = new GetWorkflowTree
                                            {
                                                ValidationContext = context,
                                            },
                                            Body = new ActivityAction<Activity>
                                            {
                                                Argument = activityInTree,
                                                Handler = new If
                                                {
                                                    Condition = new InArgument<bool>(ctx => activityInTree.Get(ctx) == sendReply.Get(ctx).Request),
                                                    Then = new Assign<bool>
                                                    {
                                                        To = requestInTree,
                                                        Value = true,
                                                    }                                                    
                                                }
                                            }
                                        },                            
                                        new AssertValidation
                                        {                                
                                            Assertion = new InArgument<bool>(ctx => requestInTree.Get(ctx)),
                                            IsWarning = false,
                                            Message = new InArgument<string>(ctx => string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.UnrootedRequestInSendReply, sendReply.Get(ctx).DisplayName))
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
        }
コード例 #13
0
ファイル: POWorkflow.cs プロジェクト: tian1ll1/WPF_Examples
        public static Activity CreateBody()
        {
            Variable<PurchaseOrder> purchaseOrder = new Variable<PurchaseOrder> { Name = "po" };

            Sequence sequence = new Sequence
            {
                Variables =
                {
                    purchaseOrder
                },

                Activities =
                {
                    new Receive
                    {
                        OperationName = "SubmitPurchaseOrder",
                        ServiceContractName = XName.Get(poContractDescription.Name),
                        CanCreateInstance = true,
                        Content = new ReceiveParametersContent
                        {
                            Parameters =
                            {
                                {"po", new OutArgument<PurchaseOrder>(purchaseOrder)}
                            }
                        }
                    },

                    new WriteLine
                    {
                       Text = new InArgument<string> (e=>"Order is received\nPO number = " + purchaseOrder.Get(e).PONumber
                           + " Customer Id = " + purchaseOrder.Get(e).CustomerId)
                    },

                    new Persist(),

                    new ExceptionThrownActivity(),

                    new WriteLine
                    {
                        Text = new InArgument<string>("Order processing is complete")
                    }
                }
            };

            return sequence;
        }
コード例 #14
0
        public static Constraint VerifyParentIsWorkflowActivity()
        {
            DelegateInArgument<Activity> element = new DelegateInArgument<Activity>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
            
            DelegateInArgument<Activity> parent = new DelegateInArgument<Activity>();
            Variable<bool> result = new Variable<bool>();

            return new Constraint<Activity>
            {
                Body = new ActivityAction<Activity, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables =
                        {
                            result
                        },
                        Activities =
                        {
                            new ForEach<Activity>
                            {
                                Values = new GetParentChain
                                {
                                    ValidationContext = context,
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = parent, 
                                    Handler = new If
                                    {
                                        Condition = new InArgument<bool>((env) => parent.Get(env).IsWorkflowActivity()),
                                        Then = new Assign<bool>
                                        {
                                            Value = true,
                                            To = result,
                                        },
                                    },
                                },
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>((env) => result.Get(env)),
                                Message = new InArgument<string>((env) => $"{element.Get(env).GetType().GetFriendlyName()} can only be added inside a {typeof(WorkflowActivity<,>).GetFriendlyName()} activity."),
                                PropertyName = new InArgument<string>((env) => element.Get(env).DisplayName),
                            },
                        },
                    },
                },
            };
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity CreateWF()
        {
            DelegateInArgument<string> current = new DelegateInArgument<string>();
            IList<string> data = new List<string>();
            for (int i = 1; i < 11; i++)
            {
                data.Add(string.Format("Branch {0}", i));
            }
            Variable<int> waitTime = new Variable<int>();

            return
                new Sequence
                {
                    Variables = { waitTime },
                    Activities =
                    {
                        new ThrottledParallelForEach<string>
                        {
                            Values = new LambdaValue<IEnumerable<string>>(c => data),
                            MaxConcurrentBranches = 3,
                            Body = new ActivityAction<string>
                            {
                                Argument = current,
                                Handler = new Sequence
                                {
                                    Activities =
                                    {
                                        new WriteLine() { Text = new InArgument<string>(ctx => string.Format("Enter {0}", current.Get(ctx))) },
                                        new Assign<int> { To = waitTime, Value = new InArgument<int>(ctx =>  new Random().Next(0, 2500)) },
                                        new WriteLine() { Text = new InArgument<string>(ctx => string.Format("...{0} will wait for {1} millisenconds...", current.Get(ctx), waitTime.Get(ctx))) },
                                        new Delay { Duration = new InArgument<TimeSpan>(ctx => new TimeSpan(0,0,0,0, waitTime.Get(ctx))) },
                                        new WriteLine() { Text = new InArgument<string>(ctx => string.Format("......Exit {0}", current.Get(ctx))) },
                                    }
                                }
                            }
                        }
                    }
                };
        }
コード例 #16
0
        public static Constraint VerifyParentIsObjectContextScope(Activity activity)
        {
            DelegateInArgument<Activity> element = new DelegateInArgument<Activity>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();
            DelegateInArgument<Activity> child = new DelegateInArgument<Activity>();
            Variable<bool> result = new Variable<bool>();

            return new Constraint<Activity>
            {
                Body = new ActivityAction<Activity, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables = { result },
                        Activities =
                        {
                            new ForEach<Activity>
                            {
                                Values = new GetParentChain
                                {
                                    ValidationContext = context
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = child,
                                    Handler = new If
                                    {
                                        Condition = new InArgument<bool>((env) => object.Equals(child.Get(env).GetType(), typeof(ObjectContextScope))),
                                        Then = new Assign<bool>
                                        {
                                            Value = true,
                                            To = result
                                        }
                                    }
                                }
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>(env => result.Get(env)),
                                Message = new InArgument<string> (string.Format("{0} can only be added inside an ObjectContextScope activity.", activity.GetType().Name)),
                                PropertyName = new InArgument<string>((env) => element.Get(env).DisplayName)
                            }
                        }
                    }
                }
            };
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static void CreateClientWorkflow()
        {
            Variable<string> message = new Variable<string> { Name = "message" };
            Variable<Uri> serviceUri = new Variable<Uri> { Name = "serviceUri" };

            workflow = new Sequence()
            {
                Variables =  {message, serviceUri},
                Activities = 
                {                    
                    new WriteLine
                    {
                        Text = new InArgument<string>("Searching for WF matching IPrintService Contract") 
                    },
                    new FindActivity
                    {
                        DiscoveredEndpointUri = new OutArgument<Uri>(serviceUri)
                    },
                    new WriteLine  
                    {                         
                        Text = new InArgument<string>(env =>("Found Service at: " + serviceUri.Get(env)))
                    },
                    new WriteLine  
                    {                         
                        Text = new InArgument<string>("Connecting to WF, sending text 'Hello from WF Client'")
                    },    
                    new Send    
                    {
                        ServiceContractName = XName.Get("IPrintService", "http://tempuri.org/"),
                        OperationName = "Print",
                        Content = new SendParametersContent    
                        {
                            Parameters =    
                            {
                                    { "message", new InArgument<string>("Hello from WF Client") }    
                            },    
                        },
                        Endpoint = new Endpoint
                        {
                            ServiceContractName = XName.Get("IPrintService", "http://tempuri.org/"),
                            Binding = new BasicHttpBinding()
                        },                      
                        EndpointAddress = new InArgument<Uri>(serviceUri),
                    },    
                },
            };
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Sequence CreateWorkflow()
        {
            Variable<string> response = new Variable<string>();

            return new Sequence()
            {
                Variables = { response },
                Activities = {
                        new WriteLine(){
                            Text = new InArgument<string>("What is your name?")},
                        new ReadLine(){
                            BookmarkName = readLineBookmark,
                            Result = new OutArgument<string>(response)},
                        new WriteLine(){
                            Text = new InArgument<string>((context) => "Hello " + response.Get(context))}}
            };
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity CreateCodeOnlyWorkflow()
        {
            Variable<Employee> e1 = new Variable<Employee>("Employee1", ctx => new Employee("John", "Doe", 55000.0));
            Variable<Employee> e2 = new Variable<Employee>("Employee2", ctx => new Employee("Frank", "Kimono", 89000.0));
            Variable<SalaryStats> stats = new Variable<SalaryStats>("SalaryStats", ctx => new SalaryStats());
            Variable<Double> v1 = new Variable<double>();

            // The most efficient way of defining expressions in code is via LambdaValue and LambdaReference activities.
            // LambdaValue represents an expression that evaluates to an r-value and cannot be assigned to.
            // LambdaReference represents an expression that evaluates to an l-value and can be the target of an assignment.
            Sequence workflow = new Sequence()
            {
                Variables =
                {
                    e1, e2, stats, v1,
                },

                Activities =
                {
                    new WriteLine()
                    {
                        Text = new LambdaValue<string>(ctx => e1.Get(ctx).FirstName + " " + e1.Get(ctx).LastName + " earns " + e1.Get(ctx).Salary.ToString("$0.00")),
                    },
                    new WriteLine()
                    {
                        Text = new LambdaValue<string>(ctx => e2.Get(ctx).FirstName + " " + e2.Get(ctx).LastName + " earns " + e2.Get(ctx).Salary.ToString("$0.00")),
                    },
                    new Assign<double>()
                    {
                        To = new LambdaReference<double>(ctx => stats.Get(ctx).MinSalary),
                        Value = new LambdaValue<double>(ctx => Math.Min(e1.Get(ctx).Salary, e2.Get(ctx).Salary))
                    },
                    new Assign<double>()
                    {
                        To = new LambdaReference<double>(ctx => stats.Get(ctx).MaxSalary),
                        Value = new LambdaValue<double>(ctx => Math.Max(e1.Get(ctx).Salary, e2.Get(ctx).Salary))
                    },
                    new Assign<double>()
                    {
                        To = new LambdaReference<double>(ctx => stats.Get(ctx).AvgSalary),
                        Value = new LambdaValue<double>(ctx => (e1.Get(ctx).Salary + e2.Get(ctx).Salary) / 2.0)
                    },
                    new WriteLine()
                    {
                        Text = new LambdaValue<string>(ctx => String.Format(
                            "Salary statistics: minimum salary is {0:$0.00}, maximum salary is {1:$0.00}, average salary is {2:$0.00}",
                            stats.Get(ctx).MinSalary, stats.Get(ctx).MaxSalary, stats.Get(ctx).AvgSalary))
                    }
                },
            };

            return workflow;
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        // Counting Workflow inplements a workflow that waits for a client to call its Start
        // method. Once called, the workflow counts from 0 to 29, incrementing the counter
        // every 2 seconds. After every counter increment the workflow persists.
        static Sequence CountingWorkflow()
        {
            Variable<int> counter = new Variable<int>() { Name="Counter", Default = 0};

            return new Sequence()
            {
                Variables = { counter },

                Activities =
                {
                    new Receive()
                    {
                        Action = "Start",
                        CanCreateInstance = true,
                        OperationName  = "Start",
                        ServiceContractName = "ICountingWorkflow",
                    },

                    new While( (env => counter.Get(env) < 30 ))
                    {
                        Body = new Sequence()
                        {
                            Activities =
                            {
                                new SaveCounter() { Counter = counter },

                                new Persist(),

                                new Delay()
                                {
                                    Duration = TimeSpan.FromSeconds(2),
                                },

                                new Assign<int>()
                                {
                                    Value = new InArgument<int>(env => counter.Get(env) + 1),
                                    To = counter
                                }
                            }
                        }
                    }
                }
            };
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity CreateWF()
        {
            Variable<string> name = new Variable<string>();
            Sequence body = new Sequence
            {
                Variables = { name },
                Activities =
                {
                    new WriteLine { Text = "What is you name? (You have 5 seconds to answer)" },
                    new Pick
                    {
                       Branches =
                       {
                           new PickBranch
                            {
                               Trigger = new ReadString
                               {
                                   Result = name,
                                   BookmarkName = bookmarkName
                               },
                               Action = new WriteLine
                               {
                                   Text = new InArgument<string>(env => "Hello " + name.Get(env))
                               }
                           },
                           new PickBranch
                            {
                               Trigger = new Delay
                               {
                                   Duration = TimeSpan.FromSeconds(5)
                               },
                               Action = new WriteLine
                               {
                                   Text = "Time is up."
                               }
                           }
                       }
                   }
               }
            };

            return body;
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static Activity CreateProgram()
        {
            Variable<int> result = new Variable<int>("result");

            return new Sequence
            {
                Variables = { result },
                Activities =
                {
                    new WriteLine { Text = new InArgument<string>("Invoking Math.Max with arguments 5 and 7")},
                    new MethodInvoke
                    {
                        TargetType = typeof(Math),
                        MethodName = "Max",
                        Parameters = { new InArgument<int>(5), new InArgument<int>(7)},
                        Result = new OutArgument<int>(result)
                    },
                    new WriteLine { Text = new InArgument<string>(context=> result.Get(context).ToString() + " is the bigger number")}
                }
            };
        }
コード例 #23
0
ファイル: PromptInt.cs プロジェクト: tian1ll1/WPF_Examples
 Activity CreateBody()
 {
     Variable<string> tmp = new Variable<string>();
     return
         new Sequence()
         {
             Variables = { tmp },
             Activities =
             {
                 new WriteLine() { Text = new InArgument<string>(env => this.Text.Get(env)) } ,
                 new ReadLine()
                 {
                      BookmarkName = new InArgument<string>(env => "Prompt-" + Text.Get(env)),
                      Result= new OutArgument<string>(tmp)
                 },
                 new Assign<int>
                 {
                      Value= new InArgument<int>(env => Convert.ToInt32(tmp.Get(env))),
                      To = new OutArgument<int>(env => this.Result.Get(env))
                 }
             }
         };
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static WorkflowService GetService()
        {
            Variable<string> incomingMessage = new Variable<string> { Name = "inmessage" };
            Variable<int> outgoingMessage = new Variable<int> { Name = "outmessage" };
            Receive receiveSecureData = new Receive
            {
                OperationName = "AskQuestion",
                ServiceContractName = "ISecuredService",
                CanCreateInstance = true,
                Content = ReceiveContent.Create(new OutArgument<string>(incomingMessage))
            };
            Sequence SecuredWorkFlow = new Sequence()
            {
                Variables = { incomingMessage, outgoingMessage },
                Activities =
                {
                    receiveSecureData,
                    new WriteLine
                    {
                        Text = new InArgument<string>(env =>("Message received: " + incomingMessage.Get(env)))
                    },
                    new SendReply
                    {
                        Request = receiveSecureData,
                        Content = SendContent.Create(new InArgument<int>(4))
                    }
                }
            };

            WorkflowService service = new WorkflowService
            {
                Name = "SecuredService",
                Body = SecuredWorkFlow,
                ConfigurationName = "SecuredService"
            };
            return service;
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: tnewark/BeginningWF
        static Activity CreateWorkflow()
        {
            var numberBells = new Variable<int>()
            {
                Name = "numberBells",
                Default = DateTime.Now.Hour
            };
            var counter = new Variable<int>()
            {
                Name = "counter",
                Default = 1
            };

            return new Sequence()
            {
                DisplayName = "Main Sequence",
                Variables = {numberBells, counter},
                Activities =
                {
                    new WriteLine()
                    {
                        DisplayName =  "Hello",
                        Text = "Hello, World!"
                    },
                    new If()
                    {
                        DisplayName = "Adjust for PM",
                        Condition = ExpressionServices.Convert
                            (env => numberBells.Get(env) > 12),
                        Then = new Assign<int>()
                        {
                            DisplayName = "Adjust Bells",
                            To = new OutArgument<int>(numberBells),
                            Value = new InArgument<int>(env => numberBells.Get(env) - 12)
                        }

                    },
                    new While()
                    {
                        DisplayName = "Sound Bells",
                        Condition = ExpressionServices.Convert<bool>
                            (env => counter.Get(env) <= numberBells.Get(env)),
                        Body = new Sequence()
                        {
                            DisplayName = "Sound Bell",
                            Activities =
                            {
                                new WriteLine()
                                {
                                    Text = new InArgument<string>(env => counter.Get(env).ToString())
                                },
                                new Assign<int>()
                                {
                                    DisplayName = "Increment Counter",
                                    To = new OutArgument<int>(counter),
                                    Value = new InArgument<int>(env => counter.Get(env) + 1)
                                },
                                new Delay()
                                {
                                    Duration = TimeSpan.FromSeconds(1)
                                }

                            }
                        }
                    },
                    new WriteLine()
                    {
                        DisplayName = "Display Time",
                        Text = $"The time is: {DateTime.Now}"
                    },
                    new If()
                    {
                        DisplayName = "Greeting",
                        Condition = ExpressionServices.Convert<bool>
                            (env => DateTime.Now.Hour >= 18),
                        Then = new WriteLine() {Text = "Good Evening" },
                        Else = new WriteLine() {Text = "Good Day" }
                    }
                }
            };
        }
        public static Constraint VerifyReceiveRequestSendResponseScopeChildren()
        {
            DelegateInArgument<ReceiveRequestSendResponseScope> element = new DelegateInArgument<ReceiveRequestSendResponseScope>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();

            DelegateInArgument<Activity> child = new DelegateInArgument<Activity>();
            Variable<int> receiveRequestCounter = new Variable<int>();
            Variable<int> sendResponseCounter = new Variable<int>();

            return new Constraint<ReceiveRequestSendResponseScope>
            {
                Body = new ActivityAction<ReceiveRequestSendResponseScope, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables =
                        {
                            receiveRequestCounter,
                            sendResponseCounter,
                        },
                        Activities =
                        {
                            new Assign<int>
                            {
                                Value = 0,
                                To = receiveRequestCounter,
                            },
                            new Assign<int>
                            {
                                Value = 0,
                                To = sendResponseCounter,
                            },
                            new ForEach<Activity>
                            {
                                Values = new GetChildSubtree
                                {
                                    ValidationContext = context,
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = child, 
                                    Handler = new Sequence
                                    {
                                        Activities = 
                                        {
                                            new If
                                            {
                                                Condition = new InArgument<bool>((env) => child.Get(env) is IReceiveRequest),
                                                Then = new Assign<int>
                                                {
                                                    Value = new InArgument<int>((env) => receiveRequestCounter.Get(env) + 1),
                                                    To = receiveRequestCounter
                                                },
                                            },
                                            new If
                                            {
                                                Condition = new InArgument<bool>((env) => child.Get(env) is ISendResponse),
                                                Then = new Assign<int>
                                                {
                                                    Value = new InArgument<int>((env) => sendResponseCounter.Get(env) + 1),
                                                    To = sendResponseCounter
                                                },
                                            },
                                        },
                                    },
                                },
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>((env) => receiveRequestCounter.Get(env) == 1),
                                Message = new InArgument<string> ($"{nameof(ReceiveRequestSendResponseScope)} activity must contain one and only one {nameof(ReceiveRequest)} activity"),                                
                                PropertyName = new InArgument<string>((env) => element.Get(env).DisplayName)
                            },
                            new AssertValidation
                            {
                                Assertion = new InArgument<bool>((env) => sendResponseCounter.Get(env) == 1),
                                Message = new InArgument<string> ($"{nameof(ReceiveRequestSendResponseScope)} activity must contain one and only one {nameof(SendResponse)} activity"),                                
                                PropertyName = new InArgument<string>((env) => element.Get(env).DisplayName)
                            },
                        },
                    },
                },
            };
        }
        public static Constraint SetWorkflowInterfaceOperationNames()
        {
            DelegateInArgument<ReceiveRequestSendResponseScope> element = new DelegateInArgument<ReceiveRequestSendResponseScope>();
            DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>();

            DelegateInArgument<Activity> parent = new DelegateInArgument<Activity>();
            DelegateInArgument<Activity> child = new DelegateInArgument<Activity>();
            Variable<IOperationActivity> receiveRequest = new Variable<IOperationActivity>();
            Variable<Type> workflowInterfaceType = new Variable<Type>();
            Variable<Type> requestResultType = new Variable<Type>();
            Variable<Type> responseParameterType = new Variable<Type>();

            return new Constraint<ReceiveRequestSendResponseScope>
            {
                Body = new ActivityAction<ReceiveRequestSendResponseScope, ValidationContext>
                {
                    Argument1 = element,
                    Argument2 = context,
                    Handler = new Sequence
                    {
                        Variables =
                        {
                            receiveRequest,
                            workflowInterfaceType,
                            requestResultType,
                            responseParameterType,
                        },
                        Activities =
                        {
                            new ForEach<Activity>
                            {
                                Values = new GetParentChain
                                {
                                    ValidationContext = context,
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = parent,
                                    Handler = new If
                                    {
                                        Condition = new InArgument<bool>((env) => parent.Get(env).IsWorkflowActivity()),
                                        Then = new Assign<Type>
                                        {
                                            Value = new InArgument<Type>((env) => parent.Get(env).GetWorkflowActivityType().GetGenericArguments()[(int)TypeParameterIndex.WorkflowInterface]),
                                            To = workflowInterfaceType,
                                        },
                                    },
                                },
                            },
                            new ForEach<Activity>
                            {
                                Values = new GetChildSubtree
                                {
                                    ValidationContext = context,
                                },
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = child,
                                    Handler = new Sequence
                                    {
                                        Activities =
                                        {
                                            new If
                                            {
                                                Condition = new InArgument<bool>((env) => child.Get(env) is IReceiveRequest),
                                                Then = new Sequence
                                                {
                                                    Activities =
                                                    {
                                                        new Assign<IOperationActivity>
                                                        {
                                                            Value = new InArgument<IOperationActivity>((env) => child.Get(env) as IOperationActivity),
                                                            To = receiveRequest
                                                        },
                                                        new Assign<Type>
                                                        {
                                                            Value = new InArgument<Type>((env) => (child.Get(env) as IReceiveRequest).RequestResultType),
                                                            To = requestResultType
                                                        },
                                                    },
                                                },
                                            },
                                            new If
                                            {
                                                Condition = new InArgument<bool>((env) => child.Get(env) is ISendResponse),
                                                Then = new Assign<Type>
                                                {
                                                    Value = new InArgument<Type>((env) => (child.Get(env) as ISendResponse).ResponseParameterType),
                                                    To = responseParameterType
                                                },
                                            },
                                        },
                                    },
                                },
                            },
                            new WorkflowInterfaceOperationNamesSetter
                            {
                                ReceiveRequest = new InArgument<IOperationActivity>((env) => receiveRequest.Get(env)),
                                WorkflowInterfaceType = new InArgument<Type>((env) => workflowInterfaceType.Get(env)),
                                RequestResultType = new InArgument<Type>((env) => requestResultType.Get(env)),
                                ResponseParameterType = new InArgument<Type>((env) => responseParameterType.Get(env)),
                            },
                        },
                    },
                },
            };
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        private static Activity CreateFlowchartWithFaults(string promoCode, int numKids)
        {
            Variable<string> promo = new Variable<string> { Default = promoCode };
            Variable<int> numberOfKids = new Variable<int> { Default = numKids };
            Variable<double> discount = new Variable<double>();
            DelegateInArgument<DivideByZeroException> ex = new DelegateInArgument<DivideByZeroException>();

            FlowStep discountNotApplied = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount not applied",
                    Text = "Discount not applied"
                },
                Next = null
            };

            FlowStep discountApplied = new FlowStep
            {
                Action = new WriteLine
                {
                    DisplayName = "WriteLine: Discount applied",
                    Text = "Discount applied "
                },
                Next = null
            };

            FlowDecision flowDecision = new FlowDecision
            {
                Condition = ExpressionServices.Convert<bool>((ctx) => discount.Get(ctx) > 0),
                True = discountApplied,
                False = discountNotApplied
            };

            FlowStep singleStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 10.0",
                    To = new OutArgument<double> (discount),
                    Value = new InArgument<double> (10.0)
                },
                Next = flowDecision
            };

            FlowStep mnkStep = new FlowStep
            {
                Action = new Assign
                {
                    DisplayName = "discount = 15.0",
                    To = new OutArgument<double> (discount),
                    Value = new InArgument<double> (15.0)
                },
                Next = flowDecision
            };

            FlowStep mwkStep = new FlowStep
            {
                Action = new TryCatch
                {
                    DisplayName = "Try/Catch for Divide By Zero Exception",
                    Try = new Assign
                    {
                        DisplayName = "discount = 15 + (1 - 1/numberOfKids)*10",
                        To = new OutArgument<double>(discount),
                        Value = new InArgument<double>((ctx) => (15 + (1 - 1 / numberOfKids.Get(ctx)) * 10))
                    },
                    Catches =
                    {
                         new Catch<System.DivideByZeroException>
                         {
                             Action = new ActivityAction<System.DivideByZeroException>
                             {
                                 Argument = ex,
                                 DisplayName = "ActivityAction - DivideByZeroException",
                                 Handler =
                                     new Sequence
                                     {
                                         DisplayName = "Divide by Zero Exception Workflow",
                                         Activities =
                                         {
                                            new WriteLine()
                                            {
                                                DisplayName = "WriteLine: DivideByZeroException",
                                                Text = "DivideByZeroException: Promo code is MWK - but number of kids = 0"
                                            },
                                            new Assign<double>
                                            {
                                                DisplayName = "Exception - discount = 0",
                                                To = discount,
                                                Value = new InArgument<double>(0)
                                            }
                                         }
                                     }
                             }
                         }
                    }
                },
                Next = flowDecision
            };

            FlowStep discountDefault = new FlowStep
            {
                Action = new Assign<double>
                {
                    DisplayName = "Default discount assignment: discount = 0",
                    To = discount,
                    Value = new InArgument<double>(0)
                },
                Next = flowDecision
            };

            FlowSwitch<string> promoCodeSwitch = new FlowSwitch<string>
            {
                Expression = promo,
                Cases =
                {
                   { "Single", singleStep },
                   { "MNK", mnkStep },
                   { "MWK", mwkStep }
                },
                Default = discountDefault
            };

            Flowchart flowChart = new Flowchart
            {
                DisplayName = "Promotional Discount Calculation",
                Variables = {discount, promo, numberOfKids},
                StartNode = promoCodeSwitch,
                Nodes =
                {
                    promoCodeSwitch,
                    singleStep,
                    mnkStep,
                    mwkStep,
                    discountDefault,
                    flowDecision,
                    discountApplied,
                    discountNotApplied
                }
            };
            return flowChart;
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        // This scenario shows how to add an entity to the database
        private static Activity EntityAddExample(string connStr)
        {
            Variable<IEnumerable<Order>> orders = new Variable<IEnumerable<Order>>();
            Variable<IEnumerable<OrderDetail>> orderDetails = new Variable<IEnumerable<OrderDetail>>();
            Variable<Order> order = new Variable<Order>();
            Variable<OrderDetail> orderDetail = new Variable<OrderDetail>();

            return new ObjectContextScope
            {
                Variables = { order, orders, orderDetail, orderDetails },
                ContainerName = "NorthwindEntities",
                ConnectionString = new InArgument<string>(connStr),
                Body = new Sequence
                {
                    Activities =
                    {
                        // get the order detail that we want to add (if exists, then we can't continue)
                        new EntitySqlQuery<OrderDetail>
                        {
                            EntitySql = @"SELECT VALUE OrderDetail
                                           FROM NorthwindEntities.OrderDetails as OrderDetail
                                          WHERE OrderDetail.OrderID == 10249 and OrderDetail.ProductID == 11",
                            Result = orderDetails
                        },

                        // if the order detail exists, we display an error message, otherwise we add it
                        new If
                        {
                            Condition = new InArgument<bool>(c=>orderDetails.Get(c).Count() > 0),
                            Then = new WriteLine{ Text = "OrderDetail already exists, cannot add to database. Run Delete Example first" },
                            Else = new Sequence
                            {
                                Activities =
                                {
                                    // get the order where we want to add the detail
                                    new EntitySqlQuery<Order>
                                    {
                                        EntitySql =  @"SELECT VALUE [Order]
                                                         FROM NorthwindEntities.Orders as [Order]
                                                        WHERE Order.OrderID == 10249",
                                        Result = orders
                                    },

                                    // store the order in a variable
                                    new Assign<Order>
                                    {
                                        To = new OutArgument<Order>(order),
                                        Value = new InArgument<Order>(c => orders.Get(c).First<Order>())
                                    },
                                    new WriteLine { Text = "Executing add" },

                                    // add the detail to the order
                                    new EntityAdd<OrderDetail>
                                    {
                                        Entity = new InArgument<OrderDetail>(c => new OrderDetail { OrderID=10249, ProductID=11, Quantity=1, UnitPrice = 15, Discount = 0, Order = order.Get(c) })
                                    },
                                    new WriteLine { Text = "Add Executed" },
                                }
                            }
                        }
                    }
                }
            };
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        // This scenario shows how to delete an entity from the database
        private static Activity EntityDeleteExample(string connStr)
        {
            Variable<IEnumerable<OrderDetail>> orderDetails = new Variable<IEnumerable<OrderDetail>>();

            return new ObjectContextScope
            {
                Variables = { orderDetails },
                ConnectionString = new InArgument<string>(connStr),
                ContainerName = "NorthwindEntities",
                Body = new Sequence
                {
                    Activities =
                    {
                        // find the entitiy to be deleted (order detail for product 11 in order 10249)
                        new EntitySqlQuery<OrderDetail>
                        {
                            EntitySql = @"SELECT VALUE OrderDetail
                                            FROM NorthwindEntities.OrderDetails as OrderDetail
                                           WHERE OrderDetail.OrderID == 10249 and OrderDetail.ProductID == 11",
                            Result = orderDetails
                        },

                        // if the order detail is found, delete it, otherwise, display a message
                        new If
                        {
                            Condition = new InArgument<bool>(c=>orderDetails.Get(c).Count() > 0),
                            Then = new Sequence
                            {
                                Activities =
                                {
                                    new WriteLine { Text = "Order Detail found for Deleting - about to delete" },

                                    //delete it!
                                    new EntityDelete<OrderDetail>
                                    {
                                        Entity = new InArgument<OrderDetail>(c => orderDetails.Get(c).First<OrderDetail>())
                                    },
                                    new WriteLine { Text = "Delete Executed" }
                                }
                            },
                            Else = new WriteLine { Text = "Order Detail for Deleting not found" }
                        }
                    }
                }
            };
        }