示例#1
0
        private bool resolveDep( OperationState dependentState, OperationState potentialDependency, bool satisfyDependency )
        {
            if( potentialDependency.Operation == operation && potentialDependency.State == operationState )
                {
                    //we are a match.  Next we want to ensure that any given dependency is only associated to one other operation state
                    //of a given operation, that is to say an operation can be a dependent to more than one KIND of operation, but only
                    //fulfill a dependency ONCE for a specific operation.

                    //first assume we have a valid slot.
                    bool hasValidSlot = true;

                    //loop through all the prexisting dependents of this potential dependency to make sure there is a valid slot.
                    foreach( OperationState stateSlot in potentialDependency.DependentStates )
                    {
                        //if this dependent's operation equals our target op, and the state slot is NOT the target opstate, this dependency
                        //has already been consumed by a different dependent of the same operation.
                    if( stateSlot.Operation == dependentState.Operation && stateSlot.Id != dependentState.Id )
                        {
                            log.Debug("DEPEDENDANT SLOT CONSUMED ", stateSlot.Operation.Name );
                            hasValidSlot = false;
                        return false;
                        }
                    }

                    if( hasValidSlot )
                    {
                        log.Debug("DEPENDENCY ", operation.Name, " RESOLVED FOR ", dependentState.Id, " BY ", potentialDependency.Id );
                        //we have found a valid operationstate to satisfy this dependency.
                        if( satisfyDependency )
                        {
                            potentialDependency.DependentStates.Add( dependentState );
                            potentialDependency.SaveRelations("DependentStates");
                        }

                    return true;
                    }
                }
            return false;
        }