Initial commit
This commit is contained in:
commit
af978406a4
|
@ -0,0 +1,34 @@
|
|||
# Common IntelliJ Platform excludes
|
||||
|
||||
# User specific
|
||||
**/.idea/**/workspace.xml
|
||||
**/.idea/**/tasks.xml
|
||||
**/.idea/shelf/*
|
||||
**/.idea/dictionaries
|
||||
**/.idea/httpRequests/
|
||||
|
||||
# Sensitive or high-churn files
|
||||
**/.idea/**/dataSources/
|
||||
**/.idea/**/dataSources.ids
|
||||
**/.idea/**/dataSources.xml
|
||||
**/.idea/**/dataSources.local.xml
|
||||
**/.idea/**/sqlDataSources.xml
|
||||
**/.idea/**/dynamic.xml
|
||||
|
||||
# Rider
|
||||
# Rider auto-generates .iml files, and contentModel.xml
|
||||
**/.idea/**/*.iml
|
||||
**/.idea/**/contentModel.xml
|
||||
**/.idea/**/modules.xml
|
||||
|
||||
*.suo
|
||||
*.user
|
||||
.vs/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
_UpgradeReport_Files/
|
||||
[Pp]ackages/
|
||||
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
.DS_Store
|
|
@ -0,0 +1,13 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/modules.xml
|
||||
/.idea.RSND.iml
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSND", "RSND\RSND.csproj", "{1C728CE6-0609-415C-99A9-9345B32243F8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1C728CE6-0609-415C-99A9-9345B32243F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1C728CE6-0609-415C-99A9-9345B32243F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1C728CE6-0609-415C-99A9-9345B32243F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C728CE6-0609-415C-99A9-9345B32243F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,47 @@
|
|||
using Newtonsoft.Json;
|
||||
using RSND.Core.DbInternals;
|
||||
using RSND.Core.Querying.Queries;
|
||||
|
||||
namespace RSND.Core;
|
||||
|
||||
public class Database
|
||||
{
|
||||
List<Table> tables = new();
|
||||
|
||||
public void CreateTable(Table table)
|
||||
{
|
||||
tables.Add(table);
|
||||
}
|
||||
|
||||
private static string GetRowsJson(Row[]? rows)
|
||||
{
|
||||
return JsonConvert.SerializeObject(new { Rows = rows });
|
||||
}
|
||||
|
||||
public string GetValue(GetQuery? query)
|
||||
{
|
||||
Console.WriteLine(tables.Count);
|
||||
var table = query?.Table;
|
||||
var where = query?.Where;
|
||||
|
||||
var split = where?.Split("|");
|
||||
var colName = split?[0];
|
||||
var condition = split?[1];
|
||||
var param = split?[2];
|
||||
|
||||
if (query?.Select != "*") return "";
|
||||
|
||||
|
||||
var tableToReturn = tables.Find(x => x.Name == table);
|
||||
var rows = tableToReturn?.Rows?.Where(x => x.Columns.FirstOrDefault(y => y.Data.Key == colName)?.Data.Value == param).ToArray();
|
||||
|
||||
return GetRowsJson(rows);
|
||||
}
|
||||
|
||||
public static void Loop()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
using Fleck;
|
||||
using Newtonsoft.Json;
|
||||
using RSND.Core.DbInternals;
|
||||
using RSND.Core.Querying;
|
||||
using RSND.Core.Querying.Queries;
|
||||
|
||||
namespace RSND.Core;
|
||||
|
||||
public class DbClient
|
||||
{
|
||||
private readonly IWebSocketConnection _socket;
|
||||
|
||||
public DbClient(IWebSocketConnection socket)
|
||||
{
|
||||
_socket = socket;
|
||||
|
||||
RsndMain.Db.CreateTable(new Table
|
||||
{
|
||||
Name = "j4ces.table",
|
||||
Rows = new []
|
||||
{
|
||||
new Row
|
||||
{
|
||||
Columns = new []
|
||||
{
|
||||
new Column("id", "1"),
|
||||
new Column("amog us", "is THE GAME")
|
||||
}
|
||||
},
|
||||
new Row
|
||||
{
|
||||
Columns = new []
|
||||
{
|
||||
new Column("id", "1"),
|
||||
new Column("fortnite", "is THE GAME")
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void InvalidQuery()
|
||||
{
|
||||
_socket.Send(JsonConvert.SerializeObject(new Response
|
||||
{
|
||||
Success = false,
|
||||
Message = "Invalid query"
|
||||
}));
|
||||
}
|
||||
|
||||
public void Handle()
|
||||
{
|
||||
_socket.OnMessage = message =>
|
||||
{
|
||||
QueryType? queryType = QueryHelper.GetQueryType(message);
|
||||
|
||||
RunQuery(message, queryType);
|
||||
};
|
||||
}
|
||||
|
||||
private void RunQuery(string? query, QueryType? queryType)
|
||||
{
|
||||
if (query == null || queryType == null)
|
||||
InvalidQuery();
|
||||
|
||||
// check if
|
||||
switch (queryType)
|
||||
{
|
||||
case QueryType.GetValue:
|
||||
{
|
||||
GetQuery getQuery = JsonConvert.DeserializeObject<GetQuery>(query);
|
||||
var queryResult = RsndMain.Db.GetValue(getQuery);
|
||||
_socket.Send(queryResult);
|
||||
Console.WriteLine($"Yooo: {queryResult}");
|
||||
break;
|
||||
}
|
||||
|
||||
case QueryType.CreateTable:
|
||||
{
|
||||
/*RsndMain.Db.CreateTable(new Table
|
||||
{
|
||||
Name = query.Table
|
||||
});*/
|
||||
break;
|
||||
}
|
||||
|
||||
case null:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
namespace RSND.Core.DbInternals;
|
||||
|
||||
public class Column
|
||||
{
|
||||
public KeyValuePair<string, string> Data;
|
||||
|
||||
public Column(string name, string value)
|
||||
{
|
||||
Data = new KeyValuePair<string, string>(name, value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace RSND.Core.DbInternals;
|
||||
|
||||
public class Row
|
||||
{
|
||||
public Column[]? Columns;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace RSND.Core.DbInternals;
|
||||
|
||||
public class Table
|
||||
{
|
||||
public string? Name;
|
||||
public Row[]? Rows;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace RSND.Core.Querying;
|
||||
|
||||
/// <summary>
|
||||
/// The required values that any query must have.
|
||||
/// </summary>
|
||||
public class BaseQuery
|
||||
{
|
||||
public BaseQuery(string type)
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public string Type { get; set; }
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace RSND.Core.Querying;
|
||||
|
||||
public interface IQuery
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace RSND.Core.Querying.Queries;
|
||||
|
||||
public class GetQuery : IQuery
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string Table { get; set; }
|
||||
public string Select { get; set; }
|
||||
public string Where { get; set; }
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace RSND.Core.Querying.Queries;
|
||||
|
||||
public static class QueryHelper
|
||||
{
|
||||
public static QueryType? GetQueryType(string queryJson)
|
||||
{
|
||||
BaseQuery? query = JsonConvert.DeserializeObject<BaseQuery>(queryJson);
|
||||
|
||||
if (query != null)
|
||||
{
|
||||
return query.Type switch
|
||||
{
|
||||
"GetValue" => QueryType.GetValue,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace RSND.Core.Querying;
|
||||
|
||||
public enum QueryType
|
||||
{
|
||||
GetValue,
|
||||
CreateTable
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace RSND.Core;
|
||||
|
||||
public class Response
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
using RSND;
|
||||
|
||||
RsndMain.Run();
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Fleck" Version="1.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,27 @@
|
|||
using Fleck;
|
||||
using RSND.Core;
|
||||
|
||||
namespace RSND;
|
||||
|
||||
public static class RsndMain
|
||||
{
|
||||
public static Database Db = new();
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
WebSocketServer server = new WebSocketServer("ws://0.0.0.0:7878");
|
||||
|
||||
FleckLog.Level = LogLevel.Error;
|
||||
|
||||
server.Start(socket =>
|
||||
{
|
||||
socket.OnOpen = () =>
|
||||
{
|
||||
var dbClient = new DbClient(socket);
|
||||
dbClient.Handle();
|
||||
};
|
||||
});
|
||||
|
||||
Database.Loop();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue