Exemplo n.º 1
0
        public async Task <int> InsertOrUpdateAsync(SessionBuffer model, UserSession session)
        {
            var id = model.Id;

            model.ModifiedBy   = session.Id;
            model.ModifiedDate = DateTime.Now;

            if (model.Id != 0)
            {
                var sessionBuffer = await _sessionBufferQueries.GetByIdAsync(model.Id);

                if (sessionBuffer == null)
                {
                    model.Id = 0;
                }
                else
                {
                    model.ModifiedBy   = session.Id;
                    model.ModifiedDate = DateTime.Now;

                    await _sessionBufferRepository.UpdateAsync(model);

                    return(id);
                }
            }

            model.CreatedBy   = session.Id;
            model.CreatedDate = DateTime.Now;
            id = await _sessionBufferRepository.AddAsync(model);

            return(id);
        }
        protected Packet ReceivePacket()
        {
            var received = new byte[1024];
            Packet receivedPacket = null;
            var sessionBuffer = new SessionBuffer(null, Socket, received);
            Socket.BeginReceive(sessionBuffer.Buffer, 0, sessionBuffer.Buffer.Length, SocketFlags.None,
                                (asyncResult) =>
                                    {
                                        var buffer =
                                            asyncResult.
                                                AsyncState as
                                            SessionBuffer;
                                        if (buffer == null) return;
                                        int bytesReceived = buffer.Socket.EndReceive(asyncResult);

                                        receivedPacket = new PacketSerializer().Deserialize(
                                            buffer.Buffer.Take(bytesReceived).
                                                ToArray()).FirstOrDefault();
                                    }, sessionBuffer);

            while (receivedPacket == null)
            {
                Thread.Sleep(10);
            }
            return receivedPacket;
        }
Exemplo n.º 3
0
        public async Task <int> AddAsync(SessionBuffer sessionBuffer)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(sessionBuffer);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Exemplo n.º 4
0
 public void WaitForData(Socket socket)
 {
     var buffer = new SessionBuffer(this, socket, Constants.DEFAULT_BUFFER_SIZE);
     socket.BeginReceive(buffer.Buffer, 0, Constants.DEFAULT_BUFFER_SIZE, SocketFlags.None, SocketReceiveCallback, buffer);
 }
Exemplo n.º 5
0
 /// <summary>
 /// sends the data to the client
 /// </summary>
 /// <param name="bytes"></param>
 public void SendToClient(byte[] bytes)
 {
     var buffer = new SessionBuffer(this, Socket, bytes);
     Socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, SendCallback, buffer);
     log.DebugFormat("Sending {0} bytes to client on Session '{1}'", bytes.Length, this.Uid);
 }
Exemplo n.º 6
0
 public void SendPacket(SessionBuffer sb)
 {
     m_dicSessionHandler[sb.SID].SendMsg(sb.Buffer);
 }
Exemplo n.º 7
0
 public void PushSessionBuffer(SocketAsyncEventArgs e)
 {
     long sessionID = Convert.ToInt64(e.UserToken);
     SessionBuffer sb = new SessionBuffer(e.Buffer, sessionID);
     m_sessionBufferQueue.Enqueue(sb);
 }
Exemplo n.º 8
0
        public async Task <int> UpdateAsync(SessionBuffer sessionBuffer)
        {
            var cmd = QueriesCreatingHelper.CreateQueryUpdate(sessionBuffer);

            return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection));
        }