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)) } } }; }
public Send() { Func<Activity> func = null; this.isOneWay = true; this.TokenImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Identification; if (func == null) { func = delegate { if (this.internalSend == null) { return null; } if (this.requestFormatter == null) { return this.internalSend; } Variable<Message> variable = new Variable<Message> { Name = "RequestMessage" }; this.requestFormatter.Message = new OutArgument<Message>(variable); this.requestFormatter.Send = this; this.internalSend.Message = new InArgument<Message>(variable); return new NoPersistScope { Body = new Sequence { Variables = { variable }, Activities = { this.requestFormatter, this.internalSend } } }; }; } base.Implementation = func; }
// Builds a sequence of two CompensableActivites where the first is explicitly compensated static Activity CompensateACompensableActivity() { Variable<CompensationToken> token = new Variable<CompensationToken>(); return new Sequence { Variables = { token }, Activities = { new WriteLine { Text = "Start of workflow" }, new CompensableActivity() { Body = new WriteLine() { Text = "CompensableActivity1: Body" }, CompensationHandler = new WriteLine() { Text = "CompensableActivity1: Compensation Handler" }, ConfirmationHandler = new WriteLine() { Text = "CompensableActivity1: Confirmation Handler" }, Result = token, }, new CompensableActivity() { Body = new WriteLine() { Text = "CompensableActivity2: Body" }, CompensationHandler = new WriteLine() { Text = "CompensableActivity2: Compensation Handler" }, ConfirmationHandler = new WriteLine() { Text = "CompensableActivity2: Confirmation Handler" }, }, new Compensate() { Target = token, }, new WriteLine { Text = "End of workflow" } } }; }
public MySequence() : base() { this.children = new Collection<Activity>(); this.variables = new Collection<Variable>(); this.currentIndex = new Variable<int>(); }
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; }
public SendInstanceIdScope() : base() { this.children = new Collection<Activity>(); this.variables = new Collection<Variable>(); this.currentIndex = new Variable<int>(); }
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")}} }; }
private static void CreateService() { Variable<Expense> expense = new Variable<Expense> { Name = "expense" }; Variable<VendorRequest> vendor = new Variable<VendorRequest> { Name = "vendor" }; Variable<PurchaseOrder> po = new Variable<PurchaseOrder> { Name = "po" }; Variable<bool> reply = new Variable<bool> { Name = "reply" }; Variable<bool> replyPO = new Variable<bool> { Name = "reply" }; Variable<VendorResponse> replyVendor = new Variable<VendorResponse> { Name = "reply" }; Parallel workflow = new Parallel { Branches = { GetApproveExpense(expense, reply), GetApprovePO(po, replyPO), GetApprovedVendor(vendor, replyVendor), } }; service = new WorkflowService { Name = "FinanceService", Body = workflow, Endpoints = { new Endpoint { ServiceContractName="FinanceService", AddressUri = new Uri(Constants.EchoServiceAddress), Binding = new BasicHttpBinding(), } } }; }
// Creates a workflow that uses FindInTable activity without predicate to retrieve entities from a Sql Server Database static Activity CreateRetrieveWithoutPredicateWF() { Variable<IList<Role>> roles = new Variable<IList<Role>>(); DelegateInArgument<Role> roleIterationVariable = new DelegateInArgument<Role>(); return new Sequence() { Variables = { roles }, Activities = { new WriteLine { Text = "\r\nAll Roles (no predicates)\r\n==============" }, new FindInSqlTable<Role> { ConnectionString = cnn, Result = new OutArgument<IList<Role>>(roles) }, new ForEach<Role> { Values = new InArgument<IEnumerable<Role>>(roles), Body = new ActivityAction<Role>() { Argument = roleIterationVariable , Handler = new WriteLine { Text = new InArgument<string>(env => roleIterationVariable.Get(env).Name) } } } } }; }
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 }; }
private static Activity CreatePrintProcessActivity(Variable<Collection<Process>> processes) { var proc = new DelegateInArgument<Process>("process"); return new Sequence { Activities = { // Loop over processes and print them out. new ForEach<Process> { Values = processes, Body = new ActivityAction<Process> { Argument = proc, Handler = new WriteLine { Text = new InArgument<string>(ctx => proc.Get(ctx).ToString()), } } }, // Print out a new line. new WriteLine(), } }; }
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) } } } } } }; }
public Receive() : base() { base.Implementation = () => { // if CacheMetadata isn't called, bail early if (this.internalReceive == null) { return null; } // requestFormatter is null if we have an untyped message situation if (this.requestFormatter == null) { return this.internalReceive; } else { Variable<Message> request = new Variable<Message> { Name = "RequestMessage" }; Variable<NoPersistHandle> noPersistHandle = new Variable<NoPersistHandle> { Name = "ReceiveNoPersistHandle" }; this.internalReceive.Message = new OutArgument<Message>(request); this.requestFormatter.Message = new InOutArgument<Message>(request); this.internalReceive.NoPersistHandle = new InArgument<NoPersistHandle>(noPersistHandle); this.requestFormatter.NoPersistHandle = new InArgument<NoPersistHandle>(noPersistHandle); return new Sequence { Variables = { request, noPersistHandle }, Activities = { this.internalReceive, this.requestFormatter } }; } }; }
protected override void CacheMetadata(NativeActivityMetadata metadata) { RuntimeArgument valuesArgument = new RuntimeArgument("Values", typeof(IEnumerable), ArgumentDirection.In, true); metadata.Bind(this.Values, valuesArgument); metadata.SetArgumentsCollection(new Collection<RuntimeArgument> { valuesArgument }); // declare the CompletionCondition as a child if (this.CompletionCondition != null) { metadata.SetChildrenCollection(new Collection<Activity> { this.CompletionCondition }); } // declare the hasCompleted variable if (this.CompletionCondition != null) { if (this.hasCompleted == null) { this.hasCompleted = new Variable<bool>(); } metadata.AddImplementationVariable(this.hasCompleted); } metadata.AddDelegate(this.Body); }
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()), }, }; }
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; }
static void Main() { Variable<string> v = new Variable<string>(); Sequence s = new Sequence() { Variables = { v }, Activities = { new Assign<string>() { To = v, Value = "hello, world" }, new Interop() { ActivityType = typeof(WriteLine), ActivityProperties = { // Bind the Text property of the WriteLine to the Variable v { "Text", new InArgument<string>(v) } }, ActivityMetaProperties = { // Provide a value for the Name meta-property of the WriteLine { "Name", "WriteLine" } } } } }; WorkflowInvoker.Invoke(s); Console.WriteLine("Press [enter] to exit"); Console.ReadLine(); }
public void Upload_ValidPackage_PackageUrl() { // Arrange var keys = new Variable<StorageServiceKeys> { Default = null, Name = "Keys" }; var sequence = new Sequence { Variables = { keys }, Activities = { new GetStorageKeys { SubscriptionId = string.Empty, CertificateThumbprintId = string.Empty, ServiceName = string.Empty, StorageKeys = keys }, new UploadPackageToBlobStorage { SubscriptionId = string.Empty, CertificateThumbprintId = string.Empty, LocalPackagePath = string.Empty, StorageServiceName = string.Empty, StorageKeys = keys } } }; // Act IDictionary<string, object> results = WorkflowInvoker.Invoke(sequence, new Dictionary<string, object>()); }
// Creates a workflow that uses FindInSqlTable activity with a more complex predicate to retrieve entities from a Sql Server Database static Activity CreateRetrieveWithComplexPredicateWF() { Variable<IList<Employee>> employees = new Variable<IList<Employee>>(); DelegateInArgument<Employee> employeeIterationVariable = new DelegateInArgument<Employee>(); return new Sequence() { Variables = { employees }, Activities = { new WriteLine { Text = "\r\nEmployees by Role and Location (more complex predicate)\r\n============================================" }, new FindInSqlTable<Employee> { ConnectionString = cnn, Predicate = new LambdaValue<Func<Employee, bool>>(c => new Func<Employee, bool>(emp => emp.Role.Equals("PM") && emp.Location.Equals("Redmond"))), Result = new OutArgument<IList<Employee>>(employees) }, new ForEach<Employee> { Values = new InArgument<IEnumerable<Employee>>(employees), Body = new ActivityAction<Employee>() { Argument = employeeIterationVariable, Handler = new WriteLine { Text = new InArgument<string>(env => employeeIterationVariable.Get(env).ToString()) } } } } }; }
public Wizard() : base() { this.LastIndex = new Variable<int>() { Name = "LastIndexHint", Default = 0 }; this.ResumeParent = new Variable<Bookmark>() { Name = "ResumeParent", Default = null }; }
public Receive() { Func<Activity> func = null; if (func == null) { func = delegate { if (this.internalReceive == null) { return null; } if (this.requestFormatter == null) { return this.internalReceive; } Variable<Message> variable = new Variable<Message> { Name = "RequestMessage" }; Variable<NoPersistHandle> variable2 = new Variable<NoPersistHandle> { Name = "ReceiveNoPersistHandle" }; this.internalReceive.Message = new OutArgument<Message>(variable); this.requestFormatter.Message = new InOutArgument<Message>(variable); this.internalReceive.NoPersistHandle = new InArgument<NoPersistHandle>(variable2); this.requestFormatter.NoPersistHandle = new InArgument<NoPersistHandle>(variable2); return new Sequence { Variables = { variable, variable2 }, Activities = { this.internalReceive, this.requestFormatter } }; }; } base.Implementation = func; }
static Activity CreateWF() { Variable<string> message = new Variable<string>(); return new Sequence() { Variables = { message }, Activities = { new AppendString() { Name = ".NET WF", Result = message }, new PrependString() { Name = message, Result = message, }, new WriteLine() { Text = message } } }; }
public TestCaseActivity() { children = new Collection<Activity>(); _currentIndex = new Variable<int>(); ErrorLevel = OnError.Continue; OwnDataFirst = true; }
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)) } } } }; }
/// <summary> /// It's constructor. /// </summary> public StateMachine() { this.internalStates = new Collection<InternalState>(); this.internalStateFuncs = new Collection<ActivityFunc<string, StateMachineEventManager, string>>(); this.eventManager = new Variable<StateMachineEventManager> { Name = "EventManager", Default = new LambdaValue<StateMachineEventManager>(ctx => new StateMachineEventManager()) }; this.onStateComplete = new CompletionCallback<string>(OnStateComplete); }
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)) } } } } } } } }; }
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 }; }
public SubscribeFileChanges() { this.WatchSubfolders = false; this.bookmark = new Variable<Bookmark>() { Name = "SubscriptionBookmark" }; }
public NoPersistScope() { // add the validation to the list of validations for this activity this.Constraints.Add(VerifiyNoChildPersistActivity()); // create the variable to hold the NoPersistHandle this.noPersistHandle = new Variable<NoPersistHandle>(); }
public RangeEnumeration() { this.loopVariable = new Variable<int>("LoopVariable"); this.invokeBody = new InvokeAction<int> { Argument = this.loopVariable, }; }
public VariableValue(System.Activities.Variable variable) { this.Variable = variable; }
public VariableReference(System.Activities.Variable variable) { this.Variable = variable; }
public void AddVariable(Variable variable) { AddVariable(variable, null); }