public IList<OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { Verify.NotNull(operation, nameof(operation)); var decoratorAttributes = operation.GetType().GetCustomAttributes(typeof(OperationBehaviorAttribute), inherit: false); return decoratorAttributes.OfType<OperationBehaviorAttribute>().Select(b => b.CreateBehavior(configuration)).ToList(); }
public void ShouldDeserializeComplexWorkflowConfiguration3() { var workFlow = new Workflow(); workFlow.Configuration = "{\"default_filter\":{\"queue\":\"WQccc\"},\"filters\":[{\"expression\":\"1==1\",\"friendly_name\":\"Prioritizing Filter\",\"targets\":[{\"priority\":\"1\",\"queue\":\"WQccc\",\"timeout\":\"300\"}]}]}"; var workFlowConfiguration = new WorkflowConfiguration(); var filter = new Filter { FriendlyName = "Prioritizing Filter", Expression = "1==1", Targets = new List<Target>() { new Target { Queue="WQccc", Priority="1", Timeout="300" } } }; workFlowConfiguration.Filters.Add(filter); workFlowConfiguration.DefaultFilter = new Target() { Queue = "WQccc" }; var config = workFlow.WorkflowConfiguration; Assert.AreEqual(workFlowConfiguration.ToString(), config.ToString()); }
public void The_simple_resolver_cannot_resolve_operations_with_unregistered_sub_dependencies(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<ComplexDependency, ComplexDependency>(); Assert.Throws<InvalidOperationException>(() => sut.Resolve<OperationWithComplexDependencies>(configuration)); }
public void ShouldSerializeComplexWorkflowConfiguration1() { var workFlowConfiguration = new WorkflowConfiguration(); var filter = new Filter { FriendlyName = "Prioritizing Filter", Expression = "1==1", Targets = new List <Target>() { new Target { Queue = "WQccc", Priority = "1", Timeout = "300" } } }; workFlowConfiguration.Filters.Add(filter); workFlowConfiguration.DefaultFilter = new Target() { Queue = "WQccc" }; var result = workFlowConfiguration.ToString(); Assert.AreEqual("{\"default_filter\":{\"queue\":\"WQccc\"},\"filters\":[{\"expression\":\"1==1\",\"friendly_name\":\"Prioritizing Filter\",\"targets\":[{\"priority\":\"1\",\"queue\":\"WQccc\",\"timeout\":\"300\"}]}]}", result); }
public void Behaviors_are_applied_sorted_by_precedence_with_the_higher_precedence_behaviors_on_the_outside_across_factories(WorkflowConfiguration configuration, FakeOperation operation) { var factory1 = new FakeOperationBehaviorFactory(); factory1.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.StateRecovery }); factory1.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.Logging }); factory1.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.WorkCompensation }); var factory2 = new FakeOperationBehaviorFactory(); factory2.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.PreRecovery }); factory2.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.Containment }); configuration.WithBehaviorFactory(factory1).WithBehaviorFactory(factory2); var result = OperationResolverHelper.ApplyBehaviors(operation, configuration); Assert.IsType<FakeOperationBehavior>(result); var behavior1 = (OperationBehavior)result; Assert.Equal(BehaviorPrecedence.Logging, behavior1.Precedence); Assert.IsType<FakeOperationBehavior>(behavior1.InnerOperation); var behavior2 = (OperationBehavior)behavior1.InnerOperation; Assert.Equal(BehaviorPrecedence.Containment, behavior2.Precedence); Assert.IsType<FakeOperationBehavior>(behavior2.InnerOperation); var behavior3 = (OperationBehavior)behavior2.InnerOperation; Assert.Equal(BehaviorPrecedence.WorkCompensation, behavior3.Precedence); Assert.IsType<FakeOperationBehavior>(behavior3.InnerOperation); var behavior4 = (OperationBehavior)behavior3.InnerOperation; Assert.Equal(BehaviorPrecedence.StateRecovery, behavior4.Precedence); Assert.IsType<FakeOperationBehavior>(behavior4.InnerOperation); var behavior5 = (OperationBehavior)behavior4.InnerOperation; Assert.Equal(BehaviorPrecedence.PreRecovery, behavior5.Precedence); Assert.IsType<FakeOperation>(behavior5.InnerOperation); }
public IList<OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { if (!(operation is IConditionalOperation)) return new OperationBehavior[0]; return new OperationBehavior[] { new ConditionalExecutionBehavior() }; }
public static EdgeDescriptor <TContext> OnFail <TContext>(this WorkflowConfiguration <TContext> config) { var edgeDescriptor = new EdgeDescriptor <TContext>(config, "Fail"); edgeDescriptor.DeterminedAs((context, result) => result == ActivityResult.Failed); return(edgeDescriptor); }
private async Task <bool> TryGetDomainEntity(WorkflowConfiguration workflowConfiguration, IWorkflowInstance workflowInstance, CancellationToken cancellationToken) { // if no domain entity has been provided ==> try loading it through domain store // 1. so it will be available for all/any scripted code as an "entity" parameter // 2. at the moment we are no saving back entity through the store at the end of processing // 2.1. we intentionally obtain domain entity for read-only purpose // 2.2. all the mutation to domain entity must happen on a remote activity processing side if (null == workflowInstance.Entity && workflowConfiguration.HasScriptWithEntityUse() && !string.IsNullOrEmpty(workflowInstance.EntityType) && !string.IsNullOrEmpty(workflowInstance.EntityId)) { workflowInstance.Entity = await WorkflowEngineBuilder.WorkflowDomainStore .GetDomainEntity(WorkflowEngineBuilder.WorkflowMessageTransportFactoryProvider, workflowConfiguration, workflowInstance, cancellationToken) .ConfigureAwait(false); if (null == workflowInstance.Entity) { throw new WorkflowException(string.Format(CultureInfo.InvariantCulture, "Cannot load domain entity [EntityType={0}], [EntityID={1}] for workflow [ID={2:D}], [State={3}] ", workflowInstance.EntityType, workflowInstance.EntityId, workflowInstance.Id, workflowInstance.CurrentStateCode)); } return(true); } return(false); }
private IWorkflowInstanceLock CreateWorkflowInstanceLock(WorkflowConfiguration workflowConfiguration) { var created = DateTime.UtcNow; // TODO: move locking configuration to workflow configuration (currently 10 seconds is the default lock duration) return(new WorkflowInstanceLock(Id, WorkflowInstanceLockMode.Locked, created, created.AddSeconds(10D))); }
/// <summary> /// create process-scope with configuration /// </summary> /// <param name="companyScopeName"></param> /// <param name="processScopeName"></param> /// <returns></returns> private string createProcessScope(string companyScopeName, string processScopeName) { IDictionary <string, string> configValues = new Dictionary <string, string> { { "cfgManagementScopeAddress", cfgWFMBaseAddress + companyScopeName + "/" + managementScopeName + "/" }, { "cfgProcessScopeAddress", cfgWFMBaseAddress + companyScopeName + "/" + processScopeName + "/" }, { "cfgWFMBaseAddress", cfgWFMBaseAddress }, { "cfgWFMUsername", cfgWFMUsername }, { "cfgWFMPassword", cfgWFMPassword }, { "cfgSQLConnectionString", cfgSQLConnectionString } }; WorkflowConfiguration Configuration = new WorkflowConfiguration(); configValues.ToList().ForEach(c => Configuration.AppSettings.Add(c)); WorkflowManagementClient client = new WorkflowManagementClient(new Uri(cfgWFMBaseAddress + companyScopeName + "/"), credentials); client = client.CurrentScope.PublishChildScope(processScopeName, new ScopeDescription() { UserComments = processScopeName, DefaultWorkflowConfiguration = Configuration }); string scope = client.ScopeUri.ToString(); return(scope); }
public ServiceProvider BuildDefault(WorkflowConfiguration workflowConfiguration = null) { if (workflowConfiguration == null) { workflowConfiguration = new WorkflowConfiguration(); } this.AddTestDbContext(); this.Services.Configure <WorkflowConfiguration>(opt => { opt.Types = workflowConfiguration.Types; }); this.Services.Configure <ProcessorConfiguration>(opt => { opt.Enabled = false; opt.Interval = 5000; }); this.Services.AddDomainServices(); this.Services.AddInfrastructureServices <TestDbContext>(); this.Services.AddJobQueueServices <TestDbContext>(); this.Services.AddAspNetCoreEngineServices(); return(this.Build()); }
public Task <WorkflowRuntimeConfiguration> GetWorkflowRuntimeConfiguration(WorkflowConfiguration workflowConfiguration, CancellationToken cancellationToken) { var workflowRuntimeConfigurationSection = _configurationProvider.GetSection <IWorkflowRuntimeConfigurationSection>(); var workflowRuntimeConfiguration = new WorkflowRuntimeConfiguration(workflowConfiguration.Id, workflowConfiguration.Class, workflowConfiguration.Code) { EndpointConfiguration = new EndpointConfiguration("workflow", EndpointConfigurationType.RabbitMq, new Uri($"{workflowRuntimeConfigurationSection.WorkflowHost}/{workflowRuntimeConfigurationSection.WorkflowRequestEndpoint}"), ConfigurationAuthentication.None), EndpointConfigurations = new List <KeyValuePair <string, IEndpointConfiguration> >() }; foreach (var workflowRuntimeConfigurationEndpoint in workflowRuntimeConfigurationSection.WorkflowRuntimeEndpoints) { IConfigurationAuthentication configurationAuthentication = ConfigurationAuthentication.None; if (null != workflowRuntimeConfigurationEndpoint.Authentication) { configurationAuthentication = new ConfigurationAuthentication( workflowRuntimeConfigurationEndpoint.Authentication.Type, workflowRuntimeConfigurationEndpoint.Authentication.Parameters); } workflowRuntimeConfiguration.EndpointConfigurations.Add(new KeyValuePair <string, IEndpointConfiguration>(workflowRuntimeConfigurationEndpoint.Code, new EndpointConfiguration(workflowRuntimeConfigurationEndpoint.Code, workflowRuntimeConfigurationEndpoint.Type, new Uri(workflowRuntimeConfigurationEndpoint.Address), configurationAuthentication, workflowRuntimeConfigurationEndpoint.Parameters))); } ; return(Task.FromResult(workflowRuntimeConfiguration)); }
public static WorkflowConfiguration <TContext> OnFail <TContext>(this WorkflowConfiguration <TContext> config, string name) { var node = config.Nodes.Peek(); node.AddConstraint(name, (context, state) => state == ActivityResult.Failed, "Fail"); return(config); }
public async Task <IEntity> GetDomainEntity(IWorkflowMessageTransportFactoryProvider workflowMessageTransportFactoryProvider, WorkflowConfiguration workflowConfiguration, IWorkflowInstance workflowInstance, CancellationToken cancellationToken = default) { var endpointCode = $"EntityType::{workflowInstance.EntityType}"; var endpointConfiguration = workflowConfiguration.FindEndpointConfiguration(endpointCode); var eventRequestWorkflowMessage = new EntityRequestWorkflowMessage(workflowInstance.EntityType, workflowInstance.EntityId); Log.Verbose("Sending entity request message [{endpointCode}::{entityId}] to {endpoint} [{workflowInstanceId}]", endpointCode, workflowInstance.EntityId, endpointConfiguration.Address, workflowInstance.Id); var messageTransport = workflowMessageTransportFactoryProvider.CreateMessageTransportFactory(endpointConfiguration.Type).CreateMessageTransport(endpointConfiguration.Address); var responseWorkflowMessage = await messageTransport.Request <IEntityRequestWorkflowMessage, IEntityResponseWorkflowMessage>( endpointConfiguration, eventRequestWorkflowMessage, cancellationToken).ConfigureAwait(false); Log.Verbose("Received entity response message [{endpointCode}::{entityId}::{status}] from {endpoint} [{workflowInstanceId}]", endpointCode, workflowInstance.EntityId, responseWorkflowMessage.ExecutionStatus, endpointConfiguration.Address, workflowInstance.Id); if (responseWorkflowMessage.ExecutionStatus == EntityRequestExecutionStatus.Completed) { return(new JsonEntity(responseWorkflowMessage.EntityJsonPayload)); } if (responseWorkflowMessage.ExecutionStatus == EntityRequestExecutionStatus.NotFound) { Log.Error("Can not find {entityType} {entityId}... stopping {workflowInstanceId} processing", workflowInstance.EntityType, workflowInstance.EntityId, workflowInstance.Id); throw new WorkflowException($"No entity has been found {workflowInstance.EntityType}::{workflowInstance.EntityId}"); } throw new WorkflowException($"An error has occurred during obtaining {workflowInstance.EntityType}::{workflowInstance.EntityId}"); }
/// <summary> /// Add Workflow /// </summary> /// <param name="workflowCode">WorkflowCode</param> /// <param name="serviceUrl">ServiceUrl</param> /// <param name="bindingConfiguration">BindingConfiguration</param> /// <param name="serviceEndpoint">ServiceEndpoint</param> public void AddWorkflow(string workflowCode, string serviceUrl, string bindingConfiguration, string serviceEndpoint) { using (var uofw = new FlowTasksUnitOfWork()) { var wfc = uofw.WorkflowCodes.FirstOrDefault(wc => wc.Code == workflowCode); if (wfc == null) { wfc = new WorkflowCode { Code = workflowCode, Description = "Added by Skecth" }; uofw.WorkflowCodes.Insert(wfc); } else { var wfcfg = uofw.WorkflowConfigurations.FirstOrDefault(w => w.WorkflowCode.Code == wfc.Code && w.ExpiryDate == null, w => w.WorkflowCode); if (wfcfg != null) { wfcfg.ExpiryDate = DateTime.Now; } } var newcfg = new WorkflowConfiguration { WorkflowCode = wfc, ServiceUrl = serviceUrl, BindingConfiguration = bindingConfiguration, ServiceEndpoint = serviceEndpoint, EffectiveDate = DateTime.Now }; uofw.WorkflowConfigurations.Insert(newcfg); uofw.Commit(); } }
public void Behaviors_are_created_with_the_workflow_configuration(WorkflowConfiguration configuration, BehaviorOperation operation) { var sut = new OperationBehaviorAttributeFactory(); var result = (FakeOperationBehavior)sut.CreateBehaviors(operation, configuration)[0]; Assert.Equal(configuration, result.Configuration); }
public void Created_operations_are_wrapped_in_ContinueOnFailure_behavior(IOperationResolver resolver) { var sut = new WorkflowConfiguration<TestOperation>() { Resolver = resolver }; var result = sut.CreateOperation(); Assert.IsType<ContinueOnFailureBehavior>(result); }
/// <summary> /// Initialize the behavior and the decorated operation. /// </summary> /// <param name="configuration">The configruation for the current /// workflow</param> public void Initialize(WorkflowConfiguration configuration) { Verify.NotNull(configuration, nameof(configuration)); _logger = configuration.Logger; InnerOperation.Initialize(configuration); }
public IList <OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { Verify.NotNull(operation, nameof(operation)); var decoratorAttributes = operation.GetType().GetCustomAttributes(typeof(OperationBehaviorAttribute), inherit: false); return(decoratorAttributes.OfType <OperationBehaviorAttribute>().Select(b => b.CreateBehavior(configuration)).ToList()); }
public void No_behaviors_are_created_when_there_are_no_behavior_attributes(WorkflowConfiguration configuration, IOperation operation) { var sut = new OperationBehaviorAttributeFactory(); var result = sut.CreateBehaviors(operation, configuration); Assert.Equal(0, result.Count); }
public void Operations_having_more_than_one_constructor_cannot_be_resolved(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency <SimpleDependency, SimpleDependency>(); Assert.Throws <InvalidOperationException>(() => sut.Resolve <OperationWithTwoConstructors>(configuration)); }
public void You_can_create_an_operation_from_the_configuration(IOperationResolver resolver) { var sut = new WorkflowConfiguration<TestOperation>() { Resolver = resolver }; var result = sut.CreateOperation(); Assert.NotNull(result); }
public void The_logging_behavior_is_not_created_when_the_configuration_has_not_defined_a_logger_to_use(IOperation operation, WorkflowConfiguration configuration) { var sut = new OperationLoggingBehaviorFactory(); var result = sut.CreateBehaviors(operation, configuration); Assert.Equal(0, result.Count); }
public void The_simple_resolver_can_resolve_operations_without_any_dependencies(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); var result = sut.Resolve<SimpleTestOperation>(configuration); Assert.NotNull(result); }
public void TestSaveExtended() { var r = WorkflowConfigurationRepository.Instance; var a = new WorkflowConfiguration { Name = "This is custom" }; r.Create(a); }
public void The_simple_resolver_can_resolve_operations_with_registered_dependencies(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); var result = sut.Resolve<OperationWithDependencies>(configuration); Assert.NotNull(result); }
public IList <OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { if (!(operation is IConditionalOperation)) { return(new OperationBehavior[0]); } return(new OperationBehavior[] { new ConditionalExecutionBehavior() }); }
public void Behaviors_are_created_for_the_available_behavior_attributes(WorkflowConfiguration configuration, BehaviorOperation operation) { var sut = new OperationBehaviorAttributeFactory(); var result = sut.CreateBehaviors(operation, configuration); Assert.Equal(1, result.Count); Assert.IsType <FakeOperationBehavior>(result[0]); }
public void Behaviors_are_created_for_the_available_behavior_attributes(WorkflowConfiguration configuration, BehaviorOperation operation) { var sut = new OperationBehaviorAttributeFactory(); var result = sut.CreateBehaviors(operation, configuration); Assert.Equal(1, result.Count); Assert.IsType<FakeOperationBehavior>(result[0]); }
public void ShouldSerializeWorkflowDefaultFilterConfiguration() { var workFlowConfiguration = new WorkflowConfiguration(); workFlowConfiguration.DefaultFilter = new Target() { Queue = "WQccc" }; var result = workFlowConfiguration.ToString(); Assert.AreEqual("{\"default_filter\":{\"queue\":\"WQccc\"},\"filters\":[]}", result); }
public WorkflowContext(IRuntimeWorkflowEngine workflowEngine, WorkflowEngineBuilder workflowEngineBuilder, IWorkflowInstance workflowInstance, WorkflowConfiguration workflowConfiguration, JsonState workflowExecutionState) { _workflowEngineBuilder = workflowEngineBuilder; WorkflowEngine = workflowEngine; WorkflowInstance = workflowInstance; WorkflowConfiguration = workflowConfiguration; WorkflowExecutionState = workflowExecutionState ?? new JsonState(); }
public IList<OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { Verify.NotNull(configuration, nameof(configuration)); if (configuration.RetryExceptionTypes.Count == 0) return new OperationBehavior[0]; return new OperationBehavior[] { new RetryBehavior(configuration.TimesToRetry, configuration.RetryDelay, configuration.RetryExceptionTypes.ToArray()) }; }
public void Dependencies_are_resolved_as_new_instances_every_time(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); var result1 = sut.Resolve<OperationWithDependencies>(configuration) as OperationWithDependencies; var result2 = sut.Resolve<OperationWithDependencies>(configuration) as OperationWithDependencies; Assert.NotSame(result1.Dependency, result2.Dependency); }
public void Resolving_the_same_operation_twice_returns_two_different_instances(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); var result1 = sut.Resolve<SimpleTestOperation>(configuration); var result2 = sut.Resolve<SimpleTestOperation>(configuration); Assert.NotSame(result1, result2); }
public void You_can_register_the_same_dependency_more_than_once(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); var result = sut.Resolve<OperationWithDependencies>(configuration); Assert.NotNull(result); }
public void Dependencies_can_be_registered_as_implementations(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency <IDependency, SimpleDependency>(); var result = sut.Resolve <OperationWithInterfaceDependency>(configuration); Assert.NotNull(result); }
public void TestSaveExtended() { var r = WorkflowConfigurationRepository.Instance; var a = new WorkflowConfiguration { Name = "This is custom" }; r.Create(a); WorkflowConfigurationRepository.Instance.DatabaseHelper.CloseConnection(); }
public void You_can_create_a_behavior_with_compensated_exception_types(WorkflowConfiguration configuration, SimpleOperationResolver resolver) { var sut = new CompensatingOperationAttribute(typeof(TestOperation), typeof(Exception)); configuration.WithResolver(resolver); var result = sut.CreateBehavior(configuration); Assert.NotNull(result); Assert.IsType<CompensatingOperationBehavior>(result); }
public void You_can_register_the_same_instance_dependency_more_than_once(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependencyInstance(new SimpleDependency()); sut.RegisterOperationDependencyInstance(new SimpleDependency()); var result = sut.Resolve <OperationWithDependencies>(configuration); Assert.NotNull(result); }
public void You_can_create_a_behavior_with_compensated_exception_types(WorkflowConfiguration configuration, SimpleOperationResolver resolver) { var sut = new CompensatingOperationAttribute(typeof(TestOperation), typeof(Exception)); configuration.WithResolver(resolver); var result = sut.CreateBehavior(configuration); Assert.NotNull(result); Assert.IsType <CompensatingOperationBehavior>(result); }
public void TestInstantiate() { IWorkflowConfiguration workflowConfiguration = new WorkflowConfiguration { Name = "Testing 123" }; Assert.IsFalse(workflowConfiguration.IsConfigurationActive); Assert.IsNotNull(workflowConfiguration.Name); Assert.IsNotNull(((IWorkflowInstantiator)workflowConfiguration).CreateInstance()); }
/// <summary> /// Creates all the applicable beahviors and applies them to /// the operation in the correct order. /// </summary> /// <param name="operation">The original workflow operation with no /// behaviors attached</param> /// <param name="configuration">The current workflow configuration</param> /// <returns>The input operation decorated with any behaviors created</returns> public static IOperation ApplyBehaviors(IOperation operation, WorkflowConfiguration configuration) { if (configuration.BehaviorFactories.Count == 0) return operation; var behaviors = configuration.BehaviorFactories.SelectMany(f => f.CreateBehaviors(operation, configuration)); var sortedBehaviors = behaviors.OrderBy(b => b.Precedence).ToList(); foreach (var behavior in sortedBehaviors) operation = behavior.AttachTo(operation); return operation; }
public void Dependencies_are_resolved_as_new_instances_every_time(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency <SimpleDependency, SimpleDependency>(); var result1 = sut.Resolve <OperationWithDependencies>(configuration) as OperationWithDependencies; var result2 = sut.Resolve <OperationWithDependencies>(configuration) as OperationWithDependencies; Assert.NotSame(result1.Dependency, result2.Dependency); }
public void Created_operations_are_wrapped_in_ContinueOnFailure_behavior(IOperationResolver resolver) { var sut = new WorkflowConfiguration <TestOperation>() { Resolver = resolver }; var result = sut.CreateOperation(); Assert.IsType <ContinueOnFailureBehavior>(result); }
public IList <OperationBehavior> CreateBehaviors(IOperation operation, WorkflowConfiguration configuration) { Verify.NotNull(configuration, nameof(configuration)); if (configuration.RetryExceptionTypes.Count == 0) { return(new OperationBehavior[0]); } return(new OperationBehavior[] { new RetryBehavior(configuration.TimesToRetry, configuration.RetryDelay, configuration.RetryExceptionTypes.ToArray()) }); }
public void You_can_create_an_operation_from_the_configuration(IOperationResolver resolver) { var sut = new WorkflowConfiguration <TestOperation>() { Resolver = resolver }; var result = sut.CreateOperation(); Assert.NotNull(result); }
public void The_last_registered_dependency_of_a_given_type_wins(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency <SimpleDependency, SimpleDependency>(); sut.RegisterOperationDependency <IDependency, SimpleDependency>(); sut.RegisterOperationDependency <IDependency, ComplexDependency>(); var result = sut.Resolve <OperationWithInterfaceDependency>(configuration) as OperationWithInterfaceDependency; Assert.IsType <ComplexDependency>(result.Dependency); }
public void ShouldDeserializeWorkflowDefaultFilterConfiguration() { var workFlow = new Workflow(); workFlow.Configuration = "{\"default_filter\":{\"queue\":\"WQccc\"},\"filters\":[]}"; var workFlowConfiguration = new WorkflowConfiguration(); workFlowConfiguration.DefaultFilter = new Target() { Queue = "WQccc" }; var config = workFlow.WorkflowConfiguration; Assert.AreEqual(workFlowConfiguration.ToString(), config.ToString()); }
/// <summary> /// Create the desired behavior instance. This behavior will always be /// applied for operations having defiend the attribute. /// </summary> /// <param name="configuration">The configuration of the executing workflow</param> /// <returns>The behavior instance, uninitialized</returns> public abstract OperationBehavior CreateBehavior(WorkflowConfiguration configuration);
public override OperationBehavior CreateBehavior(WorkflowConfiguration configuration) => new FakeOperationBehavior(configuration);
public void Operations_having_more_than_one_constructor_cannot_be_resolved(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); sut.RegisterOperationDependency<SimpleDependency, SimpleDependency>(); Assert.Throws<InvalidOperationException>(() => sut.Resolve<OperationWithTwoConstructors>(configuration)); }
/// <summary> /// Create a new atomic behavior instance. /// </summary> /// <param name="configuration">The configuration of the executing workflow</param> /// <returns>The behavior</returns> public override OperationBehavior CreateBehavior(WorkflowConfiguration configuration) { return new AtomicBehavior(); }
/// <summary> /// Create the retry behavior. /// </summary> /// <param name="configuration">The configuration of the executing workflow</param> /// <returns>The created beahvior</returns> public override OperationBehavior CreateBehavior(WorkflowConfiguration configuration) { return new RetryBehavior(_timesToRetry, TimeSpan.FromMilliseconds(_retryDelayInMilliSeconds), _retryExeptionTypes); }
/// <summary> /// Creates a new OperationBehavior instance. /// </summary> /// <param name="configuration">The configuration of the executing workflow</param> public override OperationBehavior CreateBehavior(WorkflowConfiguration configuration) { return new CompensatingOperationBehavior(CreateCompensatingOperation(configuration), _compensatedExceptionTypes); }
private Operation CreateCompensatingOperation(WorkflowConfiguration configuration) { var createMethod = typeof (Operation).GetMethod("Create", BindingFlags.Public | BindingFlags.Static); var methodWithTypeArgument = createMethod.MakeGenericMethod(_operationType); return (Operation)methodWithTypeArgument.Invoke(null, new object[] { configuration }); }
public void Resolving_operations_creates_and_applies_behaviors_to_the_created_operations(WorkflowConfiguration configuration) { var sut = new SimpleOperationResolver(); var factory = new FakeOperationBehaviorFactory(); factory.OperationBehaviors.Add(new FakeOperationBehavior { SetPrecedence = BehaviorPrecedence.StateRecovery }); var workflow = configuration.WithBehaviorFactory(factory); var result = sut.Resolve<SimpleTestOperation>(workflow); Assert.IsType<FakeOperationBehavior>(result); Assert.IsType<SimpleTestOperation>((result as OperationBehavior).InnerOperation); }