Пример #1
0
 /// <summary>
 /// Configures the mappers.
 /// </summary>
 /// <param name="document">The document.</param>
 public static void ConfigureMappers(XmlDocument document)
 {
     Mapper.Configuration.DisableConstructorMapping();
     if (document != null)
     {
         foreach (XmlNode node in document.SelectNodes("configuration/mappers/mapper"))
         {
             NodeAttributes attributes     = new NodeAttributes(node);
             Type           sourceType     = TypesManager.ResolveType(attributes.AsString("source"));
             Type           targetType     = TypesManager.ResolveType(attributes.AsString("target"));
             bool           defaultMapping = attributes.AsBool("defaultMapping", true);
             if ((sourceType != null) && (targetType != null))
             {
                 // TODO: Add mappers using Automapper.
                 //IMapper mapper = ObjectProxyFactory.NewMapper(sourceType, targetType);
                 //if (defaultMapping)
                 //{
                 //    mapper.DefaultMap();
                 //}
                 //foreach (XmlNode mapNode in node.SelectNodes("mappings/mapping"))
                 //{
                 //    NodeAttributes mapAttributes = new NodeAttributes(mapNode);
                 //    mapper.Map(mapAttributes.AsString("source"), mapAttributes.AsString("target"));
                 //}
             }
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Finds the entity type given the entity name in the telerik metamodel.
 /// </summary>
 /// <param name="entityName">Name of the entity.</param>
 /// <returns></returns>
 public Type FindEntityTypeInMetamodel(string entityName)
 {
     if (this.typeMetatables.ContainsKey(entityName.ToLower()))
     {
         string fullName = this.typeMetatables[entityName.ToLower()].FullName;
         return(TypesManager.ResolveType(fullName));
     }
     return(null);
 }
Пример #3
0
        /// <summary>
        /// Processes the type if it's a DTO
        /// </summary>
        /// <param name="type">The type.</param>
        private void ProcessDto(Type type)
        {
            DtoAttribute dtoAttribute = AttributeUtil.GetAttributeFrom <DtoAttribute>(type);

            if (dtoAttribute != null)
            {
                Type entityType = null;
                if (dtoAttribute.EntityType != null)
                {
                    entityType = dtoAttribute.EntityType;
                }
                else
                {
                    string entityName = dtoAttribute.EntityName;
                    if (string.IsNullOrEmpty(entityName))
                    {
                        entityName = this.GetEntityName(type.Name);
                    }
                    entityType = TypesManager.ResolveType(entityName);
                    if (entityType == null)
                    {
                        if (this.typeMetatables.ContainsKey(entityName.ToLower()))
                        {
                            entityName = this.typeMetatables[entityName.ToLower()].FullName;
                            entityType = TypesManager.ResolveType(entityName);
                        }
                    }
                }
                if (entityType != null)
                {
                    IMetamodelEntity metaEntity = this.Parent.MetamodelManager.RegisterEntity(entityType, type);
                    if (this.Metatables.ContainsKey(entityType.FullName))
                    {
                        MetaPersistentType metaType = this.Metatables[entityType.FullName];
                        Dictionary <MetaColumn, MetaMember> mapColumns = new Dictionary <MetaColumn, MetaMember>();
                        foreach (MetaMember member in metaType.Members)
                        {
                            MetaPrimitiveMember primitiveMember = member as MetaPrimitiveMember;
                            if (primitiveMember != null)
                            {
                                mapColumns.Add(primitiveMember.Column, member);
                            }
                        }
                        MetaTable metaTable = metaType.Table;
                        foreach (MetaColumn metaColumn in metaTable.Columns)
                        {
                            MetaMember member = mapColumns[metaColumn];
                            metaEntity.AddField(member.Name, metaColumn.IsPrimaryKey, !metaColumn.IsPrimaryKey);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Processes a type if its a BO
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        private void ProcessBO(Type type, Dictionary <string, Type> dtoMap)
        {
            BOAttribute boAttribute = AttributeUtil.GetAttributeFrom <BOAttribute>(type);

            if (boAttribute == null)
            {
                return;
            }
            if (boAttribute.DtoType != null)
            {
                this.Parent.BOManager.AddBOType(boAttribute.DtoType, type);
                return;
            }
            string name = string.IsNullOrEmpty(boAttribute.Name) ? type.Name : boAttribute.Name;

            if (name.IndexOf('.') > -1)
            {
                Type dtoType = TypesManager.ResolveType(name);
                if (dtoType != null)
                {
                    this.Parent.BOManager.AddBOType(dtoType, type);
                }
                return;
            }
            if (dtoMap.ContainsKey(name))
            {
                this.Parent.BOManager.AddBOType(dtoMap[name], type);
                return;
            }
            string testname = this.DtoPreffix + name + this.DtoSuffix;

            if (dtoMap.ContainsKey(testname))
            {
                this.Parent.BOManager.AddBOType(dtoMap[testname], type);
                return;
            }
            testname = name;
            testname = this.RemovePreffix(testname, this.BOPreffix);
            testname = this.RemoveSuffix(testname, this.BOSuffix);
            if (dtoMap.ContainsKey(testname))
            {
                this.Parent.BOManager.AddBOType(dtoMap[testname], type);
                return;
            }
            testname = this.DtoPreffix + testname + this.DtoSuffix;
            if (dtoMap.ContainsKey(testname))
            {
                this.Parent.BOManager.AddBOType(dtoMap[testname], type);
                return;
            }
        }
Пример #5
0
        /// <summary>
        /// Configures the security manager.
        /// </summary>
        /// <param name="document">The document.</param>
        private static void ConfigureSecurityManager(XmlDocument document)
        {
            ISecurityManager securityManager = null;
            XmlNode          securityNode    = document.SelectSingleNode("configuration/security");

            if (securityNode != null)
            {
                NodeAttributes securityAttributes = new NodeAttributes(securityNode);
                if (!string.IsNullOrEmpty(securityAttributes.AsString("sessionManager")))
                {
                    Type sessionManagerType = TypesManager.ResolveType(securityAttributes.AsString("sessionManager"));
                    if (sessionManagerType != null)
                    {
                        ISessionManager sessionManager = (ISessionManager)Activator.CreateInstance(sessionManagerType);
                        IoC.Register <ISessionManager>(sessionManager);
                    }
                }
                if (!string.IsNullOrEmpty(securityAttributes.AsString("auditManager")))
                {
                    Type auditManagerType = TypesManager.ResolveType(securityAttributes.AsString("auditManager"));
                    if (auditManagerType != null)
                    {
                        IAuditManager auditManager = (IAuditManager)Activator.CreateInstance(auditManagerType);
                        IoC.Register <IAuditManager>(auditManager);
                    }
                }
                if (!string.IsNullOrEmpty(securityAttributes.AsString("securityManager")))
                {
                    Type securityManagerType = TypesManager.ResolveType(securityAttributes.AsString("securityManager"));
                    if (securityManagerType != null)
                    {
                        securityManager = (ISecurityManager)Activator.CreateInstance(securityManagerType);
                        IoC.Register <ISecurityManager>(securityManager);
                        string mappersName = securityAttributes.AsString("mapper");
                        securityManager.Configure(mappersName);
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Try to get the DTO type from the parameters. If the DTO is not found, but an entity type is found, then clone the entity type to create a new DTO type..
        /// </summary>
        /// <param name="dtoTypeName">Name of the dto type.</param>
        /// <param name="dtoName">Name of the dto.</param>
        /// <param name="path">The path.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="entityTypeName">Name of the entity type.</param>
        /// <returns></returns>
        private static Type GetDtoType(string dtoTypeName, string dtoName, string path, string entityName, string entityTypeName)
        {
            Type result     = null;
            Type entityType = null;

            // Search by type name
            if (!string.IsNullOrEmpty(dtoTypeName))
            {
                result = TypesManager.ResolveType(dtoTypeName);
                if (result != null)
                {
                    return(result);
                }
            }
            ISecurityManager securityManager = IoC.Get <ISecurityManager>();

            // Search by dto name
            if (!string.IsNullOrEmpty(dtoTypeName))
            {
                IMetamodelEntity metamodelEntity = securityManager.MetamodelManager.GetEntityByDtoName(dtoName);
                if (metamodelEntity != null)
                {
                    foreach (Type type in metamodelEntity.DtoTypes)
                    {
                        if (dtoName.ToLower().Equals(type.Name.ToLower()))
                        {
                            return(type);
                        }
                    }
                }
            }
            // search by entity name
            if (!string.IsNullOrEmpty(entityName))
            {
                IMetamodelEntity metamodelEntity = securityManager.MetamodelManager.GetEntityByName(entityName);
                if (metamodelEntity != null)
                {
                    if (metamodelEntity.DtoTypes.Count > 0)
                    {
                        return(metamodelEntity.DtoTypes[0]);
                    }
                    else
                    {
                        entityType = metamodelEntity.EntityType;
                    }
                }
            }
            // search by entity type
            if ((!string.IsNullOrEmpty(entityTypeName)) && (entityType == null))
            {
                entityType = TypesManager.ResolveType(entityTypeName);
                if (entityType != null)
                {
                    IMetamodelEntity metamodelEntity = securityManager.MetamodelManager.GetEntity(entityType);
                    if ((metamodelEntity != null) && (metamodelEntity.DtoTypes.Count > 0))
                    {
                        return(metamodelEntity.DtoTypes[0]);
                    }
                }
            }
            // If not found in own metamodel, because is not loaded into the system... but we can get the entity type by name from the telerik metamodel?
            if ((entityType == null) && (!string.IsNullOrEmpty(entityName)))
            {
                entityType = securityManager.Scanner.FindEntityTypeInMetamodel(entityName);
            }
            if ((entityType == null) && (!string.IsNullOrEmpty(path)))
            {
                entityType = securityManager.Scanner.FindEntityTypeInMetamodel(path);
            }
            if (entityType == null)
            {
                return(null);
            }
            result = TypeBuilderHelper.CloneCommonType(entityType, AppDomain.CurrentDomain, "Supido.Business.Dto", "SupidoDynamicModule", entityType.Name + "Dto");
            securityManager.Scanner.ProcessDynamicDto(result, entityType);
            return(result);
        }