public static void ToString(ViewModelDescriptor obj, MethodReturnEventArgs<string> e)
 {
     e.Result = string.Format("{0} (default: {1}) [{2}]",
         obj.Description,
         obj.DefaultEditorKind,
         string.IsNullOrWhiteSpace(obj.ViewModelTypeRef) ? "(no type)" : obj.ViewModelTypeRef);
 }
示例#2
0
 public static void ToString(ViewModelDescriptor obj, MethodReturnEventArgs <string> e)
 {
     e.Result = string.Format("{0} (default: {1}) [{2}]",
                              obj.Description,
                              obj.DefaultEditorKind,
                              obj.ViewModelRef == null ? "(no type)" : obj.ViewModelRef.ToString());
 }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            EcardModel model = filterContext.Controller.ViewData.Model as EcardModel;

            if (model != null && model.Container == null)
            {
                var controller = filterContext.RouteData.Values["controller"].ToString();
                var action     = filterContext.RouteData.Values["action"].ToString();

                var controllerType = _controllerFinder.FindController(controller);
                if (controllerType == null)
                {
                    return;
                }

                var controllerTypeDesc = ViewModelDescriptor.GetTypeDescriptor(controllerType);

                PageContainer c = new PageContainer();
                c.Description = controllerTypeDesc.Description;
                c.DisplayName = controllerTypeDesc.LongName;
                c.Name        = controllerTypeDesc.Name;

                model.Container = c;
            }
        }
示例#4
0
 public static void GetName(ViewModelDescriptor obj, MethodReturnEventArgs <string> e)
 {
     if (obj.ViewModelRef != null)
     {
         e.Result = string.Format("Gui.ViewModelDescriptors.{0}", Regex.Replace(obj.ViewModelRef.ToTypeName(), @"\W", "_"));
     }
 }
 public static void ToString(ViewModelDescriptor obj, MethodReturnEventArgs<string> e)
 {
     e.Result = string.Format("{0} (default: {1}) [{2}]",
         obj.Description,
         obj.DefaultEditorKind,
         obj.ViewModelRef == null ? "(no type)" : obj.ViewModelRef.ToString());
 }
 public static void GetName(ViewModelDescriptor obj, MethodReturnEventArgs<string> e)
 {
     if (obj.ViewModelRef != null)
     {
         e.Result = string.Format("Gui.ViewModelDescriptors.{0}", Regex.Replace(obj.ViewModelRef.ToTypeName(), @"\W", "_"));
     }
 }
示例#7
0
        protected override void WriteFile(HttpResponseBase response)
        {
            var  type       = ViewModelDescriptor.GetTypeDescriptor(_itemType);
            Grid grid       = new Grid();
            var  user       = _securityHelper.GetCurrentUser();
            var  properties = type.Properties.Where(x => x.Show && (user == null || x.Permission.Check(user.CurrentUser))).OrderBy(x => x.Order).ToList();

            foreach (var propertyDescriptor in properties)
            {
                grid.Columns.Add(new GridColumn(propertyDescriptor.ShortName, 80));
            }

            foreach (var item in _items)
            {
                var row = grid.NewRow();
                for (int i = 0; i < properties.Count; i++)
                {
                    var propertyDescriptor = properties[i];
                    row[i].Text = string.Format(propertyDescriptor.ShortNameFormat, propertyDescriptor.GetValue(item));
                }
                grid.Rows.Add(row);
            }

            ExcelExport export = new ExcelExport();
            var         bytes  = export.Export(grid);

            response.BinaryWrite(bytes);
            response.End();
        }
示例#8
0
        public void Query()
        {
            var request = new TaskRequest();

            if (this.State != TaskStates.All)
            {
                request.State = State;
            }

            request.CommandTypeName = this.CommandType;
            var query = this.TaskService.Query(request);

            // fill condition
            List = query.ToList(this, x => new ListTask(x));

            // commandName, descripton object
            foreach (var task in List)
            {
                var type = Type.GetType(task.InnerObject.CommandTypeName, false, true);
                if (type != null)
                {
                    var desc = ViewModelDescriptor.GetTypeDescriptor(type);
                    task.CommandName = desc.Name;
                }
            }

            // users
            var userids =
                List.Select(x => x.InnerObject.CreatorId).Union(List.Select(x => x.InnerObject.EditorId)).ToArray();

            var users = MembershipService.GetByIds(userids).ToList();

            foreach (var task in List)
            {
                var user = users.FirstOrDefault(x => x.UserId == task.InnerObject.CreatorId);
                if (user != null)
                {
                    task.CreatorUserName = user.DisplayName;
                }
                user = users.FirstOrDefault(x => x.UserId == task.InnerObject.EditorId);
                if (user != null)
                {
                    task.EditorUserName = user.DisplayName;
                }
            }

            var accountIds =
                List.Select(x => x.InnerObject.AccountId).ToArray();
            var accounts = AccountService.GetByIds(accountIds);

            foreach (var task in List)
            {
                var account = accounts.FirstOrDefault(x => x.AccountId == task.InnerObject.AccountId);
                if (account != null)
                {
                    task.AccountName = account.Name;
                }
            }
        }
示例#9
0
 public TModelFactory CreateViewModel <TModelFactory>(ViewModelDescriptor desc) where TModelFactory : class
 {
     if (desc == null)
     {
         throw new ArgumentNullException("desc");
     }
     return(CreateViewModel <TModelFactory>(ResolveFactory(desc.ViewModelRef.AsType(true))));
 }
示例#10
0
        public static void GetName(ViewModelDescriptor obj, MethodReturnEventArgs<string> e)
        {
            if (!string.IsNullOrWhiteSpace(obj.ViewModelTypeRef) && obj.ViewModelTypeRef != "ERROR")
            {
                var spec = TypeSpec.Parse(obj.ViewModelTypeRef);

                e.Result = string.Format("Gui.ViewModelDescriptors.{0}", Regex.Replace(spec.GetSimpleName(addAssemblyNames: false), @"\W+", "_"));
            }
        }
示例#11
0
        public static RangeFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type type, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var rfmdl = new RangeFilterModel()
            {
                Label         = label,
                ValueSource   = predicate,
                ViewModelType = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_RangeFilterViewModel.Find(frozenCtx),
                RequestedKind = requestedKind,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl1  = null;
            BaseValueModel      mdl2  = null;

            if (type == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl1  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
                mdl2  = new DecimalValueModel("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <int>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl1  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
                mdl2  = new NullableStructValueModel <double>("", "", true, false, requestedArgumentKind);
            }
            else if (type == typeof(DateTime))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDateTimePropertyViewModel.Find(frozenCtx);
                mdl1  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
                mdl2  = new DateTimeValueModel("", "", true, false, DateTimeStyles.Date, requestedArgumentKind);
            }
            else
            {
                throw new NotSupportedException(string.Format("Rangefilters of Type {0} are not supported yet", type.Name));
            }

            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl1, vDesc));
            rfmdl.FilterArguments.Add(new FilterArgumentConfig(mdl2, vDesc));

            return(rfmdl);
        }
示例#12
0
        public void Ready()
        {
            var user = SecurityHelper.GetCurrentUser();
            var dashboardItemModels = (from x in DashboardItemRepository.Query()
                                       let controllerType = ControllerFinder.FindController(x.Controller)
                                                            let method = ViewModelDescriptor.GetTypeDescriptor(controllerType).GetMethod(x.Action)
                                                                         where method != null && method.Permission.Check(user.CurrentUser)
                                                                         select new DashboardItemModel(method, x)).ToList();

            List = dashboardItemModels;
        }
示例#13
0
        public static int PropertyCount(this HtmlHelper htmlHelper, Type itemType)
        {
            var  helper      = EcardContext.Container.Resolve <SecurityHelper>();
            User currentUser = helper.GetCurrentUser();
            var  buffer      = new StringBuilder();
            int  count       =
                ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where(
                    x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order).Count();

            return(count);
        }
示例#14
0
        public static MvcHtmlString Tds <TModel>(this HtmlHelper <TModel> htmlHelper, object item, Type itemType)
        {
            var  helper      = EcardContext.Container.Resolve <SecurityHelper>();
            User currentUser = helper.GetCurrentUser();
            var  buffer      = new StringBuilder();

            foreach (
                PropertyDescriptor propertyDescriptor in
                ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where(x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order))
            {
                buffer.Append(htmlHelper.Td(propertyDescriptor, item).ToHtmlString());
            }
            return(MvcHtmlString.Create(buffer.ToString()));
        }
示例#15
0
        public FilterArgumentConfig(IValueModel value, ViewModelDescriptor desc)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (desc == null)
            {
                throw new ArgumentNullException("desc");
            }

            this.Value         = value;
            this.ViewModelType = desc;
        }
示例#16
0
        /// <summary>
        /// Creates a default View for the given ViewModel.
        /// </summary>
        /// <param name="mdl">the model to be viewed</param>
        /// <returns>the configured view</returns>
        protected virtual object CreateDefaultView(ViewModel mdl)
        {
            if (mdl == null)
            {
                throw new ArgumentNullException("mdl");
            }

            ViewModelDescriptor pmd = mdl
                                      .GetType()
                                      .ToRef(FrozenContext)
                                      .GetViewModelDescriptor();

            var vDesc = mdl.RequestedKind != null
                ? pmd.GetViewDescriptor(Toolkit, mdl.RequestedKind)
                : pmd.GetViewDescriptor(Toolkit);

            return(CreateSpecificView(mdl, vDesc));
        }
示例#17
0
        public static MvcHtmlString Ths <TModel>(this HtmlHelper <TModel> htmlHelper, IEnumerable collection, Type itemType)
        {
            var         helper      = EcardContext.Container.Resolve <SecurityHelper>();
            User        currentUser = helper.GetCurrentUser().CurrentUser;
            IPageOfList pagedList   = null;

            pagedList = collection as IPageOfList;

            var buffer = new StringBuilder();

            foreach (
                PropertyDescriptor propertyDescriptor in
                ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where(x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order))
            {
                buffer.Append(htmlHelper.Th(propertyDescriptor, pagedList).ToHtmlString());
            }
            return(MvcHtmlString.Create(buffer.ToString()));
        }
示例#18
0
        /// <summary>
        /// Creates a specific View for the given ViewModel.
        /// </summary>
        /// <param name="mdl">the model to be viewed</param>
        /// <param name="kind">the kind of view to create</param>
        /// <returns>the configured view</returns>
        protected virtual object CreateSpecificView(ViewModel mdl, ControlKind kind)
        {
            if (mdl == null)
            {
                throw new ArgumentNullException("mdl");
            }
            if (kind == null)
            {
                throw new ArgumentNullException("kind");
            }

            ViewModelDescriptor pmd = mdl.GetType().ToRef(FrozenContext)
                                      .GetViewModelDescriptor();

            var vDesc = pmd.GetViewDescriptor(Toolkit, kind);

            return(CreateSpecificView(mdl, vDesc));
        }
示例#19
0
        /// <summary>
        /// Returns a list of the specified ViewModelDescriptor and its parents descriptors.
        /// </summary>
        /// <param name="pmd">the ViewModelDescriptor to inspect</param>
        /// <returns>a list, containing the requested ViewModelDescriptors sorted by ascending inheritance</returns>
        public static List <ViewModelDescriptor> AndParents(this ViewModelDescriptor pmd)
        {
            var result = new List <ViewModelDescriptor>();

            result.Add(pmd);
            var parent = pmd.ViewModelRef.Parent;

            while (parent != null)
            {
                var parentDescriptor = parent.GetViewModelDescriptor();
                if (parentDescriptor != null)
                {
                    result.Add(parentDescriptor);
                }
                parent = parent.Parent;
            }
            return(result);
        }
示例#20
0
        private static IList <TypeRef> GetAllTypes(ViewModelDescriptor self)
        {
            var allTypes = new List <TypeRef>();
            var type     = self.ViewModelRef;

            while (type != null)
            {
                allTypes.Add(type);
                type = type.Parent;
            }

            allTypes.AddRange(
                self.ViewModelRef.AsType(false).GetInterfaces()
                .OrderBy(i => i.FullName)
                .Select(i => i.ToRef(self.ReadOnlyContext))
                .Where(i => i != null)
                );
            return(allTypes);
        }
示例#21
0
        private static DataTemplate SelectDefaultTemplate(ViewModel mdl, IFrozenContext frozenCtx)
        {
            var tr = GetTypeRef(mdl, frozenCtx);

            if (tr == null)
            {
                return(null);
            }

            ViewModelDescriptor pmd = tr.GetViewModelDescriptor();

            if (pmd == null)
            {
                Logging.Log.ErrorFormat("No matching ViewModelDescriptor found for {0}", mdl.GetType());
                return(null);
            }

            return(CreateTemplate(pmd.GetViewDescriptor(Toolkit.WPF)));
        }
示例#22
0
        public static ViewModelDescriptor GetViewModelDescriptor(this TypeRef tr)
        {
            if (tr == null)
            {
                throw new ArgumentNullException("tr");
            }

            PrimeCaches(null, tr.ReadOnlyContext);

            ViewModelDescriptor result = null;

            while (result == null && tr != null)
            {
                if (_pmdCache.ContainsKey(tr.ExportGuid))
                {
                    result = _pmdCache[tr.ExportGuid];
                }
                tr = tr.Parent;
            }
            return(result);
        }
示例#23
0
        private static List<Type> GetAllTypes(ViewModelDescriptor self)
        {
            var result = new List<Type>();
            var type = Type.GetType(self.ViewModelTypeRef);

            GetAllTypes(type, result);
            result.Reverse();

            return result;
        }
示例#24
0
        private static IList<TypeRef> GetAllTypes(ViewModelDescriptor self)
        {
            var allTypes = new List<TypeRef>();
            var type = self.ViewModelRef;
            while (type != null)
            {
                allTypes.Add(type);
                type = type.Parent;
            }

            allTypes.AddRange(
                self.ViewModelRef.AsType(false).GetInterfaces()
                    .OrderBy(i => i.FullName)
                    .Select(i => i.ToRef(self.ReadOnlyContext))
                    .Where(i => i != null)
            );
            return allTypes;
        }
示例#25
0
        public static DialogCreator AddString(this DialogCreator c, object key, string label, string value = null, bool allowNullInput = false, bool isReadOnly = false, ControlKind requestedKind = null, ViewModelDescriptor vmdesc = null, string description = null, string helpText = null)
        {
            if (c == null) throw new ArgumentNullException("c");
            if (key == null) throw new ArgumentNullException("key");

            var mdl = new ClassValueModel<string>(label, description, allowNullInput, isReadOnly);
            mdl.Value = value;
            mdl.HelpText = helpText;

            BaseValueViewModel vmdl;
            if (vmdesc != null)
                vmdl = c.ViewModelFactory.CreateViewModel<StringValueViewModel.Factory>(vmdesc).Invoke(c.DataContext, null, mdl);
            else
                vmdl = c.ViewModelFactory.CreateViewModel<StringValueViewModel.Factory>().Invoke(c.DataContext, null, mdl);

            if (requestedKind != null)
                vmdl.RequestedKind = requestedKind;

            c.Add(key, vmdl);
            return c;
        }
示例#26
0
 /// <summary>
 /// Returns the default editor control kind for use in grid cells of a given ViewModelDescriptor. If empty, default grid cell is returned
 /// </summary>
 /// <param name="pmd"></param>
 /// <returns></returns>
 public static ControlKind GetDefaultGridCellEditorKind(this ViewModelDescriptor pmd)
 {
     return(pmd.AndParents().Select(p => p.DefaultGridCellEditorKind).FirstOrDefault(ck => ck != null) ?? pmd.GetDefaultEditorKind());
 }
示例#27
0
 /// <summary>
 /// Looks up the default ViewDesriptor matching the ViewModel and Toolkit;
 /// uses the ViewModelDescriptor's DefaultVisualType
 /// </summary>
 /// <param name="pmd">the specified ViewModelDescriptor</param>
 /// <param name="tk">the specified Toolkit</param>
 /// <returns>the default ViewDescriptor to display this ViewModel with this Toolkit</returns>
 public static ViewDescriptor GetViewDescriptor(
     this ViewModelDescriptor pmd,
     Toolkit tk)
 {
     return(GetViewDescriptor(pmd, tk, GetDefaultEditorKind(pmd)));
 }
示例#28
0
        //// Steps for resolving a ViewModel to View
        //// 1. Find all ViewModel requested Views matching the ControlKind
        //// 2. Find all Views supporting the ViewModel matching the ControlKind
        //// 3. Find all Views supporting the ViewModel without ControlKind

        /// <summary>
        /// Look up the ViewDescriptor for this presentable model and ControlKind
        /// </summary>
        /// <param name="self"></param>
        /// <param name="tk"></param>
        /// <param name="requestedControlKind"></param>
        /// <returns></returns>
        public static ViewDescriptor GetViewDescriptor(
            this ViewModelDescriptor self,
            Toolkit tk,
            ControlKind requestedControlKind)
        {
            // Checks
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }

            #region Cache Management
            PrimeCaches(tk, self.ReadOnlyContext);

            var key = new ViewDescriptorCache.Key(self.ViewModelRef, tk, requestedControlKind);
            if (_viewDescriptorCache.ContainsKey(key))
            {
                return(_viewDescriptorCache[key]);
            }
            #endregion

            // If the ViewModel has a more specific DefaultKind respect its choice
            if (self.DefaultEditorKind != null &&
                requestedControlKind != null &&
                self.DefaultEditorKind.AndParents().Select(i => i.ExportGuid).Contains(requestedControlKind.ExportGuid))
            {
                if (requestedControlKind != self.DefaultEditorKind)
                {
                    Logging.Log.DebugFormat("Using more specific default kind: {0} -> {1}", requestedControlKind.Name, self.DefaultEditorKind.Name);
                }
                requestedControlKind = self.DefaultEditorKind;
            }
            else
            {
                requestedControlKind = self.SecondaryControlKinds
                                       .FirstOrDefault(
                    sck => sck.AndParents()
                    .Select(i => i.ExportGuid)
                    .Contains(requestedControlKind.ExportGuid)
                    ) ?? requestedControlKind;
            }

            ViewDescriptor result = null;

            ICollection <ViewDescriptor> candidates;
            if (requestedControlKind != null)
            {
                candidates = _viewCaches[tk].GetDescriptors(requestedControlKind);
            }
            else
            {
                candidates = _viewCaches[tk].GetDescriptors();
            }

            if (candidates.Count == 0)
            {
                // Try parent
                var parent = self.ViewModelRef.Parent != null?self.ViewModelRef.Parent.GetViewModelDescriptor() : null;

                if (parent != null)
                {
                    result = GetViewDescriptor(parent, tk, requestedControlKind);
                }
                else
                {
                    Logging.Log.WarnFormat("Couldn't find ViewDescriptor for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.ViewModelRef);
                }
            }
            else if (candidates.Count == 1)
            {
                result = candidates.First();
            }
            else
            {
                var allTypes = GetAllTypes(self);
                // As allTypes is sorted from most specific to least specific first or default is perfect.
                var match = allTypes.SelectMany(t => candidates.Where(c => c.SupportedViewModels.Contains(t))).FirstOrDefault();

                // Try the most common
                if (match == null)
                {
                    match = allTypes.SelectMany(t => candidates.Where(c => c.SupportedViewModels.Count == 0)).FirstOrDefault();
                }

                // Log a warning if nothing found
                if (match == null)
                {
                    Logging.Log.WarnFormat("Couldn't find ViewDescriptor for '{1}' matching ControlKind: '{0}'", requestedControlKind, self.GetType().FullName);
                }
                result = match;
            }

            _viewDescriptorCache[key] = result;
            return(result);
        }
示例#29
0
        public static SingleValueFilterModel Create(IFrozenContext frozenCtx, string label, IFilterValueSource predicate, Type propType, ControlKind requestedKind, ControlKind requestedArgumentKind)
        {
            if (frozenCtx == null)
            {
                throw new ArgumentNullException("frozenCtx");
            }
            if (propType == null)
            {
                throw new ArgumentNullException("propType");
            }

            var fmdl = new SingleValueFilterModel()
            {
                Label                  = label,
                ValueSource            = predicate,
                Operator               = FilterOperators.Equals,
                ViewModelType          = ViewModelDescriptors.Zetbox_Client_Presentables_FilterViewModels_SingleValueFilterViewModel.Find(frozenCtx),
                RequestedKind          = requestedKind,
                RefreshOnFilterChanged = false,
            };

            ViewModelDescriptor vDesc = null;
            BaseValueModel      mdl   = null;

            if (propType == typeof(decimal))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableDecimalPropertyViewModel.Find(frozenCtx);
                mdl   = new DecimalValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(int))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Int32_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <int>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(double))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableStructValueViewModel_1_System_Double_.Find(frozenCtx);
                mdl   = new NullableStructValueModel <double>(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(bool))
            {
                vDesc = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_NullableBoolPropertyViewModel.Find(frozenCtx);
                fmdl.RefreshOnFilterChanged = true;
                if (requestedArgumentKind == null)
                {
                    requestedArgumentKind = NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_DropdownBoolKind.Find(frozenCtx);
                }
                mdl = new BoolValueModel(label, "", true, false, requestedArgumentKind);
            }
            else if (propType == typeof(string))
            {
                vDesc         = ViewModelDescriptors.Zetbox_Client_Presentables_ValueViewModels_ClassValueViewModel_1_System_String_.Find(frozenCtx);
                mdl           = new ClassValueModel <string>(label, "", true, false, requestedArgumentKind);
                fmdl.Operator = FilterOperators.Contains;
            }
            else
            {
                throw new NotSupportedException(string.Format("Singlevalue filters of Type {0} are not supported yet", propType.Name));
            }

            fmdl.FilterArguments.Add(new FilterArgumentConfig(mdl, vDesc));
            return(fmdl);
        }
示例#30
0
        public static MvcHtmlString Link(this HtmlHelper htmlHelper, string action, string controller, object routeValues, bool textEnabled, string template, bool?isPost = null)
        {
            action     = action ?? htmlHelper.ViewContext.RouteData.Values["action"] as string;
            controller = controller ?? htmlHelper.ViewContext.RouteData.Values["controller"] as string;
            var controllerFinder = ExtensionsHelper.Resolve <IControllerFinder>();

            Type controllerType = controllerFinder.FindController(controller);

            if (controllerType == null)
            {
                return(MvcHtmlString.Empty);
            }

            MethodInfo method = controllerType.GetMethods().FirstOrDefault(x => string.Equals(x.Name, action, StringComparison.InvariantCultureIgnoreCase));

            if (method == null)
            {
                return(MvcHtmlString.Empty);
            }

            isPost = isPost ?? method.GetAttribute <HttpPostAttribute>(false) != null;
            ViewModelDescriptor controllerTypeDesc = ViewModelDescriptor.GetTypeDescriptor(controllerType);

            MethodDescriptor methodDesc = controllerTypeDesc.GetMethod(action);

            if (methodDesc == null)
            {
                return(MvcHtmlString.Empty);
            }

            User user = EcardContext.Container.Resolve <SecurityHelper>().GetCurrentUser();

            if (user != null)
            {
                if (!methodDesc.Permission.Check(user))
                {
                    return(MvcHtmlString.Empty);
                }
            }

            string text        = textEnabled ? methodDesc.Name : "";
            string icon        = methodDesc.ToolbarIcon;
            string description = methodDesc.Description;
            string confirm     = methodDesc.Confirm;
            RouteValueDictionary routeValueDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(routeValues);

            if (routeValues is RouteValueDictionary)
            {
                routeValueDictionary = (RouteValueDictionary)routeValues;
            }


            return(htmlHelper.Partial(GetTemplateName(template), new ActionModel
            {
                IsPost = (bool)isPost,
                ConfirmMessage = confirm,
                Text = text,
                Icon = icon,
                Description = description,
                Action = action,
                Controller = controller,
                RouteValues = routeValueDictionary
            }));
        }
示例#31
0
 public static DialogCreator AddMultiLineString(this DialogCreator c, object key, string label, string value = null, bool allowNullInput = false, bool isReadOnly = false, ViewModelDescriptor vmdesc = null, string description = null, string helpText = null)
 {
     if (c == null) throw new ArgumentNullException("c");
     return AddString(c, key, label, value, allowNullInput, isReadOnly, Zetbox.NamedObjects.Gui.ControlKinds.Zetbox_App_GUI_MultiLineTextboxKind.Find(c.FrozenCtx), vmdesc, description, helpText);
 }
示例#32
0
        private MenuItem AddChildren(XElement parent, int level)
        {
            var children = parent.Elements("node");

            if (children.Count() == 0)
            {
                var controllerType = _controllerFinder.FindController((string)parent.Attribute("controller"));
                if (controllerType == null)
                {
                    return(null);
                }

                var typeDescriptor = ViewModelDescriptor.GetTypeDescriptor(controllerType);
                var actionMethod   = typeDescriptor.GetMethod((string)parent.Attribute("action"));
                if (actionMethod == null)
                {
                    return(null);
                }


                return(new MenuItem("", (string)parent.Attribute("title") ?? actionMethod.Name,
                                    actionMethod.Description, actionMethod.Permission,
                                    (string)parent.Attribute("controller"), (string)parent.Attribute("action"),
                                    (string)parent.Attribute("parameterObject"))
                {
                    Level = level
                });
            }
            else
            {
                var menuItem = new MenuItem((string)parent.Attribute("name"), (string)parent.Attribute("title"),
                                            (string)parent.Attribute("desc"), new Allow())
                {
                    Level = level
                };
                if (parent.Attribute("controller") != null)
                {
                    var controllerType = _controllerFinder.FindController((string)parent.Attribute("controller"));
                    if (controllerType != null)
                    {
                        var typeDescriptor = ViewModelDescriptor.GetTypeDescriptor(controllerType);
                        var actionMethod   = typeDescriptor.GetMethod((string)parent.Attribute("action"));
                        if (actionMethod == null)
                        {
                            return(null);
                        }

                        menuItem = new MenuItem("", (string)parent.Attribute("title") ?? actionMethod.Name,
                                                actionMethod.Description, actionMethod.Permission,
                                                (string)parent.Attribute("controller"), (string)parent.Attribute("action"),
                                                (string)parent.Attribute("parameterObject"))
                        {
                            Level = level
                        };
                    }
                }
                foreach (var xnode in children)
                {
                    var childMenuItem = AddChildren(xnode, level + 1);
                    if (childMenuItem != null)
                    {
                        menuItem.Add(childMenuItem);
                    }
                }
                return(menuItem);
            }
        }