Example #1
0
        private static interfaceClientHanlder GetHandlerByCommand(enumCommandType type)
        {
            interfaceClientHanlder typeResult = null;

            switch (type)
            {
            case enumCommandType.UP_HEART_SEND: typeResult = new ClientHandlerHeartBreak(); break;

            case enumCommandType.UP_PRODUCT_SEND: typeResult = new ClientHanlderProductInfo(); break;

            case enumCommandType.UP_DEVICE_SETTING_SEND: typeResult = new ClientHandlerDeviceSetting(); break;

            case enumCommandType.UP_DEVICE_REPORT_SEND: typeResult = new ClientHandlerDeviceReport(); break;

            case enumCommandType.UP_DEVICE_CALL_MATERIAL_SEND: typeResult = new ClientHandlerDeviceCallMaterial(); break;

            case enumCommandType.UP_DEVICE_STARTEND_SEND: typeResult = new ClientHandlerDeviceStartEnd(); break;

            case enumCommandType.DOWN_SHEDULE_RESP: typeResult = new ClientHandlerDownScheduleResp(); break;

            case enumCommandType.DOWN_SHEDULE_CLOSE_RESP: typeResult = new ClientHandlerDownScheCloseResp(); break;

            case enumCommandType.DOWN_SHEDULE_DISCARD_RESP: typeResult = new ClientHandlerDownScheDiscardResp(); break;

            default: break;    //typeResult = new ClientHandlerNoneDefault();
            }
            return(typeResult);
        }
Example #2
0
        private static void HandlerByProtocol(NormalDataStruct dataInfo)
        {
            try
            {
                interfaceClientHanlder clientHandler = GetHandlerByCommand(dataInfo.Code);
                byte[] byteResult = clientHandler.HandlerClientData(dataInfo.Content);
                //返回信息
                byte[] buffResp = null;
                if (clientHandler.ShouldResponse())
                {
                    Coder.EncodeServerResp(dataInfo.Code + 1, byteResult, out buffResp);
                    dataInfo.stream.Write(buffResp, 0, buffResp.Length);
                }
                int tempMachineId = dataInfo.Code == enumCommandType.UP_DEVICE_SETTING_SEND ?
                                    ConvertHelper.BytesToInt16(buffResp, buffResp.Length - 2, true) : //设置协议没有设备ID,所以用返回回去的ID
                                    ConvertHelper.BytesToInt16(dataInfo.Content, true);               //其它协议以设备ID开头

                if (netConnection.ContainsKey(tempMachineId))
                {
                    netConnection[tempMachineId] = dataInfo.stream;
                }
                else
                {
                    netConnection.Add(tempMachineId, dataInfo.stream);
                }
            }
            catch (Exception ex)
            {
                db.RecordErrorInfo(enumSystemErrorCode.TcpHandlerException, ex, dataInfo.IpAddress, dataInfo.Content);
            }
        }