Exemple #1
0
        private void FinalizeSetup(IAction action, Configuration.Action config)
        {
            if (action is IAttributesConfigurable)
            {
                Configure((IAttributesConfigurable)action, config.AnyAttr);
            }

            using (new UnsiteComponent(action))
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(action);
                // Check all required input arguments prior to execution.
                // Some may not be included in the configuration file and
                // may thus not be checked above.
                foreach (PropertyDescriptor property in properties)
                {
                    InputAttribute actioninput = (InputAttribute)property.Attributes[typeof(InputAttribute)];
                    if (actioninput != null && actioninput.Required)
                    {
                        object propertyvalue = property.GetValue(action);
                        if (propertyvalue == null || (propertyvalue is String &&
                                                      ((String)propertyvalue).Length == 0))
                        {
                            throw new ArgumentNullException(property.Name,
                                                            Properties.Resources.General_ArgumentEmpty);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void SetupInputs(IAction action, Configuration.Action config,
                                 IDictionary actions, IDictionaryService arguments)
        {
            if (config.Input != null)
            {
                // Set input properties.
                foreach (Configuration.Input parameter in config.Input)
                {
                    object value = null;
                    if (parameter.RecipeArgument != null)
                    {
                        value = arguments.GetValue(parameter.RecipeArgument);
                    }
                    else if (parameter.ActionOutput != null)
                    {
                        value = GetActionOutputValue(config, parameter, value);
                    }

                    // Retrieve the property using the type description also for extensibility.
                    PropertyDescriptor inprop = GetComponentProperty(action, parameter.Name);
                    if (inprop != null)
                    {
                        InputAttribute inputattr = (InputAttribute)inprop.Attributes[typeof(InputAttribute)];
                        if (inputattr == null)
                        {
                            throw new NotSupportedException(String.Format(
                                                                System.Globalization.CultureInfo.CurrentCulture,
                                                                Properties.Resources.Recipe_NotMarkedInput,
                                                                parameter.Name, config.Type));
                        }
                        if (inputattr.Required && (value == null ||
                                                   (value is String && ((String)value).Length == 0)))
                        {
                            throw new ArgumentNullException(parameter.Name,
                                                            Properties.Resources.General_ArgumentEmpty);
                        }
                        try
                        {
                            inprop.SetValue(action, value);
                        }
                        catch (TargetInvocationException tex)
                        {
                            // Throw with inner exception which contains the real error.
                            throw new NotSupportedException(String.Format(
                                                                System.Globalization.CultureInfo.CurrentCulture,
                                                                Properties.Resources.Recipe_CantSetActionProperty,
                                                                inprop.Name, config.Name), tex.InnerException);
                        }
                    }
                    else
                    {
                        throw new ActionExecutionException(
                                  this.Configuration.Name, config.Name,
                                  String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                Properties.Resources.Recipe_ActionPropertyMissing,
                                                parameter.Name, action.GetType()));
                    }
                }
            }
        }