示例#1
0
        private void UpdateFields(ref int maxArgIndex)
        {
            foreach (FieldInfo info in Type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                NanoSerializationAttribute attr = CustomStore.FindAttribute(Type, info.Name);
                if (attr == null)
                {
                    attr = info.GetCustomAttribute <NanoSerializationAttribute>();
                }

                if (attr != null && attr.State == NanoState.Ignore)
                {
                    continue;
                }

                NanoLocation location       = NanoLocation.Auto;
                NanoState    state          = NanoState.Serialize;
                string       name           = null;
                int          constructorArg = -1;
                if (attr != null)
                {
                    location       = attr.Location;
                    state          = attr.State;
                    constructorArg = attr.ConstructorArg;
                    if (constructorArg > maxArgIndex)
                    {
                        maxArgIndex = constructorArg;
                    }
                    name = attr.Name;
                }

                Fields.Add(new FieldWrapper(Type, info, location, state, constructorArg, name));
            }
        }
示例#2
0
        private void UpdateProperties(ref int maxArgIndex)
        {
            foreach (PropertyInfo info in Type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (!info.CanRead)
                {
                    continue;
                }

                ParameterInfo[] indexParams = info.GetIndexParameters();

                // exclude properties, that returns the same struct to void infinite recursion
                if (!Type.IsClass && info.PropertyType == Type)
                {
                    continue;
                }

                // indexers are not supported
                if (indexParams.Length > 0)
                {
                    continue;
                }

                NanoSerializationAttribute attr = CustomStore.FindAttribute(Type, info.Name);
                if (attr == null)
                {
                    attr = info.GetCustomAttribute <NanoSerializationAttribute>();
                }

                NanoLocation location       = NanoLocation.Auto;
                NanoState    state          = NanoState.Serialize;
                int          constructorArg = -1;
                string       name           = null;

                if (attr != null)
                {
                    if (attr.State == NanoState.Ignore)
                    {
                        continue;
                    }

                    location       = attr.Location;
                    constructorArg = attr.ConstructorArg;
                    if (constructorArg > maxArgIndex)
                    {
                        maxArgIndex = constructorArg;
                    }
                    state = attr.State;
                    name  = attr.Name;
                }

                Properties.Add(new PropertyWrapper(Type, info, location, state, constructorArg, name));
            }
        }
示例#3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            // if(!IsPostBack)
            ViewData["ReturnUrl"] = returnUrl;
            string         message = "";
            var            Results = new Results();
            IdentityResult rs      = new IdentityResult();

            if (ModelState.IsValid)
            {
                CryptePass hash = new CryptePass();
                // model.Password = hash.getSHA1(model.Password);
                var customStor = new CustomStore(_connectionString);
                var user       = new ApplicationUser
                {
                    LoginName = model.UserName,
                    FullName  = model.FirstName + " " + model.MiddleName + " " + model.LastName,
                    Email     = model.Email,
                    Password  = hash.getSHA1(model.Password)
                };
                var result = customStor.ChkUser(model.UserName);
                if (result == 0)
                {
                    var results = customStor.CreatedUser(user);

                    if (results == 1)
                    {
                        _logger.LogInformation("User created a new account with password.");
                        // await _signInManager.SignInAsync(user, isPersistent: false);
                        Results.status      = "success";
                        Results.Description = "Đăng ký thành công,  tài khoản chờ xét duyệt";
                        message             = JsonConvert.SerializeObject(Results);
                    }
                    else
                    {
                        Results.status      = "fail";
                        Results.Description = "Đăng ký thất bại";
                        message             = JsonConvert.SerializeObject(Results);
                    }
                }
                else
                {
                    Results.status      = "fail";
                    Results.Description = "Username đã tồn tại trong hệ thống";
                    message             = JsonConvert.SerializeObject(Results);
                }
            }
            else
            {
                return(View(model));
            }
            return(Content(message));
        }
示例#4
0
        public async Task <IActionResult> ApiGetMenu()
        {
            var customstore = new CustomStore(_connectionString);
            var rs          = await _userManager.FindByNameAsync(HttpContext.User.FindFirst(ClaimTypes.Name).Value);

            var grouplst = rs.Grp_List.Replace("'", "");
            var menu     = await customstore.bosGetApplicationTools_ByGroupUser_Onl(grouplst);

            if (menu != null)
            {
                return(Ok(menu));
            }
            return(NotFound());
        }
示例#5
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            //HttpContext.Session.SetString("username", "letrung193");

            ViewData["ReturnUrl"] = returnUrl;
            string message = "";
            var    Results = new Results();

            if (ModelState.IsValid)
            {
                await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

                var customstore = new CustomStore(_connectionString);
                var user        = await _userManager.FindByNameAsync(model.UserName);

                if (user != null)
                {
                    var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, true, lockoutOnFailure : false);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User logged in");
                        Results.status      = "success";
                        Results.Description = "Đăng nhập thành công";
                        message             = JsonConvert.SerializeObject(Results);
                    }
                    else
                    {
                        Results.status      = "fail";
                        Results.Description = "Mật khẩu không tồn tại trong hệ thống";
                        message             = JsonConvert.SerializeObject(Results);
                    }
                }
                else
                {
                    Results.status      = "fail";
                    Results.Description = "Tên đăng nhập không tồn tại trong hệ thống";
                    message             = JsonConvert.SerializeObject(Results);
                }
            }
            else
            {
                return(View(model));
            }
            return(Content(message));
        }
示例#6
0
        public TypeWrapper(Type type)
        {
            Type = type;
            int maxArgIndex = -1;

            Serializer = CustomStore.FindSerializer(type);
            if (Serializer != null)
            {
                return;
            }

            UpdateFields(ref maxArgIndex);
            UpdateProperties(ref maxArgIndex);
            createFunc = UpdateConstructors(maxArgIndex, out ConstructorArgsCount, out ConstructorArgNames);

            IsSelfSerializable = SerializationBase.HaveInterface(type, typeof(INanoSerializable));
        }
        public void CustomSerialization()
        {
            CustomSerializationClass a = new CustomSerializationClass("1111");

            a.B = NanoState.SerializeSet;
            CustomStore.RegisterCustomSerializer <CustomSerializationClass>(new CustomSerializerClass());

            XmlDocument target = new XmlDocument();

            Serializer.Serialize((SystemXmlAdapter)target, a);

            Assert.IsEmpty(target.DocumentElement.GetAttribute("a"));
            Assert.IsEmpty(target.DocumentElement.GetAttribute("b"));

            CustomSerializationClass b = Deserializer.Deserialize <CustomSerializationClass>((SystemXmlAdapter)target);

            Assert.AreEqual(a.A, b.A);
            Assert.AreEqual(a.B, b.B);
        }
        public void CustomSettings()
        {
            ThreeAttrsTestClass2 a = new ThreeAttrsTestClass2
            {
                A = 123,
                B = "testString",
                C = NanoState.Ignore
            };

            CustomStore.RegisterCustomSettings(typeof(ThreeAttrsTestClass2), nameof(ThreeAttrsTestClass2.A), serializationName: "name", location: NanoLocation.SubNode);
            CustomStore.RegisterCustomSettings(typeof(ThreeAttrsTestClass2), nameof(ThreeAttrsTestClass2.B), NanoState.Ignore);
            CustomStore.RegisterCustomSettings(typeof(ThreeAttrsTestClass2), nameof(ThreeAttrsTestClass2.C), serializationName: "value", location: NanoLocation.SubNode);

            XmlDocument target = new XmlDocument();

            Serializer.Serialize((SystemXmlAdapter)target, a);

            Assert.AreEqual(2, target.DocumentElement.ChildNodes.Count);
            Assert.AreEqual(1, target.DocumentElement.Attributes.Count);
            Assert.AreEqual("123", GetXmlValue(target, "name"));
            Assert.IsNull(GetXmlValue(target, "B"));
            Assert.AreEqual("Ignore", GetXmlValue(target, "value"));

            ThreeAttrsTestClass2 b = Deserializer.Deserialize <ThreeAttrsTestClass2>((SystemXmlAdapter)target);

            Assert.AreEqual(a.A, b.A);
            Assert.IsNull(b.B);
            Assert.AreEqual(a.C, b.C);

            ThreeAttrsTestClass2 c = new ThreeAttrsTestClass2();

            new Deserializer().FillObject(c, (SystemXmlAdapter)target);

            Assert.AreEqual(a.A, c.A);
            Assert.IsNull(c.B);
            Assert.AreEqual(a.C, c.C);
        }