Beispiel #1
0
        public override async void Process(SqlServer server)
        {
            SqlPacket packet = await DatabaseManager.GetDataArray(Query, ExpectedColumns);

            ApiResponse response;

            if (packet.Success)
            {
                string[] result = (string[])packet.Data;
                response = SqlDataArrayResponse.Create(result);
            }
            else
            {
                response = SqlErrorResponse.Create(packet.ErrorMessage);
            }
            SerializedSqlApiResponse serializedApiResponse = SerializedSqlApiResponse.Create(response);
            string data = serializedApiResponse.Serialize();

            server.Network.Send(data);
        }
Beispiel #2
0
        public override async void Process(SqlServer server)
        {
            SqlPacket packet = await DatabaseManager.GetSingleOrDefault(Query);

            ApiResponse response;

            if (packet.Success)
            {
                string result = (string)packet.Data;
                response = SqlSingleOrDefaultResponse.Create(result);
            }
            else
            {
                response = SqlErrorResponse.Create(packet.ErrorMessage);
            }
            SerializedSqlApiResponse serializedApiResponse = SerializedSqlApiResponse.Create(response);
            string data = serializedApiResponse.Serialize();

            server.Network.Send(data);
        }
        private ApiResponse GetResponse(SqlApiRequest request, out bool success)
        {
            Inititalize();
            string jsonRequest = request.Serialize();

            sqlClient.Network.Send(jsonRequest);
            byte[]      packet = packetParser.GetPacket();
            ApiResponse response;

            if (packet.Length == 0)
            {
                response = null;
            }
            else
            {
                string jsonResponse = sqlClient.Network.Encoding.GetString(packet);
                Debug.WriteLine(">> " + jsonResponse);
                SerializedSqlApiResponse serializedApiResponse = JsonConvert.DeserializeObject <SerializedSqlApiResponse>(jsonResponse);
                response = serializedApiResponse.Deserialize();
            }
            if (response == null)
            {
                ApiError.Throw(ApiErrorCode.InternalServerError, server, "Database request timed out.");
                success = false;
                return(null);
            }
            if (response.ResponseId == SqlResponseId.Error)
            {
                SqlErrorResponse sqlError = (SqlErrorResponse)response;
                ApiError.Throw(ApiErrorCode.DatabaseException, server, sqlError.Message);
                success = false;
                return(null);
            }
            success = true;
            return(response);
        }