void DoSequenceOrParallelOrAdd( IActivityMonitor monitor, Action<ActionConfiguration> collector, XElement xml ) { if( xml.Name == "Parallel" || xml.Name == "Sequence" ) { Action<ActionConfiguration> elementCollector; if( xml.Name == "Parallel" ) { var p = new ActionParallelConfiguration( xml.AttributeRequired( "Name" ).Value ); elementCollector = a => p.AddAction( a ); collector( p ); } else { var s = new ActionSequenceConfiguration( xml.AttributeRequired( "Name" ).Value ); elementCollector = a => s.AddAction( a ); collector( s ); } foreach( var action in xml.Elements() ) DoSequenceOrParallelOrAdd( monitor, collector, action ); } else { if( xml.Name != "Add" ) throw new XmlException( String.Format( "Unknown element '{0}': only <Add>, <Parallel> or <Sequence>.", xml.Name ) ); string type = xml.AttributeRequired( "Type" ).Value; Type t = FindConfigurationType( type ); HandlerConfiguration hC = (HandlerConfiguration)Activator.CreateInstance( t, xml.AttributeRequired( "Name" ).Value ); hC.DoInitialize( monitor, xml ); collector( hC ); } }
/// <summary> /// Must me implemented to create a parallel action. /// </summary> /// <param name="monitor">Monitor to use if needed.</param> /// <param name="configLock"> /// Configuration lock. It must not be solicited during the creation of the parallel: if the parallel delays /// its work, it can keep a reference to it and use it as needed. /// </param> /// <param name="c">Configuration of the parallel action.</param> /// <param name="children">Array of already created children action.</param> /// <returns>A parallel action.</returns> protected abstract TAction DoCreateParallel(IActivityMonitor monitor, IRouteConfigurationLock configLock, ActionParallelConfiguration c, TAction[] children);
public ParallelHandler( ActionParallelConfiguration c, HandlerBase[] children ) : base( c ) { _children = children; }