Skip to content

Commit

Permalink
bridge to project assembly. changed ravencontext to implement IDocSes…
Browse files Browse the repository at this point in the history
…sion.
  • Loading branch information
Ronnie Overby committed Apr 17, 2012
1 parent 2bd9ffb commit 1d5822f
Show file tree
Hide file tree
Showing 32 changed files with 96 additions and 69 deletions.
18 changes: 18 additions & 0 deletions RavenLinqpadDriver.Bridge/ConnectionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace RavenLinqpadDriver.Bridge
{
public class ConnectionInfo
{
public string Url { get; set; }
public string DefaultDatabase { get; set; }
public NetworkCredential Credentials { get; set; }
public Guid? ResourceManagerId { get; set; }


}
}
14 changes: 0 additions & 14 deletions RavenLinqpadDriver.Bridge/IConfigureDocumentStore.cs

This file was deleted.

14 changes: 14 additions & 0 deletions RavenLinqpadDriver.Bridge/ICreateDocumentStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Raven.Client;

namespace RavenLinqpadDriver.Bridge
{
public interface ICreateDocumentStore
{
/// <summary>
/// Creates an IDocumentStore.
/// </summary>
/// <param name="connectionInfo">The connection information for a RavenDB database.</param>
/// <returns>An IDocumentStore.</returns>
IDocumentStore CreateDocumentStore(ConnectionInfo connectionInfo);
}
}
3 changes: 2 additions & 1 deletion RavenLinqpadDriver.Bridge/RavenLinqpadDriver.Bridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IConfigureDocumentStore.cs" />
<Compile Include="ConnectionInfo.cs" />
<Compile Include="ICreateDocumentStore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 0 additions & 11 deletions RavenLinqpadDriver.Bridge35/Class1.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\RavenLinqpadDriver.Bridge\IConfigureDocumentStore.cs">
<Link>IConfigureDocumentStore.cs</Link>
<Compile Include="..\RavenLinqpadDriver.Bridge\ConnectionInfo.cs">
<Link>ConnectionInfo.cs</Link>
</Compile>
<Compile Include="..\RavenLinqpadDriver.Bridge\ICreateDocumentStore.cs">
<Link>ICreateDocumentStore.cs</Link>
</Compile>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Binary file modified RavenLinqpadDriver.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions RavenLinqpadDriver/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
using System.Reflection;
[assembly: AssemblyVersion("0.3.701.0")]
[assembly: AssemblyFileVersion("0.3.701.0")]
[assembly: AssemblyVersion("0.3.888.0")]
[assembly: AssemblyFileVersion("0.3.888.0")]
4 changes: 2 additions & 2 deletions RavenLinqpadDriver/RavenConectionDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace RavenLinqpadDriver
{
public partial class RavenConectionDialog : Window
{
private RavenConnectionInfo _connInfo;
private RavenConnectionDialogViewModel _connInfo;

public RavenConectionDialog(RavenConnectionInfo conn)
public RavenConectionDialog(RavenConnectionDialogViewModel conn)
{
if (conn == null)
throw new ArgumentNullException("conn", "conn is null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace RavenLinqpadDriver
{
public class RavenConnectionInfo : ViewModelBase
public class RavenConnectionDialogViewModel : ViewModelBase
{
public const string RavenConnectionInfoKey = "RavenConnectionInfo";

Expand Down Expand Up @@ -202,7 +202,7 @@ public string Namespaces
}
}

public RavenConnectionInfo()
public RavenConnectionDialogViewModel()
{
SaveCommand = new RelayCommand(Save, CanSave);
}
Expand Down Expand Up @@ -282,13 +282,13 @@ public IEnumerable<string> GetNamespaces()
yield return ns;
}

public static RavenConnectionInfo Load(IConnectionInfo cxInfo)
public static RavenConnectionDialogViewModel Load(IConnectionInfo cxInfo)
{
XElement xe = cxInfo.DriverData.Element(RavenConnectionInfoKey);
if (xe != null)
{
var json = xe.Value;
var rvnConn = JsonConvert.DeserializeObject<RavenConnectionInfo>(json);
var rvnConn = JsonConvert.DeserializeObject<RavenConnectionDialogViewModel>(json);
rvnConn.CxInfo = cxInfo;

if (!rvnConn.Password.IsNullOrWhitespace())
Expand Down
45 changes: 31 additions & 14 deletions RavenLinqpadDriver/RavenContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Raven.Client.Indexes;
using Raven.Client.Linq;
using RavenLinqpadDriver.Bridge;
using System.Reflection;
using System.Net;

namespace RavenLinqpadDriver
{
Expand All @@ -26,7 +28,7 @@ private IDocumentSession Session
}
internal TextWriter LogWriter { get; set; }

public RavenContext(RavenConnectionInfo connInfo)
public RavenContext(RavenConnectionDialogViewModel connInfo)
{
if (connInfo == null)
throw new ArgumentNullException("conn", "conn is null.");
Expand Down Expand Up @@ -64,27 +66,42 @@ void LogRequest(object sender, RequestResultArgs e)
e.Result)); // 7
}

private void InitDocStore(RavenConnectionInfo conn)
private void InitDocStore(RavenConnectionDialogViewModel conn)
{
if (conn == null)
throw new ArgumentNullException("conn", "conn is null.");

_docStore = conn.CreateDocStore();
var assemblies = new List<Assembly>(new[]
{
this.GetType().Assembly
});

foreach (var path in conn.GetAssemblyPaths())
assemblies.Add(Assembly.LoadFrom(path));

// work on this!!!
//search for a user defined initializer
var refAssemblyNames = this.GetType().Assembly.GetReferencedAssemblies();
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var initType = (from a in assemblies
//let a = Assembly.Load(an)
from t in a.TypesImplementing<IConfigureDocumentStore>()
select t).FirstOrDefault();
var docStoreCreatorType = (from a in assemblies
from t in a.TypesImplementing<ICreateDocumentStore>()
select t).FirstOrDefault();

if (initType != null)
if (docStoreCreatorType != null)
{
var docStoreInit = (IConfigureDocumentStore)initType.CreateInstance();
docStoreInit.ConfigureDocumentStore(_docStore);
var docStoreCreator = (ICreateDocumentStore)docStoreCreatorType.CreateInstance();
_docStore = docStoreCreator.CreateDocumentStore(new ConnectionInfo
{
Url = conn.Url,
DefaultDatabase = conn.DefaultDatabase,
Credentials = new NetworkCredential
{
UserName = conn.Username,
Password = conn.Password
},
ResourceManagerId = conn.ResourceManagerId,
//conn.ApiKey
});
}
else
{
_docStore = conn.CreateDocStore();
}

_docStore.Initialize();
Expand Down
16 changes: 8 additions & 8 deletions RavenLinqpadDriver/RavenDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RavenLinqpadDriver
{
public class RavenDriver : StaticDataContextDriver
{
RavenConnectionInfo _connInfo;
RavenConnectionDialogViewModel _connInfo;

public override string Author
{
Expand All @@ -17,7 +17,7 @@ public override string Author

public override string GetConnectionDescription(IConnectionInfo cxInfo)
{
_connInfo = RavenConnectionInfo.Load(cxInfo);
_connInfo = RavenConnectionDialogViewModel.Load(cxInfo);
return string.Format("RavenDB: {0}", _connInfo.Name);
}

Expand All @@ -36,8 +36,8 @@ public override string Name
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection)
{
_connInfo = isNewConnection
? new RavenConnectionInfo { CxInfo = cxInfo }
: RavenConnectionInfo.Load(cxInfo);
? new RavenConnectionDialogViewModel { CxInfo = cxInfo }
: RavenConnectionDialogViewModel.Load(cxInfo);

var win = new RavenConectionDialog(_connInfo);
var result = win.ShowDialog() == true;
Expand All @@ -54,14 +54,14 @@ public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConn

public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
{
_connInfo = RavenConnectionInfo.Load(cxInfo);
_connInfo = RavenConnectionDialogViewModel.Load(cxInfo);

return new[] { new ParameterDescriptor("connInfo", "RavenLinqpadDriver.RavenConnectionInfo") };
return new[] { new ParameterDescriptor("connInfo", "RavenLinqpadDriver.RavenConnectionDialogViewModel") };
}

public override object[] GetContextConstructorArguments(IConnectionInfo cxInfo)
{
_connInfo = RavenConnectionInfo.Load(cxInfo);
_connInfo = RavenConnectionDialogViewModel.Load(cxInfo);
return new[] { _connInfo };
}

Expand Down Expand Up @@ -118,7 +118,7 @@ public override List<ExplorerItem> GetSchema(IConnectionInfo cxInfo, Type custom

public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
{
_connInfo = RavenConnectionInfo.Load(cxInfo);
_connInfo = RavenConnectionDialogViewModel.Load(cxInfo);

var rc = context as RavenContext;
rc.LogWriter = executionManager.SqlTranslationWriter;
Expand Down
2 changes: 1 addition & 1 deletion RavenLinqpadDriver/RavenLinqpadDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<Compile Include="RavenConectionDialog.xaml.cs">
<DependentUpon>RavenConectionDialog.xaml</DependentUpon>
</Compile>
<Compile Include="RavenConnectionInfo.cs" />
<Compile Include="RavenConnectionDialogViewModel.cs" />
<Compile Include="RavenContext.cs" />
<Compile Include="Utility.cs" />
</ItemGroup>
Expand Down
Binary file modified RavenLinqpadDriver/bin/Debug/RavenLinqpadDriver.dll
Binary file not shown.
Binary file modified RavenLinqpadDriver/bin/Debug/RavenLinqpadDriver.pdb
Binary file not shown.
Binary file modified RavenLinqpadDriver/bin/Release/RavenLinqpadDriver.dll
Binary file not shown.
Binary file not shown.
Binary file modified RavenLinqpadDriver/obj/Debug/RavenLinqpadDriver.dll
Binary file not shown.
Binary file modified RavenLinqpadDriver/obj/Debug/RavenLinqpadDriver.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DEBUG;TRACE

2-629771635
1-2080279558
81020814063
872423325
26-1480214086
App.xaml;RavenConectionDialog.xaml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DEBUG;TRACE

2-629771635
1-2080279558
9401608380
9-546782358
26-1480214086
App.xaml;RavenConectionDialog.xaml;

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ TRACE

2-629771635
1-2080279558
9401608380
24-867411369
9-546782358
261185733493
App.xaml;RavenConectionDialog.xaml;

True
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C:\code\raven-linqpad-driver\RavenLinqpadDriver\obj\Release\GeneratedInternalTypeHelper.g.i.cs


FC:\code\raven-linqpad-driver\RavenLinqpadDriver\RavenConectionDialog.xaml

4 changes: 2 additions & 2 deletions RavenLinqpadDriver35/RavenLinqpadDriver35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
<Link>RavenConectionDialog.xaml.cs</Link>
<DependentUpon>RavenConectionDialog.xaml</DependentUpon>
</Compile>
<Compile Include="..\RavenLinqpadDriver\RavenConnectionInfo.cs">
<Link>RavenConnectionInfo.cs</Link>
<Compile Include="..\RavenLinqpadDriver\RavenConnectionDialogViewModel.cs">
<Link>RavenConnectionDialogViewModel.cs</Link>
</Compile>
<Compile Include="..\RavenLinqpadDriver\RavenContext.cs">
<Link>RavenContext.cs</Link>
Expand Down
Binary file modified RavenLinqpadDriver35/bin/Debug/RavenLinqpadDriver35.dll
Binary file not shown.
Binary file modified RavenLinqpadDriver35/bin/Debug/RavenLinqpadDriver35.pdb
Binary file not shown.
Binary file modified RavenLinqpadDriver35/obj/Debug/RavenLinqpadDriver35.dll
Binary file not shown.
Binary file modified RavenLinqpadDriver35/obj/Debug/RavenLinqpadDriver35.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DEBUG;TRACE;NET35

2290151892
1-2080279558
81779050512
8-1729862004
21988149429
..\RavenLinqpadDriver\RavenConectionDialog.xaml;App.xaml;

Binary file not shown.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ RavenDB LINQPadDriver

Yeah... a RavenDB driver for LINQPad.

Uses RavenDB client build 701.
Uses RavenDB client build 888.
Referencing another version of the client in LINQPad SHOULD take precedence.

Watch the video at http://youtu.be/XgsPvyk0bjM for help getting started.
Expand Down

0 comments on commit 1d5822f

Please sign in to comment.