public static void OnInitialized()
        {
            DataEventSystemFacade.SubscribeToDataBeforeUpdate <NewsItem>(NewsFacade.SetTitleUrl, true);
            DataEventSystemFacade.SubscribeToDataBeforeAdd <NewsItem>(NewsFacade.SetTitleUrl, true);

            DataUrls.RegisterGlobalDataUrlMapper <NewsItem>(new NewsDataUrlMapper());
        }
Ejemplo n.º 2
0
        public static void OnInitialized()
        {
            DataEventSystemFacade.SubscribeToDataBeforeUpdate <Entries>(BlogFacade.SetTitleUrl, true);
            DataEventSystemFacade.SubscribeToDataBeforeAdd <Entries>(BlogFacade.SetTitleUrl, true);

            DataEventSystemFacade.SubscribeToDataAfterAdd <Entries>(BlogFacade.ClearRssFeedCache, true);
            DataEventSystemFacade.SubscribeToDataAfterUpdate <Entries>(BlogFacade.ClearRssFeedCache, true);
            DataEventSystemFacade.SubscribeToDataDeleted <Entries>(BlogFacade.ClearRssFeedCache, true);

            DataUrls.RegisterGlobalDataUrlMapper <Entries>(new BlogEntryDataUrlMapper());
            UrlToEntityTokenFacade.Register(new BlogUrlToEntityTokenMapper());
        }
Ejemplo n.º 3
0
 public void AddUrlMapping(Type dataType, Guid pageId, string actionName = null, string fieldName = null)
 {
     DataUrls.RegisterGlobalDataUrlMapper(dataType, new MvcFunctionDataUrlMapper(dataType, pageId, actionName, fieldName));
 }
Ejemplo n.º 4
0
        public void AutoDiscoverFunctions(Assembly assembly)
        {
            foreach (var type in assembly.GetTypes().Where(IsController))
            {
                // Searching for [C1Function] attribute on controller or on its methods
                var attribute = type.GetCustomAttributes <C1FunctionAttribute>(false).SingleOrDefault();

                MvcControllerFunction controllerFunction = null;
                if (attribute != null)
                {
                    controllerFunction = RegisterController(type, attribute, null);
                }


                foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    var    actionNameAttribute = method.GetCustomAttributes <ActionNameAttribute>(false).SingleOrDefault();
                    string actionName          = actionNameAttribute != null ? actionNameAttribute.Name : method.Name;

                    MvcFunctionBase controlerToAttachUrlMapperTo = controllerFunction;
                    string          urlMapperAction = actionName;

                    attribute = method.GetCustomAttributes <C1FunctionAttribute>(false).SingleOrDefault();
                    if (attribute != null)
                    {
                        var routeAttribute = method.GetCustomAttributes <RouteAttribute>(false)
                                             .SingleOrDefaultOrException(
                            "Multiple [Route] attributes defined on method '{0}' of controller class '{1}'",
                            method.Name, type.FullName);

                        var parameters = routeAttribute != null?GetFunctionParameters(method, routeAttribute) : GetFunctionParameters(method);

                        var methodBasedMvcFunction = RegisterActionFunction(type, actionName, routeAttribute != null, attribute, parameters);

                        controlerToAttachUrlMapperTo = methodBasedMvcFunction;
                        urlMapperAction = null;
                    }

                    // Attaching url mappers
                    if (controlerToAttachUrlMapperTo != null)
                    {
                        var dynamicUrlMapperAttributes = method.GetCustomAttributes <DynamicUrlMapperAttribute>(false).ToList();
                        var globalUrlMapperAttributes  = method.GetCustomAttributes <GlobalUrlMapperAttribute>(false).ToList();

                        foreach (var mapperAttr in dynamicUrlMapperAttributes)
                        {
                            var mapper = new MvcFunctionDataUrlMapper(mapperAttr.DataType, null, urlMapperAction, mapperAttr.FieldName);
                            controlerToAttachUrlMapperTo.AssignDynamicUrlMapper(mapperAttr.DataType, mapper);
                        }

                        foreach (var mapperAttr in globalUrlMapperAttributes)
                        {
                            var mapper = new MvcFunctionDataUrlMapper(mapperAttr.DataType, mapperAttr.PageId, urlMapperAction, mapperAttr.FieldName);
                            DataUrls.RegisterGlobalDataUrlMapper(mapperAttr.DataType, mapper);
                        }
                    }
                }
            }

            MvcFunctionProvider.Reload();
        }