public static void BuildModel(LyniconSystem sys) { //if (!Collator.Instance.RepositoryBuilt) // throw new Exception("In CoreDb.OnModelCreating because there was a use of CoreDb before repository was built"); Debug.WriteLine("Building SummaryDb"); var requiredBaseTypes = ContentTypeHierarchy.AllContentTypes .Select(ct => Collator.Instance.ContainerType(ct)) .Select(crt => sys.Extender.ExtensionTypes().Contains(crt) ? sys.Extender.Base(crt) : crt) .Distinct() .Where(crt => Repository.Instance.Registered(crt).DataSourceFactory is CoreDataSourceFactory) .ToList(); var builder = new ModelBuilder(SqlServerConventionSetBuilder.Build()); sys.Extender.BaseTypes.Do(t => builder.Ignore(t)); foreach (var sumsType in sys.Extender.BaseTypes.Where(bt => requiredBaseTypes.Contains(bt))) { builder.Entity(sys.Extender.Summarised(sumsType)).ToTable(LinqX.GetTableName(sumsType)); } SummaryModel = builder.Model; }
/// <summary> /// Create a new BasicRepository /// </summary> public BasicRepository(LyniconSystem sys, IDataSourceFactory dataSourceFactory) { IdName = null; this.DataSourceFactory = dataSourceFactory; QueryTimeoutSecs = null; System = sys; }
public CoreDataSource(LyniconSystem sys, ContextLifetimeMode contextLifetimeMode, bool forSummaries) { this.contextLifetimeMode = contextLifetimeMode; System = sys; DataSourceSpecifier = sys.Settings.SqlConnectionString; Db = GetDb(dbc => sys.Settings.ApplyDbContext(dbc, DataSourceSpecifier), forSummaries); }
public ContentRepository(LyniconSystem sys, IDataSourceFactory dataSourceFactory) { BypassChangeProblems = false; DataSourceFactory = dataSourceFactory; System = sys; System.Repository.Register(typeof(ContentItem), this); }
public EFDataSource(LyniconSystem sys, Dictionary <Type, Func <TContext, IQueryable> > dbSetSelectors, ContextLifetimeMode contextLifetimeMode, bool forSummaries) { this.System = sys; this.contextLifetimeMode = contextLifetimeMode; this.dbSetSelectors = dbSetSelectors; Db = GetDb(); }
public LyniconSystemFixture() { ContentTypeHierarchy.RegisterControllersFromAssemblies(new List <Assembly> { this.GetType().GetTypeInfo().Assembly }); LyniconSystem = new LyniconSystem(new LyniconSystemOptions() .UseTypeSetup(col => { col.SetupTypeForBasic <TestData>(); col.SetupType <HeaderContent>(); col.SetupType <HeaderContent2>(); col.SetupType <Sub1TContent>(); col.SetupType <Sub2TContent>(); col.SetupType <RefContent>(); col.SetupType <RefTargetContent>(); col.SetupType <RestaurantContent>(); col.SetupType <ChefContent>(); col.SetupType <PathAddressData>(); col.SetupType <SplitAddressData>(); col.SetupType <PropertyRedirectContent>(); col.SetupTypeForBasic <RedirectData>(); col.SetupType <RedirectTargetContent>(); col.SetupType <SingleContent>(); col.System.Repository.Register(null, new ContentRepository(col.System, new MockDataSourceFactory(col.System))); col.System.Repository.Register(typeof(TestData), new BasicRepository(col.System, new MockDataSourceFactory(col.System))); col.System.Repository.Register(typeof(RedirectData), new BasicRepository(col.System, new MockDataSourceFactory(col.System))); col.System.Repository.Register(typeof(ContentItem), new ContentRepository(col.System, new MockDataSourceFactory(col.System))); })); LyniconSystem.Extender.AddExtensionRule(typeof(TestData), typeof(IExtTestData)); LyniconSystem.Extender.AddExtensionRule(typeof(ICoreMetadata), typeof(IPublishable)); LyniconSystem.Extender.AddExtensionRule(typeof(ICoreMetadata), typeof(IInternational)); LyniconSystem.Construct(new Lynicon.Extensibility.Module[] { new CoreModule(LyniconSystem) }); LyniconSystem.Modules.SkipDbStateCheck = true; LyniconSystem.SetAsPrimarySystem(); LyniconSystem.Initialise(); //SetupLyniconSystemWithDb(); //VersionManager.Instance.RegisterVersion(new TestVersioner()); var testingRoutes = new RouteCollection(); testingRoutes.AddTestDataRoute <HeaderContent>("header", "header/{_0}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <TestData>("test-data", "testd/{_0}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <ChefContent>("chef", "header/{_0}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <HeaderContent2>("hc2", "header2", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <SingleContent>("single", "single/{abc}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <RefContent>("ref", "ref/{_0}/{_1}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <RestaurantContent>("rest", "restaurant/{abc}", new { controller = "mock", action = "mock" }); testingRoutes.AddTestDataRoute <HeaderContent>("header-write", "header-write/{_0}", new { controller = "mock", action = "mock" }, new ContentPermission((roles, data) => true)); ContentMap.Instance.RouteCollection = testingRoutes; VersionManager.Instance.RegisterVersion(new PublishingVersioner(LyniconSystem, t => t == typeof(HeaderContent))); VersionManager.Instance.RegisterVersion(new I18nVersioner(LyniconSystem, new string[] { "en-GB", "es-ES" }, "locale", "en-GB", s => s)); Collator.Instance.SetupType <TestContent>(new TestCollator(), null); }
/// <summary> /// Construct a module with caching /// </summary> /// <param name="name">Name of the module</param> /// <param name="dependentOn">List of names of other modules this is dependent on (these will start up before this one)</param> public Cache(LyniconSystem sys, IHostingEnvironment env, string name, params string[] dependentOn) : base(sys, name, dependentOn) { hosting = env; SerializationMode = CacheSerialization.Json; Serializer = new JsonSerializer { TypeNameHandling = TypeNameHandling.All }; }
/// <summary> /// Construct a general collator from its associated global repository /// </summary> /// <param name="repository"></param> public Collator(LyniconSystem sys) { RepositoryBuilt = false; System = sys; sys.Collator = this; this.DefaultHandler = new ContentCollator(sys) as ICollator; }
public I18nVersioner(LyniconSystem sys, string[] localeSet, string localeRouteKey, string defaultLocale, Func <string, string> routeLocaleFromLocale, Func <Type, bool> isVersionable) : base(sys, isVersionable) { this.localeSet = localeSet; this.localeRouteKey = localeRouteKey; this.defaultLocale = defaultLocale; this.routeLocaleFromLocale = routeLocaleFromLocale; }
public void EnsureSummaryCache(LyniconSystem sys) { if (summary != null) { this.GetSummary(sys); this.summaryObject = null; // no longer needed: save space } }
public Repository(LyniconSystem sys) { this.System = sys; sys.Repository = this; this.DefaultHandler = new ContentRepository(sys, new CoreDataSourceFactory(sys)); this.NoTypeProxyingInScope = true; this.QueryTimeoutSecs = null; this.AvoidConnection = false; }
public IdentityAdaptorSecurityManager( LyniconSystem sys, Func <TContext> getContext, Func <UserManager <TUser> > getUserManager, Func <SignInManager <TUser> > getSignInManager) { this.getContext = getContext; this.getUserManager = getUserManager; this.getSignInManager = getSignInManager; }
/// <summary> /// Get the Summaries of the content items which contain references to a given content item /// </summary> /// <typeparam name="TContent">The type of the content item referred to</typeparam> /// <param name="sys">The Lynicon system in which this process is to run</param> /// <param name="o">The content item or container to which the references refer</param> /// <param name="propertyName">The property name on the referring content item of the reference being considered</param> /// <returns>The summaries of all the content items referring to the target</returns> public static IEnumerable <Summary> GetReferencesFrom <TContent>(LyniconSystem sys, object o, string propertyName) where TContent : class { if (o is IContentContainer) { return(GetReferencesFrom <TContent>(sys, new ItemVersionedId(sys, o), propertyName)); } var cont = sys.Collator.GetContainer(o); return(GetReferencesFrom <TContent>(sys, cont, propertyName)); }
/// <summary> /// Given a container, extract its ItemVersionedId (which may be abstract) and generate /// a list of all the specifically versioned ItemVersionedIds that are included in it /// </summary> /// <param name="container">A container</param> /// <returns>A list of specific ItemVersionedIds</returns> public static List <ItemVersionedId> CreateExpanded(LyniconSystem sys, object container) { var vsn = new ItemVersion(sys, container); ItemId iid = new ItemId(sys.Collator, container); var res = new List <ItemVersionedId>(); foreach (var v in vsn.MatchingVersions(sys.Versions, iid.Type)) { res.Add(new ItemVersionedId(iid, v)); } return(res); }
/// <summary> /// Creates a list of VersionedAddresses by taking the (possibly abstract) version of the versioned /// address of a container, and producing all the specific versions contained in it attached to the /// ItemId of the container /// </summary> /// <param name="container">The container</param> /// <returns>List of specific VersionedAddresses</returns> public static List <VersionedAddress> CreateExpanded(LyniconSystem sys, object container) { var vsn = new ItemVersion(sys, container); Address a = new Address(container); var res = new List <VersionedAddress>(); foreach (var v in vsn.MatchingVersions(sys.Versions, a.Type)) { res.Add(new VersionedAddress(a, v)); } return(res); }
/// <summary> /// Add services for Lynicon /// </summary> /// <param name="services">The services collection</param> /// <param name="optionsAction">Action to build options</param> /// <returns>LyniconSystemBuilder for chaining</returns> public static LyniconSystemBuilder AddLynicon(this IServiceCollection services, Action <LyniconSystemOptions> optionsAction) { var options = new LyniconSystemOptions(); optionsAction(options); var lynSystem = new LyniconSystem(options); lynSystem.SetAsPrimarySystem(); LyniconSystem.Instance = lynSystem; services.AddSingleton <LyniconSystem>(lynSystem); services.AddSingleton <IAuthorizationHandler, ContentPermissionHandler>(); services.AddSingleton <ICommandRunner, CommandRunner>(); return(new LyniconSystemBuilder(lynSystem, services)); }
/// <summary> /// Create a module supplying its name and the names of any modules on which it is dependent. /// </summary> /// <param name="name">Name of the module</param> /// <param name="dependentOn">Names (if any) of modules on which it is dependent</param> public Module(LyniconSystem system, string name, params string[] dependentOn) { Name = name; System = system; DependentOn = dependentOn == null ? new List <string>() : dependentOn.ToList(); MustFollow = DependentOn; MustPrecede = new List <string>(); IncompatibleWith = new List <string>(); Blocked = false; ManagerView = null; Error = null; AppliesToType = t => true; NeverAppliesTo = new List <Type>(); }
public EFDataSourceFactory(LyniconSystem sys) { System = sys; DbSetSelectors = typeof(TContext).GetProperties() .Where(pi => pi.PropertyType.IsGenericType() && pi.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>)) .ToDictionary( pi => pi.PropertyType.GenericTypeArguments[0], pi => { var x = Expression.Parameter(typeof(TContext)); var getDbSet = Expression.MakeMemberAccess(x, pi); var castDbSet = Expression.TypeAs(getDbSet, typeof(IQueryable)); var selector = Expression.Lambda <Func <TContext, IQueryable> >(castDbSet, x); return(selector.Compile()); }); }
/// <summary> /// Run the initialise method on all operating modules in the correct order. If initialisation /// fails or returns false, the module is blocked, which may in a cascade block other modules /// dependent on it. /// </summary> public void Initialise(LyniconSystem sys) { foreach (Module module in ModuleSequence) { if (module.DependentOn.Any(mn => Modules[mn].Blocked)) { module.Blocked = true; log.ErrorFormat("Module {0} dependent on a blocked module", module.Name); module.Error = "Dependent on blocked module"; continue; } try { bool initialised = module.Initialise(); if (!initialised) { module.Blocked = true; log.ErrorFormat("Module {0} blocked, initialiser returned false", module.Name); if (module.Error == null) { module.Error = "Initialiser returned false"; } } } catch (Exception ex) { module.Blocked = true; log.Error("Module " + module.Name + " blocked, initialisation exception", ex); module.Error = "Initialisation exception: " + ex.ToHtml(); } } Initialised = true; // Tell UI to show an alert if there was a problem and this is the primary module manager if (this.AnyBlocked && this == Instance) { LyniconUi.Instance.ShowProblemAlert = true; } // Run any registered startup processes Task.Run(() => sys.Events.ProcessEvent("StartupProcess", null, null)); }
/// <summary> /// Get the summary of the contained content item /// </summary> /// <returns>The summary</returns> public Summary GetSummary(LyniconSystem sys) { if (summaryObject != null) { summaryObject.Version = sys.Versions.GetVersion(this); return(summaryObject); } var summType = GetSummaryType(ContentType); var summMap = GetSummaryProperties(ContentType); if (summMap.Count > 0 && !string.IsNullOrEmpty(this.Summary)) { summaryObject = (Summary)JsonConvert.DeserializeObject(this.Summary, summType, GetSerializerSettings(summType, this.Id)); } else { summaryObject = null; } if (summaryObject == null) { summaryObject = new Summary(); Type contentType = this.ContentType; if (typeof(PageContent).IsAssignableFrom(contentType)) { // The call to GetContent with an empty TypeExtender won't create an extended type but this is no problem PageContent pageContent = this.GetContent <PageContent>(new TypeExtender()); summaryObject.Title = pageContent.PageTitle; } } summaryObject.Url = ContentMap.Instance.GetUrl(this); summaryObject.Type = ContentType; summaryObject.Id = this.Identity; summaryObject.Version = sys.Versions.GetVersion(this); if (!string.IsNullOrEmpty(this.Title)) { summaryObject.Title = this.Title; } summaryObject.UniqueId = this.Id; return(summaryObject); }
/// <summary> /// Get the Summaries of the content items which contain references to a given content item /// </summary> /// <typeparam name="TContent">The type of the content item referred to</typeparam> /// <param name="sys">The Lynicon system in which this process is to run</param> /// <param name="ividToItem">The ItemVersionedId of the item to which the references refer</param> /// <param name="propertyName">The property name on the referring content item of the reference being considered</param> /// <returns>The summaries of all the content items referring to the target</returns> public static IEnumerable <Summary> GetReferencesFrom <TContent>(LyniconSystem sys, ItemVersionedId ividToItem, string propertyName) where TContent : class { if (ividToItem == null) { yield break; } if (ReferenceGetter == null) { // constructs expression for x => x.propertyName != null && x.propertyName.VersionedId == ividToItem var xParam = Expression.Parameter(typeof(TContent), "x"); var refProp = typeof(TContent).GetProperty(propertyName); if (refProp == null) { throw new ArgumentException(string.Format("While getting references, could not find reference property {0} on type {1}", propertyName, typeof(TContent).FullName)); } var xGetRef = Expression.MakeMemberAccess(xParam, refProp); var neNull = Expression.NotEqual(xGetRef, Expression.Constant(null)); if (!typeof(Reference).IsAssignableFrom(refProp.PropertyType)) { throw new ArgumentException(string.Format("Trying to get references for type {0} property {1} which is not of Reference type", typeof(TContent).FullName, propertyName)); } var xGetIvid = Expression.MakeMemberAccess(xGetRef, refProp.PropertyType.GetProperty("ItemId")); var ividConst = Expression.Constant(new ItemId(ividToItem)); var comp = Expression.Equal(xGetIvid, ividConst); var test = Expression.AndAlso(neNull, comp); var lambda = Expression.Lambda <Func <TContent, bool> >(test, xParam); foreach (var item in sys.Collator.Get <TContent, TContent>(iq => iq.Where(lambda))) { yield return(sys.Collator.GetSummary <Summary>(item)); } } else { foreach (var summ in ReferenceGetter(ividToItem, typeof(TContent), propertyName)) { yield return(summ); } } }
/// <summary> /// Set the contained content item /// </summary> /// <param name="value">The content item object</param> public void SetContent(LyniconSystem sys, object value) { if (!(value is ICoreMetadata)) { throw new ArgumentException("Value for ContentItem.SetContent must be ICoreMetadata"); } DataType = value.GetType().UnextendedType().FullName; var summMap = GetSummaryProperties(ContentType); var summType = GetSummaryType(ContentType); var sz = JsonSerializer.Create(GetSerializerSettings(value.GetType(), this.Id)); JObject jObjectContent = JObject.FromObject(value, sz); if (summType != typeof(Summary) || summMap.Count > 0) { summMap.Do(kvp => // key = summary property name, value = content property info { jObjectContent.Remove(kvp.Value.Name); }); var summ = GetSummary(sys, value); JObject jObjectSummary = JObject.FromObject(summ); jObjectSummary.Remove("Url"); jObjectSummary.Remove("Type"); jObjectSummary.Remove("Id"); jObjectSummary.Remove("Version"); jObjectSummary.Remove("Title"); jObjectSummary.Remove("UniqueId"); this.Summary = jObjectSummary.ToString(); this.Title = summ.Title; } //this.References = SetReferenceProperties(value); this.Content = jObjectContent.ToString(); this.contentObject = value; // set cached content object }
private void SetupLyniconSystemWithDb() { LyniconSystemWithDb = new LyniconSystem(new LyniconSystemOptions() .UseConnectionString("Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=LynTest;Integrated Security=True") .UseTypeSetup(col => { col.SetupTypeForBasic <TestData>(); col.SetupType <HeaderContent>(); col.System.Repository.Register(null, new ContentRepository(new CoreDataSourceFactory(col.System))); col.System.Repository.Register(typeof(TestData), new BasicRepository(col.System, new CoreDataSourceFactory(col.System))); col.System.Repository.Register(typeof(ContentItem), new ContentRepository(new CoreDataSourceFactory(col.System))); })); LyniconSystemWithDb.Collator = new Collator(LyniconSystemWithDb); LyniconSystemWithDb.Modules = new LyniconModuleManager(); LyniconSystemWithDb.Construct(new Lynicon.Extensibility.Module[] { new CoreModule(LyniconSystemWithDb) }); LyniconSystemWithDb.Modules.SkipDbStateCheck = true; LyniconSystemWithDb.Initialise(); }
/// <summary> /// Create a new IdentityAdaptorCollator /// </summary> /// <param name="userManager">A function which returns the current UserManager</param> public IdentityAdaptorCollator(LyniconSystem sys) : base(new BasicCollator(sys), null, null) { this.PropertyMap = new Dictionary <string, string>(); this.IdWriteConvert = id => "'" + id.ToString() + "'"; // single quotes stop guid as string being converted to guid in ItemId this.readConvert = ReadConvert; this.writeConvert = WriteConvert; this.userManager = () => null; // RequestContextManager.Instance.CurrentContext.Request..GetOwinContext().GetUserManager<TUserManager>(); extUserType = System.Extender[typeof(User)] ?? typeof(User); propertyInfos = new List <Tuple <PropertyInfo, PropertyInfo> >(); foreach (PropertyInfo innerPi in typeof(TUser).GetPersistedProperties()) { var outerPi = extUserType.GetProperty(innerPi.Name); if (outerPi != null) { propertyInfos.Add(Tuple.Create(outerPi, innerPi)); } } }
public InitializeAdminCmd(LyniconSystem sys) { this.sys = sys; }
public Collator() { System = LyniconSystem.Instance; }
public NullDataSourceFactory(LyniconSystem sys) { System = sys; }
/// <summary> /// Get the items of a given content type with a given property which is a reference to this referenced item /// </summary> /// <typeparam name="T">The content type (or parent type or interface) of the referring items</typeparam> /// <param name="propName">The property on the referencing item which must refer to this item</param> /// <returns>List of referencing items</returns> public virtual IEnumerable <Summary> GetReferencingItems <T>(LyniconSystem sys, ItemVersion version, string propName) where T : class { return(Reference.GetReferencesFrom <T>(sys, new ItemVersionedId(this.ItemId, version), propName)); }
public InitializeDatabaseCmd(LyniconSystem sys) { this.sys = sys; }
public ContentCollator(LyniconSystem sys, bool doCollation) : base(sys, doCollation) { }