示例#1
0
        /// <summary>
        /// Get the widget definition package path
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string GetWidgetPath(string path)
        {
            if (path.StartsWith("~") || path.StartsWith("/"))
            {
                throw new Exception("The path could not be start with \"~\" or \"\"/");
            }

            if (Model != null)
            {
                return(UrlUtility.CreateUrlHelper().Content("~/content/widgets/" + Model.WidgetDescriptor.InstalledPath.Replace("\\", "/") + "/" + path));
            }

            return("");
        }
示例#2
0
        public static dynamic ToJSON(this WidgetPackage pkg, IWidgetDescriptorRepository repository)
        {
            var widget = pkg.Model;
            var Url    = UrlUtility.CreateUrlHelper();
            //var repository = WebSiteContext.Current.DataContext.WidgetDescriptors;
            var installPath = pkg.Category + "\\" + pkg.Name;

            return(new
            {
                id = pkg.Name,
                category = pkg.Category,
                uid = widget.ID,
                name = new
                {
                    shortname = widget.Name != null ? widget.Name.ShortName : "Unknown",
                    fullname = widget.Name != null ? widget.Name.FullName : "Unknown"
                },
                icons = widget.Icons != null ? (widget.Icons.Select(i => new
                {
                    src = Url.Content(pkg.ResolveUri(i.Source)),
                    width = i.Width,
                    height = i.Height
                })) : null,
                desc = GE.GetContent(widget.Description),
                author = widget.Author != null ? new        //The user object is read from remote
                {
                    name = widget.Author.Name,
                    href = widget.Author.Uri,
                    email = widget.Author.Email
                } : null,
                totalUses = repository.InusingWidgetsCount(installPath),
                ratings = 0,       // from remote
                installed = repository.Contains(w => w.UID.Equals(widget.ID, StringComparison.OrdinalIgnoreCase)),
                version = widget.Version,
                languages = pkg.GetSupportLanguages(),
                //signed = pkg.HasSigned,
                //verified = pkg.Verify(),
                licenses = widget.Licenses != null ? (widget.Licenses.Select(l => new
                {
                    name = l.Text,
                    href = l.Source
                })) : null
                           //modified = tmpl.Modified
            });
        }
示例#3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var returnUrl = "";

            if (filterContext.RequestContext.RouteData.Values.ContainsKey("returnUrl"))
            {
                returnUrl = (string)filterContext.RequestContext.RouteData.Values["returnUrl"];
            }

            if (string.IsNullOrEmpty(returnUrl) && filterContext.HttpContext.Request.QueryString.AllKeys.Contains("returnUrl", StringComparer.OrdinalIgnoreCase))
            {
                returnUrl = filterContext.HttpContext.Request.QueryString["returnUrl"];
            }

            if (!string.IsNullOrEmpty(returnUrl) && UrlUtility.CreateUrlHelper().IsLocalUrl(returnUrl))
            {
                filterContext.Result = new RedirectResult(returnUrl);
            }
            else
            {
                base.OnActionExecuted(filterContext);
            }
        }
示例#4
0
        private static IEnumerable <DashboardGroup> GetItemGroups <T>(WebContext context)
            where T : DashboardBaseAttribute
        {
            var groups = new List <DashboardGroup>();
            var items  = new List <DashboardItem>();
            var url    = UrlUtility.CreateUrlHelper();

            var typeSearcher = TypeSearcher.Instance();
            var controllers  = typeSearcher.SearchTypesByBaseType(typeof(Controller));

            foreach (Type controller in controllers)
            {
                var methods = controller.GetMethods(BindingFlags.Public | BindingFlags.Instance);
                var actions = from MethodInfo method in methods
                              where (method.GetCustomAttributes(typeof(T), true).Length > 0)
                              select method;
                var sol = ModuleRegistration.Modules.Select(s => s.Value).FirstOrDefault(s => !string.IsNullOrEmpty(s.RouteName) && s.AssemblyFullName.Equals(controller.Assembly.FullName));

                foreach (MethodInfo action in actions)
                {
                    T      attr         = (T)Attribute.GetCustomAttribute(action, typeof(T));
                    string text         = attr.Text;
                    var    securityAttr = Attribute.GetCustomAttribute(action, typeof(SecurityActionAttribute));

                    if (securityAttr != null)
                    {
                        if (!context.HasPermisson(controller, action.Name))
                        {
                            continue;
                        }
                    }

                    var httpPostAttr = Attribute.GetCustomAttribute(action, typeof(HttpPostAttribute));
                    if (httpPostAttr != null)
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(attr.Text) && string.IsNullOrEmpty(attr.ResKey))
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(attr.ResKey))
                    {
                        if (!string.IsNullOrEmpty(attr.ResBaseName))
                        {
                            text = App.GetResourceString(attr.ResBaseName, attr.ResKey);
                        }
                        else
                        {
                            text = App.GetResourceString(attr.ResKey);
                        }
                    }

                    string _controller = controller.Name.Replace("Controller", "");
                    var    curGroup    = groups.FirstOrDefault(g => g.Name.Equals(attr.Group, StringComparison.OrdinalIgnoreCase));

                    if (curGroup == null)
                    {
                        curGroup = new DashboardGroup()
                        {
                            Name = attr.Group
                        };
                        groups.Add(curGroup);
                    }

                    if (!string.IsNullOrEmpty(attr.GroupResKey) && !string.IsNullOrEmpty(attr.ResBaseName) && string.IsNullOrEmpty(curGroup.Title))
                    {
                        curGroup.Title = App.GetResourceString(attr.ResBaseName, attr.GroupResKey);
                    }

                    var area = GetArea(controller);

                    var _item = new DashboardItem()
                    {
                        Order         = attr.Sequence,
                        Title         = text,
                        Icon          = attr.Icon,
                        Action        = action.Name,
                        Controller    = _controller,
                        Area          = area,
                        ImageUrl      = string.IsNullOrEmpty(attr.Icon) ? url.Content("~/content/images/icon_process_16.png") : url.Content("~/content/images/" + attr.Icon),
                        NavigationUrl = url.Action(action.Name, _controller, new { Area = area, website = context.Website, locale = context.Locale })
                    };

                    var _routeName = attr.RouteName;

                    if (sol != null && string.IsNullOrEmpty(_routeName))
                    {
                        if (typeof(T) == typeof(HostDashboardAttribute))
                        {
                            _routeName = "host_module_" + sol.Name + "_" + _controller + "_" + action.Name;
                        }
                        else
                        {
                            if (typeof(T) == typeof(MyDashboardAttribute))
                            {
                                _routeName = "mysite_" + sol.Name + "_" + _controller + "_" + action.Name;
                            }
                            else
                            {
                                _routeName = sol.RouteName;
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(_routeName))
                    {
                        var route       = RouteTable.Routes[_routeName] as Route;
                        var routeValues = new RouteValueDictionary(new
                        {
                            Area       = area,
                            website    = context.Website,
                            action     = action.Name,
                            controller = _controller,
                            locale     = context.Locale
                        });

                        var path = url.RouteUrl(_routeName, routeValues);

                        if (string.IsNullOrEmpty(path))
                        {
                            path = route.Url;
                            foreach (string key in route.Defaults.Keys)
                            {
                                path = path.Replace("{" + key + "}", routeValues.Keys.Contains(key) ? routeValues[key].ToString() : route.Defaults[key].ToString());
                            }

                            foreach (string key in route.Constraints.Keys)
                            {
                                var constr = route.Constraints[key].ToString();
                                if (!constr.StartsWith("("))
                                {
                                    path = path.Replace("{" + key + "}", constr);
                                }
                            }

                            foreach (string key in routeValues.Keys)
                            {
                                path = path.Replace("{" + key + "}", routeValues[key].ToString());
                            }
                        }
                        _item.NavigationUrl = url.Content("~/" + path);
                    }

                    if (curGroup.Items.Count(i => i.NavigationUrl.Equals(_item.NavigationUrl, StringComparison.OrdinalIgnoreCase)) == 0)
                    {
                        curGroup.Items.Add(_item);
                    }
                }
            }
            return(groups.OrderBy(g => g.Name).ToList());
        }