Ejemplo n.º 1
0
 private static Parameter getResultFromMethod(Method method, object result)
 {
     method.ReturnParameter = method.Parameters.Where(x => x.Value.Direction == ParameterDirection.ReturnValue).Select(x => x.Value).FirstOrDefault();
     if (method.ReturnParameter != null)
         method.ReturnParameter.Value = result;
     return method.ReturnParameter;
 }
Ejemplo n.º 2
0
        public static Method[] GetMethods(PluginBase plugin)
        {
            var result = new List<Method>();
            if (plugin == null)
                return result.ToArray();

            var methods = plugin.GetType().GetMethods();

            foreach (var me in methods)
            {
                var method = new Method();
                method.AssemblyName = plugin.GetType().Assembly.ManifestModule.Name;
                method.NameSpace = plugin.GetType().Namespace;
                method.ClassName = plugin.GetType().Name;
                method.MethodName = me.Name;

                method.Parameters = new Dictionary<string, Parameter>();
                foreach (var par in me.GetParameters())
                {
                    var parameter = new Parameter(par.ParameterType, par.Name, par.DefaultValue, ParameterDirection.Input);
                    method.Parameters.Add(par.Name, parameter);
                }

                method.ReturnParameter = new Parameter(me.ReturnType, "ReturnValue", null, ParameterDirection.ReturnValue);

                result.Add(method);
            }
            
            return result.ToArray();
        }    
Ejemplo n.º 3
0
        public static Parameter ExecuteMethod(PluginBase plugin, Method method)
        {
            var equalsMethodsInClass = plugin.GetMethods().Where(x => x.Equals(method)).OrderByDescending(x => x.Parameters.Count).ToList();
            if (equalsMethodsInClass.Count <= 0)
                throw new PluginsException(string.Format("Method {0} in class {1} was not found", method.MethodName, plugin.ToString()));

            var onlyInputParams =
                method.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList();

            foreach (var methodInClass in equalsMethodsInClass)
            {
                var methodInClassOnlyInput = methodInClass.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList();
                object[] parameters;
                Type[] types;
                if (sameParameters(methodInClassOnlyInput, onlyInputParams, out parameters, out types))
                {
                    var result = plugin.GetType().GetMethod(method.MethodName, types).Invoke(plugin, parameters);
                    return getResultFromMethod(method, result);
                }
            }

            throw new PluginsException(string.Format("Method {0} in class {1} was found, but it has different parameters", method.MethodName, plugin.ToString()));
        }
Ejemplo n.º 4
0
 public Parameter ExecuteMethod(Method method)
 {
     return PluginExecuter.ExecuteMethod(this, method);
 }
Ejemplo n.º 5
0
 protected bool Equals(Method other)
 {
     return string.Equals(AssemblyName.ToLower(), other.AssemblyName.ToLower()) && string.Equals(NameSpace, other.NameSpace) &&
            string.Equals(ClassName, other.ClassName) && string.Equals(MethodName, other.MethodName);
 }