CK.RouteConfig.Impl.ProtoDeclaredAction.Override C# (CSharp) Method

Override() private method

private Override ( IActivityMonitor monitor, IReadOnlyList fullPath, ActionConfiguration a ) : bool
monitor IActivityMonitor
fullPath IReadOnlyList
a ActionConfiguration
return bool
        internal bool Override( IActivityMonitor monitor, IReadOnlyList<string> fullPath, ActionConfiguration a )
        {
            var e = fullPath.GetEnumerator();
            if( !e.MoveNext() ) throw new ArgumentException( "Must not be empty.", "fullPath" );
            if( e.Current != _action.Name ) throw new ArgumentException( "Must start with the action name.", "fullPath" );
            if( !e.MoveNext() )
            {
                _action = a;
                _isCloned = false;
                monitor.SendLine( LogLevel.Info, string.Format( "Action '{0}' has been overridden.", a.Name ), null );
                return true;
            }
            ActionCompositeConfiguration parent;
            int idx = FindInComposite( e, out parent );
            if( idx >= 0 )
            {
                Debug.Assert( _action is ActionCompositeConfiguration, "It is a composite." );
                Debug.Assert( _action.IsCloneable, "A composite is cloneable." );
                if( !_isCloned )
                {
                    _action = ((ActionCompositeConfiguration)_action).CloneComposite( true );
                    monitor.SendLine( LogLevel.Info, string.Format( "Action '{0}' has been cloned in order to override an inner action.", string.Join( "/", fullPath ) ), null );
                    _isCloned = true;
                    idx = FindInComposite( e, out parent );
                }
                Debug.Assert( parent.Children[idx].Name == fullPath.Last() );
                parent.Override( idx, a );
                monitor.SendLine( LogLevel.Info, string.Format( "Inner action '{0}' has been overridden.", string.Join( "/", fullPath ) ), null );
                return true;
            }
            monitor.SendLine( LogLevel.Error, string.Format( "Action '{0}' not found. Unable to override it.", string.Join( "/", fullPath ) ), null );
            return false;
        }