Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug #46, added settings dialog, refactored #49

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LiteDB.Studio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteDB.Studio", "LiteDB.Studio\LiteDB.Studio.csproj", "{0002E0FF-C91F-4B8B-B29B-2A477E184408}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteDb.Studio.IntegrationTest", "LiteDb.Studio.IntegrationTest\LiteDb.Studio.IntegrationTest.csproj", "{470C04A1-2F06-49DB-8B31-830BEC37E8E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Release|Any CPU.Build.0 = Release|Any CPU
{470C04A1-2F06-49DB-8B31-830BEC37E8E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{470C04A1-2F06-49DB-8B31-830BEC37E8E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{470C04A1-2F06-49DB-8B31-830BEC37E8E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{470C04A1-2F06-49DB-8B31-830BEC37E8E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
36 changes: 20 additions & 16 deletions LiteDB.Studio/App.config
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="LiteDB.Studio.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<userSettings>
<LiteDB.Studio.Properties.Settings>
<setting name="ApplicationSettings" serializeAs="String">
<value />
</setting>
</LiteDB.Studio.Properties.Settings>
</userSettings>
</configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="LiteDB.Studio.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<LiteDB.Studio.Properties.Settings>
<setting name="ApplicationSettings" serializeAs="String">
<value />
</setting>
</LiteDB.Studio.Properties.Settings>
</userSettings>
</configuration>
48 changes: 18 additions & 30 deletions LiteDB.Studio/Classes/Debugger/DatabaseDebugger.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
using LiteDB;
using LiteDB.Engine;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace LiteDB.Studio
namespace LiteDB.Studio.Classes.Debugger
{
public class DatabaseDebugger : IDisposable
{
private LiteDatabase _db;
private readonly LiteDatabase _db;
private HttpListener _listener;
private readonly int _port;

public DatabaseDebugger(LiteDatabase db, int port)
{
_db = db;
_port = port;
Port = port;
}

public int Port => _port;
public int Port { get; }

public void Dispose()
{
Expand All @@ -41,14 +31,13 @@ public Task Start()
{
_listener = new HttpListener();

_listener.Prefixes.Add($"http://localhost:{_port}/");
_listener.Prefixes.Add($"http://localhost:{Port}/");

_listener.Start();

Console.WriteLine("Start debbugger listen: " + _port);
Console.WriteLine("Start debbugger listen: " + Port);

while (true)
{
try
{
var context = _listener.GetContext();
Expand All @@ -60,11 +49,13 @@ public Task Start()

if (Regex.IsMatch(context.Request.RawUrl, @"^\/(\d+)?$"))
{
var pageID = context.Request.RawUrl == "/" ? 0 : int.Parse(context.Request.RawUrl.Substring(1));
var pageID = context.Request.RawUrl == "/"
? 0
: int.Parse(context.Request.RawUrl.Substring(1));

var page = context.Request.HttpMethod == "GET" ?
_db.GetCollection($"$dump({pageID})").Query().FirstOrDefault() :
GetPost(context.Request.InputStream);
var page = context.Request.HttpMethod == "GET"
? _db.GetCollection($"$dump({pageID})").Query().FirstOrDefault()
: GetPost(context.Request.InputStream);

if (page == null)
{
Expand All @@ -80,7 +71,8 @@ public Task Start()
else if (Regex.IsMatch(context.Request.RawUrl, @"^\/list/(\d+)$"))
{
var pageID = int.Parse(context.Request.RawUrl.Substring(6));
var exp = new HtmlPageList(_db.GetCollection($"$page_list({pageID})").Query().Limit(1000).ToEnumerable());
var exp = new HtmlPageList(_db.GetCollection($"$page_list({pageID})").Query()
.Limit(1000).ToEnumerable());

body = exp.Render();
}
Expand All @@ -101,7 +93,6 @@ public Task Start()
catch (Exception)
{
}
}
});
}

Expand All @@ -111,12 +102,9 @@ private BsonDocument GetPost(Stream input)
var bytes = text.Trim().Split(' ');
var buffer = new byte[bytes.Length];

for(var i = 0; i < bytes.Length; i++)
{
buffer[i] = Convert.ToByte(bytes[i].Trim(), 16);
}
for (var i = 0; i < bytes.Length; i++) buffer[i] = Convert.ToByte(bytes[i].Trim(), 16);

return new BsonDocument { ["buffer"] = buffer };
return new BsonDocument {["buffer"] = buffer};
}
}
}
}
Loading