ClientNode.cs 4.3 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dolen.Agv
{
    /// <summary>
    /// 客户端节点
    /// </summary>
    public class ClientNode
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int ID { get; private set; }
        /// <summary>
        /// IP地址
        /// </summary>
        public string IP { get; private set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 别名
        /// </summary>
        public string AliceName { get; set; } = "";
        /// <summary>
        /// 料架号
        /// </summary>
        public string RFID { set; get; } = "";
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { set; get; } = "";
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool Online { get; private set; } = false;
        /// <summary>
        /// 是否开启
        /// </summary>
        public bool Enabled { private set; get; }
        /// <summary>
        /// 动作
        /// </summary>
        public ClientAction Action { set; get; } = ClientAction.None;
        /// <summary>
        /// 优先级
        /// </summary>
        public ClientLevel Level { set; get; } = ClientLevel.None;
        /// <summary>
        /// 客户端类型
        /// </summary>
        public ClientType Type {private set; get; } = ClientType.None;
        /// <summary>
        /// 料架类型
        /// </summary>
        public ClientShelf Shelf { private set; get; } = ClientShelf.None;

        public ClientNode(int id,string ip,string name,bool enabled=false,ClientType clientType = ClientType.None)
        {
            ID = id;
            IP = ip;
            Name = name;
            AliceName = name;
            Enabled = enabled;
            Type = clientType;
        }
        /// <summary>
        /// 修改节点状态
        /// </summary>
        /// <param name="action">动作</param>
        /// <param name="rfid">rfid</param>
        /// <param name="clientShelf">料架类型</param>
        /// <param name="level">紧急程度</param>
        public void ChangeState(ClientAction action, string rfid = "",ClientShelf clientShelf = ClientShelf.None,ClientLevel level= ClientLevel.None)
        {
            Action = action;
            RFID = rfid;
            Level = level;
        }

        /// <summary>
        /// 所有属性的文本形式
        /// </summary>
        /// <returns></returns>
        public string ToText()
        {
            System.Reflection.PropertyInfo[] info = this.GetType().GetProperties();
            string[] arr = new string[info.Length];
            for (int i = 0; i < info.Length; i++)
                arr[i] = info[i].Name + "=" + info[i].GetValue(this).ToString();
            return string.Join(",", arr);
        }
        public override bool Equals(object obj)
        {
            if (obj is ClientNode)
            {
                ClientNode node = (ClientNode)obj;
                if (ID.Equals(node.ID) && RFID.Equals(node.RFID) && Remark.Equals(node.Remark) &&
                    Action.Equals(node.Action) && Level.Equals(node.Level) && Type.Equals(node.Type) &&
                    Shelf.Equals(node.Shelf))
                    return true;
                else
                    return false;
            }
            return false;
        }
        ///// <summary>
        ///// 拷贝一个新的实例
        ///// </summary>
        ///// <returns></returns>
        //public Node ToCopy()
        //{
        //    Node node = new Node();
        //    System.Reflection.PropertyInfo[] info1 = node.GetType().GetProperties();
        //    System.Reflection.PropertyInfo[] info2 = this.GetType().GetProperties();
        //    for (int i = 0; i < info1.Length; i++)
        //        info1[i].SetValue(node, info2[i].GetValue(this));
        //    return node;

        //}

        /// <summary>
        /// 节点离线
        /// </summary>
        public void Offline()
        {
            RFID = "";
            Remark = "";
            Action = ClientAction.None;
            Level = ClientLevel.None;
            Shelf = ClientShelf.None;
            Online = false;
        }
    }
}