public ExecutionNode BuildNode() { if (!OptionSet) { throw new InvalidOperationException(); } ExecutionNode node; if (ActivityType != null) { throw new NotImplementedException("Projection in the graph of a reference type not supported"); } else if (ProxyActivity != null) { node = new ComponentNode(ProxyActivity); } else if (ActivityBranchBuilder != null) { node = ActivityBranchBuilder.BuildNode(); } else { node = new BuilderNode(Name, Decision != null, false, false, Metadata); } return(node); }
public void Branch(Action <IActivityBranchBuilder> branch) { AssertOptionNotSet(); var builder = new ActivityBranchBuilder(); branch(builder); ActivityBranchBuilder = builder; OptionSet = true; }
public IActivity Build(IBuildContext context) { if (!OptionSet) { throw new ActivityBuildException("No valid option was set for the build of an activity"); } try { IActivity activity; if (ActivityType != null) { if (context == null) { throw new ActivityResolveException(ActivityType, "The builder references a type that cannot be resolved outside a context"); } activity = (IActivity)context.Resolve(ActivityType); if (activity == null) { throw new ActivityResolveException(ActivityType, $"The type '{ActivityType}' is not a valid instance of {typeof(IActivity)}"); } } else if (ProxyActivity != null) { activity = ProxyActivity; } else if (ActivityBranchBuilder != null) { activity = ActivityBranchBuilder.Build(context); } else { activity = new Activity(Name, Decision, Execution); if (Metadata != null) { ((Activity)activity).SetMetadata(Metadata); } } if (Factory) { if (StateFactory == null && StateFactoryType == null) { throw new InvalidOperationException("Invalid setup for a state factory"); } var factory = StateFactory; if (factory == null && StateFactoryType != null) { factory = context.Resolve(StateFactoryType) as IStateFactory; } activity = new ActivityFactoryActivity(Name, Decision, activity, factory); } return(activity); } catch (ActivityBuildException) { throw; } catch (Exception ex) { throw new ActivityBuildException("Could not build the activity because of an error: see inner exception for details.", ex); } }