using System;
using System.Data;


namespace Core.Mes.IBaseInterface
{

    /// <summary>
    /// 消息原型
    /// </summary>
    [Serializable]
    public struct CallingMessage
    {
        //== 服务名
        public string ServerName;
        //== 程序集名
        public string AssemblyName;
        //== 类名
        public string ClassName;
        //== 方法名
        public string MethodName;
        //== 参数数组
        public object[] args;
        //== 网络传输方式
        public NetWorkTransType TransType;
        //== 服务类型
        public MesServerType ServerType;
        //== 访问类型
        public VisitType visitType;

        public RequestType requestType;

        public CallingMessage(string ServerName, string AssemblyName, string ClassName, string MethodName, object[] args)
        {
            this.ServerName = ServerName;
            //== 常用

            this.AssemblyName = AssemblyName;
            this.ClassName = ClassName;
            this.MethodName = MethodName;
            this.args = args;

            //== 特殊
            this.TransType = NetWorkTransType.Remoting;
            this.ServerType = MesServerType.IComponentContainServer;
            this.visitType = VisitType.Method;
            this.requestType = RequestType.DirectReturn;
        }
    }

    /// <summary>
    /// 消息原型
    /// </summary>
    [Serializable]
    public struct CallingMessageEx
    {
        //== 服务名
        public string ServerName;
        //== 程序集名
        public string AssemblyName;
        //== 类名
        public string ClassName;
        //== 方法名
        public string MethodName;
        //== 参数数组
        public object[] args;
        //== 网络传输方式
        public NetWorkTransType TransType;
        //== 服务类型
        public MesServerType ServerType;
        //== 访问类型
        public VisitType visitType;

        public RequestType requestType;

        public int RedirectLimit;
        public bool InnerServerRedirect;

        public CallingMessageEx(string ServerName, string AssemblyName, string ClassName, string MethodName, object[] args)
        {
            this.ServerName = ServerName;
            //== 常用

            this.AssemblyName = AssemblyName;
            this.ClassName = ClassName;
            this.MethodName = MethodName;
            this.args = args;

            //== 特殊
            this.TransType = NetWorkTransType.Remoting;
            this.ServerType = MesServerType.IComponentContainServer;
            this.visitType = VisitType.Method;
            this.requestType = RequestType.DirectReturn;

            this.RedirectLimit = 3;
            this.InnerServerRedirect = true;
        }

        public CallingMessage ToCallingMessage()
        {
            CallingMessage cm;
            cm.args = this.args;
            cm.AssemblyName = this.AssemblyName;
            cm.ClassName = this.ClassName;
            cm.MethodName = this.MethodName;
            cm.requestType = this.requestType;
            cm.ServerName = this.ServerName;
            cm.ServerType = this.ServerType;
            cm.TransType = this.TransType;
            cm.visitType = this.visitType;
            return cm;
        }

        public void FromCallingMessage(CallingMessage cm)
        {
            this.args = cm.args;
            this.AssemblyName = cm.AssemblyName;
            this.ClassName = cm.ClassName;
            this.MethodName = cm.MethodName;
            this.requestType = cm.requestType;
            this.ServerName = cm.ServerName;
            this.ServerType = cm.ServerType;
            this.TransType = cm.TransType;
            this.visitType = cm.visitType;
            this.RedirectLimit = 0;
            this.InnerServerRedirect = true;
        }
    }

    /// 

    /// <summary>
    /// 网络传输方式枚举
    [Serializable]
    public enum NetWorkTransType
    {
        Remoting,
        XmlWebService
    }
    /// <summary>
    /// 服务类型
    [Serializable]
    public enum MesServerType
    {
        IComponentContainServer,
        MesSystemBaseServer
    }
    /// <summary>
    /// 访问类型
    /// </summary>
    [Serializable]
    public enum VisitType
    {
        Method,
        Property
    }
    /// <summary>
    /// 请求方式
    /// </summary>
    [Serializable]
    public enum RequestType
    {
        DirectReturn,
        DirectBroakcast,
        AfterHandlerBroakcast
    }
    /// <summary>
    /// 用户验证信息 
    /// </summary>
    [Serializable]
    public struct ValidateInfo
    {
        public string ValidateGuid;

        public string LoginID;

        public ValidateInfo(string validateGuid, string loginID)
        {
            this.ValidateGuid = validateGuid;
            this.LoginID = loginID;
        }
    }
    /// <summary>
    /// 存储于服务端的客户信息
    /// </summary>
    [Serializable]
    public struct UserInfo
    {
        public string ValidateGuid;

        public string UserName;

        public string LoginID;	//登录ID

        public string UserID;		//用户ID

        public string UserBc;		//班次

        public string UserBb;		//班别

        public string UserRz;		//工作制

        public string UserDepID;	//部门

        public string UserDepName;

        public string UserRoleID;	//角色

        public string UserRoleName;

        public System.IO.Stream MenuConfigStream;

    }
    /// <summary>
    /// 客户端调用服务端的返回对象，包括错误代码、错误信息和返回对象实体。
    /// 在Web传输中，返回对象实体如果是DataSet类型，将存入RealDataSet中。
    /// </summary>
    [Serializable]
    public struct ReturnObject
    {
        //== 错误代码
        public int ErrCode;
        //== 错误信息
        public string ErrMessage;

        public object RealObject;


        //== 用于Web传输时存放DataSet类型的返回实体
        public DataSet RealDataSet;

        public ReturnObject(object RealObject)
        {
            this.RealObject = RealObject;
            this.ErrCode = 0;
            this.ErrMessage = "";
            this.RealDataSet = null;
        }

        public ReturnObject(object RealObject, string ErrMessage)
        {
            this.RealObject = RealObject;
            this.ErrCode = 1;
            this.ErrMessage = ErrMessage;
            this.RealDataSet = null;
        }

        public ReturnObject(object RealObject, int ErrCode)
        {
            this.RealObject = RealObject;
            this.ErrCode = ErrCode;
            this.ErrMessage = "";
            this.RealDataSet = null;
        }

        public ReturnObject(object RealObject, int ErrCode, string ErrMessage)
        {
            this.RealObject = RealObject;

            this.ErrCode = ErrCode;
            this.ErrMessage = ErrMessage;
            this.RealDataSet = null;
        }

    }
    /// <summary>
    /// 客户端调用服务端的返回对象类型，用于指示返回值类型：正常数据集；重定向请求地址；服务器端缓存文件类型。
    /// </summary>
    [Serializable]
    public enum ReturnObjectType
    {
        NormalDataSet = 1,
        RedirectURL = 2,
        FileAddress = 3
    }
    /// <summary>
    /// 客户端调用服务端的返回对象 ， 用于指示服务器端缓存文件地址。
    /// </summary>
    [Serializable]
    public class ReturnFileInfo
    {
        string _serverAddress = "";
        public string Server { get { return _serverAddress; } }

        string _fullFileName = "";
        public string FullFileName { get { return _fullFileName; } }

        int _fileSize = 0;
        public int FileSize { get { return FileSize; } }


        string _taskId = "";
        public string TaskID { get { return _taskId; } }

        public ReturnFileInfo(string _server, string _filename, int _size, string _taskid)
        {
            _serverAddress = _server;
            _fullFileName = _filename;
            _fileSize = _size;
            _taskId = _taskid;
        }
    }
    /// <summary>
    /// 客户端调用服务端的返回对象，包括错误代码、错误信息和返回对象实体。
    /// 在Web传输中，返回对象实体如果是DataSet类型，将存入RealDataSet中。
    /// </summary>
    [Serializable]
    public struct ReturnObjectEx
    {
        //== 错误代码
        public int ErrCode;
        //== 错误信息
        public string ErrMessage;

        public object RealObject;

        public string ReDirectURL;

        public ReturnObjectType ObjectType;

        //== 用于Web传输时存放DataSet类型的返回实体
        public DataSet RealDataSet;

        public ReturnObjectEx(object RealObject)
        {
            this.RealObject = RealObject;
            this.ErrCode = 0;
            this.ErrMessage = "";
            this.ReDirectURL = "";
            this.RealDataSet = null;
            this.ObjectType = ReturnObjectType.NormalDataSet;
        }

        public ReturnObjectEx(string ReDirectTo)
        {
            this.RealObject = null;
            this.ErrCode = 0;
            this.ErrMessage = "";
            this.RealDataSet = null;
            this.ReDirectURL = ReDirectTo;
            this.ObjectType = ReturnObjectType.RedirectURL;
        }

        public ReturnObjectEx(object RealObject, string ErrMessage)
        {
            this.RealObject = RealObject;
            this.ErrCode = 1;
            this.ErrMessage = ErrMessage;
            this.RealDataSet = null;
            this.ReDirectURL = "";
            this.ObjectType = ReturnObjectType.NormalDataSet;
        }

        public ReturnObjectEx(object RealObject, int ErrCode)
        {
            this.RealObject = RealObject;
            this.ErrCode = ErrCode;
            this.ErrMessage = "";
            this.ReDirectURL = "";
            this.RealDataSet = null;
            this.ObjectType = ReturnObjectType.NormalDataSet;
        }

        public ReturnObjectEx(object RealObject, int ErrCode, string ErrMessage)
        {
            this.RealObject = RealObject;

            this.ErrCode = ErrCode;
            this.ErrMessage = ErrMessage;
            this.ReDirectURL = "";
            this.RealDataSet = null;
            this.ObjectType = ReturnObjectType.NormalDataSet;
        }

    }
    /// <summary>
    /// 客户端调用服务端的返回对象，包括错误代码、错误信息。 
    /// </summary>
    [Serializable]
    public struct SimpleReturnObject
    {
        //== 错误代码
        public int ErrCode;
        //== 错误信息
        public string ErrMessage;

        public SimpleReturnObject(string ErrMessage)
        {
            this.ErrCode = 1;
            this.ErrMessage = ErrMessage;
        }

        public SimpleReturnObject(int ErrCode)
        {
            this.ErrCode = ErrCode;
            this.ErrMessage = "";
        }

        public SimpleReturnObject(int ErrCode, string ErrMessage)
        {
            this.ErrCode = ErrCode;
            this.ErrMessage = ErrMessage;
        }

    }


    public interface ICommon
    {
        ReturnObject MethodHandler(CallingMessage message, ValidateInfo info);
        ReturnObjectEx MethodHandlerEx(CallingMessageEx message, ValidateInfo info);
    }

}

