Пример #1
0
        private static Activity GetApprovePO(Variable<PurchaseOrder> po, Variable<bool> replyPO)
        {
            Receive approvePO = new Receive
            {
                OperationName = "ApprovePurchaseOrder",
                CanCreateInstance = true,
                ServiceContractName = "FinanceService",
                SerializerOption = SerializerOption.XmlSerializer,
                Content = ReceiveContent.Create(new OutArgument<PurchaseOrder>(po))
            };

            Activity workflow = new CorrelationScope()
            {
                Body = new Sequence
                {
                    Variables = { po, replyPO },
                    Activities =
                    {
                        approvePO,
                        new WriteLine
                        {
                            Text = new InArgument<string>(env =>("Purchase order approval request received"))
                        },
                        new If
                        {
                           Condition = new InArgument<bool> (env => (po.Get(env).RequestedAmount <= 100)),
                           Then =
                               new Assign<bool>
                               {
                                   Value = true,
                                   To = new OutArgument<bool>(replyPO)
                               },
                           Else =
                               new Assign<bool>
                               {
                                   Value = false,
                                   To = new OutArgument<bool>(replyPO)
                               },
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (replyPO),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Purchase Order Approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Purchase Order Cannot be Approved")
                                },
                        },
                        new SendReply
                        {
                            Request = approvePO,
                            Content = SendContent.Create(new InArgument<bool>(replyPO)),
                        },
                    }
                }
            };
            return workflow;
        }
Пример #2
0
        private static Activity GetApprovedVendor(Variable<VendorRequest> vendor, Variable<VendorResponse> replyVendor)
        {
            Receive approvedVendor = new Receive
            {
                OperationName = "ApprovedVendor",
                CanCreateInstance = true,
                ServiceContractName = "FinanceService",
                Content = ReceiveContent.Create(new OutArgument<VendorRequest>(vendor))
            };

            Activity workflow = new CorrelationScope()
            {
                Body = new Sequence
                {
                    Variables = { vendor, replyVendor },
                    Activities =
                    {
                        approvedVendor,
                        new WriteLine
                        {
                            Text = new InArgument<string>(env =>("Query for approved vendor received"))
                        },
                        new If
                        {
                           Condition = new InArgument<bool> (env => ((vendor.Get(env).requestingDepartment == "Finance"))||Constants.vendors.Contains(vendor.Get(env).Name)),
                           Then =
                               new Assign<VendorResponse>
                               {
                                   Value = new InArgument<VendorResponse>( (e) => new VendorResponse{isPreApproved = true} ),
                                   To = new OutArgument<VendorResponse>(replyVendor)
                               },
                           Else =
                               new Assign<VendorResponse>
                               {
                                   Value = new InArgument<VendorResponse>( (e) => new VendorResponse{isPreApproved = false} ),
                                   To = new OutArgument<VendorResponse>(replyVendor)
                               },
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (env => replyVendor.Get(env).isPreApproved),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Vendor is pre-approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Vendor is not pre-approved")
                                },
                        },
                        new SendReply
                        {
                            Request = approvedVendor,
                            Content = SendContent.Create(new InArgument<VendorResponse>(replyVendor)),
                        },
                    }
                }
            };
            return workflow;
        }
Пример #3
0
        private static Activity GetApproveExpense(Variable<Expense> expense, Variable<bool> reply)
        {
            Receive approveExpense = new Receive
            {
                OperationName = "ApproveExpense",
                CanCreateInstance = true,
                ServiceContractName = "FinanceService",
                SerializerOption = SerializerOption.DataContractSerializer,
                Content = ReceiveContent.Create(new OutArgument<Expense>(expense))
            };
            approveExpense.KnownTypes.Add(typeof(Travel));
            approveExpense.KnownTypes.Add(typeof(Meal));

            Activity workflow = new CorrelationScope()
            {
                Body = new Sequence
                {
                    Variables = { expense, reply },
                    Activities =
                    {
                        approveExpense,
                        new WriteLine
                        {
                            Text = new InArgument<string>(env =>("Expense approval request received"))
                        },
                        new If
                        {
                           Condition = new InArgument<bool> (env => (expense.Get(env).Amount <= 100)),
                           Then =
                               new Assign<bool>
                               {
                                   Value = true,
                                   To = new OutArgument<bool>(reply)
                               },
                           Else =
                               new Assign<bool>
                               {
                                   Value = false,
                                   To = new OutArgument<bool>(reply)
                               },
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (reply),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Expense Approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Expense Cannot be Approved")
                                },
                        },
                        new SendReply
                        {
                            Request = approveExpense,
                            Content = SendContent.Create(new InArgument<bool>(reply)),
                        },
                    },
                }
            };
            return workflow;
        }