public async static Task <IModule> LoadModuleAsync(this ControllerBase ctrl, Type type, params object[] args)
        {
            if (type == null)
            {
                return(null);
            }

            var r = Activator.CreateInstance(type) as IModule;

            Task t = type.CallMethod(r, () => type.GetMethods().Where(it => it.Name == "Init" && it.ReturnType == typeof(Task)), (mtype, atype) =>
            {
                if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype))
                {
                    return(ctrl);
                }

                return(null);
            }, args) as Task;

            if (t != null)
            {
                await t;
            }

            if (r != null)
            {
                WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r);
            }

            return(r);
        }
Esempio n. 2
0
        public static bool HasModule(this HtmlHelper helper, string moduleName, bool ignoreCase = false)
        {
            var mt = Type.GetType(moduleName, false, ignoreCase);

            if (mt != null)
            {
                return(helper.GetStorage().ContainsKey(WebExModuleExtensions.MakeViewDataKey(mt)));
            }

            return(false);
        }
Esempio n. 3
0
 public static void RegisterModule(IDictionary storage, IModule r)
 {
     if (r == null)
     {
         throw new ArgumentNullException(nameof(r));
     }
     if (storage == null)
     {
         throw new ArgumentNullException(nameof(storage));
     }
     storage[WebExModuleExtensions.MakeViewDataKey(r.GetType())] = new CachedModule(r);
 }
Esempio n. 4
0
        public static IModule LoadModule(IDictionary storage, Type type, params object[] args)
        {
            if (type == null)
            {
                return(null);
            }

            var r = type.CreateInstance(null, args) as IModule;

            if (r != null)
            {
                WebExModuleExtensions.RegisterModule(storage, r);
            }

            return(r);
        }
        public static IModule LoadModule(this ControllerBase ctrl, Type type, params object[] args)
        {
            if (type == null)
            {
                return(null);
            }

            var r = type.CreateInstance((mtype, atype) =>
            {
                if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype))
                {
                    return(ctrl);
                }

                return(null);
            }, args) as IModule;

            if (r != null)
            {
                WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r);
            }

            return(r);
        }
Esempio n. 6
0
 internal static CachedModule _GetModule(this ControllerBase ctrl, string moduleName, bool ignoreCase = false)
 {
     return(WebExModuleExtensions._GetModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, ModulesCatalog.GetModule(ctrl.ControllerContext.HttpContext.Application, moduleName, ignoreCase)));
 }
Esempio n. 7
0
        public static IModule LoadModule(this ControllerBase ctrl, Type type, params object[] args)
        {
            if (type == null)
            {
                return(null);
            }

            var r = type.CreateInstance((mtype, atype) =>
            {
                if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(atype))
                {
                    return(ctrl);
                }

                return(null);
            }, args) as IModule;

            //foreach (var method in type.GetConstructors())
            //{
            //    var methodParams = method.GetParameters();
            //    if (methodParams.Count() == 0)
            //    {
            //        r = Activator.CreateInstance(type) as IModule;
            //    }
            //    else
            //    {
            //        var params2Call = new object[methodParams.Count()];
            //        int j = 0;
            //        for (int i = 0; i < params2Call.Length; i++)
            //        {
            //            var mtype = methodParams[i].ParameterType;
            //            object arg = null;
            //            if (args != null && args.Length > j)
            //                arg = args[j];

            //            if (arg == null)
            //            {
            //                if (typeof(ControllerBase).IsAssignableFrom(mtype))
            //                    params2Call[i] = ctrl;

            //                if (args != null && args.Length > j)
            //                    j++;
            //            }
            //            else
            //            {
            //                if (mtype == arg.GetType())
            //                {
            //                    params2Call[i] = arg;
            //                    j++;
            //                }
            //                else if (typeof(ControllerBase).IsAssignableFrom(mtype) && !typeof(ControllerBase).IsAssignableFrom(arg.GetType()))
            //                {
            //                    params2Call[i] = ctrl;
            //                }
            //                else
            //                {
            //                    try
            //                    {
            //                        params2Call[i] = Convert.ChangeType(arg, mtype);
            //                        j++;
            //                    }
            //                    catch(Exception ex)
            //                    {
            //                        //eat an exception
            //                    }
            //                }
            //            }
            //        }
            //        r = Activator.CreateInstance(type, params2Call) as IModule;
            //    }
            //}

            if (r != null)
            {
                WebExModuleExtensions.RegisterModule(ctrl.ControllerContext.RequestContext.HttpContext.Items, r);
            }

            return(r);
        }
Esempio n. 8
0
 public static bool HasModule(this HtmlHelper helper, Type module)
 {
     return(helper.GetStorage().ContainsKey(WebExModuleExtensions.MakeViewDataKey(module)));
 }
Esempio n. 9
0
 internal static CachedModule _GetModule(this HtmlHelper helper, string moduleName, bool ignoreCase = false)
 {
     return(WebExModuleExtensions._GetModule(helper.ViewContext.RequestContext.HttpContext.Items, ModulesCatalog.GetModule(helper.ViewContext.HttpContext.Application, moduleName, ignoreCase)));
 }