コード例 #1
0
        protected void UpdateDelegates()
        {
            foreach (ContractParameter genericParam in this.GetAllDescendents())
            {
                ParameterDelegate <Vessel> param = genericParam as ParameterDelegate <Vessel>;
                if (param == null)
                {
                    continue;
                }

                string oldTitle = param.Title;
                if (matchingSubjects.Count == experiment.Count)
                {
                    if (param.ID.Contains("Destination:") || param.ID.Contains("Biome:") || param.ID.Contains("Situation:") ||
                        param.ID.Contains("Location:"))
                    {
                        param.ClearTitle();
                    }
                    else if (param.ID.Contains("Subject"))
                    {
                        string exp = param.ID.Remove(param.ID.IndexOf("Subject"));

                        param.SetTitle(matchingSubjects[exp].title);
                        param.SetState(ParameterState.Complete);
                    }
                }
                else
                {
                    if (param.ID.Contains("Subject"))
                    {
                        string exp = param.ID.Remove(param.ID.IndexOf("Subject"));
                        if (matchingSubjects.ContainsKey(exp))
                        {
                            param.SetTitle(matchingSubjects[exp].title);
                            param.SetState(ParameterState.Complete);
                        }
                        else
                        {
                            param.ClearTitle();
                        }
                    }
                    else
                    {
                        param.ResetTitle();
                    }
                }

                if (param.Title != oldTitle)
                {
                    ContractsWindow.SetParameterTitle(param, param.Title);
                    ContractConfigurator.OnParameterChange.Fire(Root, param);
                }
            }

            ContractsWindow.SetParameterTitle(this, GetTitle());
        }
コード例 #2
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        public static bool CheckChildConditions(ContractParameter param, T value, bool checkOnly = false)
        {
            bool conditionMet = true;
            int  count        = param.ParameterCount;

            for (int i = 0; i < param.ParameterCount; i++)
            {
                ParameterDelegate <T> delegateParam = param[i] as ParameterDelegate <T>;
                if (delegateParam != null)
                {
                    conditionMet &= delegateParam.SetState(value);
                }
            }

            return(conditionMet);
        }
コード例 #3
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        protected static BitArray CheckChildConditions(ContractParameter param, IEnumerable <T> values, ref bool conditionMet, bool checkOnly = false)
        {
            int      count   = values.Count();
            BitArray current = null;

            int paramCount = param.ParameterCount;

            for (int i = 0; i < paramCount; i++)
            {
                ParameterDelegate <T> paramDelegate = param[i] as ParameterDelegate <T>;
                if (paramDelegate != null)
                {
                    LoggingUtil.LogVerbose(paramDelegate, "Checking condition for '{0}', conditionMet = {1}", paramDelegate.title, conditionMet);

                    paramDelegate.InitializeBitArrays(values, current);
                    paramDelegate.SetState(values, ref conditionMet, checkOnly);

                    LoggingUtil.LogVerbose(paramDelegate, "  after, conditionMet = {0}", conditionMet);

                    if (paramDelegate.matchType == ParameterDelegateMatchType.FILTER)
                    {
                        current = paramDelegate.dest;
                    }
                    int newCount = GetCount(values, paramDelegate.dest);
                    switch (paramDelegate.matchType)
                    {
                    case ParameterDelegateMatchType.FILTER:
                        count = newCount;
                        break;

                    case ParameterDelegateMatchType.VALIDATE:
                        conditionMet &= newCount > 0;
                        break;

                    case ParameterDelegateMatchType.VALIDATE_ALL:
                        conditionMet &= count == newCount;
                        break;

                    case ParameterDelegateMatchType.NONE:
                        conditionMet &= newCount == 0;
                        break;
                    }
                }
            }

            return(current);
        }
コード例 #4
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        protected static IEnumerable <T> CheckChildConditions(ContractParameter param, IEnumerable <T> values, ref bool conditionMet, bool checkOnly = false)
        {
            int count = values.Count();

            int paramCount = param.ParameterCount;

            for (int i = 0; i < paramCount; i++)
            {
                ParameterDelegate <T> paramDelegate = param[i] as ParameterDelegate <T>;
                if (paramDelegate != null)
                {
                    LoggingUtil.LogVerbose(paramDelegate, "Checking condition for '" + paramDelegate.title + "', input.Any() = " + values.Any());

                    IEnumerable <T> newValues = paramDelegate.SetState(values, ref conditionMet, checkOnly);
                    if (paramDelegate.matchType == ParameterDelegateMatchType.FILTER)
                    {
                        values = newValues;
                    }
                    switch (paramDelegate.matchType)
                    {
                    case ParameterDelegateMatchType.FILTER:
                        count = values.Count();
                        break;

                    case ParameterDelegateMatchType.VALIDATE:
                        conditionMet &= newValues.Any();
                        break;

                    case ParameterDelegateMatchType.VALIDATE_ALL:
                        conditionMet &= count == newValues.Count();
                        break;

                    case ParameterDelegateMatchType.NONE:
                        conditionMet &= !newValues.Any();
                        break;
                    }
                }
            }

            return(values);
        }
コード例 #5
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        public static bool CheckChildConditions(ContractParameter param, IEnumerable <T> values, bool checkOnly = false)
        {
            bool conditionMet = true;
            int  count        = values.Count();

            foreach (ContractParameter child in param.AllParameters)
            {
                if (child is ParameterDelegate <T> )
                {
                    ParameterDelegate <T> paramDelegate = (ParameterDelegate <T>)child;
                    LoggingUtil.LogVerbose(paramDelegate, "Checking condition for '" + paramDelegate.title + "', input.Any() = " + values.Any());
                    IEnumerable <T> newValues = paramDelegate.SetState(values, ref conditionMet, checkOnly);
                    if (paramDelegate.matchType == ParameterDelegateMatchType.FILTER)
                    {
                        values = newValues;
                    }
                    switch (paramDelegate.matchType)
                    {
                    case ParameterDelegateMatchType.FILTER:
                        conditionMet &= values.Any();
                        break;

                    case ParameterDelegateMatchType.VALIDATE:
                        conditionMet &= newValues.Any();
                        break;

                    case ParameterDelegateMatchType.VALIDATE_ALL:
                        conditionMet &= count == newValues.Count();
                        break;

                    case ParameterDelegateMatchType.NONE:
                        conditionMet &= !newValues.Any();
                        break;
                    }
                }
            }

            return(conditionMet);
        }