Skip to content

Commit

Permalink
Wire server to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullin committed Feb 19, 2013
1 parent 13944b6 commit 4d02c23
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/Btw.Redis.Tests/TestRedisManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Name()
using (var test = new RedisClient())
using (var store = new RedisAppendOnlyStore(test))
{
store.Append("test", Encoding.UTF8.GetBytes("me data"), -1);
store.Append("test2", Encoding.UTF8.GetBytes("me data"), -1);
}

}
Expand Down
4 changes: 0 additions & 4 deletions Source/Btw.Redis/Btw.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
<Project>{A435667B-5C71-41A0-A7C8-4700BDADF8B2}</Project>
<Name>Btw.Portable</Name>
</ProjectReference>
<ProjectReference Include="..\Gtd.Console\Gtd.Shell.csproj">
<Project>{B5516C60-3F2C-4CF1-9174-ED3ED2C7BF75}</Project>
<Name>Gtd.Shell</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 0 additions & 2 deletions Source/Btw.Redis/RedisAppendOnlyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ public IEnumerable<StoreData> ReadRecords(long afterVersion, int maxCount)
{
yield return new StoreData(items[i], i + start + 1);
}

throw new Exception(items.ToArray().ToString());
}

public void Close()
Expand Down
10 changes: 10 additions & 0 deletions Source/Gtd.Console/Gtd.Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<Reference Include="protobuf-net">
<HintPath>..\..\Library\ProtoBuf-net\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces">
<HintPath>..\..\Library\ServiceStack\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Redis">
<HintPath>..\..\Library\ServiceStack\ServiceStack.Redis.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
Expand Down Expand Up @@ -85,6 +91,10 @@
<Project>{A435667B-5C71-41A0-A7C8-4700BDADF8B2}</Project>
<Name>Btw.Portable</Name>
</ProjectReference>
<ProjectReference Include="..\Btw.Redis\Btw.Redis.csproj">
<Project>{66A6C5E4-3732-4955-8247-620377E261F2}</Project>
<Name>Btw.Redis</Name>
</ProjectReference>
<ProjectReference Include="..\Gtd.CoreDomain\Gtd.CoreDomain.csproj">
<Project>{BAB02576-30C8-4DE2-AC43-23766F9FD6A1}</Project>
<Name>Gtd.CoreDomain</Name>
Expand Down
48 changes: 42 additions & 6 deletions Source/Gtd.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Gtd.CoreDomain;
using Gtd.Redis;
using Gtd.Shell.Commands;
using Gtd.Shell.Filters;
using Gtd.Shell.Projections;
using ServiceStack.Redis;

namespace Gtd.Shell
{
Expand All @@ -18,8 +21,13 @@ static void Main(string[] args)
// setup and wire our console environment
Log.Info("Starting Being The Worst interactive GTD shell :)");

var setup = new Setup();
setup.UseRedis = true;

Log.Info(setup.ToString());

Log.Info("");
var env = ConsoleEnvironment.Build();
var env = ConsoleEnvironment.Build(setup);
Log.Info("");
Log.Info("Type 'help' to get more info");
Log.Info("");
Expand Down Expand Up @@ -65,6 +73,19 @@ static void Main(string[] args)
}
}

public class Setup
{
public bool UseRedis;

public override string ToString()
{
var builder = new StringBuilder();
builder.AppendFormat("UseRedis={0}", UseRedis).AppendLine();

return builder.ToString();
}
}

public sealed class ConsoleEnvironment
{
public IEventStore Store { get; private set; }
Expand All @@ -79,18 +100,33 @@ public sealed class ConsoleEnvironment

public DateTime CurrentDate { get { return DateTime.Now; } }

public static ConsoleEnvironment Build()
public static ConsoleEnvironment Build(Setup setup)
{
var handler = new SynchronousEventHandler();

var inbox = new ConsoleProjection();
handler.RegisterHandler(inbox);
IAppendOnlyStore store;
if (setup.UseRedis)
{
store = new RedisAppendOnlyStore(new RedisClient());
try
{
store.GetCurrentVersion();
}
catch (RedisException ex)
{
throw new ApplicationException("It looks like redis is not running. Please start Library\\Redis.Win\\redis.server.exe :)");
}
}
else
{
var file = new FileAppendOnlyStore(new DirectoryInfo(Directory.GetCurrentDirectory()));
file.Initialize();
store = file;
}

//var store = new InMemoryStore(handler);


var store = new FileAppendOnlyStore(new DirectoryInfo(Directory.GetCurrentDirectory()));
store.Initialize();
var messageStore = new MessageStore(store);
messageStore.LoadDataContractsFromAssemblyOf(typeof(ActionDefined));
var currentVersion = store.GetCurrentVersion();
Expand Down

0 comments on commit 4d02c23

Please sign in to comment.