private void SetupControlState() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var allTypes = assemblies.SelectMany(x => x.GetTypes()).ToList(); var extendableClrTypes = allTypes .HavingAttribute <WarpCoreEntityAttribute>() .Where(x => typeof(WarpCoreEntity).IsAssignableFrom(x)); //.ToLookup(x => x.GetCustomAttribute<WarpCoreEntityAttribute>().TypeExtensionUid); List <EntityViewModel> vms = new List <EntityViewModel>(); var allDynamicContentTypes = new ContentTypeMetadataRepository().Find(); foreach (var t in allDynamicContentTypes) { vms.Add(new EntityViewModel { DisplayName = t.Name, ContentTypeId = t.ContentId }); } foreach (var t in extendableClrTypes) { var contentTypeId = t.GetCustomAttribute <WarpCoreEntityAttribute>().TypeExtensionUid; vms.Add(new EntityViewModel { DisplayName = t.Name, ContentTypeId = contentTypeId }); } var repo = new ContentInterfaceRepository(); var contentInterfaceLookup = repo.Find().ToLookup(x => x.ContentTypeId); foreach (var entityViewModel in vms) { var appliedInterfaces = contentInterfaceLookup[entityViewModel.ContentTypeId]; foreach (var contentInterface in appliedInterfaces) { entityViewModel.EditableInterfaces.Add(new EntityInterfaceViewModel { InterfaceId = contentInterface.ContentId, Name = contentInterface.InterfaceName }); } } _controlState.Entities = vms.ToList(); //var repo = new ContentInterfaceRepository(); //var allEntities = repo.Find() // .Select(x => new EntityViewModel // { // ContentTypeId = x.ContentTypeId, // DisplayName = clrLookup[x.ContentTypeId].FirstOrDefault()?.Name // }); //_controlState.Entities = allEntities.ToList(); }
protected override void OnInit(EventArgs e) { base.OnInit(e); EnsureLayoutInitialized(); _activatedConfigurators = GetDescendantControls(surface, typeof(IConfiguratorControl)).Cast <IConfiguratorControl>().ToList(); //_dynamicFormRequest = Context.ToDynamicFormRequestContext(); _repo = RepositoryActivator.ActivateRepository <ISupportsCmsForms>(_cmsForm.RepositoryUid); var draft = GetDraft(); if (draft.IsNew) { var metadataRepo = new ContentTypeMetadataRepository(); var metadata = metadataRepo.GetContentType(draft.GetType()); FormTitleAdd.InnerText = $"Add {metadata.ContentNameSingular}"; FormTitleEdit.Visible = false; } else { FormTitleAdd.Visible = false; FormTitleEditName.InnerText = draft.Title; } //var d = draft.GetPropertyValues(ToolboxPropertyFilter.SupportsOrm); //var configuratorEditingContext = new ConfiguratorBuildArguments //{ // ClrType = draft.GetType(), // PropertyFilter = ToolboxPropertyFilter.SupportsOrm, // DefaultValues = d //}; //configuratorEditingContext.Events = CmsFormReadWriter.AddEventTracking(surface, configuratorEditingContext, _activatedConfigurators).Events; //CmsFormReadWriter.InitializeEditing(_activatedConfigurators, configuratorEditingContext); //SetConfiguratorEditingContextDefaultValuesFromUrl(configuratorEditingContext); //CmsFormReadWriter.SetDefaultValues(_activatedConfigurators, configuratorEditingContext); }
public static void RegisterExtensibleTypesWithApi(AppDomain domain) { var assemblies = domain.GetAssemblies(); var allTypes = assemblies.SelectMany(x => x.GetTypes()).ToList(); var repositoryDescriptions = TypeSearcher.FindRepositoriesKnownToWarpCore(allTypes); foreach (var repositoryDescription in repositoryDescriptions) { BuildUpRepositoryMetadata(repositoryDescription); } //Break this one out later. var entities = TypeSearcher.FindEntitiesKnownToWarpCore(allTypes); var contentTypeMetadataRepository = new ContentTypeMetadataRepository(); var typeExtensionRepo = new ContentInterfaceRepository(); foreach (var entityType in entities) { var repositoryUid = entityType.GetCustomAttribute <WarpCoreEntityAttribute>(); var preexistingContentType = contentTypeMetadataRepository.Find().SingleOrDefault(x => x.TypeResolverId == repositoryUid.TypeExtensionUid); if (preexistingContentType == null) { preexistingContentType = new DynamicContentType { TypeResolverId = repositoryUid.TypeExtensionUid, } } ; preexistingContentType.ContentNameSingular = repositoryUid.ContentNameSingular; preexistingContentType.ContentNamePlural = repositoryUid.ContentNamePlural; if (string.IsNullOrWhiteSpace(preexistingContentType.ContentNameSingular)) { preexistingContentType.ContentNameSingular = entityType.Name; } if (string.IsNullOrWhiteSpace(preexistingContentType.ContentNamePlural)) { //todo: replace //PluralizationService.CreateService(CultureInfo.CurrentCulture) // .Pluralize(preexistingContentType.ContentNameSingular); } preexistingContentType.SupportsCustomFields = repositoryUid.SupportsCustomFields; preexistingContentType.TitleProperty = repositoryUid.TitleProperty; contentTypeMetadataRepository.Save(preexistingContentType); if (preexistingContentType.SupportsCustomFields) { var preexisting = typeExtensionRepo.Find().SingleOrDefault(x => x.ContentTypeId == repositoryUid.TypeExtensionUid && x.InterfaceName == KnownTypeExtensionNames.CustomFields); if (preexisting == null) { typeExtensionRepo.Save(new ContentInterface { ContentTypeId = repositoryUid.TypeExtensionUid, InterfaceName = KnownTypeExtensionNames.CustomFields }); } } } }