public HostIp DataRowToHostIp(DataRow row)
        {
            var ip = new HostIp
            {
                Id        = int.Parse(row["Id"] + ""),
                IpAddress = row["IpAddress"] + ""
            };

            return(ip);
        }
        /// <summary>
        /// 添加或更新host指向
        /// </summary>
        /// <param name="name"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public int AddHostDirect(HostName name, HostIp ip)
        {
            //先查找
            var sql = $"select * from HostToIp where NameId={name.Id}";
            var dt  = Helper.Select(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                sql = $"update hosttoip set Ipid={ip.Id} where NameId={name.Id}";
            }
            else
            {
                sql = $"insert into HostToIp(NameId,IpId) values({name.Id},{ip.Id})";
            }
            return(Helper.Execute(sql));
        }
Beispiel #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            hash ^= devices_.GetHashCode();
            hash ^= tags_.GetHashCode();
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            hash ^= processingModules_.GetHashCode();
            if (IsDedicatedProcessingNode != false)
            {
                hash ^= IsDedicatedProcessingNode.GetHashCode();
            }
            if (HostIp.Length != 0)
            {
                hash ^= HostIp.GetHashCode();
            }
            if (MetadataJson.Length != 0)
            {
                hash ^= MetadataJson.GetHashCode();
            }
            if (State != 0)
            {
                hash ^= State.GetHashCode();
            }
            if (Latency != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Latency);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #4
0
 public override int GetHashCode() {
   int hash = 1;
   if (HostName.Length != 0) hash ^= HostName.GetHashCode();
   if (HostIp.Length != 0) hash ^= HostIp.GetHashCode();
   if (ProcessId != 0) hash ^= ProcessId.GetHashCode();
   if (NodeName.Length != 0) hash ^= NodeName.GetHashCode();
   if (NodeId != 0UL) hash ^= NodeId.GetHashCode();
   if (ChannelName.Length != 0) hash ^= ChannelName.GetHashCode();
   if (ChannelId != 0UL) hash ^= ChannelId.GetHashCode();
   if (MessageType.Length != 0) hash ^= MessageType.GetHashCode();
   if (ProtoDesc.Length != 0) hash ^= ProtoDesc.GetHashCode();
   if (Id != 0UL) hash ^= Id.GetHashCode();
   if (qosProfile_ != null) hash ^= QosProfile.GetHashCode();
   if (socketAddr_ != null) hash ^= SocketAddr.GetHashCode();
   if (ServiceName.Length != 0) hash ^= ServiceName.GetHashCode();
   if (ServiceId != 0UL) hash ^= ServiceId.GetHashCode();
   return hash;
 }
        /// <summary>
        /// 添加ip地址
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public HostIp AddHostIp(HostIp ip)
        {
            var conn = new SQLiteCommand(new SQLiteConnection(ExtentionClass.ConnectinString));

            conn.Connection.Open();
            var h = new SQLiteHelper(conn);

            var sql = $"insert into hostip(IpAddress) values('{ip.IpAddress}')";
            var n   = h.Execute(sql);

            if (n > 0)
            {
                sql = "select last_insert_rowid() as Id from hostip;";
                var id = h.ExecuteScalar <int>(sql);

                sql = $"select * from hostip where id = {id}";
                var dt = h.Select(sql);
                return(dt?.AsEnumerable().Select(DataRowToHostIp).FirstOrDefault());
            }
            return(null);
        }
Beispiel #6
0
        private Host GetHost(LogEventInfo logEventInfo)
        {
            var hostId   = HostId?.Render(logEventInfo);
            var hostName = HostName?.Render(logEventInfo);
            var hostIp   = HostIp?.Render(logEventInfo);

            if (string.IsNullOrEmpty(hostId) &&
                string.IsNullOrEmpty(hostName) &&
                string.IsNullOrEmpty(hostIp))
            {
                return(null);
            }

            var host = new Host
            {
                Id   = hostId,
                Name = hostName,
                Ip   = string.IsNullOrEmpty(hostIp) ? null : new[] { hostIp }
            };

            return(host);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            hash ^= devices_.GetHashCode();
            hash ^= tags_.GetHashCode();
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            hash ^= processingModules_.GetHashCode();
            if (IsDedicatedProcessingNode != false)
            {
                hash ^= IsDedicatedProcessingNode.GetHashCode();
            }
            if (HostIp.Length != 0)
            {
                hash ^= HostIp.GetHashCode();
            }
            if (MetadataJson.Length != 0)
            {
                hash ^= MetadataJson.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #8
0
        public SQLResult Validate()
        {
            SQLResult result = new SQLResult(true, "Xác thực thành công.");

            //Validate Name
            if (Name == null || Name.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Tên thiết bị không được để trống.";
                return(result);
            }

            //Validate IP
            if (IP == null || IP.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Địa chỉ IP không được để trống.";
                return(result);
            }

            if (!ValidateIp(IP))
            {
                result.Result = false;
                result.Detail = "Định dạng IP không đúng.";
                return(result);
            }

            //Valid Gateway
            if (GateWay == null || GateWay.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Gateway không được để trống.";
                return(result);
            }

            if (!ValidateIp(GateWay))
            {
                result.Result = false;
                result.Detail = "Định dạng Gateway không đúng.";
                return(result);
            }

            //Valid Subnet
            if (Subnet == null || Subnet.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Subnet không được để trống.";
                return(result);
            }

            if (!ValidateIp(Subnet))
            {
                result.Result = false;
                result.Detail = "Định dạng subnet không đúng.";
                return(result);
            }

            //Valid HostIP
            if (HostIp == null || HostIp.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Địa chỉ host không được để trống.";
                return(result);
            }

            if (!ValidateIp(HostIp))
            {
                result.Result = false;
                result.Detail = "Định dạng địa chỉ host không đúng.";
                return(result);
            }

            //Validate MAC
            if (MAC == null || MAC.Count() <= 0)
            {
                result.Result = false;
                result.Detail = "Địa chỉ MAC không được để trống.";
                return(result);
            }
            else
            {
                string inputMAC = MAC.Replace(" ", "").Replace(":", "").Replace("-", "");
                Regex  r        = new Regex("^[a-fA-F0-9]{12}$");
                if (!r.IsMatch(inputMAC))
                {
                    result.Result = false;
                    result.Detail = "Định dạng địa chỉ MAC không đúng.";
                    return(result);
                }
            }

            return(result);
        }