Skip to content

Commit

Permalink
Started adding support for RavenDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Olav Loftum committed Feb 19, 2012
1 parent 46f3d00 commit 22269fe
Show file tree
Hide file tree
Showing 27 changed files with 35,953 additions and 31 deletions.
10 changes: 5 additions & 5 deletions DbTool/DbTool.Lib/CSharp/Mono/DbToolInteractive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ namespace DbTool.Lib.CSharp.Mono
{
public class DbToolInteractive
{
private static readonly DynamicSqlQuery DynamicSql = new DynamicSqlQuery();
private static readonly DynamicQuery DynamicQuery = new DynamicQuery();

public static Evaluator Evaluator;
public static TextWriter Output = new StringWriter();

public static IEnumerable<dynamic> Schema(string collection)
{
return DynamicSql.Schema(collection);
return DynamicQuery.Schema(collection);
}

public static IEnumerable<dynamic> Query(string sql)
{
return DynamicSql.Query(sql);
return DynamicQuery.Query(sql);
}

public static void SetDb(DbToolDatabase db)
{
DynamicSql.ConnectionData = db.GetConnectionData();
DynamicQuery.ConnectionData = db.GetConnectionData();
}

public static void SetConnection(DbConnection connection)
{
DynamicSql.DbConnection = connection;
DynamicQuery.DbConnection = connection;
}

public static string vars
Expand Down
48 changes: 48 additions & 0 deletions DbTool/DbTool.Lib/Communication/DbCommands/Dynamic/DynamicQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Data.Common;
using DbTool.Lib.Configuration;

namespace DbTool.Lib.Communication.DbCommands.Dynamic
{
public class DynamicQuery
{
private ConnectionData _connectionData;
public ConnectionData ConnectionData
{
get { return _connectionData; }
set
{
_connectionData = value;
_sqlQuery.ConnectionData = _connectionData;
}
}

private DbConnection _dbConnection;
public DbConnection DbConnection
{
get { return _dbConnection; }
set
{
_dbConnection = value;
_sqlQuery.DbConnection = _dbConnection;
}
}

private readonly DynamicSqlQuery _sqlQuery;

public DynamicQuery()
{
_sqlQuery = new DynamicSqlQuery();
}

public IEnumerable<dynamic> Schema(string collection)
{
return _sqlQuery.Schema(collection);
}

public IEnumerable<dynamic> Query(string sql)
{
return _sqlQuery.Query(sql);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class DynamicSqlQuery
{
public ConnectionData ConnectionData { get; set; }
public DbConnection DbConnection { get; set; }


public IEnumerable<dynamic> Schema(string collection)
{
Expand Down
48 changes: 30 additions & 18 deletions DbTool/DbTool.Lib/Configuration/ConnectionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public string ProviderName
{
switch (DatabaseType)
{
case "sqlserver":
case DbType.SqlServer:
case DbType.SqlServer2005:
case DbType.SqlServer2008:
return "System.Data.SqlClient";
case "mysql":
case DbType.MySql:
return "MySql.Data.MySqlClient";
default:
return "System.Data.SqlClient";
Expand All @@ -30,19 +32,42 @@ public bool HasConnectionString
public string Database { get; set; }
public string DatabaseType { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public DbToolCredentials Credentials { get; set; }

public string GetConnectionString(bool includeDatabase = true)
public string GetConnectionString()
{
switch(DatabaseType)
{
case "mysql":
return GetConnectionStringForMySql();
case DbType.RavenDB:
return GetRavenConnectionString();
default:
return GetDefaultConnectionString();
}
}

private string GetRavenConnectionString()
{
var elements = new List<string>();
elements.Add(string.Format("Url={0}", GetHttpHostAndPort()));
if (Database.IsNotNullOrEmpty())
{
elements.Add(string.Format("Database={0}", Database));
}
if (Credentials.User.IsNotNullOrEmpty())
{
elements.Add(string.Format("User={0}", Credentials.User));
elements.Add(string.Format("Password={0}", Credentials.Password));
}
return string.Join(";", elements);
}

private string GetHttpHostAndPort()
{
var host = Host.StartsWith("http://") ? Host : string.Format("http://{0}", Host);
return Port > 0 ? string.Format("{0}:{1}", host, Port) : host;
}

private string GetDefaultConnectionString()
{
var elements = new List<string>();
Expand All @@ -62,18 +87,5 @@ private string GetDefaultConnectionString()
}
return string.Join(";", elements);
}

private string GetConnectionStringForMySql()
{
var elements = new List<string>();
elements.Add(string.Format("Server={0}", Host));
if (Database.IsNotNullOrEmpty())
{
elements.Add(string.Format("Database={0}", Database));
}
elements.Add(string.Format("Uid={0}", Credentials.User));
elements.Add(string.Format("Pwd={0}", Credentials.Password));
return string.Join(";", elements);
}
}
}
1 change: 1 addition & 0 deletions DbTool/DbTool.Lib/Configuration/DbToolContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DbToolContext
public string Name { get; set; }
public string DatabaseType { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public DbToolCredentials Credentials { get; set; }
public IList<DbToolDatabase> Databases { get; set; }
[JsonIgnore]
Expand Down
7 changes: 7 additions & 0 deletions DbTool/DbTool.Lib/Configuration/DbToolDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public string Host
set { _host = value; }
}

private int _port;
public int Port
{
get { return _port > 0 ? _port : FromParentOrDefault(p => p.Port); }
set { _port = value; }
}

private DbToolCredentials _credentials;
public DbToolCredentials Credentials
{
Expand Down
18 changes: 17 additions & 1 deletion DbTool/DbTool.Lib/DbTool.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AsyncCtpLibrary">
<HintPath>..\..\Lib\3rdParty\RavenDB-Build-616\Client\AsyncCtpLibrary.dll</HintPath>
</Reference>
<Reference Include="Migrator">
<HintPath>..\BuildAssets\Migrator\Migrator.dll</HintPath>
</Reference>
Expand All @@ -51,6 +54,18 @@
<Reference Include="Ninject">
<HintPath>..\..\Lib\3rdParty\Ninject-2.2.0.0-release-net-4.0\Ninject.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\Lib\3rdParty\RavenDB-Build-616\Client\NLog.dll</HintPath>
</Reference>
<Reference Include="Raven.Abstractions">
<HintPath>..\..\Lib\3rdParty\RavenDB-Build-616\Client\Raven.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Raven.Client.Debug">
<HintPath>..\..\Lib\3rdParty\RavenDB-Build-616\Client\Raven.Client.Debug.dll</HintPath>
</Reference>
<Reference Include="Raven.Client.Lightweight">
<HintPath>..\..\Lib\3rdParty\RavenDB-Build-616\Client\Raven.Client.Lightweight.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -79,6 +94,7 @@
<Compile Include="Communication\DbCommands\Dynamic\ClassGenerator.cs" />
<Compile Include="Communication\DbCommands\Dynamic\DynamicDataRow.cs" />
<Compile Include="Communication\DbCommands\Dynamic\DynamicDataRowPropertyDescriptor.cs" />
<Compile Include="Communication\DbCommands\Dynamic\DynamicQuery.cs" />
<Compile Include="Communication\DbCommands\Dynamic\DynamicSqlQuery.cs" />
<Compile Include="Communication\DbCommands\IDbCommandExecutor.cs" />
<Compile Include="Communication\DbCommands\IExecutorProvider.cs" />
Expand Down Expand Up @@ -113,7 +129,7 @@
<Compile Include="CSharp\ICSharpEvaluator.cs" />
<Compile Include="CSharp\Mono\DbToolInteractive.cs" />
<Compile Include="CSharp\Mono\MonoCSharpEvaluator.cs" />
<Compile Include="DatabaseType.cs" />
<Compile Include="DbType.cs" />
<Compile Include="Data\ColumnDescriptor.cs" />
<Compile Include="Data\Property.cs" />
<Compile Include="Data\Record.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

namespace DbTool.Lib
{
public class DatabaseType
public class DbType
{
public const string RavenDB = "ravendb";
public const string SqlServer = "sqlserver";
public const string SqlServer2005 = "sqlserver2005";
public const string SqlServer2008 = "sqlserver2008";
Expand Down
2 changes: 1 addition & 1 deletion DbTool/DbTool.Lib/Migrating/MigSharpRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void MigrateToLatest()

private MigSharp.Migrator CreateMigrator()
{
var providerName = DatabaseType.ToMigSharpProvider(_database.DatabaseType);
var providerName = DbType.ToMigSharpProvider(_database.DatabaseType);
var connection = _database.GetConnectionData();
var options = new MigrationOptions();
options.SupportedProviders.Set(providerName.AsArray());
Expand Down
14 changes: 10 additions & 4 deletions DbTool/DbToolGui/Controls/Syntax/EditorTextBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ protected override void OnPreviewKeyDown(KeyEventArgs e)
if (SelectedText != string.Empty)
{
string[] lines = SelectedText.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < lines.Length; i++)
for (int ii = 0; ii < lines.Length; ii++)
{
if (lines[i].StartsWith(Tab))
if (lines[ii].StartsWith(Tab))
{
lines[i] = lines[i].Substring(Tab.Length);
lines[ii] = lines[ii].Substring(Tab.Length);
}
else
lines[i] = lines[i].TrimStart(' ');
{
lines[ii] = lines[ii].TrimStart(' ');
}
}
SelectedText = String.Join(Environment.NewLine, lines);
}
Expand All @@ -221,9 +223,13 @@ protected override void OnPreviewKeyDown(KeyEventArgs e)
var startLine = Text.IndexOf(Environment.NewLine, lastLine, StringComparison.Ordinal);

if (startLine != -1)
{
startLine += Environment.NewLine.Length;
}
else
{
startLine = 0;
}

// find empty spaces
var spaces = 0;
Expand Down
Binary file not shown.
Loading

0 comments on commit 22269fe

Please sign in to comment.