int FindInComposite( IEnumerator<string> path, out ActionCompositeConfiguration parent ) { parent = null; ActionCompositeConfiguration composite = _action as ActionCompositeConfiguration; if( composite == null ) return -1; return FindInComposite( composite, path, ref parent ); }
internal ActionCompositeConfigurationResolved( IActivityMonitor monitor, int index, IReadOnlyList<string> path, ActionCompositeConfiguration a, bool flattenUselessComposite ) : base( index, path, a ) { _isParallel = a.IsParallel; _children = new List<ActionConfigurationResolved>(); AppendChildren( monitor, a, path.Append( a.Name ).ToArray(), flattenUselessComposite ); }
int FindInComposite(IEnumerator <string> path, out ActionCompositeConfiguration parent) { parent = null; ActionCompositeConfiguration composite = _action as ActionCompositeConfiguration; if (composite == null) { return(-1); } return(FindInComposite(composite, path, ref parent)); }
void AppendChildren( IActivityMonitor monitor, ActionCompositeConfiguration a, IReadOnlyList<string> childPath, bool flattenUselessComposite ) { foreach( var child in a.Children ) { ActionCompositeConfiguration composite = child as ActionCompositeConfiguration; if( flattenUselessComposite && composite != null && composite.IsParallel == a.IsParallel ) { AppendChildren( monitor, composite, childPath = childPath.Append( composite.Name ).ToArray(), true ); } else _children.Add( ActionConfigurationResolved.Create( monitor, child, flattenUselessComposite, _children.Count, childPath ) ); } }
/// <summary> /// Internal factory for ActionConfigurationResolved avoids externally visible virtual protected method on ActionConfiguration. /// This prevents any other composite implementations than our. /// </summary> internal static ActionConfigurationResolved Create(IActivityMonitor monitor, ActionConfiguration a, bool flattenUselessComposite, int index = 0, IReadOnlyList <string> path = null) { if (path == null) { path = Util.Array.Empty <string>(); } Impl.ActionCompositeConfiguration c = a as Impl.ActionCompositeConfiguration; if (c != null) { return(new Impl.ActionCompositeConfigurationResolved(monitor, index, path, c, flattenUselessComposite)); } return(new ActionConfigurationResolved(index, path, a)); }
void AppendChildren(IActivityMonitor monitor, ActionCompositeConfiguration a, IReadOnlyList <string> childPath, bool flattenUselessComposite) { foreach (var child in a.Children) { ActionCompositeConfiguration composite = child as ActionCompositeConfiguration; if (flattenUselessComposite && composite != null && composite.IsParallel == a.IsParallel) { AppendChildren(monitor, composite, childPath = childPath.Append(composite.Name).ToArray(), true); } else { _children.Add(ActionConfigurationResolved.Create(monitor, child, flattenUselessComposite, _children.Count, childPath)); } } }
ActionCompositeConfiguration( ActionCompositeConfiguration toCopy, bool copyCompositeOnly ) : base( toCopy.Name ) { _isParallel = toCopy.IsParallel; if( copyCompositeOnly ) { _children = new List<ActionConfiguration>( toCopy.Children ); for( int i = 0; i < _children.Count; ++i ) { ActionCompositeConfiguration composite = _children[i] as ActionCompositeConfiguration; if( composite != null ) _children[i] = new ActionCompositeConfiguration( composite, true ); } } else { _children = new List<ActionConfiguration>( toCopy.Children.Select( c => c.IsCloneable ? c.Clone() : c ) ); } }
static int FindInComposite( ActionCompositeConfiguration start, IEnumerator<string> path, ref ActionCompositeConfiguration parent ) { string current = path.Current; for( int i = 0; i < start.Children.Count; ++i ) { if( start.Children[i].Name == current ) { if( !path.MoveNext() ) { parent = start; return i; } ActionCompositeConfiguration newStart = start.Children[i] as ActionCompositeConfiguration; if( newStart == null ) return -1; return FindInComposite( newStart, path, ref parent ); } } return -1; }
internal bool CheckAndOptimize(IActivityMonitor monitor) { bool formalError = false; HashSet <string> formalNames = new HashSet <string>(); formalNames.Add(Name); for (int i = 0; i < _children.Count; ++i) { ActionConfiguration a = _children[i]; if (!formalNames.Add(a.Name)) { if (a.Name == Name) { monitor.SendLine(LogLevel.Warn, string.Format("Action n°{2} '{0}' has the name of its parent {1}.", a.Name, TypeDisplayName, i + 1), null); } else { if (_isParallel) { monitor.SendLine(LogLevel.Warn, string.Format("Duplicate name '{0}' found in {1} (action n°{2}).", a.Name, _parDisplayName, i + 1), null); } else { monitor.SendLine(LogLevel.Error, string.Format("Action n°{2}'s name '{0}' alreay appears in {1}. In a {1}, names must be unique.", a.Name, _seqDisplayName), null); formalError = true; } } } ActionCompositeConfiguration composite = a as ActionCompositeConfiguration; if (composite != null) { formalError |= composite.CheckAndOptimize(monitor); if (composite.IsParallel == _isParallel) { _children.RemoveAt(i); _children.InsertRange(i, composite.Children); i += composite.Children.Count; } } } return(!formalError); }
ActionCompositeConfiguration(ActionCompositeConfiguration toCopy, bool copyCompositeOnly) : base(toCopy.Name) { _isParallel = toCopy.IsParallel; if (copyCompositeOnly) { _children = new List <ActionConfiguration>(toCopy.Children); for (int i = 0; i < _children.Count; ++i) { ActionCompositeConfiguration composite = _children[i] as ActionCompositeConfiguration; if (composite != null) { _children[i] = new ActionCompositeConfiguration(composite, true); } } } else { _children = new List <ActionConfiguration>(toCopy.Children.Select(c => c.IsCloneable ? c.Clone() : c)); } }
static int FindInComposite(ActionCompositeConfiguration start, IEnumerator <string> path, ref ActionCompositeConfiguration parent) { string current = path.Current; for (int i = 0; i < start.Children.Count; ++i) { if (start.Children[i].Name == current) { if (!path.MoveNext()) { parent = start; return(i); } ActionCompositeConfiguration newStart = start.Children[i] as ActionCompositeConfiguration; if (newStart == null) { return(-1); } return(FindInComposite(newStart, path, ref parent)); } } return(-1); }
internal ActionCompositeConfigurationResolved(IActivityMonitor monitor, int index, IReadOnlyList <string> path, ActionCompositeConfiguration a, bool flattenUselessComposite) : base(index, path, a) { _isParallel = a.IsParallel; _children = new List <ActionConfigurationResolved>(); AppendChildren(monitor, a, path.Append(a.Name).ToArray(), flattenUselessComposite); }