Beispiel #1
0
        public void PrepareOutgoingData(SocketAsyncEventArgs e, DataHolder handledDataHolder, byte[] data)
        {
            try
            {
                DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;   
                //Determine the length of all the data that we will send back.
                int lengthOfCurrentOutgoingMessage = data.Length;
                 
                //So, now we convert the length integer into a byte array.
                //Aren't byte arrays wonderful? Maybe you'll dream about byte arrays tonight!
                Byte[] arrayOfBytesInPrefix = BitConverter.GetBytes(lengthOfCurrentOutgoingMessage);

                //Create the byte array to send.
                theUserToken.dataToSend = new Byte[theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage];

                //Now copy the 3 things to the theUserToken.dataToSend.
                Buffer.BlockCopy(arrayOfBytesInPrefix, 0, theUserToken.dataToSend, 0, theUserToken.sendPrefixLength);
                //The message that the client sent is already in a byte array, in DataHolder.
                Buffer.BlockCopy(data, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength, data.Length);
                theUserToken.sendBytesRemainingCount = theUserToken.sendPrefixLength +  lengthOfCurrentOutgoingMessage;
                theUserToken.bytesSentAlreadyCount = 0;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Beispiel #2
0
        protected virtual void OnDataReceived(DataHolder e)
        {
            if (null != DataReceived)
            {
                DataReceived(this, e);
            }

        }
Beispiel #3
0
 public void HandleData(DataHolder incomingDataHolder)
 {   
     //if (Program.watchProgramFlow == true)   //for testing
     //{
     //    receiveSendToken = (DataHoldingUserToken)this.saeaObject.UserToken;
     //    Program.testWriter.WriteLine("Mediator HandleData() " + receiveSendToken.TokenId);
     //}
     theDataHolder = theIncomingDataPreparer.HandleReceivedData(incomingDataHolder, this.saeaObject);
 }
Beispiel #4
0
 public DataHoldingUserToken(SocketAsyncEventArgs e, Int32 rOffset, Int32 sOffset, Int32 receivePrefixLength, Int32 sendPrefixLength, Int32 identifier)
 {
     this.idOfThisObject = identifier;
    
     //Create a Mediator that has a reference to the SAEA object.
     this.theMediator = new Mediator(e);
     this.bufferOffsetReceive = rOffset;
     this.bufferOffsetSend = sOffset;
     this.receivePrefixLength = receivePrefixLength;
     this.sendPrefixLength = sendPrefixLength;
     this.receiveMessageOffset = rOffset + receivePrefixLength;
     this.permanentReceiveMessageOffset = this.receiveMessageOffset;
     theDataHolderCache = new DataHolder();
 }
Beispiel #5
0
 public DataHolder HandleReceivedData(DataHolder incomingDataHolder, SocketAsyncEventArgs theSaeaObject)
 {
     DataHoldingUserToken receiveToken = (DataHoldingUserToken)theSaeaObject.UserToken;
     if (Program.watchProgramFlow == true)   //for testing
     {
         Program.testWriter.WriteLine("HandleReceivedData() " + receiveToken.TokenId);
     }
     theDataHolder = incomingDataHolder;
     theDataHolder.sessionId = receiveToken.SessionId;
     receiveToken.userTokenId = theDataHolder.userTokenId; 
     theDataHolder.receivedTransMissionId = this.ReceivedTransMissionIdGetter();            
     theDataHolder.remoteEndpoint = this.GetRemoteEndpoint();
     //if ((Program.watchData == true) & (Program.runLongTest == false))
     //{
     //    this.AddDataHolder();
     //}
     
     return theDataHolder;
 }
Beispiel #6
0
        public void PreparePureOutgoingData(SocketAsyncEventArgs e, DataHolder handledDataHolder, byte[] data)
        {
            try
            {
                DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;
                //Determine the length of all the data that we will send back.
                int lengthOfCurrentOutgoingMessage = data.Length;
                 
                //Create the byte array to send.
                theUserToken.dataToSend = new Byte[lengthOfCurrentOutgoingMessage];

                //Now copy the 3 things to the theUserToken.dataToSend.
                Buffer.BlockCopy(data, 0, theUserToken.dataToSend, 0, lengthOfCurrentOutgoingMessage);
                //The message that the client sent is already in a byte array, in DataHolder. 
                theUserToken.sendBytesRemainingCount =lengthOfCurrentOutgoingMessage;
                theUserToken.bytesSentAlreadyCount = 0;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Beispiel #7
0
 public DataPreparer(DataHolder incomingDataHolder)
 {
     theDataHolder = incomingDataHolder;
     theDataHolder.receivedTransMissionId = TransMissionIdGetter();
 }
Beispiel #8
0
 //新修改版本
 public void CreateNewDataHolder()
 {
     //theDataHolder = new DataHolder();//原版
    // if (null == theDataHolder)
         theDataHolder = new DataHolder();
     //else
     //{
     //    theDataHolder = theDataHolderCache;
     //    theDataHolder.Clear();
     //    theDataHolderCache = theDataHolder;
     //}
 }