Skip to content

Commit 6363575

Browse files
author
Joel Christner
committed
v1.0.3, retarget to .NET Core and .NET framework, update packages
1 parent dd075df commit 6363575

38 files changed

+3576
-169
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@ RESTful HTTP/HTTPS server for Microsoft SQL Server, MySQL, and PostgreSQL databa
55
## Description
66
RestDb spawns a RESTful HTTP/HTTPS server that exposes a series of APIs allowing you to perform SELECT, INSERT, UPDATE, DELETE, and TRUNCATE against tables in Microsoft SQL Server, MySQL, and PostgreSQL.
77

8-
## New in v1.0.2
9-
- PostgreSQL support
8+
## New in v1.0.3
9+
- Retarget to .NET Core and .NET Framework
10+
11+
## Important Notes
12+
- If you specify a listener other than ```localhost``` or ```127.0.0.1```, you may have to run with elevated privileges.
13+
- The HTTP HOST header MUST match the listener hostname, otherwise you'll get ```Bad Request``` errors back.
14+
- By default, access to RestDb is UNAUTHENTICATED. Configure ```System.json``` with API keys to enable authentication, and set the ```RequireAuthentication``` value to ```true```.
15+
16+
## Execution
17+
In Windows, using .NET Framework
18+
```
19+
> cd RestDb\bin\debug\net462
20+
> RestDb.exe
21+
```
22+
23+
In Windows, using .NET Core
24+
```
25+
> cd RestDb\bin\debug\netcoreapp2.2
26+
> dotnet RestDb.dll
27+
```
28+
29+
In Linux/Mac, using .NET Core
30+
```
31+
$ cd RestDb/bin/debug/netcoreapp2.2
32+
$ dotnet RestDb.dll
33+
```
1034

11-
## Running in Mono
12-
Before starting in Linux or Mac environments, you should run the Mono AOT.
35+
In Mono with .NET Framework environments, you should run the Mono AOT.
1336
```
1437
mono --aot=nrgctx-trampolines=8096,nimt-trampolines=8096,ntrampolines=4048 --server RestDb.exe
1538
mono --server RestDb.exe
@@ -18,10 +41,8 @@ mono --server RestDb.exe
1841
## Setup
1942
Simply compile from source, run ```RestDb.exe```, and a system configuration file will be created for you. Setup scripts for both MSSQL and MySQL are included in the Docs directory of the project, which create the test database and person table used in the examples below.
2043

21-
1) Start RestDb.exe
44+
1) Start RestDb.exe (.NET Framework) or RestDb.dll (.NET Core) as described above.
2245
```
23-
Windows : C:\RestDb\RestDb.exe
24-
Linux/Mac : $ mono --server RestDb.exe
2546
RestDb :: Starting Watson Webserver at http://localhost:8000
2647
```
2748

@@ -248,6 +269,7 @@ To enable authentication, set ```Server.RequireAuthentication``` to ```true``` a
248269
Notes from previous versions (starting with v1.0.0) will be moved here.
249270

250271
v1.0.x
272+
- PostgreSQL support
251273
- Authentication via API key
252274
- Initial release
253275

RestDb.sln

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26403.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RestDb", "RestDb\RestDb.csproj", "{9D53A716-9A4C-482D-9C25-C91257A60B00}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestDb", "RestDb\RestDb.csproj", "{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{9D53A716-9A4C-482D-9C25-C91257A60B00}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{49AC22AD-7AA0-4BCF-BC2E-0237AAE4CC2F}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {EF516CBA-7C5E-4DDD-8CD8-3C1F25FCB5D8}
24+
EndGlobalSection
2225
EndGlobal

RestDb/APIs/Get/GetTable.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Linq;
5+
using System.Net;
56
using System.Text;
67
using System.Threading.Tasks;
78
using System.Web;
@@ -82,7 +83,7 @@ static WatsonWebserver.HttpResponse GetTable(WatsonWebserver.HttpRequest req)
8283

8384
if (req.QuerystringEntries.ContainsKey("_index_start")) indexStart = Convert.ToInt32(req.QuerystringEntries["_index_start"]);
8485
if (req.QuerystringEntries.ContainsKey("_max_results")) maxResults = Convert.ToInt32(req.QuerystringEntries["_max_results"]);
85-
if (req.QuerystringEntries.ContainsKey("_order_by")) orderBy = HttpUtility.UrlDecode(req.QuerystringEntries["_order_by"]);
86+
if (req.QuerystringEntries.ContainsKey("_order_by")) orderBy = WebUtility.UrlDecode(req.QuerystringEntries["_order_by"]);
8687
if (req.QuerystringEntries.ContainsKey("_return_fields")) returnFields = Common.CsvToStringList(req.QuerystringEntries["_return_fields"]);
8788

8889
result = db.Select(tableName, indexStart, maxResults, returnFields, filter, orderBy);

RestDb/Classes/AuthManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ public bool Authenticate(HttpRequest req)
7070
if (String.IsNullOrEmpty(curr.Key)) continue;
7171
if (curr.Key.ToLower().Equals(apiKey.ToLower()))
7272
{
73-
switch (req.Method.ToLower())
73+
switch (req.Method)
7474
{
75-
case "get":
76-
case "head":
75+
case HttpMethod.GET:
76+
case HttpMethod.HEAD:
7777
return curr.AllowGet;
7878

79-
case "put":
79+
case HttpMethod.PUT:
8080
return curr.AllowPut;
8181

82-
case "post":
82+
case HttpMethod.POST:
8383
return curr.AllowPost;
8484

85-
case "delete":
85+
case HttpMethod.DELETE:
8686
return curr.AllowDelete;
8787

8888
default:

RestDb/Classes/Common.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
using System.Xml;
1515
using System.Xml.Linq;
1616
using System.Xml.XPath;
17-
using Newtonsoft.Json;
18-
using Mono.Posix;
19-
using Mono.Unix;
20-
using Mono.Unix.Native;
17+
using Newtonsoft.Json;
2118

2219
namespace RestDb
2320
{
@@ -789,34 +786,7 @@ public static bool IsLaterThanNow(DateTime dt)
789786
#endregion
790787

791788
#region Environment
792-
793-
public static bool IsAdmin()
794-
{
795-
int platform = (int)Environment.OSVersion.Platform;
796-
if ((platform == 4) || (platform == 6) || (platform == 128))
797-
{
798-
#region Linux
799-
800-
// see http://stackoverflow.com/questions/2615997/winforms-console-application-on-mono-how-to-know-it-runs-as-root
801-
if (Mono.Unix.Native.Syscall.getuid() == 0) return true;
802-
803-
#endregion
804-
}
805-
else
806-
{
807-
#region Windows
808-
809-
// see http://stackoverflow.com/questions/11660184/c-sharp-check-if-run-as-administrator
810-
var identity = WindowsIdentity.GetCurrent();
811-
var principal = new WindowsPrincipal(identity);
812-
if (principal.IsInRole(WindowsBuiltInRole.Administrator)) return true;
813-
814-
#endregion
815-
}
816-
817-
return false;
818-
}
819-
789+
820790
public static void ExitApplication(string method, string text, int returnCode)
821791
{
822792
Console.WriteLine("---");

RestDb/Classes/Setup.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ private void RunSetup()
5757
Console.WriteLine("------------");
5858
Console.WriteLine("We'll collect some values and put together your initial configuration.");
5959
Console.WriteLine("");
60-
Console.WriteLine("On which hostname should this node listen? The hostname supplied here must");
60+
Console.WriteLine("On which hostname should this node listen? The hostname supplied here MUST");
6161
Console.WriteLine("match the host header received on incoming RESTful HTTP requests. It is");
6262
Console.WriteLine("recommended that you use the DNS hostname of the machine.");
6363
Console.WriteLine("");
64+
Console.WriteLine("NOTE: using anything other than 127.0.0.1 or localhost may require that you");
65+
Console.WriteLine("run RestDb with elevated/admin privileges.");
66+
Console.WriteLine("");
6467

6568
ret.Server = new ServerSettings();
6669
ret.Server.ListenerHostname = Common.InputString("Hostname?", "localhost", false);

RestDb/RestDb.csproj

Lines changed: 27 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,37 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{9D53A716-9A4C-482D-9C25-C91257A60B00}</ProjectGuid>
84
<OutputType>Exe</OutputType>
9-
<RootNamespace>RestDb</RootNamespace>
10-
<AssemblyName>RestDb</AssemblyName>
11-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12-
<FileAlignment>512</FileAlignment>
13-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
5+
<TargetFrameworks>netcoreapp2.2;net462</TargetFrameworks>
6+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
7+
<Version>1.0.3</Version>
8+
<Authors>Joel Christner</Authors>
9+
<Description>C:\Code\Misc\RestDb\RestDbOriginal\APIs\</Description>
10+
<Copyright>(c)2019 Joel Christner</Copyright>
11+
<PackageProjectUrl>https://github.com/jchristn/restdb</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/jchristn/restdb</RepositoryUrl>
13+
<RepositoryType>Github</RepositoryType>
14+
<PackageTags>rest,database,api,db</PackageTags>
15+
<PackageReleaseNotes>Retarget to .NET Core and .NET Framework</PackageReleaseNotes>
1416
</PropertyGroup>
15-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16-
<PlatformTarget>AnyCPU</PlatformTarget>
17-
<DebugSymbols>true</DebugSymbols>
18-
<DebugType>full</DebugType>
19-
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
22-
<ErrorReport>prompt</ErrorReport>
23-
<WarningLevel>4</WarningLevel>
24-
</PropertyGroup>
25-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<PlatformTarget>AnyCPU</PlatformTarget>
27-
<DebugType>pdbonly</DebugType>
28-
<Optimize>true</Optimize>
29-
<OutputPath>bin\Release\</OutputPath>
30-
<DefineConstants>TRACE</DefineConstants>
31-
<ErrorReport>prompt</ErrorReport>
32-
<WarningLevel>4</WarningLevel>
33-
</PropertyGroup>
34-
<ItemGroup>
35-
<Reference Include="DatabaseWrapper, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
36-
<HintPath>..\packages\DatabaseWrapper.1.2.1\lib\DatabaseWrapper.dll</HintPath>
37-
</Reference>
38-
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
39-
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
40-
</Reference>
41-
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
42-
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
43-
</Reference>
44-
<Reference Include="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
45-
<HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath>
46-
</Reference>
47-
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
48-
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
49-
</Reference>
50-
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
51-
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
52-
</Reference>
53-
<Reference Include="Npgsql, Version=3.2.2.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
54-
<HintPath>..\packages\Npgsql.3.2.2\lib\net451\Npgsql.dll</HintPath>
55-
</Reference>
56-
<Reference Include="RegexMatcher, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
57-
<HintPath>..\packages\RegexMatcher.1.0.0\lib\RegexMatcher.dll</HintPath>
58-
</Reference>
59-
<Reference Include="SyslogLogging, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
60-
<HintPath>..\packages\SyslogLogging.1.0.8\lib\SyslogLogging.dll</HintPath>
61-
</Reference>
62-
<Reference Include="System" />
63-
<Reference Include="System.ComponentModel.DataAnnotations" />
64-
<Reference Include="System.Core" />
65-
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
66-
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
67-
</Reference>
68-
<Reference Include="System.Web" />
69-
<Reference Include="System.Xml.Linq" />
70-
<Reference Include="System.Data.DataSetExtensions" />
71-
<Reference Include="Microsoft.CSharp" />
72-
<Reference Include="System.Data" />
73-
<Reference Include="System.Net.Http" />
74-
<Reference Include="System.Xml" />
75-
<Reference Include="Watson, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
76-
<HintPath>..\packages\Watson.1.2.1\lib\Watson.dll</HintPath>
77-
</Reference>
78-
</ItemGroup>
17+
7918
<ItemGroup>
80-
<Compile Include="APIs\Delete\DeleteTable.cs" />
81-
<Compile Include="APIs\Get\GetDatabase.cs" />
82-
<Compile Include="APIs\Get\GetDatabaseClients.cs" />
83-
<Compile Include="APIs\Get\GetTable.cs" />
84-
<Compile Include="APIs\Get\GetHelloWorld.cs" />
85-
<Compile Include="APIs\Get\GetDatabases.cs" />
86-
<Compile Include="APIs\Post\PostTable.cs" />
87-
<Compile Include="APIs\Put\PutTable.cs" />
88-
<Compile Include="APIs\Support\DeserializeExpression.cs" />
89-
<Compile Include="Classes\AuthManager.cs" />
90-
<Compile Include="Classes\ApiKey.cs" />
91-
<Compile Include="ControlQueryKeys.cs" />
92-
<Compile Include="Classes\ErrorResponse.cs" />
93-
<Compile Include="Classes\Column.cs" />
94-
<Compile Include="Classes\Common.cs" />
95-
<Compile Include="Classes\Table.cs" />
96-
<Compile Include="Classes\Settings.cs" />
97-
<Compile Include="Classes\Setup.cs" />
98-
<Compile Include="Classes\DatabaseManager.cs" />
99-
<Compile Include="Classes\Template.cs" />
100-
<Compile Include="Classes\Database.cs" />
101-
<Compile Include="Server.cs" />
102-
<Compile Include="Properties\AssemblyInfo.cs" />
103-
</ItemGroup>
104-
<ItemGroup>
105-
<None Include="App.config" />
106-
<None Include="DatabaseWrapper.dll.config" />
107-
<None Include="packages.config" />
19+
<None Remove="Docs\MsSqlSample.txt" />
20+
<None Remove="Docs\MySqlSample.txt" />
21+
<None Remove="Docs\PgSqlSample.txt" />
10822
</ItemGroup>
23+
10924
<ItemGroup>
11025
<Content Include="Docs\MsSqlSample.txt" />
11126
<Content Include="Docs\MySqlSample.txt" />
11227
<Content Include="Docs\PgSqlSample.txt" />
11328
</ItemGroup>
114-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
115-
</Project>
29+
30+
<ItemGroup>
31+
<PackageReference Include="DatabaseWrapper" Version="1.2.7" />
32+
<PackageReference Include="SyslogLogging" Version="1.0.10" />
33+
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />
34+
<PackageReference Include="Watson" Version="1.6.0" />
35+
</ItemGroup>
36+
37+
</Project>

0 commit comments

Comments
 (0)