예제 #1
0
        public ClientIP Add(ClientIP clientIP)
        {
            clientIP.CreatedDate = DateTime.Now;
            clientIP.LastUpdatedDate = DateTime.Now;

            using (var dbContext = new DataEntities())
            {
                dbContext.ClientIPs.AddObject(clientIP);
                dbContext.SaveChanges();
            }

            return clientIP;
        }
예제 #2
0
 /// <summary>
 /// 创建新的 ClientIP 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 public static ClientIP CreateClientIP(global::System.Int32 id)
 {
     ClientIP clientIP = new ClientIP();
     clientIP.ID = id;
     return clientIP;
 }
예제 #3
0
 /// <summary>
 /// 用于向 ClientIPs EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToClientIPs(ClientIP clientIP)
 {
     base.AddObject("ClientIPs", clientIP);
 }
예제 #4
0
        public MonitorDataResponse MoniterServerSubmitToCenterrServer([FromBody]MonitorDataRequest monitorData)
        {
            if (monitorData == null)
            {
                throw new BadRequestException();
            }

            // 查询客户端IP所属的运营商
            IPRepository ipRep = new IPRepository();
            var ipEntity = ipRep.RetriveIP(monitorData.ClientPublicIP);

            string realOperator = ipEntity == null ? null : ipEntity.IPBelongTo;

            string realOperatorProvince = null;
            string realOperatorCity = null;
            if (ipEntity != null)
            {
                realOperatorProvince = ipEntity.Province;
                realOperatorCity = ipEntity.City;
            }

            bool isSameProvice = false;

            if(String.IsNullOrWhiteSpace(realOperatorProvince) && String.IsNullOrWhiteSpace(monitorData.ExpectedOperatorProvice))
            {
                isSameProvice = true;
            }
            else if(monitorData.ExpectedOperatorProvice.Equals(realOperatorProvince))
            {
                isSameProvice = true;
            }

            var status = IPMonitorStatus.Pending;

            if (!String.IsNullOrEmpty(realOperator))
            {
                realOperator = realOperator.Trim();
            }

            if (String.IsNullOrEmpty(realOperator))
            {
                if (ipEntity != null)
                {
                    realOperator = ipEntity.IPBelongTo = ipEntity.Country;
                }
                status = IPMonitorStatus.Unknown;
            }
            else if (isSameProvice && isISPMatched(monitorData.ExpectedOperator,realOperator))
            {
                status = IPMonitorStatus.Normal;
            }
            else
            {
                status = IPMonitorStatus.Exception;
            }

            ClientIP clientIP = new ClientIP
            {
                ClientProvince = monitorData.ClientProvince,
                ClientCity = monitorData.ClientCity,
                ClientDistinct = monitorData.ClientDistinct,
                ClientDetailAddr = monitorData.ClientDetailAddress,
                ClientRecordor = monitorData.ClientRecordor,
                ClientPublicIP = monitorData.ClientPublicIP,
                ClientPrivateIP = monitorData.ClientPrivateIP,
                SubmitFromServerIP = Context.ClientIP,
                Status = (int)status,
                ExpectedOperatorProvince = monitorData.ExpectedOperatorProvice,
                ExpectedOperatorCity = monitorData.ExpectedOperatorCity,
                ExpectedOperator = monitorData.ExpectedOperator,
                RealOperator = realOperator,
                RealOperatorProvince = realOperatorProvince,
                RealOperatorCity = realOperatorCity,
                UserName = Context.LoginName
            };

            MonitorDataRepository mdr = new MonitorDataRepository();
            clientIP = mdr.Add(clientIP);

            MonitorDataResponse response = new MonitorDataResponse();
            response.UID = clientIP.ID;
            response.RealOperator = realOperator;
            response.RealOperatorProvince = realOperatorProvince;
            response.RealOperatorCity = realOperatorCity;

            return response;
        }