Ejemplo n.º 1
0
        public ExFieldInfo SearchExField(string name)
        {
            var fieldArray = MType.GetFields();

            foreach (FieldInfo field in fieldArray)
            {
                if (ReflectionUtil.IsDeclare(MType, field))
                {
                    CodeAttribute propertyAttr = Attribute.GetCustomAttribute(field, typeof(CodeAttribute)) as CodeAttribute;
                    if (propertyAttr == null)
                    {
                        if (field.Name == name)
                        {
                            return(GclUtil.CreatExFieldInfo(field, ForType));
                            //return field;
                        }
                    }
                    else
                    {
                        if (propertyAttr.Code == name)
                        {
                            return(GclUtil.CreatExFieldInfo(field, ForType));
                            //return field;
                        }
                    }
                }
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchExField(name));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public ExPropertyInfo SearchExProperty(string name)
        {
            var propertyArray = MType.GetProperties(/*BindingFlags.DeclaredOnly*/);

            foreach (var property in propertyArray)
            {
                if (ReflectionUtil.IsDeclare(MType, property))
                {
                    CodeAttribute propertyAttr = Attribute.GetCustomAttribute(property, typeof(CodeAttribute)) as CodeAttribute;
                    if (propertyAttr == null)
                    {
                        if (property.Name == name)
                        {
                            return(GclUtil.CreatExPropertyInfo(property, ForType));
                            //return property;
                        }
                    }
                    else
                    {
                        if (propertyAttr.Code == name)
                        {
                            return(GclUtil.CreatExPropertyInfo(property, ForType));
                            //return property;
                        }
                    }
                }
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchExProperty(name));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = MType.GetMethods( );

            foreach (var method in methodArray)
            {
                CodeAttribute procAttr = Attribute.GetCustomAttribute(method, typeof(CodeAttribute)) as CodeAttribute;
                if (procAttr == null)
                {
                    ExMethodInfo exMethod     = GclUtil.CreatExMethodInfo(method, this.ForType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        return(typeProcDesc);
                    }
                }
                else
                {
                    ProcDescCodeParser parser = new ProcDescCodeParser();
                    parser.InitType(ForType, method);
                    TKTProcDesc typeProcDesc = parser.Parser(WordDict, procAttr.Code);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        ExMethodInfo exMethod = GclUtil.CreatExMethodInfo(method, this.ForType);
                        typeProcDesc.ExMethod = exMethod;
                        return(typeProcDesc);
                    }
                }
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Ejemplo n.º 4
0
        public override ExPropertyInfo[] GetPropertyInfoes()
        {
            List <ExPropertyInfo> exList = new List <ExPropertyInfo>();
            var propertyArray            = this.SharpType.GetProperties();

            foreach (var property in propertyArray)
            {
                ZCodeAttribute[] arrs = AttributeUtil.GetAttributes <ZCodeAttribute>(property);
                foreach (var zcattr in arrs)
                {
                    ExPropertyInfo exPI = new ExPropertyInfo(property, true, zcattr.Code);
                    exList.Add(exPI);
                }
            }
            if (ParentMapping != null && !isRoot())
            {
                ExPropertyInfo[] pArr = ParentMapping.GetPropertyInfoes();
                foreach (ExPropertyInfo pitem in pArr)
                {
                    pitem.IsSelf = false;
                }
                exList.AddRange(pArr);
            }
            return(exList.ToArray());
        }
Ejemplo n.º 5
0
        public override ExPropertyInfo SearchExProperty(string name)
        {
            var propertyArray = this.SharpType.GetProperties();

            foreach (var property in propertyArray)
            {
                if (!ReflectionUtil.IsDeclare(this.SharpType, property))
                {
                    continue;
                }
                /* 映射类可能有多个同义的属性名称对应同一个实际属性 */
                ZCodeAttribute[] arrs = AttributeUtil.GetAttributes <ZCodeAttribute>(property);
                foreach (var zcode in arrs)
                {
                    if (zcode.Code == name)
                    {
                        return(new ExPropertyInfo(property, true, name));
                    }
                }
            }
            if (ParentMapping != null && !isRoot())
            {
                ExPropertyInfo epi = ParentMapping.SearchExProperty(name);
                if (epi != null)
                {
                    epi.IsSelf = false;
                    return(epi);
                }
            }
            return(null);
        }
        public override void Visit(ParentMapping parentMapping)
        {
            var writer = serviceLocator.GetWriter<ParentMapping>();
            var parentXml = writer.Write(parentMapping);

            document.ImportAndAppendChild(parentXml);
        }
        public override void Visit(ParentMapping parentMapping)
        {
            var writer    = serviceLocator.GetWriter <ParentMapping>();
            var parentXml = writer.Write(parentMapping);

            document.ImportAndAppendChild(parentXml);
        }
Ejemplo n.º 8
0
        public override TKTProcDesc[] GetProces()
        {
            List <TKTProcDesc> list = new List <TKTProcDesc>();
            var methodArray         = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute     procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);
                ProcDescCodeParser parser   = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc  typeProcDesc = parser.Parser(procAttr.Code);
                ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                typeProcDesc.ExMethod = exMethod;
                list.Add(typeProcDesc);
            }
            if (ParentMapping != null)
            {
                TKTProcDesc[] epi = ParentMapping.GetProces();
                foreach (var pitem in epi)
                {
                    pitem.ExMethod.IsSelf = false;
                }
                list.AddRange(epi);
            }
            return(list.ToArray());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Maps a property of the component class as a reference back to the containing entity
        /// </summary>
        /// <param name="expression">Parent reference property</param>
        /// <returns>Component being mapped</returns>
        public void ParentReference(Expression <Func <T, object> > expression)
        {
            var parentMapping = new ParentMapping
            {
                ContainingEntityType = entity
            };

            parentMapping.Set(x => x.Name, Layer.Defaults, expression.ToMember().Name);
            attributes.Set("Parent", Layer.Defaults, parentMapping);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            //Map Address to User
            var userAddressMap = new OneToOneMapping<User, Address>(address => address.Id, user => user.AddressId, (user, address) => user.Address = address);

            //Map Address to Employer & Employer to User
            var employerAddressMap = new OneToOneMapping<Employer, Address>(address => address.Id, employer => employer.AddressId, (employer, address) => employer.Address = address);
            var userEmployerMap = new OneToOneMapping<User, Employer>(employer => employer.Id, user => user.EmployerId, (user, employer) => user.Employer = employer);
            userEmployerMap.AddMapping(employerAddressMap);

            //Map Car to user
            var userCarMap = new ManyToManyMapping<User, Car, UserCar>(car => car.Id, userCar => userCar.CarId, userCar => userCar.UserId,
                (user, cars) =>
                {
                    foreach (var car in cars)
                    {
                        user.Cars.Add(car);
                        car.Users.Add(user);
                    }
                });

            //User Mapping
            var userMap = new ParentMapping<User>(user => user.Id);
            userMap.AddMapping(userAddressMap);
            userMap.AddMapping(userEmployerMap);
            userMap.AddMapping(userCarMap);

            //var dataBroker = new SqlDataBroker(@"Server=(localdb)\ProjectsV12;Database=DemoDatabase;Integrated security=True", new DapperGridReaderFactory());
            var gridReaderFactory = new SqlGridReaderFactory();
            gridReaderFactory.AddEntityFactory(new AddressFactory());
            gridReaderFactory.AddEntityFactory(new CarFactory());
            gridReaderFactory.AddEntityFactory(new EmployerFactory());
            gridReaderFactory.AddEntityFactory(new UserFactory());
            gridReaderFactory.AddEntityFactory(new UserCarFactory());

            var dataBroker = new SqlDataBroker(@"Server=(localdb)\ProjectsV12;Database=DemoDatabase;Integrated security=True", gridReaderFactory);
            dataBroker.AddMapping(userMap);

            var totalTime = 0L;
            for (int i = 0; i < 100; i++)
            {
                Stopwatch watch = new Stopwatch();

                watch.Start();
                //var parameterList = new List<IDbParameter>();
                //parameterList.Add(new DbParameter("BirthDate", DateTime.Parse("06-01-1975"), DbType.Date));
                var users = dataBroker.ExecuteStoredProcedure<User>("dbo.ReadUser");
                watch.Stop();

                totalTime += watch.ElapsedMilliseconds;
            }

            var test = totalTime;
        }
Ejemplo n.º 11
0
        private TBuilder ParentReference(Member property)
        {
            var parentMapping = new ParentMapping
            {
                ContainingEntityType = typeof(TEntity)
            };

            parentMapping.Set(x => x.Name, Layer.Defaults, property.Name);
            attributes.Set("Parent", Layer.Defaults, parentMapping);

            return((TBuilder)this);
        }
Ejemplo n.º 12
0
        public override ExPropertyInfo SearchExProperty(string name)
        {
            var propertyArray = this.SharpType.GetProperties();

            foreach (var property in propertyArray)
            {
                if (!ReflectionUtil.IsDeclare(this.SharpType, property))
                {
                    continue;
                }

                ZCodeAttribute propertyAttr  = Attribute.GetCustomAttribute(property, typeof(ZCodeAttribute)) as ZCodeAttribute;
                string         zpropertyName = null;
                if (propertyAttr != null)
                {
                    //zpropertyName = property.Name;
                    zpropertyName = propertyAttr.Code;
                    if (zpropertyName == name)
                    {
                        return(new ExPropertyInfo(property, true, name));
                    }
                }
                //else
                //{
                //    zpropertyName = property.Name;
                //}
                //if (zpropertyName == name)
                //{
                //    return new ExPropertyInfo(property, true, name);
                //}
            }
            //if (ParentMapping != null)
            //{
            ExPropertyInfo epi = ParentMapping.SearchExProperty(name);

            if (epi != null)
            {
                epi.IsSelf = false;
                return(epi);
            }
            //}
            return(null);
        }
Ejemplo n.º 13
0
        void ParentReference(Member property, Action <ParentPropertyPart> customMapping)
        {
            var parentMapping = new ParentMapping
            {
                ContainingEntityType = entity
            };

            parentMapping.Set(x => x.Name, Layer.Defaults, property.Name);

            var access = MemberAccessResolver.Resolve(property);

            if (access != Access.Property && access != Access.Unset)
            {
                parentMapping.Set(x => x.Access, Layer.Defaults, access.ToString());
            }

            customMapping?.Invoke(new ParentPropertyPart(parentMapping));

            attributes.Set("Parent", Layer.Defaults, parentMapping);
        }
Ejemplo n.º 14
0
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods( );

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);// Attribute.GetCustomAttribute(method, typeof(ZCodeAttribute)) as ZCodeAttribute;
                //if (procAttr == null)
                //{
                //    ExMethodInfo exMethod = ZTypeHelper.CreatExMethodInfo(method, this.SharpType);
                //    TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                //    if (typeProcDesc.Eq(procDesc))
                //    {
                //        return typeProcDesc;
                //    }
                //}
                //else
                //{
                ProcDescCodeParser parser = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc typeProcDesc = parser.Parser(procAttr.Code);
                if (typeProcDesc.Eq(procDesc))
                {
                    ExMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    typeProcDesc.ExMethod = exMethod;
                    return(typeProcDesc);
                }
                //}
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Ejemplo n.º 15
0
        public override void establish_context()
        {
            parentMapping            = new ParentMapping();
            externalComponentMapping = new ExternalComponentMapping(ComponentType.Component);
            externalComponentMapping.Set(x => x.Access, Layer.Defaults, "access");
            externalComponentMapping.Set(x => x.Insert, Layer.Defaults, true);
            externalComponentMapping.Set(x => x.Lazy, Layer.Defaults, true);
            externalComponentMapping.Set(x => x.OptimisticLock, Layer.Defaults, true);
            externalComponentMapping.Set(x => x.Parent, Layer.Defaults, parentMapping);
            externalComponentMapping.Set(x => x.Unique, Layer.Defaults, true);
            externalComponentMapping.Set(x => x.Update, Layer.Defaults, true);
            externalComponentMapping.AddAny(new AnyMapping());
            externalComponentMapping.AddCollection(CollectionMapping.Bag());
            externalComponentMapping.AddComponent(new ComponentMapping(ComponentType.Component));
            externalComponentMapping.AddFilter(new FilterMapping());
            externalComponentMapping.AddOneToOne(new OneToOneMapping());
            externalComponentMapping.AddProperty(new PropertyMapping());
            externalComponentMapping.AddReference(new ManyToOneMapping());

            memberProperty            = new DummyPropertyInfo("Component", typeof(Target)).ToMember();
            referenceComponentMapping = new ReferenceComponentMapping(ComponentType.Component, memberProperty, typeof(ComponentTarget), typeof(Target), "column-prefix");
        }
Ejemplo n.º 16
0
        TBuilder ParentReference(Member property, Action <ParentPropertyPart> customMapping)
        {
            var parentMapping = new ParentMapping
            {
                ContainingEntityType = typeof(TEntity)
            };

            parentMapping.Set(x => x.Name, Layer.Defaults, property.Name);

            var defaultAccess = MemberAccessResolver.Resolve(property);

            if (defaultAccess != Mapping.Access.Property && defaultAccess != Mapping.Access.Unset)
            {
                parentMapping.Set(x => x.Access, Layer.Defaults, defaultAccess.ToString());
            }

            customMapping?.Invoke(new ParentPropertyPart(parentMapping));

            attributes.Set("Parent", Layer.Defaults, parentMapping);

            return((TBuilder)this);
        }
Ejemplo n.º 17
0
        public override ExPropertyInfo[] GetPropertyInfoes()
        {
            List <ExPropertyInfo> exList = new List <ExPropertyInfo>();
            var propertyArray            = this.SharpType.GetProperties();

            foreach (var property in propertyArray)
            {
                ZCodeAttribute propertyAttr = Attribute.GetCustomAttribute(property, typeof(ZCodeAttribute)) as ZCodeAttribute;
                if (propertyAttr != null)
                {
                    var            zpropertyName = propertyAttr.Code;
                    ExPropertyInfo exPI          = new ExPropertyInfo(property, ReflectionUtil.IsDeclare(this.SharpType, property), zpropertyName);
                    exList.Add(exPI);
                }
            }
            ExPropertyInfo[] pArr = ParentMapping.GetPropertyInfoes();
            foreach (ExPropertyInfo pitem in pArr)
            {
                pitem.IsSelf = false;
            }
            exList.AddRange(pArr);
            return(exList.ToArray());
        }
Ejemplo n.º 18
0
        public override void establish_context()
        {
            parent_mapping             = new ParentMapping();
            external_component_mapping = new ExternalComponentMapping(ComponentType.Component)
            {
                Access         = "access",
                Insert         = true,
                Lazy           = true,
                OptimisticLock = true,
                Parent         = parent_mapping,
                Unique         = true,
                Update         = true
            };
            external_component_mapping.AddAny(new AnyMapping());
            external_component_mapping.AddCollection(new BagMapping());
            external_component_mapping.AddComponent(new ComponentMapping(ComponentType.Component));
            external_component_mapping.AddFilter(new FilterMapping());
            external_component_mapping.AddOneToOne(new OneToOneMapping());
            external_component_mapping.AddProperty(new PropertyMapping());
            external_component_mapping.AddReference(new ManyToOneMapping());

            member_property             = new DummyPropertyInfo("Component", typeof(Target)).ToMember();
            reference_component_mapping = new ReferenceComponentMapping(ComponentType.Component, member_property, typeof(ComponentTarget), typeof(Target), "column-prefix");
        }
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userExists = await userManager.FindByNameAsync(model.Email);

            var studentId = 0;

            if (!model.IsParent)
            {
                var existingRoleNumber = _context.UserProfiles.Where(x => x.RollNumber == model.Rollnumber).FirstOrDefault();

                if (userExists != null || existingRoleNumber != null)
                {
                    ModelState.AddModelError("error", "User already exists!");

                    return(View("Register", model));
                }
            }
            else
            {
                var studentEmailAddress = _context.UserProfiles.Where(x => x.EmailAddress == model.StudentEmail).FirstOrDefault();
                if (studentEmailAddress == null)
                {
                    ModelState.AddModelError("error", "The student email address doesnt exist");

                    return(View("Register", model));
                }
                studentId = studentEmailAddress.Id;
            }
            var applicationUser = new ApplicationUser()
            {
                Email         = model.Email,
                SecurityStamp = Guid.NewGuid().ToString(),
                UserName      = model.Email
            };
            var result = await userManager.CreateAsync(applicationUser, model.Password);

            if (!result.Succeeded)
            {
                ModelState.AddModelError("error", "User creation failed! Please check user details and try again.");

                return(View("Register", model));
            }

            var newlyCreatedUser = await userManager.FindByNameAsync(model.Email);

            if (newlyCreatedUser != null)
            {
                var user = new UserProfile()
                {
                    Name              = model.Firstname + " " + model.Lastname,
                    EmailAddress      = model.Email,
                    Department        = model.Department,
                    RollNumber        = model.Rollnumber,
                    ApplicationUserId = newlyCreatedUser.Id
                };
                Random generator = new Random();
                int    r         = generator.Next(100000, 1000000);

                _context.Add(user);
                _context.SaveChanges();

                if (!model.IsParent)
                {
                    var card = new Card()
                    {
                        CardNumber       = $"CN{r}SM",
                        IsActive         = true,
                        AvailableBalance = 0,
                        UserProfileId    = user.Id
                    };
                    _context.Add(card);
                }
                else
                {
                    var parentMapping = new ParentMapping()
                    {
                        StudentId = studentId,
                        ParentId  = user.Id
                    };
                    _context.Add(parentMapping);
                }
                _context.SaveChanges();
            }
            if (!model.IsParent)
            {
                if (!await roleManager.RoleExistsAsync(UserRoles.Student))
                {
                    await roleManager.CreateAsync(new IdentityRole(UserRoles.Student));
                }

                if (await roleManager.RoleExistsAsync(UserRoles.Student))
                {
                    await userManager.AddToRoleAsync(newlyCreatedUser, UserRoles.Student);
                }
            }
            else
            {
                if (!await roleManager.RoleExistsAsync(UserRoles.Parents))
                {
                    await roleManager.CreateAsync(new IdentityRole(UserRoles.Parents));
                }

                if (await roleManager.RoleExistsAsync(UserRoles.Parents))
                {
                    await userManager.AddToRoleAsync(newlyCreatedUser, UserRoles.Parents);
                }
            }
            return(RedirectToAction(nameof(Index), new { message = "User has been created and which needs to be verfied by admin. " +
                                                                   "Please contact admin to verify your registration." }));
        }
 public virtual void Visit(ParentMapping parentMapping)
 {
 }
 public virtual void ProcessParent(ParentMapping parentMapping)
 {
 }
Ejemplo n.º 22
0
 public void CreateDsl()
 {
     mapping   = new ParentMapping();
     inspector = new ParentInspector(mapping);
 }
 public void Initialize()
 {
     MockChildMapping = new Mock<IChildMapping<ParentItem>>();
     MockGridReader = new Mock<IGridReader>();
     ParentMapping = new ParentMapping<ParentItem>(parentItem => parentItem.Id);
 }
Ejemplo n.º 24
0
 public ParentInspector(ParentMapping mapping)
 {
     this.mapping = mapping;
 }
Ejemplo n.º 25
0
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 映射类可能有多个同义的方法对应同一个实际方法 */
                ZCodeAttribute[] attrs = AttributeUtil.GetAttributes <ZCodeAttribute>(method);
                /* 编译器生成的类可能没有标注,没有标注的方法必定在ZMappingType上 */
                if (attrs.Length == 0)
                {
                    ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    TKTProcDesc  typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                    if (typeProcDesc.Eq(procDesc))
                    {
                        TKTProcDesc rdesc = ProcDescHelper.CreateProcDesc(exMethod);
                        return(rdesc);
                    }
                }
                else if (attrs.Length > 0)
                {
                    ParameterInfo[] paramArray = method.GetParameters();
                    parser.InitType(SharpType, method);
                    foreach (ZCodeAttribute attr in attrs)
                    {
                        ZCodeAttribute zCodeAttribute = attr as ZCodeAttribute;
                        TKTProcDesc    typeProcDesc   = parser.Parser(zCodeAttribute.Code);
                        if (method.IsStatic && !method.IsAbstract && typeProcDesc.HasSubject() &&
                            typeProcDesc.GetSubjectArg().ArgType == this.SharpType)
                        {
                            typeProcDesc = typeProcDesc.CreateTail();
                        }
                        if (typeProcDesc.Eq(procDesc))
                        {
                            ExMethodInfo exMethod = null;// getExMethod(method);
                            /* 非 Abstract 的方法肯定从被映射的类中搜索 */
                            if (method.IsAbstract)
                            {
                                var method2 = searchMethodFromSharp(method);
                                exMethod = ZTypeUtil.CreatExMethodInfo(method2, this.SharpType);
                                //return exMethod;
                            }
                            else
                            {
                                exMethod = ZTypeUtil.CreatExMethodInfo(method, this.ZMappingType);
                                //return exMethod;
                            }
                            typeProcDesc.ExMethod = exMethod;
                            return(typeProcDesc);
                        }
                    }
                }
            }
            if (ParentMapping != null && !isRoot())
            {
                var epi = ParentMapping.SearchProc(procDesc);
                if (epi != null)
                {
                    //epi.IsSelf = false;
                    return(epi);
                }
            }
            return(null);
        }
Ejemplo n.º 26
0
 public ParentPropertyPart(ParentMapping mapping)
 {
     Access = new AccessStrategyBuilder <ParentPropertyPart>(this,
                                                             value => mapping.Set(x => x.Access, Layer.UserSupplied, value));
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Returns the hash code for the property
 /// </summary>
 /// <returns>The hash code for the property</returns>
 public override int GetHashCode() => Name.GetHashCode(StringComparison.Ordinal) * ParentMapping.GetHashCode() % int.MaxValue;