public ServerSessionResponseHandler(Socket acceptedSocket, PackageAdapter adapter, GameLogger logger) { Logger = logger; AcceptedSocket = acceptedSocket; Adapter = adapter; Connected = false; Error = false; ErrorMessage = ""; }
public string Delete(string Json) { try { string TableName = JsonAdapter.TableNameFromJson(Json); List <Packet> packets = PackageAdapter.PacketsFromJson(Json); string Condition = FilterAdapter.GetCondition(TableName, packets.ToArray()); string sql = $"DELETE FROM \"{TableName}\" WHERE {Condition}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public string Update(string Json) { try { string TableName = JsonAdapter.TableNameFromJson(Json); List <Packet> packets = PackageAdapter.PacketsFromJson(Json); string Condition = FilterAdapter.GetCondition(TableName, packets.ToArray()); List <UpdatePacket> updatePackets = SetConverter.FromJson(Json); string Sets = RowCollector.Set(updatePackets); string Sql = $"UPDATE \"{TableName}\" {Sets} WHERE {Condition}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(Sql))); } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public string Adapt(string Json) { string MainTable = JsonAdapter.TableNameFromJson(Json); string TableName = ""; List <Packet> packets = PackageAdapter.PacketsONFromJson(Json); PackageAdapter.Normalize(ref packets); packets = SetTableName(MainTable, packets.ToArray()); try { TableName = $"{GetTableNameFromPackets(packets.ToArray())}"; } catch (Exception ex) { throw ex; } string condition = new FilterAdapter().GetOnCondition(TableName, packets.ToArray()); string Sql = $"INNER JOIN {TableName} ON {condition}"; return(Sql); }
public string Where(string Json) { Validators.CheckPackets check = new Validators.CheckPackets(); try { LimitPacket limitPacket = GetLimit(ref Json); string limit = limitPacket == null ? "" : $" {LimitAdapter.AdaptToSql(limitPacket)}"; OrderByPacket orderByPacket = GetOrderBy(ref Json); string OrderBy = orderByPacket == null ? "" : $" {OrderByAdapter.ToSql(orderByPacket)}"; if (check.CheckJoin(Json)) { string Condition = ""; Joining.JoinAdapter adapter = new Joining.JoinAdapter(); string TableName = JsonAdapter.TableNameFromJson(Json); if (check.CheckPacket(Json)) { List <Packet> packets = PackageAdapter.PacketsFromJson(Json); PackageAdapter.Normalize(ref packets); Condition = $"WHERE {FilterAdapter.GetCondition(TableName, packets.ToArray())}"; } string JoinCondition = adapter.Adapt(Json); string sql = $"SELECT * FROM \"{TableName}\" {JoinCondition} {Condition}{OrderBy}{limit}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } else { string TableName = JsonAdapter.TableNameFromJson(Json); List <Packet> packets = PackageAdapter.PacketsFromJson(Json); string Condition = FilterAdapter.GetCondition(TableName, packets.ToArray()); string sql = $"SELECT * FROM \"{TableName}\" WHERE {Condition}{OrderBy}{limit}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }
public NetworkConnection(TCPPacketConnection tcpConnection, ResponseRequest responseRequest, PackageAdapter adapter) { Adapter = adapter; TcpPackages = new SafeStack <PackageInterface>(); m_openResponses = new SafeList <ResponseRequest>(); if (responseRequest != null) { m_openResponses.Add(responseRequest); } ClientSession = null; TcpConnection = tcpConnection; RemoteEndPoint = tcpConnection.Remote; OnDisconnect = TcpConnection.OnDisconnect.CreateRelay(this); TcpConnection.DataReceivedEvent += ReceiveTCP; TcpConnection.OnDisconnect.Event += HandleDisconnect; TcpConnection.InitializeReceiving(); }