public Activity Create(DependencyObject target)
        {
            string correlationHandleName = ActivityDesignerHelper.GenerateUniqueVariableNameForContext(target, correlationHandleNamePrefix);

            Variable<CorrelationHandle> requestReplyCorrelation = new Variable<CorrelationHandle> { Name = correlationHandleName };
           
            Send send = new Send
            {
                OperationName = "Operation1",
                ServiceContractName = XName.Get("IService", "http://tempuri.org/"),
                CorrelationInitializers =
                {
                    new RequestReplyCorrelationInitializer
                    {
                        CorrelationHandle = new VariableValue<CorrelationHandle> { Variable = requestReplyCorrelation }
                    }
                }
            };

            Sequence sequence = new Sequence()
            {
                Variables = { requestReplyCorrelation },
                Activities =
                {
                    send,
                    new ReceiveReply
                    {      
                        DisplayName = "ReceiveReplyForSend",
                        Request = send,
                    },
                }
            };
            return sequence;
        }
Example #2
0
        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))
                        }
                    }
                }
            };
        }
Example #3
0
        static Activity BuildRequestReply()
        {
            Send send = new Send
            {
                OperationName = "DoRequestReply",
                EndpointConfigurationName = "clientEndpoint",
                ServiceContractName = XName.Get("ISuppressSample", "http://tempuri.org/"),
            };

            return new CorrelationScope
            {
                Body = new Sequence
                {
                    Activities =
                    {
                        new WriteLine { Text = "Beginning RequestReply sequence" },

                        send,
                        new PrintTxID(),
                        new ReceiveReply
                        {
                            Request = send,
                        },

                        new WriteLine { Text = "End RequestReply sequence" },
                    },
                },
            };
        }
Example #4
0
        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." }
                }
            };
        }
Example #5
0
        static void CreateClientWorkflow()
        {
            Variable<string> message = new Variable<string>("message", "client");
            Variable<string> result = new Variable<string> { Name = "result" };

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

            Send requestEcho = new Send
            {
                ServiceContractName = XName.Get("Echo", "http://tempuri.org/"),
                Endpoint = endpoint,
                OperationName = "Echo",
                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>("Hello")
                        },
                        requestEcho,
                        new ReceiveReply
                        {
                            Request = requestEcho,
                            Content = new ReceiveParametersContent
                            {
                                Parameters =
                                {
                                    { "echo", new OutArgument<string>(result) }
                                }
                            }
                        },
                        new WriteLine {
                            Text = new InArgument<string>(result)
                        }
                    }
                }
            };
        }
        private Activity InternalImplementation()
        {
            Variable<string> reply = new Variable<string> { Name = "replyString" };

            Send send = new Send
            {
                OperationName = "StartSample",
                Content = SendContent.Create(new InArgument<string>("Client side: Send request.")),
                EndpointConfigurationName = "codeServiceEndpoint",
                ServiceContractName = "ITransactedReceiveService",
            };

            return new CorrelationScope
            {
                Body = new Sequence
                {
                    Variables = { reply },
                    Activities =
                    {
                        new WriteLine { Text = "Client workflow begins." },

                         new TransactionScope
                         {
                            Body = new Sequence
                            {
                                Activities =
                                {
                                    // Transaction DistributedIdentifier will be emtpy until the send activity causes the transaction to promote to MSDTC
                                    new PrintTransactionInfo(),
                                    new WriteLine { Text = new InArgument<string>("Client side: Beginning send.") },
                                    send,
                                    new WriteLine { Text = new InArgument<string>("Client side: Send complete.") },
                                    new ReceiveReply
                                    {
                                      Request = send,
                                      Content = ReceiveContent.Create(new OutArgument<string>(reply))
                                    },
                                    new WriteLine { Text = new InArgument<string>(new VisualBasicValue<string>() { ExpressionText = "\"Client side: Reply received = '\" + replyString.toString() + \"'\"" }) },
                                    new PrintTransactionInfo(),
                                    new WriteLine { Text = new InArgument<string>("Client side: Receive complete.") },
                                },
                            },
                        },
                        new WriteLine { Text = "Client workflow ends." }
                    }
                }
            };
        }
 public static OperationDescription CreateOneWayOperationDescription(Send send)
 {
     Fx.Assert(send != null, "Argument cannot be null!");
     return CreateOperationDescriptionCore(send, null);
 }
Example #8
0
        static Sequence VendorApprovalRequest(Endpoint endpoint)
        {
            Variable<VendorRequest> vendor = new Variable<VendorRequest>
            {
                Name = "vendor",
            };
            Variable<VendorResponse> result = new Variable<VendorResponse>
            {
                Name = "result"
            };

            Send approvedVendor = new Send
            {
                ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"),
                Endpoint = endpoint,
                OperationName = "ApprovedVendor",
                Content = SendContent.Create(new InArgument<VendorRequest>(vendor)),
            };

            Sequence workflow = new Sequence
            {
                Variables = { vendor, result },
                Activities =
                    {
                        new Assign<VendorRequest>
                        {
                           Value = new InArgument<VendorRequest>( (e) => new VendorRequest { Name = "Vendor1", requestingDepartment = "HR" }),
                           To = new OutArgument<VendorRequest>(vendor)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>("Hello")
                        },
                        approvedVendor,
                        new ReceiveReply
                        {
                            Request = approvedVendor,
                            Content = ReceiveContent.Create(new OutArgument<VendorResponse>(result))
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (env => result.Get(env).isPreApproved),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Vendor Approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Vendor is not Approved")
                                },
                        },

                    }
            };
            return workflow;
        }
Example #9
0
        static Activity GetClientWorkflow()
        {
            Variable<PurchaseOrder> po = new Variable<PurchaseOrder>();
            Variable<Customer> customer = new Variable<Customer>();

            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, customer },
                Activities =
                {
                    new Assign<PurchaseOrder>
                    {
                        To = po,
                        Value = new InArgument<PurchaseOrder>( (e) => new PurchaseOrder() { PartName = "Widget", Quantity = 150 } )
                    },
                    new Assign<Customer>
                    {
                        To = customer,
                        Value = new InArgument<Customer>( (e) => new Customer() { Id = 12345678, Name = "John Smith" } )
                    },
                    new WriteLine { Text = new InArgument<string>( (e) => string.Format("Submitting new PurchaseOrder for {0} {1}s", po.Get(e).Quantity, po.Get(e).PartName) ) },
                    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("Received ID for new PO: {0}", po.Get(e).Id) ) },
                    new Assign<int> { To = new OutArgument<int>( (e) => po.Get(e).Quantity ), Value = 250 },
                    new WriteLine { Text = "Updated PO with new quantity: 250.  Resubmitting updated PurchaseOrder based on POId." },
                    new Send
                    {
                        Endpoint = clientEndpoint,
                        ServiceContractName = Constants.POContractName,
                        OperationName = Constants.UpdatePOName,
                        Content = SendContent.Create(new InArgument<PurchaseOrder>(po))
                    },
                    new Assign<int>
                    {
                        To = new OutArgument<int>( (e) => po.Get(e).CustomerId ),
                        Value = new InArgument<int>( (e) => customer.Get(e).Id )
                    },
                    new WriteLine { Text = "Updating customer data based on CustomerId." },
                    new Send
                    {
                        Endpoint = clientEndpoint,
                        ServiceContractName = Constants.POContractName,
                        OperationName = Constants.AddCustomerInfoName,
                        Content = SendContent.Create(new InArgument<PurchaseOrder>(po))
                    },
                    new Send
                    {
                        Endpoint = clientEndpoint,
                        ServiceContractName = Constants.POContractName,
                        OperationName = Constants.UpdateCustomerName,
                        Content = SendContent.Create(new InArgument<Customer>(customer))
                    },
                    new WriteLine { Text = "Client completed." }
                }
            };
        }
Example #10
0
        private Activity InternalImplementation()
        {
            string correlationKey = Guid.NewGuid().ToString();

            Send sendBootstrap = new Send
            {
                OperationName = "Bootstrap",
                EndpointConfigurationName = endpointConfigurationName,
                Content = SendMessageContent.Create(new InArgument<string>(correlationKey)),
                ServiceContractName = Constants.ServiceContractName,
            };

            // In this sample there is no client side transaction, so transaction flow is not occuring.
            // Instead the service workflow is creating and scoping the transaction.
            return new CorrelationScope()
            {
                Body = new Sequence
                {
                    Activities =
                    {
                        new WriteLine { Text = "Client: Workflow begins." },

                        new WriteLine { Text = "Client: Bootstrap service." },

                        // The service requires an initial Request represented by this "bootstrap" message.
                        sendBootstrap,

                        new ReceiveReply
                        {
                            Request = sendBootstrap
                        },

                        new WriteLine { Text = "Client: Beginning parallel sends." },

                        // The service workflow is now in a state where it's accepting multiple requests in parallel.
                        // All of these requests will execute under the same server side transaction.
                        new Parallel()
                        {
                            CompletionCondition = false,
                            Branches =
                            {
                                new Send
                                {
                                    OperationName = "WorkBranch1",
                                    ServiceContractName = Constants.ServiceContractName,
                                    EndpointConfigurationName = endpointConfigurationName,
                                    Content = SendMessageContent.Create(new InArgument<string>(correlationKey))
                                },
                                new Send
                                {
                                    OperationName = "WorkBranch2",
                                    ServiceContractName = Constants.ServiceContractName,
                                    EndpointConfigurationName = endpointConfigurationName,
                                    Content = SendMessageContent.Create(new InArgument<string>(correlationKey)),
                                },
                                new Send
                                {
                                    OperationName = "WorkBranch3",
                                    ServiceContractName = Constants.ServiceContractName,
                                    EndpointConfigurationName = endpointConfigurationName,
                                    Content = SendMessageContent.Create(new InArgument<string>(correlationKey)),
                                },
                            },
                        },

                        new WriteLine { Text = "Client: All sends complete." },

                        new WriteLine { Text = "Client: Workflow ends." }
                    }
                }
            };
        }
Example #11
0
        static Sequence ExpenseRequest(Endpoint endpoint)
        {
            Variable<Expense> mealExpense = new Variable<Expense>
            {
                Name = "mealExpense",
            };
            Variable<bool> result = new Variable<bool>
            {
                Name = "result"
            };

            Send approveExpense = new Send
            {
                ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"),
                Endpoint = endpoint,
                OperationName = "ApproveExpense",
                Content = SendContent.Create(new InArgument<Expense>(mealExpense))
            };
            approveExpense.KnownTypes.Add(typeof(Travel));
            approveExpense.KnownTypes.Add(typeof(Meal));

            Sequence workflow = new Sequence
            {
                Variables = { mealExpense, result },
                Activities =
                    {
                        new Assign<Expense>
                        {
                           Value = new InArgument<Expense>( (e) => new Meal { Amount = 50, Location = "Redmond", Vendor = "KFC" }),
                           To = new OutArgument<Expense>(mealExpense)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>("Hello")
                        },
                        approveExpense,
                        new ReceiveReply
                        {
                            Request = approveExpense,
                            Content = ReceiveContent.Create(new OutArgument<bool>(result))
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (result),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Expense Approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Expense Cannot be Approved")
                                },
                        },

                    }
            };
            return workflow;
        }
Example #12
0
        static Activity GetClientWorkflow()
        {
            Variable<PurchaseOrder> po = new Variable<PurchaseOrder>();
            Variable<bool> invalidorder = new Variable<bool>() { Default = true };
            Variable<string> replytext = new Variable<string>();
            DelegateInArgument<FaultException<POFault>> poFault = new DelegateInArgument<FaultException<POFault>>();
            DelegateInArgument<FaultException<ExceptionDetail>> unexpectedFault = new DelegateInArgument<FaultException<ExceptionDetail>>();

            // submits a purchase order for the part and quantity stored in the po variable
            Send submitPO = new Send
            {
                Endpoint = new Endpoint
                {
                    Binding = Constants.Binding,
                    AddressUri = new Uri(Constants.ServiceAddress)
                },
                ServiceContractName = Constants.POContractName,
                OperationName = Constants.SubmitPOName,
                KnownTypes = { typeof(POFault) },
                Content = SendContent.Create(new InArgument<PurchaseOrder>(po))
            };

            return new CorrelationScope
            {
                Body = new Sequence
                {
                    Variables = { invalidorder, po },
                    Activities =
                    {
                        // defines the original desired parts and quantity: 155 pencils
                        new Assign<PurchaseOrder>
                        {
                            To = po,
                            Value = new InArgument<PurchaseOrder>( (e) => new PurchaseOrder() { PartName = "Pencil", Quantity = 155 } )
                        },
                        new While
                        {
                            // loop until a valid order is submitted
                            Condition = invalidorder,
                            Variables = { replytext },
                            Body = new Sequence
                            {
                                Activities =
                                {
                                    // print out the order that will be submitted
                                    new WriteLine { Text = new InArgument<string>((env) => string.Format("Submitting Order: {0} {1}s", po.Get(env).Quantity, po.Get(env).PartName)) },
                                    // submit the order
                                    submitPO,
                                    new TryCatch
                                    {
                                        Try = new Sequence
                                        {
                                            Activities =
                                            {
                                                // receive the result of the order
                                                // if ReceiveReply gets a Fault message, then we will handle those faults below
                                                new ReceiveReply
                                                {
                                                    Request = submitPO,
                                                    Content = ReceiveContent.Create(new OutArgument<string>(replytext))
                                                },
                                                new WriteLine { Text = replytext },
                                                // this order must be valid, so set invalidorder to false
                                                new Assign<bool>
                                                {
                                                    To = invalidorder,
                                                    Value = false
                                                }
                                            }
                                        },
                                        Catches =
                                        {
                                            // catch a known Fault type: POFault
                                            new Catch<FaultException<POFault>>
                                            {
                                                Action = new ActivityAction<FaultException<POFault>>
                                                {
                                                    Argument = poFault,
                                                    Handler = new Sequence
                                                    {
                                                        Activities =
                                                        {
                                                            // print out the details of the POFault
                                                            new WriteLine { Text = new InArgument<string>((env) => string.Format("\tReceived POFault: {0}", poFault.Get(env).Reason.ToString())) },
                                                            new WriteLine { Text = new InArgument<string>((env) => string.Format("\tPOFault Problem: {0}", poFault.Get(env).Detail.Problem)) },
                                                            new WriteLine { Text = new InArgument<string>((env) => string.Format("\tPOFault Solution: {0}", poFault.Get(env).Detail.Solution)) },
                                                            // update the order to buy Widgets instead
                                                            new Assign<string>
                                                            {
                                                                To = new OutArgument<string>( (e) => po.Get(e).PartName ),
                                                                Value = "Widget"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            // catch any unknown fault types
                                            new Catch<FaultException<ExceptionDetail>>
                                            {
                                                Action = new ActivityAction<FaultException<ExceptionDetail>>
                                                {
                                                    Argument = unexpectedFault,
                                                    Handler = new Sequence
                                                    {
                                                        Activities =
                                                        {
                                                            // print out the details of the fault
                                                            new WriteLine
                                                            {
                                                                Text = new InArgument<string>((e) => string.Format("\tReceived Fault: {0}",
                                                                    unexpectedFault.Get(e).Message
                                                                    ))
                                                            },
                                                            // update the order to buy 10 less of the item
                                                            new Assign<int>
                                                            {
                                                                To = new OutArgument<int>( (e) => po.Get(e).Quantity ),
                                                                Value = new InArgument<int>( (e) => po.Get(e).Quantity - 10 )
                                                            }
                                                        }
                                                    }
                                                }
                                            },

                                        }
                                    }
                                }
                            }

                        },
                        new WriteLine { Text = "Order successfully processed." }
                    }
                }
            };
        }
Example #13
0
        static Sequence PurchaseOrderRequest(Endpoint endpoint)
        {
            Variable<PurchaseOrder> po = new Variable<PurchaseOrder>
            {
                Name = "po"
            };
            Variable<bool> result = new Variable<bool>
            {
                Name = "result"
            };

            Send approveExpense = new Send
            {
                ServiceContractName = XName.Get("FinanceService", "http://tempuri.org/"),
                Endpoint = endpoint,
                OperationName = "ApprovePurchaseOrder",
                Content = SendContent.Create(new InArgument<PurchaseOrder>(po)),
                SerializerOption = SerializerOption.XmlSerializer
            };

            Sequence workflow = new Sequence
            {
                Variables = { po, result },
                Activities =
                    {
                        new Assign<PurchaseOrder>
                        {
                           Value = new InArgument<PurchaseOrder>( (e) => new PurchaseOrder { RequestedAmount = 500, Description = "New PC" }),
                           To = new OutArgument<PurchaseOrder>(po)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>("Hello")
                        },
                        approveExpense,
                        new ReceiveReply
                        {
                            Request = approveExpense,
                            Content = ReceiveContent.Create(new OutArgument<bool>(result))
                        },

                        new If
                        {
                           Condition = new InArgument<bool> (result),
                           Then =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Purchase order Approved")
                                },
                           Else =
                                new WriteLine
                                {
                                    Text = new InArgument<string>("Purchase order Cannot be Approved")
                                },
                        },

                    }
            };
            return workflow;
        }
Example #14
0
        // Define workflow
        static Activity ClientWorkflow()
        {
            string correlationKey = Guid.NewGuid().ToString();

            Send requestOne = new Send
            {
                Endpoint = Constants.ServerEndpoint,
                ServiceContractName = Constants.ServiceContractName,
                OperationName = "ScenarioOne",
                Content = new SendMessageContent { Message = new InArgument<string>(correlationKey) },
            };

            Send requestTwo = new Send
            {
                Endpoint = Constants.ServerEndpoint,
                ServiceContractName = Constants.ServiceContractName,
                OperationName = "ScenarioTwo",
                Content = new SendMessageContent { Message = new InArgument<string>(correlationKey) },
            };

            return new CorrelationScope
            {
                Body = new Sequence
                {
                    Activities =
                    {
                        new WriteLine { Text = "Begin Client Workflow" },

                        new TransactionScope
                        {
                            // Initiate Transaction for Scenario One
                            Body = new Sequence
                            {
                                Activities =
                                {
                                    new WriteLine { Text = "Scenario One Started" },

                                    // Transaction has not flowed yet, so it remains local
                                    new PrintTxInfo(),

                                    requestOne,

                                    new ReceiveReply
                                    {
                                        Request = requestOne,
                                    },

                                    // Transaction has flowed to service and has promoted to be a distributed transaction
                                    new PrintTxInfo(),

                                    new WriteLine { Text = "Scenario One Complete\n" },
                                }
                            }
                        },

                        new TryCatch
                        {
                            //Set up trycatch as we anticipate Scenario Two to fail
                            Try = new TransactionScope
                            {
                                // Initiate Transaction for Scenario Two
                                // When set to false a TransactionAbortedException will propogate instead of aborting the workflow.
                                AbortInstanceOnTransactionFailure = false,
                                Body = new Sequence
                                {
                                    Activities =
                                    {
                                        new WriteLine { Text = "Scenario Two Started" },

                                        // Transaction has not flowed yet, so it remains local
                                        new PrintTxInfo(),

                                        requestTwo,

                                        new ReceiveReply
                                        {
                                            Request = requestTwo,
                                        },

                                        // Transaction has flowed to service and has promoted to be a distributed transaction
                                        new PrintTxInfo(),
                                    }
                                }
                            },
                            Catches =
                            {
                                new Catch<TransactionAbortedException>
                                {
                                    Action = new ActivityAction<TransactionAbortedException>
                                    {
                                        Handler = new WriteLine { Text = "The transaction was aborted on the server and a TransactionAbortedException was sent." },
                                    },
                                },
                            },
                            Finally = new WriteLine { Text = "Scenario Two Complete\n" },
                        },

                        new WriteLine { Text = "End Client Workflow" },
                    }
                }
            };
        }
 public static OperationDescription CreateTwoWayOperationDescription(Send send, ReceiveReply receiveReply)
 {
     Fx.Assert(send != null && receiveReply != null, "Arguments cannot be null!");
     return CreateOperationDescriptionCore(send, receiveReply);
 }
 public static OperationDescription CreateTwoWayOperationDescription(Send send, ReceiveReply receiveReply)
 {
     return CreateOperationDescriptionCore(send, receiveReply);
 }
 public static OperationDescription CreateOneWayOperationDescription(Send send)
 {
     return CreateOperationDescriptionCore(send, null);
 }
        public SendRequest()
        {
            // Define the variables used by this workflow
            Variable<ReservationRequest> request = 
                new Variable<ReservationRequest> { Name = "request" };
            Variable<string> requestAddress = 
                new Variable<string> { Name = "RequestAddress" };

            // Define the Send activity
            Send submitRequest = new Send
            {
                ServiceContractName = "ILibraryReservation",
                EndpointAddress = new InArgument<Uri>(env => new Uri("http://localhost:" + requestAddress.Get(env) + "/LibraryReservation")),
                Endpoint = new Endpoint
                {
                    Binding = new BasicHttpBinding()
                },
                OperationName = "RequestBook",
                Content = SendContent.Create (new InArgument<ReservationRequest>(request))
            };

            // Define the SendRequest workflow
            this.Implementation = () => new Sequence
            {
                DisplayName = "SendRequest",
                Variables = { request, requestAddress },
                Activities = 
                {
                    new CreateRequest
                    {
                        Title = new InArgument<string>(env => Title.Get(env)),
                        Author = new InArgument<string>(env => Author.Get(env)),
                        ISBN = new InArgument<string>(env => ISBN.Get(env)),
                        Request = new OutArgument<ReservationRequest>
                            (env => request.Get(env)),
                        RequestAddress = new OutArgument<string>
                            (env => requestAddress.Get(env))
                    },
                    new CorrelationScope
                    {
                        Body = new Sequence
                        {
                            Activities = 
                            {
                                submitRequest,
                                new WriteLine
                                {
                                    Text = new InArgument<string>
                                        (env => "Request sent; waiting for response"),
                                },
                                new ReceiveReply
                                {
                                    Request = submitRequest,
                                    Content = ReceiveContent.Create
                                        (new OutArgument<ReservationResponse>
                                            (env => Response.Get(env)))
                                }
                            }
                        }
                    },
                    new WriteLine
                    {
                        Text = new InArgument<string>
                            (env => "Response received from " + 
                             Response.Get(env).Provider.BranchName),
                    },
                }
            };     
        }
 public static OperationDescription CreateTwoWayOperationDescription(Send send, ReceiveReply receiveReply)
 {
     return(CreateOperationDescriptionCore(send, receiveReply));
 }
 public static OperationDescription CreateOneWayOperationDescription(Send send)
 {
     return(CreateOperationDescriptionCore(send, null));
 }
        static OperationDescription CreateOperationDescriptionCore(Send send, ReceiveReply receiveReply)
        {
            XName contractXName = send.ServiceContractName;
            ProvideDefaultNamespace(ref contractXName);

            // Infer Name, Namespace, ConfigurationName
            ContractDescription contract = new ContractDescription(contractXName.LocalName, contractXName.NamespaceName);
            contract.ConfigurationName = send.EndpointConfigurationName;

            OperationDescription operation = new OperationDescription(NamingHelper.XmlName(send.OperationName), contract);
            if (send.ProtectionLevel.HasValue)
            {
                operation.ProtectionLevel = send.ProtectionLevel.Value;
            }

            AddKnownTypesToOperation(operation, send.KnownTypes);

            // Infer In-Message
            send.InternalContent.InferMessageDescription(operation, send, MessageDirection.Input);

            // Infer Out-Message
            if (receiveReply != null)
            {
                receiveReply.InternalContent.InferMessageDescription(operation, receiveReply, MessageDirection.Output);
            }

            PostProcessOperation(operation);
            AddSerializerProvider(operation, send.SerializerOption);

            contract.Operations.Add(operation);

            return operation;
        }
        public EnterLead()
        {
            // Define the variables used by this workflow
            Variable<Lead> lead = new Variable<Lead> { Name = "lead" };
            Variable<string> assignedTo = new Variable<string> { Name = "assignedTo" };
            Send send = new Send
                {
                    OperationName = "Assign",
                    ServiceContractName = "CreateAssignment",
                    Content = new SendParametersContent
                    {
                        Parameters =
                    {
                                    {
                                    "leadID",
                                    new InArgument<int> (env => lead.Get(env).LeadID)
                                    },
                                    {
                                    "assignedTo",
                                    new InArgument<string>(env => assignedTo.Get(env))
                                    }
                    }
                    },
                    EndpointAddress = new InArgument<Uri>
                    (env => new Uri("http://localhost/CreateAssignment")),
                    Endpoint = new Endpoint
                    {
                        Binding = new BasicHttpBinding()
                    }
                };

            // Define the SendRequest workflow
            this.Implementation = () => new Sequence
            {
                DisplayName = "EnterLead",
                Variables = { lead, assignedTo },
                Activities =
                {
                    new CreateLead
                    {
                    ContactName = new InArgument<string>
                    (env => ContactName.Get(env)),
                    ContactPhone = new InArgument<string>
                    (env => ContactPhone.Get(env)),
                    Interests = new InArgument<string>
                    (env => Interests.Get(env)),
                    Notes = new InArgument<string>(env => Notes.Get(env)),
                    //ConnectionString = new InArgument<string>(env => ConnectionString.Get(env)),
                    Lead = new OutArgument<Lead>(env => lead.Get(env)),
                    },
                new WriteLine
                {
                Text = new InArgument<string>
                (env => "Lead received [" + Rating.Get(env).ToString()
                + "]; waiting for assignment"),
                TextWriter = new InArgument<TextWriter>
                (env => Writer.Get(env))
                },
                new InvokeMethod
                {
                    TargetType = typeof(ApplicationInterface),
                    MethodName = "NewLead",
                    Parameters =
                    {
                    new InArgument<Lead>(env => lead.Get(env))
                    }
                },
                new AddComment
                {
                Comment = new InArgument<string>(env => "Lead has been created")
                },
                
                

               new WaitForInput<string>
                {
                BookmarkName = "GetAssignment",
                Input = new OutArgument<string>(env => assignedTo.Get(env))
                },
                //funziona capitolo 15
                //new TransactionScope
                //{
                //    Body = new Sequence
                //    {
                //        Activities =
                //        {

                //            new AssignLead
                //            {
                //            AssignedTo = new InArgument<string>(env => assignedTo.Get(env)),
                //            Lead = new InOutArgument<Lead>(env => lead.Get(env)),
                //            },
                //            new Delay
                //            {
                //            Duration = TimeSpan.FromSeconds(20)
                //            },
                //            new CreateAssignment
                //            {
                //            AssignedTo = new InArgument<string>(env => assignedTo.Get(env)),
                //            LeadID = new InArgument<int>(env => lead.Get(env).LeadID),
                //            }
                //        }
                //    },
                // },
                new AssignLead
                {
                    AssignedTo = new InArgument<string>
                    (env => assignedTo.Get(env)),
                    Lead = new InOutArgument<Lead>(env => lead.Get(env)),
                    },
                    new CorrelationScope
                    {
                    Body = new Sequence
                    {
                    Activities =
                    {
                    send,
                    new ReceiveReply
                    {
                    Request = send
                    }
                    }
                    }
                },

                 new InvokeMethod
                                {
                                TargetType = typeof(ApplicationInterface),
                                MethodName = "UpdateLead",
                                Parameters =
                                {
                                new InArgument<Lead>(env => lead.Get(env))
                                }
                                },

                new AddComment
                {
                Comment = new InArgument<string>(env => "Lead is being assigned")
                },
                new WriteLine
                {
                Text = new InArgument<string>
                (env => "Lead assigned [" + Rating.Get(env).ToString()
                + "] to " + lead.Get(env).AssignedTo),
                TextWriter = new InArgument<TextWriter>
                (env => Writer.Get(env))
                }
                }
            };

        }