public GlobalConfigMappings(IStoredConfigAsService storedConfigAsService, IYuzuConfiguration config, IYuzuDeliveryImportConfiguration importConfig, IVmHelperService vmHelperService) { var globalConfigs = storedConfigAsService.GetAll <GlobalStoreContentAs>(); foreach (var global in globalConfigs) { var vmName = global.Key; var documentTypeAlias = global.Value.DocumentTypeAlias; if (string.IsNullOrEmpty(documentTypeAlias)) { documentTypeAlias = vmHelperService.Get(vmName).ContentType.Alias; } var groupName = global.Value.StoreContentAs.GroupName; var sourceType = config.CMSModels.Where(x => x.Name.ToLower() == documentTypeAlias.ToLower()).FirstOrDefault(); var dest = config.ViewModels.Where(x => x.Name == vmName).FirstOrDefault(); if (sourceType != null && dest != null) { ManualMaps.AddGlobal(sourceType, dest, groupName); } } }
public YuzuDefinitionTemplates(IMapper mapper, IYuzuConfiguration config, IEnumerable <IMapperAddItem> mapperAddItems, IYuzuTypeFactoryRunner typeFactoryRunner) { this.mapper = mapper; this.config = config; this.mapperAddItems = mapperAddItems; this.typeFactoryRunner = typeFactoryRunner; }
public ReferencesService(IYuzuConfiguration config) { pagePath = config.TemplateLocations.Where(x => x.Name == "Pages").Select(x => x.Schema).FirstOrDefault(); blockPath = config.TemplateLocations.Where(x => x.Name == "Partials").Select(x => x.Schema).FirstOrDefault(); pagePath = pagePath.EndsWith("/") ? pagePath : string.Format("{0}\\", pagePath); blockPath = blockPath.EndsWith("/") ? blockPath : string.Format("{0}\\", blockPath); }
public void Setup() { mapper = MockRepository.GenerateStub <IMapper>(); config = MockRepository.GenerateStub <IYuzuConfiguration>(); mapperAddItems = new List <IMapperAddItem>(); svc = MockRepository.GeneratePartialMock <YuzuDefinitionTemplates>(new object[] { mapper, config, mapperAddItems.ToArray() }); settings = new RenderSettings(); config.GetRenderedHtmlCache = null; config.SetRenderedHtmlCache = null; templates = new Dictionary <string, Func <object, string> >(); templateName = "template"; templateRenderer = (object data) => { return(html); }; config.GetTemplatesCache = () => { return(templates); }; exampleModel = new ExampleModel() { Text = "text" }; exampleViewModel = new vmPage_ExampleViewModel(); inputMappingItems = new Dictionary <string, object>(); Func <object, IDictionary <string, object>, vmPage_ExampleViewModel> doFunction = (object source, IDictionary <string, object> items) => { usedMappingItems = items; return(exampleViewModel); }; mapper.Stub(x => x.Map <vmPage_ExampleViewModel>(null, null)).IgnoreArguments().Do(doFunction); Mapper.Reset(); }
public GroupedConfigMappings(IStoredConfigAsService storedConfigAsService, IYuzuConfiguration config, IYuzuDeliveryImportConfiguration importConfig, IVmGetterService vmGetterService) { var groupedConfigs = storedConfigAsService.GetAll <GroupStoreContentAs>(); foreach (var group in groupedConfigs) { var vmName = group.Key; var documentTypeAlias = group.Value.DocumentTypeAlias; var groupSettings = group.Value.StoreContentAs.As <GroupStoreContentAs>(); var groupName = group.Value.StoreContentAs.GroupName; if (string.IsNullOrEmpty(groupName)) { groupName = importConfig.DefaultPropertyGroup; } var parentPropertyName = groupSettings.ParentPropertyName; var sourceType = config.CMSModels.Where(x => x.Name.ToLower() == documentTypeAlias.ToLower()).FirstOrDefault(); var destParent = config.ViewModels.Where(x => x.Name == groupSettings.ParentPropertyType).FirstOrDefault(); var destChild = config.ViewModels.Where(x => x.Name == vmName).FirstOrDefault(); if (sourceType != null && destParent != null && destChild != null) { ManualMaps.AddGroup(sourceType, destParent, destChild, parentPropertyName, groupName); } } }
public GridAutoMapping(IVmPropertyMappingsFinder vmPropertyMappingsFinder, ISchemaMetaService schemaMetaService, IYuzuConfiguration config, IYuzuDeliveryImportConfiguration importConfig) { this.schemaMetaService = schemaMetaService; this.config = config; this.importConfig = importConfig; var rowMappings = vmPropertyMappingsFinder.GetMappings <vmBlock_DataRows>(); foreach (var i in rowMappings) { var configType = AddConfigMapping <vmBlock_DataRows>(i.DestProperty, ConfigType.Rows); Type resolverType = null; if (i.SourceType != null) { if (configType == null) { resolverType = typeof(GridRowConvertor <,>).MakeGenericType(i.SourceType, i.DestType); } else { resolverType = typeof(GridRowConvertor <, ,>).MakeGenericType(i.SourceType, i.DestType, configType); } AddResolverMapping(i, resolverType); } } var gridMappings = vmPropertyMappingsFinder.GetMappings <vmBlock_DataGrid>(); foreach (var i in gridMappings) { var rowsConfigType = AddConfigMapping <vmBlock_DataGrid>(i.DestProperty, ConfigType.Rows); var colsConfigType = AddConfigMapping <vmBlock_DataGrid>(i.DestProperty, ConfigType.Cells); Type resolverType = null; if (i.SourceType != null) { if (rowsConfigType == null && colsConfigType == null) { resolverType = typeof(GridRowColumnConvertor <,>).MakeGenericType(i.SourceType, i.DestType); } else if (colsConfigType == null) { resolverType = typeof(GridRowColumnConvertor <, ,>).MakeGenericType(i.SourceType, i.DestType, rowsConfigType); } else { resolverType = typeof(GridRowColumnConvertor <, , ,>).MakeGenericType(i.SourceType, i.DestType, rowsConfigType, colsConfigType); } AddResolverMapping(i, resolverType); } } }
public BuildViewModelsService(GenerateViewmodelService generateViewmodelService, IEnumerable <IViewmodelPostProcessor> postProcessors, IYuzuConfiguration config, IYuzuViewmodelsBuilderConfig builderConfig) { this.generateViewmodelService = generateViewmodelService; this.postProcessors = postProcessors; this.builderConfig = builderConfig; pagePath = config.TemplateLocations.Where(x => x.Name == "Pages").Select(x => x.Schema).FirstOrDefault(); blockPath = config.TemplateLocations.Where(x => x.Name == "Partials").Select(x => x.Schema).FirstOrDefault(); pagePath = pagePath.EndsWith("/") ? pagePath : string.Format("{0}\\", pagePath); blockPath = blockPath.EndsWith("/") ? blockPath : string.Format("{0}\\", blockPath); }
public static Type GetComponent(this Type type, IYuzuConfiguration config) { if (type.Name.IsComponentVm(true)) { return(type); } else { return(config.ViewModels.Where(x => x.GetProperties().Any(y => HasPropertyType(type, y))) .FirstOrDefault()); } }
public void Setup() { hbs = MockRepository.GenerateStub <IHandlebarsProvider>(); config = MockRepository.GenerateStub <IYuzuConfiguration>(); templates = new Dictionary <string, Func <object, string> >(); templateLocations = new List <ITemplateLocation>(); directory = MockRepository.GenerateStub <DirectoryInfo>(); subdirectory = MockRepository.GenerateStub <DirectoryInfo>(); files = new List <FileInfo>(); directory.Stub(x => x.GetDirectories()).Return(new DirectoryInfo[] { subdirectory }); config.TemplateLocations = templateLocations; constantsConfig.TemplateFileExtension = fileExtension; svc = MockRepository.GeneratePartialMock <YuzuDefinitionTemplateSetup>(new object[] { hbs, config }); }
public void Setup() { schemaMetaPropertyService = MockRepository.GenerateStub <ISchemaMetaPropertyService>(); config = MockRepository.GenerateStub <IYuzuConfiguration>(); config.SchemaMetaLocations = new List <IDataLocation>(); svc = MockRepository.GeneratePartialMock <SchemaMetaService>(new object[] { schemaMetaPropertyService, config }); jsonPaths = @"{ 'refs': { '/contentRows': [ '/parTest', '/parTest2' ] } }"; jsonOfTypeParent = @"{ 'refs': { '/content': [ '/parDataGridRows^parGrid' ], } }"; jsonOfTypeChild = @"{ 'parGrid': { 'refs': { '/rows/columns/items': [ '/parRte', '/parImage' ] } }, 'anyOfTypes': [ 'parGrid' ] }"; }
public void Setup() { blockType = MockRepository.GenerateStub <Type>(); blockType.Stub(x => x.Name).Return("vmBlock_Test"); subBlockType = MockRepository.GenerateStub <Type>(); subBlockType.Stub(x => x.Name).Return("vmSub_Test"); subListBlockType = MockRepository.GenerateStub <Type>(); subListBlockType.Stub(x => x.IsGenericType).Return(true); subListBlockType.Stub(x => x.GenericTypeArguments).Return(new Type[] { subBlockType }); parentBlockType = MockRepository.GenerateStub <Type>(); parentBlockType.Stub(x => x.Name).Return("vmSub_Parent"); subExternalBlockType = MockRepository.GenerateStub <Type>(); subExternalBlockType.Stub(x => x.Name).Return("vmBlock_External"); ViewModels = new List <Type>(); ViewModels.Add(blockType); config = MockRepository.GeneratePartialMock <YuzuConfiguration>(new object[] { new List <IUpdateableConfig>() }); config.Stub(x => x.ViewModels).Return(ViewModels); }
public AddedMapContext CreateMap <Source, DestParent, DestChild>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) { var settings = baseSettings as YuzuGroupMapperSettings; if (settings != null) { var groupNameWithoutSpaces = settings.GroupName.Replace(" ", ""); cfg.RecognizePrefixes(groupNameWithoutSpaces); mapContext.AddOrGet <Source, DestChild>(cfg); var parentMap = mapContext.AddOrGet <Source, DestParent>(cfg); parentMap.ForMember(settings.PropertyName, opt => opt.MapFrom(y => y)); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuGroupMapperSettings"); } }
public AddedMapContext CreateMap <Dest, TService>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where TService : class, IYuzuTypeFactory <Dest> { var settings = baseSettings as YuzuTypeFactoryMapperSettings; if (settings != null) { Func <IYuzuTypeFactory> getFactory = () => { return(factory.GetInstance(typeof(TService)) as TService); }; if (!config.ViewmodelFactories.ContainsKey(settings.Dest)) { config.ViewmodelFactories.Add(settings.Dest, getFactory); } config.AddActiveManualMap <TService, Dest>(); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuTypeFactoryMapperSettings"); } }
public SubBlocksObjectResolver(IMapper mapper, IYuzuConfiguration config) { this.mapper = mapper; this.config = config; }
public AddedMapContext CreateMap <Source, Dest>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) { var settings = baseSettings as YuzuGlobalMapperSettings; if (settings != null) { if (settings.GroupName != null) { cfg.RecognizePrefixes(settings.GroupName); } mapContext.AddOrGet <Source, Dest>(cfg); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuGlobalMapperSettings"); } }
public AddedMapContext CreateMap <Source, Dest, TService>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where TService : class, IYuzuTypeConvertor <Source, Dest> { var settings = baseSettings as YuzuTypeConvertorMapperSettings; if (settings != null) { config.AddActiveManualMap <TService, Dest>(); if (settings.IgnoreReturnType) { importConfig.IgnoreViewmodels.Add(typeof(Dest).Name); } var map = mapContext.AddOrGet <Source, Dest>(cfg); Func <Source, Dest, ResolutionContext, Dest> mappingFunction = (Source source, Dest dest, ResolutionContext context) => { var typeConvertor = factory.GetInstance(typeof(TService)) as TService; var yuzuContext = contextFactory.From <UmbracoMappingContext>(context.Items); return(typeConvertor.Convert(source, yuzuContext)); }; map.ConvertUsing(mappingFunction); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuTypeMappingSettings"); } }
public ManualMappingsMappings(ICustomManualMappersService manualMappersConfigService, IYuzuConfiguration config, IVmHelperService vmHelper) { foreach (var m in manualMappersConfigService.Mappers) { var manualMap = config.InstalledManualMaps.Where(x => x.Concrete.Name == m.Mapper).FirstOrDefault(); var link = vmHelper.Get(m.Dest); if (manualMap != null) { if (manualMap.Concrete.HasInterface <IYuzuTypeAfterConvertor>()) { ManualMaps.AddTypeAfterMap(manualMap.Concrete); } if (manualMap.Concrete.HasInterface <IYuzuTypeConvertor>()) { ManualMaps.AddTypeReplace(manualMap.Concrete); } //Can't do this yet, automapper AddTransofrm bug //if (manualMap.Concrete.HasInterface<IYuzuPropertyAfterResolver>()) // ManualMaps.AddPropertyAfter(manualMap.Concrete, destVm, m.DestMember, m.Group); if (manualMap.Concrete.HasInterface <IYuzuPropertyReplaceResolver>()) { ManualMaps.AddPropertyReplace(manualMap.Concrete, link.Viewmodel, m.DestMember, m.Group); } if (manualMap.Concrete.HasInterface <IYuzuTypeFactory>() && !string.IsNullOrEmpty(m.DestMember)) { ManualMaps.AddPropertyFactory(manualMap.Concrete, link.CMSModel, link.Viewmodel, m.DestMember, m.Group); } if (manualMap.Concrete.HasInterface <IYuzuTypeFactory>() && string.IsNullOrEmpty(m.DestMember)) { ManualMaps.AddTypeFactory(manualMap.Concrete, link.Viewmodel); } } } }
public UmbracoTypeFactoryRunner(IYuzuConfiguration config, IMappingContextFactory contextFactory) { this.config = config; this.contextFactory = contextFactory; }
public AddedMapContext CreateMap <DestMember, Source, Dest, TService>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where TService : class, IYuzuTypeFactory <DestMember> { var settings = baseSettings as YuzuPropertyFactoryMapperSettings; if (settings != null) { config.AddActiveManualMap <TService, Dest>(settings.DestPropertyName); Func <Source, Dest, object, ResolutionContext, DestMember> mappingFunction = (Source m, Dest v, object o, ResolutionContext context) => { var propertyResolver = factory.GetInstance(typeof(TService)) as TService; var yuzuContext = contextFactory.From <UmbracoMappingContext>(context.Items); return(propertyResolver.Create(yuzuContext)); }; var map = mapContext.AddOrGet <Source, Dest>(cfg); map.ForMember(settings.DestPropertyName, opt => opt.MapFrom(mappingFunction)); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuPropertyFactoryMapperSettings"); } }
public AddedMapContext CreateMap <Source, Dest, Resolver>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where Resolver : class, IYuzuTypeAfterConvertor <Source, Dest> { var settings = baseSettings as YuzuTypeAfterMapperSettings; if (settings != null) { config.AddActiveManualMap <Resolver, Dest>(); var map = mapContext.AddOrGet <Source, Dest>(cfg); Action <Source, Dest, ResolutionContext> mappingFunction = (Source source, Dest dest, ResolutionContext context) => { var typeConvertor = factory.GetInstance(typeof(Resolver)) as Resolver; var yuzuContext = contextFactory.From <UmbracoMappingContext>(context.Items); typeConvertor.Apply(source, dest, yuzuContext); }; map.AfterMap(mappingFunction); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuTypeMappingSettings"); } }
public AddedMapContext CreateMap <Source, DestMember, Dest, Resolver>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where Resolver : class, IYuzuPropertyAfterResolver <Source, DestMember> { var settings = baseSettings as YuzuPropertyAfterMapperSettings; if (settings != null) { //need a fix here //config.AddActiveManualMap<Resolver, Dest>(settings.DestProperty); if (!string.IsNullOrEmpty(settings.GroupName)) { cfg.RecognizePrefixes(settings.GroupName); } Func <DestMember, DestMember> mappingFunction = (DestMember input) => { var propertyResolver = factory.GetInstance(typeof(Resolver)) as Resolver; return(propertyResolver.Apply(input)); }; var map = mapContext.AddOrGet <Source, Dest>(cfg); map.ForMember <DestMember>(settings.DestProperty as Expression <Func <Dest, DestMember> >, opt => opt.AddTransform(x => mappingFunction(x))); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuPropertyMappingSettings"); } }
public DefaultUmbracoMappingFactory(IYuzuConfiguration config) { this.config = config; }
public AddedMapContext CreateMap <Source, Dest, SourceMember, DestMember, Resolver>(MapperConfigurationExpression cfg, YuzuMapperSettings baseSettings, IFactory factory, AddedMapContext mapContext, IYuzuConfiguration config) where Resolver : class, IYuzuFullPropertyResolver <Source, Dest, SourceMember, DestMember> { var settings = baseSettings as YuzuFullPropertyMapperSettings; if (settings != null) { if (settings.IgnoreProperty) { importConfig.IgnorePropertiesInViewModels.Add(new KeyValuePair <string, string>(typeof(Dest).Name, settings.DestPropertyName)); } if (settings.IgnoreReturnType) { importConfig.IgnoreViewmodels.Add(typeof(Type).Name); } if (!string.IsNullOrEmpty(settings.GroupName)) { cfg.RecognizePrefixes(settings.GroupName); } Func <Source, Dest, object, ResolutionContext, DestMember> mappingFunction = (Source m, Dest v, object o, ResolutionContext context) => { var propertyResolver = factory.GetInstance(typeof(Resolver)) as Resolver; var sourceValue = ((SourceMember)typeof(Source).GetProperty(settings.SourcePropertyName).GetValue(m)); var yuzuContext = contextFactory.From <UmbracoMappingContext>(context.Items); return(propertyResolver.Resolve(m, v, sourceValue, settings.DestPropertyName, yuzuContext)); }; var map = mapContext.AddOrGet <Source, Dest>(cfg); map.ForMember(settings.DestPropertyName, opt => opt.MapFrom(mappingFunction)); return(mapContext); } else { throw new Exception("Mapping settings not of type YuzuPropertyMappingSettings"); } }
public YuzuDefinitionTemplateSetup(IHandlebarsProvider hbsProvider, IYuzuConfiguration config) { this.hbsProvider = hbsProvider; this.config = config; }
public DefaultTypeFactoryMapper(IYuzuConfiguration config) { this.config = config; }
public YuzuDefinitionTemplates(IMapper mapper, IYuzuConfiguration config, IMapperAddItem[] mapperAddItems) { this.mapper = mapper; this.config = config; this.mapperAddItems = mapperAddItems; }
public SchemaMetaPropertyService(IYuzuConfiguration config) { this.config = config; }
public SchemaMetaService(ISchemaMetaPropertyService schemaMetaPropertyService, IYuzuConfiguration config) { this.schemaMetaPropertyService = schemaMetaPropertyService; this.config = config; }