コード例 #1
0
        private DataSet ReadData(CommandSendData csd)
        {
            // Build DataSet Scheme

            DataSet   ds1   = new DataSet();
            DataTable table = new DataTable(DateTime.Now.ToString("hh-mm-ss"));

            ds1.Tables.Add(table);

            table.Columns.Add(new DataColumn("CommandGUID", typeof(System.String)));
            table.Columns.Add(new DataColumn("Commandtype", typeof(System.String)));

            foreach (string paramname in csd.Params.Keys)
            {
                table.Columns.Add(new DataColumn(paramname, typeof(System.String)));
            }

            // Insert Data to DataSet
            DataRow dr = table.NewRow();

            dr["CommandGUID"] = csd.CommandGUID;
            dr["Commandtype"] = Convert.ToInt32(csd.CommandType).ToString();

            foreach (string paraname in csd.Params.Keys)
            {
                dr[paraname] = csd.Params[paraname];
            }

            table.Rows.Add(dr);
            return(ds1);
        }
コード例 #2
0
        private string SendMsgToServer(CommandSendData csd)
        {
            try
            {
                _ClientSocket.Connect();

                PacketHead ph = csd.PacketHead;

                //ph.SourceIP = _ClientSocket.LocalIP;
                //ph.SourcePort = _ClientSocket.LocalPort;

                csd.PacketHead = ph;

                string result = _ClientSocket.SendMsg(csd.EncodePackage());
                _ClientSocket.DisConnect(false);
                return(result);
            }
            catch (Exception ex)
            {
                Program.Log.Write(ex);
                return(null);
            }
        }
コード例 #3
0
        private void SendCommand2Server(SocketOutChannel ch, DataSet ds)
        {
            CommandSendData csd = new CommandSendData();

            PacketHead ph = new PacketHead();

            ph.PacketType      = CommandSendData.PacketType;
            ph.DestinationIP   = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.ClientSocketParams.ServerIP;
            ph.DestinationPort = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.ClientSocketParams.ServerPort;
            ph.SourceIP        = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.ClientSocketParams.CallbackIP;
            ph.SourcePort      = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.ClientSocketParams.CallbackPort;

            csd.PacketHead = ph;


            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                csd.Params.Clear();
                csd.CommandGUID = "";

                foreach (SocketOutQueryResultItem item in ch.Rule.QueryResult.MappingList)
                {
                    //string TargetField = item.ThirdPartyDBPatamter.FieldName.Trim();
                    string TargetField = item.TargetField.Trim();
                    if (TargetField == "")
                    {
                        continue;
                    }

                    if (TargetField.ToUpper() == ("CommandGUID").ToUpper())
                    {
                        csd.CommandGUID = dr[TargetField].ToString();
                        continue;
                    }
                    if (TargetField.ToUpper().ToUpper() == ("Commandtype").ToUpper())
                    {
                        csd.CommandType = (CommandBase.CommandTypeEnum)Convert.ToInt32(dr[TargetField].ToString());
                        continue;
                    }

                    if (ds.Tables[0].Columns.IndexOf(TargetField) < 0)
                    {
                        Program.Log.Write(LogType.Error, TargetField + " is not exist in dataset!\r\n");
                    }
                    else
                    {
                        csd.Params.Add(TargetField, dr[TargetField].ToString());
                    }
                }

                if (csd.CommandGUID == null || csd.CommandGUID.Trim() == "")
                {
                    csd.CommandGUID = Guid.NewGuid().ToString();
                }

                //byte[] result = _ClientSocket.SendMsg(csd.EncodePackage());
                string result = this.SendMsgToServer(csd);

                if (result != null)
                {
                    CommandRespSendData crsd = new CommandRespSendData();
                    crsd.DecodePackagea(result);
                    if (OnDataDischarge != null)
                    {
                        OnDataDischarge(new string[] { dr["Data_ID"].ToString() });
                    }
                    Program.Log.Write(LogType.Error, "SendMsg Success! SendResult= " + crsd.SendResult + "\r\n");


                    //if (crsd.SendResult == "1")
                    //{
                    //    if (OnDataDischarge != null)
                    //        OnDataDischarge(new string[] { dr["Data_ID"].ToString() });
                    //    Program.Log.Write(LogType.Debug, "SendMsg Success! SendResult=1\r\n");
                    //}
                    //else //2007-3-9 Add: Send success, Set Processflag =1, and write a log
                    //{
                    //    if (OnDataDischarge != null)
                    //        OnDataDischarge(new string[] { dr["Data_ID"].ToString() });
                    //    Program.Log.Write(LogType.Error, "SendMsg Success! SendResult= " + crsd.SendResult + "\r\n");
                    //}
                }
                else
                {
                    Program.Log.Write(LogType.Error, "SendMsg Failure!\r\n");
                }
            }
        }