Ejemplo n.º 1
0
        private static string GetControlIdentification(MvcDirectMethod method)
        {
            DirectMethodProxyIDMode _idMode = method.Attribute.IDMode;
            string alias = method.Attribute.IDAlias ?? "";

            if (_idMode == DirectMethodProxyIDMode.Default)
            {
                _idMode = method.DirectControlerAttr.IDMode;
                alias   = method.DirectControlerAttr.Alias;
            }

            if (alias.IsNotEmpty() && (_idMode == DirectMethodProxyIDMode.Default || _idMode == DirectMethodProxyIDMode.ClientID))
            {
                _idMode = DirectMethodProxyIDMode.Alias;
            }

            switch (_idMode)
            {
            case DirectMethodProxyIDMode.None:
                return(null);

            case DirectMethodProxyIDMode.ClientID:
            case DirectMethodProxyIDMode.ID:
                return(method.DirectControlerAttr.AreaName);

            case DirectMethodProxyIDMode.Alias:
                return(alias);

            case DirectMethodProxyIDMode.AliasPlusID:
                return(alias + method.DirectControlerAttr.AreaName);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        public static MvcDirectMethod[] GetMethods()
        {
            string cacheKey             = "Ext.Net.MVC.DirectMethods";
            List <MvcDirectMethod> list = null;
            var context = HttpContext.Current;

            if (!MvcDirectMethod.IsDebugging)
            {
                list = context.Cache[cacheKey] as List <MvcDirectMethod>;
            }

            if (list == null)
            {
                list = new List <MvcDirectMethod>();
                var assemblies = BuildManager.GetReferencedAssemblies();
                foreach (Assembly assembly in assemblies)
                {
                    try
                    {
                        if (!assembly.IsDynamic)
                        {
                            var types = assembly.GetTypes().Where(type =>
                                                                  type.IsPublic &&
                                                                  type.IsSubclassOf(typeof(System.Web.Mvc.Controller)) &&
                                                                  System.Attribute.IsDefined(type, typeof(Ext.Net.MVC.DirectControllerAttribute))
                                                                  );

                            foreach (Type type in types)
                            {
                                MvcDirectMethod.GetControllerMethods(type, list);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }

                if (!MvcDirectMethod.IsDebugging)
                {
                    context.Cache.Insert(cacheKey, list);
                }
            }

            return(list.ToArray());
        }
Ejemplo n.º 3
0
        public static string BuildProxy(ViewContext viewContext)
        {
            Dictionary <string, Dictionary <string, List <MvcDirectMethod> > > methods = MvcDirectMethod.GetGroupedMethods(viewContext);
            StringBuilder sb = new StringBuilder(256);

            UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext, RouteTable.Routes);

            foreach (KeyValuePair <string, Dictionary <string, List <MvcDirectMethod> > > ns in methods)
            {
                string nsName = ns.Key;

                sb.AppendFormat("Ext.ns(\"{0}\");", nsName);

                Dictionary <string, List <MvcDirectMethod> > scopes = ns.Value;

                sb.Append("Ext.apply(".ConcatWith(nsName, ", { "));

                foreach (KeyValuePair <string, List <MvcDirectMethod> > scope in scopes)
                {
                    string scopeName = scope.Key;
                    List <MvcDirectMethod> directMethods = scope.Value;

                    if (scopeName.IsNotEmpty())
                    {
                        sb.Append(scopeName);
                        sb.Append(":{");
                    }

                    bool needComma = false;

                    foreach (MvcDirectMethod method in directMethods)
                    {
                        if (needComma)
                        {
                            sb.Append(",");
                        }
                        method.UrlHelper = urlHelper;
                        method.GenerateProxy(sb, null, null);
                        needComma = true;
                    }

                    if (scopeName.IsNotEmpty())
                    {
                        sb.Append("}");
                    }

                    sb.Append(",");
                }

                if (sb[sb.Length - 1] == ',')
                {
                    sb.Remove(sb.Length - 1, 1);
                }

                sb.Append(" });");
            }

            return(sb.ToString());
        }
Ejemplo n.º 4
0
        public static Dictionary <string, Dictionary <string, List <MvcDirectMethod> > > GetGroupedMethods(ViewContext viewContext)
        {
            Dictionary <string, Dictionary <string, List <MvcDirectMethod> > > methods = new Dictionary <string, Dictionary <string, List <MvcDirectMethod> > >();
            var dm = MvcDirectMethod.GetMethods();

            if (dm.Length == 0)
            {
                return(methods);
            }

            var    context    = HttpContext.Current;
            string area       = null;
            string controller = null;

            if (viewContext.RouteData.DataTokens["area"] != null)
            {
                area = viewContext.RouteData.DataTokens["area"].ToString();
            }

            if (viewContext.RouteData.DataTokens["controller"] != null)
            {
                controller = viewContext.RouteData.DataTokens["controller"].ToString();
            }

            foreach (MvcDirectMethod method in dm)
            {
                if (method.Attribute.ClientProxy == ClientProxy.Ignore)
                {
                    continue;
                }

                if (!method.DirectControlerAttr.GenerateProxyForOtherAreas && method.DirectControlerAttr.AreaName != area)
                {
                    continue;
                }

                if (!method.DirectControlerAttr.GenerateProxyForOtherControllers)
                {
                    if (method.DirectControlerAttr.AreaName != area || method.Controller != controller)
                    {
                        continue;
                    }
                }

                string ns = method.Attribute.Namespace;

                if (!methods.ContainsKey(ns))
                {
                    methods[ns] = new Dictionary <string, List <MvcDirectMethod> >();
                }

                string name = MvcDirectMethod.GetControlIdentification(method) ?? "";

                if (!methods[ns].ContainsKey(name))
                {
                    methods[ns][name] = new List <MvcDirectMethod>();
                }

                methods[ns][name].Add(method);
            }

            return(methods);
        }
Ejemplo n.º 5
0
        private static string GetControlIdentification(MvcDirectMethod method)
        {
            DirectMethodProxyIDMode _idMode = method.Attribute.IDMode;
            string alias = method.Attribute.IDAlias ?? "";

            if (_idMode == DirectMethodProxyIDMode.Default)
            {
                _idMode = method.DirectControlerAttr.IDMode;
                alias = method.DirectControlerAttr.Alias;
            }
            
            if (alias.IsNotEmpty() && (_idMode == DirectMethodProxyIDMode.Default || _idMode == DirectMethodProxyIDMode.ClientID))
            {
                _idMode = DirectMethodProxyIDMode.Alias;
            }

            switch (_idMode)
            {
                case DirectMethodProxyIDMode.None:
                    return null;
                case DirectMethodProxyIDMode.ClientID:
                case DirectMethodProxyIDMode.ID:
                    return method.DirectControlerAttr.AreaName;                
                case DirectMethodProxyIDMode.Alias:
                    return alias;
                case DirectMethodProxyIDMode.AliasPlusID:
                    return alias + method.DirectControlerAttr.AreaName;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }