コード例 #1
0
        // 构造属性描述
        private List <IArgumentDescription> GetFieldDescriptions(Type classType, BindingFlags flags)
        {
            FieldInfo[] fieldInfos             = classType.GetFields(flags);
            List <IArgumentDescription> fields = new List <IArgumentDescription>(fieldInfos.Length);

            foreach (FieldInfo fieldInfo in fieldInfos)
            {
                Type fieldType = fieldInfo.FieldType;
                AddToAssemblyMapping(fieldType);
                DescriptionAttribute descriptionAttribute = fieldInfo.GetCustomAttribute <DescriptionAttribute>();
                string descriptionStr = (null == descriptionAttribute) ? string.Empty : descriptionAttribute.Description;

                TypeDescription typeDescription = new TypeDescription()
                {
                    AssemblyName = fieldType.Assembly.GetName().Name,
                    Category     = string.Empty,
                    Description  = descriptionStr,
                    Name         = GetTypeName(fieldType),
                    Namespace    = GetNamespace(fieldType)
                };

                ArgumentDescription propertyDescription = new ArgumentDescription()
                {
                    Name            = fieldInfo.Name,
                    ArgumentType    = GetKindOfType(fieldType),
                    Description     = descriptionStr,
                    Modifier        = ArgumentModifier.None,
                    DefaultValue    = null,
                    TypeDescription = typeDescription,
                    IsOptional      = false
                };
                fields.Add(propertyDescription);
            }
            return(fields);
        }
コード例 #2
0
        // 构造一个参数信息
        private ArgumentDescription GetReturnInfo(ParameterInfo parameterInfo)
        {
            Type propertyType = parameterInfo.ParameterType;

            if ("Void".Equals(propertyType.Name))
            {
                return(null);
            }
            AddToAssemblyMapping(propertyType);
            TypeDescription typeDescription = new TypeDescription()
            {
                AssemblyName = propertyType.Assembly.GetName().Name,
                Category     = string.Empty,
                Description  = string.Empty,
                Name         = GetTypeName(propertyType),
                Namespace    = GetNamespace(propertyType)
            };

            ArgumentDescription paramDescription = new ArgumentDescription()
            {
                Name            = string.Empty,
                ArgumentType    = GetKindOfType(propertyType),
                Description     = string.Empty,
                Modifier        = ArgumentModifier.None,
                DefaultValue    = null,
                TypeDescription = typeDescription,
                IsOptional      = false,
            };

            return(paramDescription);
        }
コード例 #3
0
ファイル: ModuleUtils.cs プロジェクト: spartajet/Testflow
        private static void InitializeArgumentType(ISequenceManager sequenceManager,
                                                   DescriptionDataTable descriptionCollection, IArgumentDescription argumentDescription)
        {
            ArgumentDescription argDescription = (ArgumentDescription)argumentDescription;

            // 如果类型描述类为空且TypeData非空,则说明该argDescription已经被修改过,无需再执行处理
            if (argDescription.TypeDescription == null)
            {
                if (null == argDescription.Type)
                {
                    I18N i18N = I18N.GetInstance(Constants.I18nName);
                    throw new TestflowRuntimeException(ModuleErrorCode.TypeCannotLoad,
                                                       i18N.GetFStr("InvalidArgType", argDescription.Name));
                }
                return;
            }
            string fullName = GetFullName(argDescription.TypeDescription);

            if (descriptionCollection.ContainsType(fullName))
            {
                argDescription.Type = descriptionCollection.GetTypeData(fullName);
            }
            else
            {
                ITypeData typeData = sequenceManager.CreateTypeData(argDescription.TypeDescription);
                descriptionCollection.AddTypeData(fullName, typeData);
                argDescription.Type = typeData;
            }
            argDescription.TypeDescription = null;
        }
コード例 #4
0
        /// <summary>
        /// Generates the comments for an actions method argument including its name.
        /// </summary>
        /// <param name="argumentDesc">The argument description describing the argument of the action.</param>
        /// <returns>A string containing a single line comment.</returns>
        private string GenerateArgumentDescriptionComment(ArgumentDescription argumentDesc)
        {
            StateVariableDescription lsdDesc = argumentDesc.RelatedStateVariableDescription;

            return(string.Format(
                       CodeGenProvider.ArgumentComment,
                       argumentDesc.Name,
                       GenerateStateVariableDescriptionComment(lsdDesc)));
        }
コード例 #5
0
        public override void Start(ArgumentDescription[] args)
        {
            _value = new PositionBuffer();

            _value.Append(
                @"using System;
using System.Text;
using System.Web;
using BlogServer;
using BlogServer.Model;

public class Template
{
    private static string HtmlEncode(string val)
    {
        return System.Web.HttpUtility.HtmlEncode(val);
    }

    private static string HtmlAttributeEncode(string val)
    {
        return System.Web.HttpUtility.HtmlAttributeEncode(val);
    }

    private static string HtmlDecode(string val)
    {
        return System.Web.HttpUtility.HtmlDecode(val);
    }

    private static string UrlEncode(string val)
    {
        return System.Web.HttpUtility.UrlEncode(val);
    }

    private static string UrlPathEncode(string val)
    {
        return System.Web.HttpUtility.UrlPathEncode(val);
    }

    private static string UrlDecode(string val)
    {
        return System.Web.HttpUtility.UrlDecode(val);
    }

    public static string Process(object[] parameters)
    {
        StringBuilder ___output = new StringBuilder();
");
            for (int ___i = 0; ___i < args.Length; ___i++)
            {
                ArgumentDescription arg = args[___i];

                string argType = arg.Type.FullName;

                _value.AppendFormat("{0} {1} = ({0})parameters[{2}];", argType, arg.Identifier, ___i);
            }
        }
コード例 #6
0
 private void InitConstructorParamDescription(ConstructorInfo constructor,
                                              FunctionInterfaceDescription funcDescription)
 {
     ParameterInfo[] paramInfo = constructor.GetParameters();
     funcDescription.Arguments = new List <IArgumentDescription>(paramInfo.Length);
     foreach (ParameterInfo parameterInfo in paramInfo)
     {
         ArgumentDescription paramDescription = GetParameterInfo(parameterInfo);
         funcDescription.Arguments.Add(paramDescription);
     }
     funcDescription.Return = null;
 }
コード例 #7
0
 // 构造方法入参描述信息
 private void InitMethodParamDescription(MethodInfo method,
                                         FunctionInterfaceDescription funcDescription)
 {
     ParameterInfo[] paramInfo = method.GetParameters();
     funcDescription.Arguments = new List <IArgumentDescription>(paramInfo.Length);
     foreach (ParameterInfo parameterInfo in paramInfo)
     {
         ArgumentDescription paramDescription = GetParameterInfo(parameterInfo);
         funcDescription.Arguments.Add(paramDescription);
     }
     funcDescription.Return = GetReturnInfo(method.ReturnParameter);
 }
コード例 #8
0
        /// <summary>
        /// Generates the code for an out argument which is NOT on its own in the action.
        /// </summary>
        /// <param name="argumentDesc">The argument description.</param>
        /// <param name="outArgumentIndex">The out argument index (0).</param>
        /// <param name="outArguments">A StringBuilder to append the out arguments to.</param>
        /// <param name="outSetValues">A StringBuilder to append the out set value code to.</param>
        /// <param name="enumStateVar">True if the argument is an enumeration type.</param>
        /// <param name="argFriendlyName">The code friendly name of the out argument.</param>
        /// <param name="relatedStateVarFriendlyName">The related state variable code friendly name.</param>
        /// <param name="type">The data type for the argument.</param>
        /// <param name="comments">A StringBuilder to append the comments line for the parameter to.</param>
        private void GenerateOutArgumentCode(
            ArgumentDescription argumentDesc,
            int outArgumentIndex, StringBuilder outArguments, StringBuilder outSetValues, bool enumStateVar,
            string argFriendlyName, string relatedStateVarFriendlyName, string type, StringBuilder comments)
        {
            // Generate argument comment line
            comments.Append(
                string.Format(
                    CodeGenProvider.ActionOutParamComment,
                    argFriendlyName,
                    GenerateArgumentDescriptionComment(argumentDesc)
                    )
                );

            // Generate argument definition
            outArguments.Append(
                string.Format(
                    CodeGenProvider.ActionOutArgument,
                    type, argFriendlyName,
                    (outArguments.Length > 0 ? CodeGenProvider.ParameterSeperator : String.Empty)
                    )
                );

            // Generate out set value code
            if (enumStateVar)
            {
                outSetValues.Append(
                    string.Format(
                        CodeGenProvider.OutSetValueEnum,
                        argFriendlyName,
                        relatedStateVarFriendlyName,
                        outArgumentIndex
                        )
                    );
            }
            else
            {
                outSetValues.Append(
                    string.Format(
                        CodeGenProvider.OutSetValue,
                        argFriendlyName,
                        type,
                        outArgumentIndex
                        )
                    );
            }
        }
コード例 #9
0
        /// <summary>
        /// Generates the code for an in argument.
        /// </summary>
        /// <param name="argumentDesc">The argument description.</param>
        /// <param name="inArgumentIndex">The argument index.</param>
        /// <param name="inArguments">The StringBuilder to append the argument definition to.</param>
        /// <param name="inSetValues">The StringBuilder to append the argument set values to.</param>
        /// <param name="enumStateVar">True if the state variable is an enumeration type.</param>
        /// <param name="argFriendlyName">The code friendly argument name.</param>
        /// <param name="relatedStateVarFriendlyName">The related state variable code friendly name.</param>
        /// <param name="type">The data type for the argument.</param>
        /// <param name="comments">A StringBuilder to append the comments line for the parameter to.</param>
        private void GenerateInArgumentCode(
            ArgumentDescription argumentDesc,
            int inArgumentIndex, StringBuilder inArguments, StringBuilder inSetValues,
            bool enumStateVar, string argFriendlyName, string relatedStateVarFriendlyName,
            string type, StringBuilder comments)
        {
            // Generate argument comment line
            comments.Append(
                string.Format(
                    CodeGenProvider.ActionInParamComment,
                    argFriendlyName,
                    GenerateArgumentDescriptionComment(argumentDesc)
                    )
                );

            // Generate argument definition
            inArguments.Append(
                string.Format(
                    CodeGenProvider.ActionInArgument,
                    type, argFriendlyName,
                    (inArguments.Length > 0 ? CodeGenProvider.ParameterSeperator : String.Empty)
                    )
                );

            // Generate in set value code
            if (enumStateVar)
            {
                inSetValues.Append(
                    string.Format(
                        CodeGenProvider.InSetValueEnum,
                        inArgumentIndex,
                        relatedStateVarFriendlyName,
                        argFriendlyName
                        )
                    );
            }
            else
            {
                inSetValues.Append(
                    string.Format(
                        CodeGenProvider.InSetValue,
                        inArgumentIndex,
                        argFriendlyName
                        )
                    );
            }
        }
コード例 #10
0
ファイル: ctlUPnPActionInfo.cs プロジェクト: xilefer/upnptest
        /// <summary>
        /// Adds an input or output value to the data grids.
        /// </summary>
        /// <param name="argDesc">The argument description for the argument.</param>
        /// <param name="svDesc">The state variable description for the linked state variable to the argument.</param>
        /// <param name="inputIndex">The current input index.</param>
        /// <param name="outputIndex">The current output index.</param>
        protected void AddIOValue(ArgumentDescription argDesc, StateVariableDescription svDesc, ref int inputIndex, ref int outputIndex)
        {
            StateVariableDataType ldtType;

            // Get the data type for the state variable description
            if (svDesc == null)
            {
                ldtType = StateVariableDataType.tunknown;
            }
            else
            {
                ldtType = svDesc.DataTypeValue;
            }

            switch (argDesc.DirectionValue)
            {
            case ArgumentDirection.In:
                // If its an input then add it
                int liIndex = dgInputs.Rows.Add(
                    argDesc.Name,
                    ldtType.Description(),
                    ldtType.StringFromValue(ldtType.Default()));

                // Set its row info
                dgInputs.Rows[liIndex].Tag = new RowInfo(argDesc, svDesc, inputIndex);

                // Increment the input index
                inputIndex++;

                break;

            case ArgumentDirection.Out:
                // If its an output then add it
                liIndex = dgOutputs.Rows.Add(
                    argDesc.Name,
                    ldtType.Description(),
                    String.Empty);

                // Set its row info
                dgOutputs.Rows[liIndex].Tag = new RowInfo(argDesc, svDesc, outputIndex);

                // Increment the output index
                outputIndex++;

                break;
            }
        }
コード例 #11
0
        // 构造属性描述
        private List <IArgumentDescription> GetPropertyDescriptions(Type classType, BindingFlags flags)
        {
            PropertyInfo[] propertyInfos           = classType.GetProperties(flags);
            List <IArgumentDescription> properties = new List <IArgumentDescription>(propertyInfos.Length);

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                // 如果属性没有set方法,则返回
                if (null == propertyInfo.GetSetMethod())
                {
                    continue;
                }
                Type propertyType = propertyInfo.PropertyType;
                AddToAssemblyMapping(propertyType);

                DescriptionAttribute descriptionAttribute = propertyInfo.GetCustomAttribute <DescriptionAttribute>();
                string descriptionStr = (null == descriptionAttribute) ? string.Empty : descriptionAttribute.Description;

                TypeDescription typeDescription = new TypeDescription()
                {
                    AssemblyName = propertyType.Assembly.GetName().Name,
                    Category     = string.Empty,
                    Description  = descriptionStr,
                    Name         = GetTypeName(propertyType),
                    Namespace    = GetNamespace(propertyType)
                };

                ArgumentDescription propertyDescription = new ArgumentDescription()
                {
                    Name            = propertyInfo.Name,
                    ArgumentType    = GetKindOfType(propertyType),
                    Description     = descriptionStr,
                    Modifier        = ArgumentModifier.None,
                    DefaultValue    = null,
                    TypeDescription = typeDescription,
                    IsOptional      = false
                };
                properties.Add(propertyDescription);
            }
            return(properties);
        }
コード例 #12
0
        // 构造参数信息
        private ArgumentDescription GetParameterInfo(ParameterInfo parameterInfo)
        {
            Type parameterType = parameterInfo.ParameterType;

            AddToAssemblyMapping(parameterType);
            DescriptionAttribute descriptionAttribute = parameterInfo.GetCustomAttribute <DescriptionAttribute>();
            string descriptionStr = (null == descriptionAttribute) ? string.Empty : descriptionAttribute.Description;

            TypeDescription typeDescription = new TypeDescription()
            {
                AssemblyName = parameterType.Assembly.GetName().Name,
                Category     = string.Empty,
                Description  = descriptionStr,
                Name         = GetParamTypeName(parameterType),
                Namespace    = GetNamespace(parameterType)
            };

            ArgumentModifier modifier = ArgumentModifier.None;

            if (parameterInfo.ParameterType.IsByRef)
            {
                modifier = parameterInfo.IsOut ? ArgumentModifier.Out : ArgumentModifier.Ref;
            }
            ArgumentDescription paramDescription = new ArgumentDescription()
            {
                Name            = parameterInfo.Name,
                ArgumentType    = GetKindOfType(parameterType),
                Description     = descriptionStr,
                Modifier        = modifier,
                DefaultValue    = null,
                TypeDescription = typeDescription,
                IsOptional      = parameterInfo.IsOptional
            };

            if (parameterInfo.HasDefaultValue)
            {
                paramDescription.DefaultValue = parameterInfo.DefaultValue?.ToString() ?? CommonConst.NullValue;
            }
            return(paramDescription);
        }
コード例 #13
0
        /// <summary>
        /// Generates the code for an out argument which is on its own in the action.
        /// </summary>
        /// <param name="argumentDesc">The argument description.</param>
        /// <param name="outArgumentIndex">The out argument index (0).</param>
        /// <param name="outSetValues">A StringBuilder to append the out set value code to.</param>
        /// <param name="enumStateVar">True if the argument is an enumeration type.</param>
        /// <param name="relatedStateVarFriendlyName">The related state variable code friendly name.</param>
        /// <param name="type">The data type for the argument.</param>
        /// <param name="comments">A StringBuilder to append the comments line for the return parameter to.</param>
        private void GenerateOutArgumentReturnCode(
            ArgumentDescription argumentDesc,
            int outArgumentIndex, StringBuilder outSetValues, bool enumStateVar,
            string relatedStateVarFriendlyName, string type, StringBuilder comments)
        {
            // Generate argument comment line
            comments.Append(
                string.Format(
                    CodeGenProvider.ActionReturnsComment,
                    relatedStateVarFriendlyName,
                    GenerateArgumentDescriptionComment(argumentDesc)
                    )
                );

            // Generate the return statement code
            if (enumStateVar)
            {
                outSetValues.Append(string.Format(CodeGenProvider.OutReturnValueEnum, relatedStateVarFriendlyName, outArgumentIndex));
            }
            else
            {
                outSetValues.Append(string.Format(CodeGenProvider.OutReturnValue, type, outArgumentIndex));
            }
        }
コード例 #14
0
 public abstract void Start(ArgumentDescription[] argDescs);
コード例 #15
0
        /// <summary>
        /// Gets the help string.
        /// </summary>
        protected virtual string GetHelpString(ArgumentDescription[] commands)
        {
            StringBuilder text = new StringBuilder();
            text.Append("These are the supported arguments:\r\n");

            for (int ii = 0; ii < commands.Length; ii++)
            {
                ArgumentDescription command = commands[ii];

                text.Append("\r\n");

                if (command.ValueRequired)
                {
                    text.AppendFormat("{0}:<value> {1}", command.Name, command.Description);
                }
                else if (command.ValueAllowed)
                {
                    text.AppendFormat("{0}[:<value>] {1}", command.Name, command.Description);
                }
                else
                {
                    text.AppendFormat("{0} {1}", command.Name, command.Description);
                }
            }

            text.Append("\r\n");
            return text.ToString();
        }
コード例 #16
0
ファイル: ctlUPnPActionInfo.cs プロジェクト: xilefer/upnptest
 /// <summary>
 /// Creates a new row info structure.
 /// </summary>
 /// <param name="argDesc">The argument description for the input or output.</param>
 /// <param name="stateVarDesc">The state variable description for the input or output.</param>
 /// <param name="index">The index of the input or output.</param>
 public RowInfo(ArgumentDescription argDesc, StateVariableDescription stateVarDesc, int index)
 {
     madArgDesc      = argDesc;
     msvStateVarDesc = stateVarDesc;
     miIndex         = index;
 }
コード例 #17
0
        public override void Start(ArgumentDescription[] args)
        {
            _value = new PositionBuffer();

            _value.Append(
@"using System;
using System.Text;
using System.Web;
using BlogServer;
using BlogServer.Model;

public class Template
{
    private static string HtmlEncode(string val)
    {
        return System.Web.HttpUtility.HtmlEncode(val);
    }

    private static string HtmlAttributeEncode(string val)
    {
        return System.Web.HttpUtility.HtmlAttributeEncode(val);
    }

    private static string HtmlDecode(string val)
    {
        return System.Web.HttpUtility.HtmlDecode(val);
    }

    private static string UrlEncode(string val)
    {
        return System.Web.HttpUtility.UrlEncode(val);
    }

    private static string UrlPathEncode(string val)
    {
        return System.Web.HttpUtility.UrlPathEncode(val);
    }

    private static string UrlDecode(string val)
    {
        return System.Web.HttpUtility.UrlDecode(val);
    }

    public static string Process(object[] parameters)
    {
        StringBuilder ___output = new StringBuilder();
");
            for (int ___i = 0; ___i < args.Length; ___i++)
            {
                ArgumentDescription arg = args[___i];

                string argType = arg.Type.FullName;

                _value.AppendFormat("{0} {1} = ({0})parameters[{2}];", argType, arg.Identifier, ___i);
            }
        }
コード例 #18
0
        public override void Start(ArgumentDescription[] args)
        {
            _value = new PositionBuffer();

            _value.Append(
                @"using System;
using System.Text;
using System.Web;

//[assembly: System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.RequestMinimum, Flags = System.Security.Permissions.SecurityPermissionFlag.Execution, Unrestricted = true)]
//[assembly: System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.RequestOptional, Flags = System.Security.Permissions.SecurityPermissionFlag.Execution, Unrestricted = true)]

public class Template
{
    private static string HtmlEncode(string val)
    {
        return System.Web.HttpUtility.HtmlEncode(val);
    }

    private static string HtmlAttributeEncode(string val)
    {
        return System.Web.HttpUtility.HtmlAttributeEncode(val);
    }

    private static string HtmlDecode(string val)
    {
        return System.Web.HttpUtility.HtmlDecode(val);
    }

    private static string UrlEncode(string val)
    {
        return System.Web.HttpUtility.UrlEncode(val);
    }

    private static string UrlPathEncode(string val)
    {
        return System.Web.HttpUtility.UrlPathEncode(val);
    }

    private static string UrlDecode(string val)
    {
        return System.Web.HttpUtility.UrlDecode(val);
    }

    public static string Process(object state, object[] parameters)
    {
        StringBuilder ___output = new StringBuilder();
        string _selection = state as string;
");
            for (int ___i = 0; ___i < args.Length; ___i++)
            {
                ArgumentDescription arg = args[___i];

                string argType;
                switch (arg.Type)
                {
                case ArgumentType.TextString:
                case ArgumentType.TextStringExtended:
                case ArgumentType.HtmlString:
                case ArgumentType.HtmlStringExtended:
                    argType = "string";
                    break;

                case ArgumentType.Double:
                    argType = "double";
                    break;

                case ArgumentType.Integer:
                    argType = "int";
                    break;

                case ArgumentType.Boolean:
                    argType = "bool";
                    break;

                case ArgumentType.DateTime:
                    argType = "System.DateTime";
                    break;

                default:
                    throw new ArgumentException("Unexpected argument type: " + arg.Type);
                }

                _value.AppendFormat("{0} {1} = ({0})parameters[{2}];", argType, arg.Identifier, ___i);
            }
        }