예제 #1
0
 /// <summary>
 /// Copy across persistent input parameter values from another action of the same type
 /// </summary>
 /// <param name="action"></param>
 /// <param name="other"></param>
 public static void CopyPersistentValuesFrom(this IAction action, IAction other)
 {
     if (other != null && action.GetType().IsAssignableFrom(other.GetType()))
     {
         IList <PropertyInfo> inputs = action.InputParameters();
         foreach (PropertyInfo input in inputs)
         {
             ActionInputAttribute inputAtt = ActionInputAttribute.ExtractFrom(input);
             if (inputAtt != null && inputAtt.Persistant)
             {
                 input.SetValue(action, input.GetValue(other, null), null);
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Use the current input manager to prompt the user for all necessary inputs to this action
        /// </summary>
        /// <returns>True if all inputs successful, false if user cancels</returns>
        public virtual bool PromptUserForInputs(bool chain = false)
        {
            IList <PropertyInfo> inputs        = InputParameters();
            IList <PropertyInfo> dialogOptions = null;

            foreach (PropertyInfo input in inputs)
            {
                object               value      = input.GetValue(this, null); //Initial value
                object[]             attributes = input.GetCustomAttributes(typeof(ActionInputAttribute), true);
                ActionInputAttribute inputAtt   = null;
                if (attributes.Count() > 0)
                {
                    inputAtt = (ActionInputAttribute)attributes[0];
                }
                if (inputAtt != null && inputAtt.Manual)
                {
                    if (inputAtt.Dialog)
                    {
                        if (dialogOptions == null)
                        {
                            dialogOptions = new List <PropertyInfo>();
                        }
                        dialogOptions.Add(input);
                    }
                    else if (!Core.Instance.Host.Input.EnterInput(input.PropertyType, ref value, input, this, chain) && inputAtt.Required)
                    {
                        return(false);
                    }
                }
                input.SetValue(this, value, null);
            }
            if (dialogOptions != null)
            {
                //TODO!
                //if (!Core.Instance.Host.GUI.ShowGeneratedDialog(this, dialogOptions)) return false;
            }
            return(true);
        }