using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dispatch
{
    /// <summary>
    /// 接收事务数据
    /// </summary>
    public class ReceivedEventArgs : EventArgs
    {
        /// <summary>
        ///  字节缓存
        /// </summary>
        public byte[] buffer;
        /// <summary>
        /// 类型
        /// </summary>
        public string type;
    }
    /// <summary>
    /// 虚拟通信基类
    /// </summary>
    public abstract class CommunicationBase
    {
    /// <summary>
    /// 发送数据
    /// </summary>
    /// <param name="buffer"></param>
    /// <param name="o"></param>
        public abstract void SendData(byte[] buffer,object o);
        /// <summary>
        /// 接收事件操作
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        public delegate void ReceivedEventHandler(object o, ReceivedEventArgs e);
        /// <summary>
        /// 接收事件
        /// </summary>
        public event ReceivedEventHandler ReceivedEvent;
        /// <summary>
        /// 打开联接
        /// </summary>
        public abstract void Open();
        /// <summary>
        /// 关闭联接
        /// </summary>
        public abstract void Close();
        private bool isOpen;
        /// <summary>
        /// 通信标识
        /// </summary>
        /// <returns></returns>
        public virtual object GetTag()
        {
            return null;
        }
        /// <summary>
        /// 联接是否打开
        /// </summary>
        public bool IsOpen
        {
            get { return isOpen; }
            set { isOpen = value; }
        }
        /// <summary>
        /// 接收信息处理
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        protected virtual void OnReceivedEvent(object o, ReceivedEventArgs e)
        {
            if (ReceivedEvent != null)
            {
                ReceivedEvent(o, e);
            }
        }
        /// <summary>
        /// 释放联接
        /// </summary>
        public virtual void Dispose()
        {
            
        }
    }
}
