Beispiel #1
0
        /// <summary>
        /// Configure the data system to map requests for User type onto TUser via Identity mechanisms
        /// </summary>
        public virtual void InitialiseDataApi()
        {
            ContentTypeHierarchy.RegisterType(typeof(User));
            ContentTypeHierarchy.RegisterType(typeof(TUser));

            var sys = LyniconSystem.Instance;

            var extender = LyniconSystem.Instance.Extender;

            extender.RegisterForExtension(typeof(User));
            //extender.RegisterExtensionType(typeof(LyniconIdentityUser));

            var efDSFactory     = new EFDataSourceFactory <TContext>(sys);
            var appDbRepository = new BasicRepository(sys, efDSFactory);

            efDSFactory.DbSetSelectors[typeof(TUser)] = db => db.Users.AsNoTracking();
            efDSFactory.ContextLifetimeMode           = ContextLifetimeMode.PerCall;

            // We DON'T want to register TUser with CompositeTypeManager
            var basicCollator = new BasicCollator(sys);

            Collator.Instance.Register(typeof(TUser), new BasicCollator(sys));
            Repository.Instance.Register(typeof(TUser), appDbRepository);

            // override existing collator registration for User
            var identityAdaptorCollator = new IdentityAdaptorCollator <TUser, TUserManager>(sys);

            Collator.Instance.Register(typeof(User), identityAdaptorCollator);
            //Repository.Instance.Register(typeof(User), new BasicRepository());
        }
Beispiel #2
0
        /// <summary>
        /// Initialise the core dbcontext, the collator, the repository and the editor redirect for a content type
        /// </summary>
        /// <param name="t">content type</param>
        /// <param name="coll">the collator</param>
        /// <param name="repo">the repository</param>
        /// <param name="redir">the editor redirect</param>
        public void SetupType(Type t, ICollator coll, IRepository repo, DiversionStrategy divert)
        {
            if ((coll ?? this.Registered(null)).ContainerType(t) == t) // type t is its own container, so it may be extended
            {
                System.Extender.RegisterForExtension(t);
            }

            if (!typeof(IContentContainer).IsAssignableFrom(t))
            {
                ContentTypeHierarchy.RegisterType(t);
            }

            if (coll != null)
            {
                coll.System = this.System;
                this.Register(t, coll);
            }

            if (repo != null)
            {
                System.Repository.Register(t, repo);
            }

            if (divert != null)
            {
                DataDiverter.Instance.Register(t, divert);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a PageRoute with DataRoute functionality for providing data to routes in a classic ASP.Net application
        /// </summary>
        /// <typeparam name="TData">The type of the content data attached by the PageDataRoute</typeparam>
        /// <param name="routes">The route collection</param>
        /// <param name="name">Name of the route table entry</param>
        /// <param name="url">The url matching pattern</param>
        /// <param name="pageUrl">The url of the .aspx page template</param>
        /// <returns>The PageDataRoute that was created and registered</returns>
        static public DataRoute <TData> AddPageDataRoute <TData>(this RouteCollection routes, string name, string url, string pageUrl)
            where TData : class, new()
        {
            ContentTypeHierarchy.RegisterType(typeof(TData));
            var route = new DataRoute <TData>(url, new RouteValueDictionary(), new PageRouteHandler(pageUrl));

            routes.Add(name, route);
            return(route);
        }
        /// <summary>
        /// Configure the data system to map requests for User type onto TUser via Identity mechanisms
        /// </summary>
        public virtual void InitialiseDataApi()
        {
            ContentTypeHierarchy.RegisterType(typeof(User));
            var sys = LyniconSystem.Instance;

            sys.Extender.RegisterForExtension(typeof(User));

            Collator.Instance.Register(typeof(User), new BasicCollator(sys));
            Repository.Instance.Register(typeof(User), new BasicRepository(sys, new CoreDataSourceFactory(sys)));
        }
Beispiel #5
0
        /// <summary>
        /// Add a DataRoute to an RouteCollection with route name, url pattern, default values and constraints
        /// </summary>
        /// <typeparam name="TData">The type of the content data attached by the DataRoute</typeparam>
        /// <param name="routes">A RouteCollection to add the route to</param>
        /// <param name="name">Name of the route table entry</param>
        /// <param name="url">The url matching pattern</param>
        /// <param name="defaults">Default values for unmatched pattern elements</param>
        /// <param name="constraints">Constraints for when the route should match</param>
        /// <returns>The DataRoute that was created and registered</returns>
        static public DataRoute <TData> AddDataRoute <TData>(this RouteCollection routes, string name, string url, object defaults, object constraints)
            where TData : class, new()
        {
            ValidateRouteSpec(name, typeof(TData), url, defaults);
            ContentTypeHierarchy.RegisterType(typeof(TData));
            var route = new DataRoute <TData>(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new MvcRouteHandler());

            routes.Add(name, route);
            return(route);
        }
Beispiel #6
0
        /// <summary>
        /// Adds a route to the <see cref="IRouteBuilder"/> configured for data fetching, with the specified name, template, default values, and
        /// data tokens.
        /// </summary>
        /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param>
        /// <param name="name">The name of the route.</param>
        /// <param name="template">The URL pattern of the route.</param>
        /// <param name="defaults">
        /// An object that contains default values for route parameters. The object's properties represent the names
        /// and values of the default values.
        /// </param>
        /// <param name="constraints">
        /// An object that contains constraints for the route. The object's properties represent the names and values
        /// of the constraints.
        /// </param>
        /// <param name="dataTokens">
        /// An object that contains data tokens for the route. The object's properties represent the names and values
        /// of the data tokens.
        /// </param>
        /// <param name="writePermission">
        /// A permission object which specifies who can create or edit the content item via this route
        /// </param>
        /// <param name="divertOverride">
        /// A function which checks whether to switch out the default inner router with one which diverts the user
        /// to an editor controller
        /// </param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IRouteBuilder MapDataRoute <T>(
            this IRouteBuilder routeBuilder,
            string name,
            string template,
            object defaults    = null,
            object constraints = null,
            object dataTokens  = null,
            ContentPermission writePermission = null,
            DiversionStrategy divertOverride  = null)
            where T : class, new()
        {
            if (routeBuilder.DefaultHandler == null)
            {
                throw new InvalidOperationException("Default handler must be set");
            }

            var inlineConstraintResolver = (IInlineConstraintResolver)routeBuilder
                                           .ServiceProvider
                                           .GetService(typeof(IInlineConstraintResolver));

            // Interpose a DataFetchingRouter between the classic Route and the DefaultHandler, which
            // tries to fetch the data for the route
            var dataFetchingRouter = new DataFetchingRouter <T>(routeBuilder.DefaultHandler, false, writePermission, divertOverride);

            var dataRoute = new DataRoute(
                dataFetchingRouter,
                name,
                template,
                new RouteValueDictionary(defaults),
                new RouteValueDictionary(constraints),
                new RouteValueDictionary(dataTokens),
                inlineConstraintResolver);

            routeBuilder.Routes.Add(dataRoute);

            // Record the data route on Lynicon's internal RouteCollection used for reverse url generation
            if (ContentMap.Instance.RouteCollection == null)
            {
                ContentMap.Instance.RouteCollection = new RouteCollection();
            }
            ContentMap.Instance.RouteCollection.Add(dataRoute);

            Type registerType = typeof(T);

            if (registerType.IsGenericType() && registerType.GetGenericTypeDefinition() == typeof(List <>))
            {
                registerType = registerType.GetGenericArguments()[0];
            }

            ContentTypeHierarchy.RegisterType(registerType);

            return(routeBuilder);
        }
Beispiel #7
0
        public CoreModule(params string[] dependentOn)
            : base("Core", dependentOn)
        {
            if (!VerifyDbState("LyniconInit 0.1"))
            {
                this.Blocked = true;
                return;
            }

            ContentTypeHierarchy.RegisterType(typeof(User));

            Collator.Instance.SetupType(typeof(ContentItem), null, null);
            Collator.Instance.SetupType(typeof(User), new BasicCollator(Repository.Instance), new UserRepository());
        }
Beispiel #8
0
        /// <summary>
        /// Add a DataRoute to an RouteCollection with route name, url pattern, default values and constraints
        /// </summary>
        /// <typeparam name="TData">The type of the content data attached by the DataRoute</typeparam>
        /// <param name="routes">A RouteCollection to add the route to</param>
        /// <param name="name">Name of the route table entry</param>
        /// <param name="url">The url matching pattern</param>
        /// <param name="defaults">Default values for unmatched pattern elements</param>
        /// <param name="constraints">Constraints for when the route should match</param>
        /// <param name="dataTokens">Data tokens to add to the route</param>
        /// <param name="redirectOverride">An editor redirect to use with this route</param>
        /// <returns>The DataRoute that was created and registered</returns>
        static public DataRoute <TData> AddDataRoute <TData>(this RouteCollection routes, string name, string url, object defaults, object constraints, object dataTokens, IEditorRedirect redirectOverride)
            where TData : class, new()
        {
            ValidateRouteSpec(name, typeof(TData), url, defaults);
            ContentTypeHierarchy.RegisterType(typeof(TData));
            var route = new DataRoute <TData>(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new RouteValueDictionary(dataTokens), new MvcRouteHandler());

            if (redirectOverride != null)
            {
                route.RedirectOverride = redirectOverride;
            }
            routes.Add(name, route);
            return(route);
        }
Beispiel #9
0
        /// <summary>
        /// Add a DataRoute to an AreaRegistractionContext with route name, url pattern, default values and specific EditorRedirect to use
        /// </summary>
        /// <typeparam name="TData">The type of the content data attached by the DataRoute</typeparam>
        /// <param name="areaReg">An AreaRegistrationContext</param>
        /// <param name="name">Name of the route table entry</param>
        /// <param name="url">The url matching pattern</param>
        /// <param name="defaults">Default values for unmatched pattern elements</param>
        /// <param name="constraints">Constraints for when the route should match</param>
        /// <param name="dataTokens">Data tokens to add to the route</param>
        /// <param name="redirectOverride">An editor redirect to use with this route</param>
        /// <returns>The DataRoute that was created and registered</returns>
        static public DataRoute <TData> AddDataRoute <TData>(this AreaRegistrationContext areaReg, string name, string url, object defaults, object constraints, object dataTokens, IEditorRedirect redirectOverride)
            where TData : class, new()
        {
            ValidateRouteSpec(name, typeof(TData), url, defaults);
            ContentTypeHierarchy.RegisterType(typeof(TData));
            DataRoute <TData> route = areaReg.Routes.AddDataRoute <TData>(name, url, defaults, constraints, dataTokens, redirectOverride);

            route.DataTokens["area"] = areaReg.AreaName;

            // disabling the namespace lookup fallback mechanism keeps this areas from accidentally picking up
            // controllers belonging to other areas
            //bool useNamespaceFallback = (namespaces == null || namespaces.Length == 0);
            //route.DataTokens["UseNamespaceFallback"] = useNamespaceFallback;
            return(route);
        }
Beispiel #10
0
        public static void Initialise()
        {
            // Set up data types here
            ContentTypeHierarchy.RegisterType(typeof(HeaderContent));
            ContentTypeHierarchy.RegisterType(typeof(HeaderContent2));
            ContentTypeHierarchy.RegisterType(typeof(TestData));
            ContentTypeHierarchy.RegisterType(typeof(Sub1TContent));
            ContentTypeHierarchy.RegisterType(typeof(Sub2TContent));
            ContentTypeHierarchy.RegisterType(typeof(RefContent));
            ContentTypeHierarchy.RegisterType(typeof(RefTargetContent));
            ContentTypeHierarchy.RegisterType(typeof(PathAddressData));
            ContentTypeHierarchy.RegisterType(typeof(SplitAddressData));
            ContentTypeHierarchy.RegisterType(typeof(RestaurantContent));
            ContentTypeHierarchy.RegisterType(typeof(ChefContent));

            LyniconModuleManager.Instance.Initialise();
        }
Beispiel #11
0
        /// <summary>
        /// Adds a route to the <see cref="IRouteBuilder"/> configured for data fetching, with the specified name, template, default values, and
        /// data tokens.
        /// </summary>
        /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param>
        /// <param name="name">The name of the route.</param>
        /// <param name="template">The URL pattern of the route.</param>
        /// <param name="defaults">
        /// An object that contains default values for route parameters. The object's properties represent the names
        /// and values of the default values.
        /// </param>
        /// <param name="constraints">
        /// An object that contains constraints for the route. The object's properties represent the names and values
        /// of the constraints.
        /// </param>
        /// <param name="dataTokens">
        /// An object that contains data tokens for the route. The object's properties represent the names and values
        /// of the data tokens.
        /// </param>
        /// <param name="divertOverride">
        /// A function which checks whether to switch out the default inner router with one which diverts the user
        /// to an editor controller
        /// </param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IRouteBuilder MapDataRoute <T>(
            this IRouteBuilder routeBuilder,
            string name,
            string template,
            object defaults,
            object constraints,
            object dataTokens,
            Func <IRouter, RouteContext, object, IRouter> divertOverride)
            where T : class, new()
        {
            if (routeBuilder.DefaultHandler == null)
            {
                throw new InvalidOperationException("Default handler must be set");
            }

            var inlineConstraintResolver = (IInlineConstraintResolver)routeBuilder
                                           .ServiceProvider
                                           .GetService(typeof(IInlineConstraintResolver));

            // Interpose a DataFetchingRouter between the classic Route and the DefaultHandler, which
            // tries to fetch the data for the route
            var dataFetchingRouter = new DataFetchingRouter <T>(routeBuilder.DefaultHandler, false, divertOverride);

            var dataRoute = new DataRoute(
                dataFetchingRouter,
                name,
                template,
                new RouteValueDictionary(defaults),
                new RouteValueDictionary(constraints),
                new RouteValueDictionary(dataTokens),
                inlineConstraintResolver);

            routeBuilder.Routes.Add(dataRoute);

            // Record the data route on Lynicon's internal RouteCollection used for reverse url generation
            if (ContentMap.Instance.RouteCollection == null)
            {
                ContentMap.Instance.RouteCollection = new RouteCollection();
            }
            ContentMap.Instance.RouteCollection.Add(dataRoute);

            ContentTypeHierarchy.RegisterType(typeof(T));

            return(routeBuilder);
        }
        /// <summary>
        /// Configure the data system to map requests for User type onto TUser via Identity mechanisms
        /// </summary>
        public virtual void InitialiseDataApi()
        {
            ContentTypeHierarchy.RegisterType(typeof(TUser));
            CompositeTypeManager.Instance.RegisterExtensionType(typeof(LyniconIdentityUser));

            var efDSFactory     = new EFDataSourceFactory <TContext>();
            var appDbRepository = new BasicRepository(efDSFactory);

            efDSFactory.DbSetSelectors[typeof(TUser)] = db => db.Users.Include(u => u.Roles);
            efDSFactory.ContextLifetimeMode           = ContextLifetimeMode.PerCall;

            // We DON'T want to register TUser with CompositeTypeManager
            Collator.Instance.Register(typeof(TUser), new BasicCollator(Repository.Instance));
            Repository.Instance.Register(typeof(TUser), appDbRepository);

            // override existing collator registration for User
            var identityAdaptorCollator = new IdentityAdaptorCollator <TUser, TUserManager>(GetUserManager);

            identityAdaptorCollator.Repository = Repository.Instance;
            Collator.Instance.Register(typeof(User), identityAdaptorCollator);
        }
Beispiel #13
0
 public static void Init()
 {
     ContentTypeHierarchy.RegisterType(typeof(PropertyRedirectContent));
 }