Esempio n. 1
0
        public DNS.ExternalInterfaces.IMessage Query(string domain, RecordType queryType, IPEndPoint dnsServer = null, RecordClass rClass = RecordClass.In)
        {
            if (!string.IsNullOrEmpty(domain) && domain.TrySubstring(domain.Length - 1) != ".")
            {
                domain = string.Format("{0}.", domain);
            }

            IMessage request = new Message
            {
                Header = new Header(null)
                {
                    OpCode  = OpCode.Query,
                    QdCount = 1,
                    Id      = (ushort)(new Random()).Next(),
                    Rd      = UseRecursion,
                },
                Questions = new List <IQuestion>
                {
                    new Question(null)
                    {
                        QName  = (queryType == RecordType.PtrRecord ? domain.ToArpa() : domain),
                        QType  = queryType,
                        QClass = rClass,
                    },
                },
            };

            var cached = Cache.CheckCache(request.Questions);

            if (cached != null && cached.Answers != null && cached.Answers.Any())
            {
                cached.Header    = request.Header;
                cached.Questions = request.Questions;
                return(cached.GetExternalAnswer());
            }


            var result = Transport.SendRequest(request, dnsServer ?? _defaultServer1, TimeOut);

            if (result == null || result.Header == null || result.Header.RCode == ResponseCode.FormErr || result.Header.RCode == ResponseCode.ServFail)
            {
                for (var ndx = 1; ndx < Retries; ++ndx)
                {
                    result = Transport.SendRequest(request, dnsServer ?? _defaultServer1, TimeOut);
                    if (result != null && result.Header != null && (result.Header.RCode != ResponseCode.FormErr && result.Header.RCode != ResponseCode.ServFail))
                    {
                        ndx = Retries;
                    }
                }
            }

            if (result != null)
            {
                Cache.AddCache(result);
            }

            return(result != null?result.GetExternalAnswer() : null);
        }
Esempio n. 2
0
        public ActionResult GetToken(string account, string Pwd)
        {
            //account = "admin";
            //Pwd = "4a7d1ed414474e4033ac29ccb8653d9b";
            Sys_User    user = UserService.GetEntity(u => u.F_Account == account).FirstOrDefault();
            LoginResult loginResult;

            if (user == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "用户不存在",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            Sys_UserLogOn userLogOn = UserLogService.GetEntityByUserId(user.F_Id);

            if (userLogOn == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "查询不到密码信息",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            string key = userLogOn.F_UserSecretkey;
            string pwd = DESEncrypt.Encrypt(Pwd, key).ToLower().ToMd5().ToLower();

            if (userLogOn.F_UserPassword == pwd) //登录成功
            {
                Payload payload = new Payload()
                {
                    Account = account,
                    Exp     = DateTime.Now.AddDays(7),
                    Issuer  = "IServer",
                    IMEI    = "0000"
                };
                //创建一个token
                string token = JwtUtils.EncodingToken(payload);
                Cache.AddCache(token, payload, payload.Exp);

                return(Content(token));
            }
            loginResult = new LoginResult()
            {
                Message = "用户名密码错误", Status = false, ResultCode = ResultCode.Error
            };
            return(Json(loginResult));
        }
Esempio n. 3
0
        public DNS.ExternalInterfaces.IMessage Query(IEnumerable <DNS.ExternalInterfaces.IQuestion> questions, IPEndPoint dnsServer = null)
        {
            IMessage request = new Message
            {
                Header = new Header(null)
                {
                    OpCode  = OpCode.Query,
                    QdCount = 1,
                    Id      = (ushort)(new Random()).Next(),
                    Rd      = UseRecursion,
                },
            };

            request.Questions = questions.ToQuestions();

            var cached = Cache.CheckCache(request.Questions);

            if (cached != null && cached.Answers != null && cached.Answers.Any())
            {
                cached.Header    = request.Header;
                cached.Questions = request.Questions;
                return(cached.GetExternalAnswer());
            }

            var result = Transport.SendRequest(request, dnsServer ?? _defaultServer1, TimeOut);

            if (result == null || result.Header == null || result.Header.RCode == ResponseCode.FormErr || result.Header.RCode == ResponseCode.ServFail)
            {
                for (var ndx = 1; ndx < Retries; ++ndx)
                {
                    result = Transport.SendRequest(request, dnsServer ?? _defaultServer1, TimeOut);
                    if (result != null && result.Header != null && (result.Header.RCode != ResponseCode.FormErr && result.Header.RCode != ResponseCode.ServFail))
                    {
                        ndx = Retries;
                    }
                }
            }

            if (result != null)
            {
                Cache.AddCache(result);
            }

            return(result != null?result.GetExternalAnswer() : null);
        }
Esempio n. 4
0
        public ActionResult SearchAllClass()
        {
            List <Buildings> list;

            list = new List <Buildings>();
            var buildings  = ZRoomService.GetEntity(u => u.F_RoomType == "Building").ToList();
            var Floors     = ZRoomService.GetEntity(u => u.F_RoomType == "Floor").ToList();
            var ClassRooms = ZRoomService.GetEntity(u => u.F_RoomType == "ClassRoom").ToList();

            foreach (var item in buildings)
            {
                Buildings building = new Buildings();
                building.Name = item.F_FullName;
                List <Floors> FList = new List <Floors>();
                foreach (var f in Floors)
                {
                    if (f.F_ParentId != item.F_Id)
                    {
                        continue;
                    }
                    Floors floors = new Floors();
                    floors.Name = f.F_FullName;
                    List <ClassRoom> classRooms = new List <ClassRoom>();
                    foreach (var rooms in ClassRooms)
                    {
                        if (rooms.F_ParentId != f.F_Id)
                        {
                            continue;
                        }
                        ClassRoom classRoom = new ClassRoom();
                        AutoMapperConfig.Map(building, classRoom);
                        AutoMapperConfig.Map(floors, classRoom);
                        AutoMapperConfig.Map(rooms, classRoom);
                        classRooms.Add(classRoom);
                    }
                    floors.ClassRooms = classRooms;
                    FList.Add(floors);
                }
                building.Floors = FList;
                list.Add(building);
            }
            Cache.AddCache("AllClasses", list, DateTime.Now.AddDays(1));
            return(Json(list, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        /// <summary>
        /// 处理照明灯的逻辑
        /// </summary>
        /// <param name="index">模块数量</param>
        /// <param name="data">数据</param>
        /// <param name="type">类型编码</param>
        /// <param name="name">模块名称</param>
        /// <returns></returns>
        private int ProcessLamp(int index, byte[] data, int type, string name)
        {
            Actuator Lamp1    = new Actuator();
            string   moduleId = Convert.ToString(data[index++], 16);

            Lamp1.Name = name;
            Lamp1.Type = type;
            int state     = data[index++];
            int moduleNum = state >> 7;

            if (moduleNum == 1)   //一个节点控制两盏灯
            {
                //将单个节点控制多个灯的状态值保存起来
                Cache.AddCache(classRoomId, state);
                int moduleState = state & 0x1;
                Lamp1.Id     = moduleId + "_0";
                Lamp1.State  = moduleState != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp1.IsOpen = moduleState == 1;
                //数据位第4位表示在线状态
                Lamp1.Online       = OnLineState(state);
                Lamp1.Controllable = true;
                Sensors.Add(Lamp1);
                Actuator Lamp2 = new Actuator();
                Lamp2.Name = name;
                Lamp2.Type = type;
                Lamp2.Id   = moduleId + "_1";
                int module1State = (state >> 1) & 0x1;
                Lamp2.State        = module1State != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp2.IsOpen       = module1State == 1;
                Lamp2.Online       = OnLineState(state);
                Lamp2.Controllable = true;
                Sensors.Add(Lamp2);
            }
            else
            {
                Lamp1.Id           = moduleId;
                Lamp1.State        = (state & 1) != 0 ? StateType.StateOpen : StateType.StateClose;
                Lamp1.IsOpen       = (state & 1) == 1;
                Lamp1.Online       = OnLineState(state);
                Lamp1.Controllable = true;
                Sensors.Add(Lamp1);
            }
            return(index);
        }
Esempio n. 6
0
        public StudentModel GetById(int id)
        {
            var key   = string.Format("{0}_id={1}", this.GetType().FullName, id);
            var cache = Cache.GetCache <StudentModel>(key);

            if (cache != null)
            {
                return(cache);
            }

            var test = base.Get <Test_Student, StudentModel>((q) =>
                                                             q.StudentId > 5
                                                             );
            var mod = unitOfWork.GetRepository <Test_Student>().dbSet.FirstOrDefault();
            var map = new MapperConfiguration(x => x.CreateMap <Test_Student, StudentModel>()).CreateMapper();
            var stu = map.Map <StudentModel>(mod);

            Cache.AddCache <StudentModel>(key, stu, DateTime.Now.Date.AddDays(1));
            Cache.RemoverCache(m => m.StartsWith(this.GetType().FullName));
            return(stu);
        }
        /// <summary>
        /// 缓存权限
        /// </summary>
        public void StoragePermissions()
        {
            #region 用户缓存
            //获取用户 Model
            Sys_UserAccount admin = DapperCommand.SelectSingle <Sys_UserAccount>(new { GUID }, " GUID=@GUID ");
            Cache.AddCache(GUID.ToString() + "-Admin", admin, SystemExtends.CacheExpiredTime);
            #endregion
            if (GetAdmin.IsAdmin == 0)
            {
                #region 角色缓存
                //获取用户角色集合
                List <Sys_UserRole> listUserRole = DapperCommand.Select <Sys_UserRole>(new { UserAccId = GUID }, " UserAccId=@UserAccId ").ToList();
                //获取角色OID集合
                List <string> listRoleOID = new List <string>();
                listUserRole.ForEach(x =>
                {
                    if (x.RoleID != null && x.RoleID != "")
                    {
                        string item = "'" + x.RoleID + "'";
                        if (!listRoleOID.Contains(item))
                        {
                            listRoleOID.Add(item);
                        }
                    }
                });

                //获取角色集合 保存至 缓存
                List <Sys_Role> listRoles = DapperCommand.Select <Sys_Role>(new { GUID = listRoleOID.ToArray() }, " GUID in ({0}) and Deleted = 0 ").ToList();
                Cache.AddCache(GUID.ToString() + "-Roles", listRoles, SystemExtends.CacheExpiredTime);
                #endregion

                #region 权限缓存
                //获取角色权限集合
                List <Sys_RoleRight> listRoleRight = DapperCommand.Select <Sys_RoleRight>(new { RoleID = listRoleOID.ToArray() }, " RoleID in ({0}) Deleted = 0 ").ToList();

                //获取权限OID集合
                List <string> listRightOID = new List <string>();
                listRoleRight.ForEach(x =>
                {
                    if (x.RightID != null && x.RightID != "")
                    {
                        string item = "'" + x.RightID + "'";
                        if (!listRightOID.Contains(item))
                        {
                            listRightOID.Add(item);
                        }
                    }
                });
                //获取权限集合 保存至缓存
                List <Sys_Right> listRights = DapperCommand.Select <Sys_Right>(new { GUID = listRightOID.ToArray() }, " GUID in ({0}) Deleted = 0 ").ToList();
                Cache.AddCache(GUID.ToString() + "-Rights", listRights, SystemExtends.CacheExpiredTime);
                #endregion

                #region 模块缓存
                //获取模块OID
                List <string> listModulesOID = new List <string>();
                listRights.ForEach(x =>
                {
                    if (x.ForModuleID != null && x.ForModuleID != "")
                    {
                        string item = "'" + x.ForModuleID + "'";
                        if (!listModulesOID.Contains(item))
                        {
                            listModulesOID.Add(item);
                        }
                    }
                });
                //获取模块集合 保存至缓存
                List <Sys_Module> listModule = DapperCommand.Select <Sys_Module>(new { GUID = listModulesOID.ToArray() }, " GUID in ({0}) Deleted = 0 ").ToList();
                Cache.AddCache(GUID.ToString() + "-Module", listModule, SystemExtends.CacheExpiredTime);
                #endregion
            }
        }
Esempio n. 8
0
        public ActionResult Logon(string account, string Pwd, string imei = "0000")
        {
            //TODO 最终上线要删除
            //测试初始化登录-begin
            //account = "admin";
            //Pwd = "4a7d1ed414474e4033ac29ccb8653d9b";
            Sys_User    user = UserService.GetEntity(u => u.F_Account == account).FirstOrDefault();
            LoginResult loginResult;

            if (user == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "用户不存在",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };

                return(Json(loginResult));
            }
            Sys_UserLogOn userLogOn = UserLogService.GetEntityByUserId(user.F_Id);

            if (userLogOn == null)
            {
                loginResult = new LoginResult()
                {
                    Message    = "查询不到密码信息",
                    Status     = false,
                    ResultCode = ResultCode.Error
                };
                return(Json(loginResult));
            }
            string key = userLogOn.F_UserSecretkey;
            string pwd = DESEncrypt.Encrypt(Pwd, key).ToLower().ToMd5().ToLower();

            if (userLogOn.F_UserPassword == pwd) //登录成功
            {
                if (userLogOn.F_LastVisitTime != null)
                {
                    userLogOn.F_PreviousVisitTime = userLogOn.F_LastVisitTime;
                }
                userLogOn.F_LastVisitTime = DateTime.Now;
                userLogOn.F_LogOnCount    = userLogOn.F_LogOnCount + 1;
                UserLogService.UpdateEntityInfo(userLogOn);
                Payload payload = new Payload()
                {
                    Account = account,
                    Exp     = DateTime.Now.AddDays(7),
                    IMEI    = imei,
                    Issuer  = "IServer"
                };
                //创建一个token
                string token = JwtUtils.EncodingToken(payload);
                Cache.AddCache(token, payload, DateTime.Now.AddDays(7));
                loginResult = new LoginResult
                {
                    Message    = "登录成功",
                    Status     = true,
                    AppendData = token,
                    ResultCode = ResultCode.Ok
                };
                return(Json(loginResult));
            }
            loginResult = new LoginResult()
            {
                Message = "用户名密码错误", Status = false, ResultCode = ResultCode.Error
            };
            return(Json(loginResult));
        }
Esempio n. 9
0
        /// <summary>
        /// 解析Model类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">Model类</param>
        /// <returns></returns>
        public static TableInfo GetDataFields <T>(T obj = null) where T : class, new()
        {
            Type type;

            if (obj == null)
            {
                type = typeof(T);
            }
            else
            {
                type = obj.GetType();
            }
            TableInfo tableInfo = new TableInfo();

            //type.Name 即为Class名称
            tableInfo.TableName = type.Name;
            //Model字段List
            tableInfo.Colums = new List <ColumInfo>();
            //判断是否存在缓存中
            object obj2 = Cache.ReadCache(type.Name);

            if (obj2 != null)
            {
                tableInfo = (TableInfo)obj2;
            }
            else
            {
                //读取Model下所有的公共字段(属性)
                PropertyInfo[] properties = type.GetProperties();
                tableInfo.Props = properties;
                PropertyInfo[] array = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyInfo propertyInfo = array[i];
                    //获取SqlFieldAttribute特性
                    SqlFieldAttribute[] array2    = (SqlFieldAttribute[])propertyInfo.GetCustomAttributes(typeof(SqlFieldAttribute), false);
                    ColumInfo           columInfo = new ColumInfo();
                    columInfo.ColName = propertyInfo.Name;
                    columInfo.ColType = propertyInfo.PropertyType;
                    if (array2 != null && array2.Length > 0)
                    {
                        //存在SqlFieldAttribute特性就读取
                        SqlFieldAttribute sqlFieldAttribute = array2[0];
                        columInfo.ColCanWrite = !sqlFieldAttribute.Identity;
                        columInfo.Identity    = sqlFieldAttribute.Identity;
                        columInfo.ColIsKey    = sqlFieldAttribute.Key;
                        columInfo.ColIsIgnore = sqlFieldAttribute.Ignore;
                    }
                    else
                    {
                        //不存在则默认
                        columInfo.ColIsKey    = false;
                        columInfo.ColCanWrite = true;
                        columInfo.ColIsIgnore = false;
                        columInfo.Identity    = false;
                    }
                    tableInfo.Colums.Add(columInfo);
                }
                //添加到缓存
                Cache.AddCache(tableInfo.TableName, tableInfo, DateTime.Now.AddMonths(1));
            }
            return(tableInfo);
        }