예제 #1
0
 /// <summary>
 /// On the connection of a client.
 /// </summary>
 /// <param name="Server">The DatabaseServer that initiated the connection</param>
 public void OnConnect(DatabaseServer Server)
 {
 }
예제 #2
0
        /// <summary>
        /// On the recievement of a message from a client. Does the message handling.
        /// </summary>
        /// <param name="Server">The DatabaseServer that initiated the connection</param>
        /// <param name="buffer">The recieved message buffer</param>
        public void OnReceive(DatabaseServer Server, byte[] buffer)
        {
            // Command message is first byte
            DatabaseMessage command = (DatabaseMessage)buffer[0];

            switch (command)
            {
            case DatabaseMessage.Comm_Insert:
                try
                {
                    PerformInsert(buffer);
                }
                catch (ArgumentException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (KeyNotFoundException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (OutOfMemoryException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_OutOfMemory);
                }
                catch (IndexOutOfRangeException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (FormatException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (XmlException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_DatabaseError);
                }

                SuccessReply(Server);

                break;

            case DatabaseMessage.Comm_Update:
                try
                {
                    PerformUpdate(buffer);
                }
                catch (KeyNotFoundException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_ItemNotFound);
                }
                catch (IndexOutOfRangeException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (FormatException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (XmlException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_DatabaseError);
                }

                SuccessReply(Server);

                break;

            case DatabaseMessage.Comm_Find_MemberID:
                try
                {
                    DataRecord record     = PerformFind(buffer);
                    byte[]     sendbuffer = record.ToBytes();
                    sendbuffer[0] = (byte)DatabaseMessage.Client_Found_Record;

                    Server.Send(GetID(), sendbuffer);
                }
                catch (KeyNotFoundException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_ItemNotFound);
                }
                catch (IndexOutOfRangeException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_InvalidArgs);
                }
                catch (XmlException)
                {
                    ErrorReply(Server, DatabaseMessage.Error_DatabaseError);
                }

                SuccessReply(Server);

                break;
            }
        }
예제 #3
0
 /// <summary>
 /// On the disconnection of a client
 /// </summary>
 /// <param name="Server">DatabaseServer that the client disconnected from</param>
 public void OnClose(DatabaseServer Server)
 {
 }