コード例 #1
0
ファイル: AccountCore.cs プロジェクト: jingyung/patstest
 public void AddNetWorkIdItem(SocketAsyncEventArgs S, string NetworkId, string Seq, string UserId, string Data)
 {
     try
     {
         lock (_NetworkIdItem)
         {
             NetWorkIdItem item = new NetWorkIdItem();
             //DataToken tk = (DataToken)S.UserToken;
             //item.TokenId = tk.TokenId;
             item.OldSeq = Seq;
             item.NewSeq = Seq;
             item.UserId = UserId;
             item.Data   = Data;
             _NetworkIdItem[NetworkId] = item;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
ファイル: TradeProvider.cs プロジェクト: jingyung/patstest
        /// <summary>
        /// 新增單回AP
        /// </summary>
        /// <param name="Account"></param>
        /// <param name="buffer"></param>
        private byte[] SendOrderDataToAP(string Account, byte head, string NetWorkID, byte[] buffer)
        {
            byte[] retBuffer = null;
            try
            {
                Dictionary <int, SocketAsyncEventArgs> Sockets = this._AccountCore.FindSAEA(Account);
                SocketRaw.Header Head = new SocketRaw.Header();
                Head.HEAD = new byte[1] {
                    head
                };
                Head.MESSAGETIME = ASCIIEncoding.ASCII.GetBytes(DateTime.Now.ToString("HHmmssfff"));
                byte[] headbyte;
                byte[] netoworkid = ASCIIEncoding.ASCII.GetBytes(NetWorkID);
                //取seq
                NetWorkIdItem item = _AccountCore.FindNetWorkIdItem(netoworkid);
                if (item != null)
                {
                    Head.OLDSEQ = ASCIIEncoding.ASCII.GetBytes(item.OldSeq.PadRight(9, ' '));
                    Head.NEWSEQ = ASCIIEncoding.ASCII.GetBytes(item.NewSeq.PadRight(9, ' '));
                    Head.USERID = ASCIIEncoding.ASCII.GetBytes(item.UserId.PadRight(20, ' '));


                    byte[] Data      = Encoding.Default.GetBytes(item.Data);
                    byte[] byteReply = buffer;
                    var    list      = new List <byte>();
                    list.AddRange(byteReply);
                    list.AddRange(Data);
                    buffer = list.ToArray();
                }

                else
                {
                    Head.OLDSEQ = ASCIIEncoding.ASCII.GetBytes("".PadRight(9, ' '));
                    Head.NEWSEQ = ASCIIEncoding.ASCII.GetBytes("".PadRight(9, ' '));
                    Head.USERID = ASCIIEncoding.ASCII.GetBytes("".PadRight(20, ' '));
                }
                Head.LENGTH = BitConverter.GetBytes(UInt16.Parse(buffer.Length.ToString()));
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(Head.LENGTH);
                }

                retBuffer = new byte[50 + buffer.Length + 1];
                headbyte  = SocketRaw.StructureToByteArray(Head);
                Array.Copy(headbyte, 0, retBuffer, 0, headbyte.Length);
                Array.Copy(buffer, 0, retBuffer, headbyte.Length, buffer.Length);
                retBuffer[retBuffer.Length - 1] = SocketRaw.End;
                if (Sockets != null)
                {
                    int[] arr = Sockets.Keys.ToArray();
                    try
                    {//有可能在取得socket 物件後 斷線
                        //foreach (int key in Sockets.Keys.ToArray())
                        for (int i = 0; i < arr.Length; i++)
                        {
                            try
                            {
                                this._SAEA.SendData(Sockets[arr[i]], _DataEncode ? SocketRaw.EncodeData(retBuffer) : retBuffer);
                                // WriteLog("SAEAServerLogSend" + Sockets[arr[i]].AcceptSocket.RemoteEndPoint.ToString().Replace(":", ";"), retBuffer);

                                string RemoteIP = ((System.Net.IPEndPoint)Sockets[arr[i]].AcceptSocket.RemoteEndPoint).Address.ToString();
                                WriteLog("SAEAServerLogSend" + RemoteIP, retBuffer);
                            }
                            catch (Exception ex)
                            {
                                WriteLog("DataAgentLog", "Socket is null:" + Account + ex.Message + ex.StackTrace.ToString() + ex.Source.ToString());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog("DataAgentLog", "Sockets is null:" + Account + ex.Message + ex.StackTrace.ToString() + ex.Source.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog("DataAgentLog", "SendOrderDataToAP:" + Account + ex.Message + ex.StackTrace.ToString() + ex.Source.ToString());
            }
            finally
            {
            }
            return(retBuffer);
        }