Skip to content

Commit

Permalink
3rd push
Browse files Browse the repository at this point in the history
  • Loading branch information
sachabarber committed Mar 26, 2015
1 parent 0e2e79e commit 37f86ce
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,51 @@ namespace SachaBarber.CQRS.Demo.ConsoleClient
{
class Program
{
static void Main(string[] args)
{

public async Task Run()
{
Guid id = Guid.NewGuid();


IOrderService invoker = new OrderServiceInvoker();
invoker.SendCommand(new CreateOrderCommand()
{
ExpectedVersion = 1,
Id = id,
Address = "This is the address",
Description = "Description1",
OrderItems = new List<OrderItem>()
});

var x = await new OrderServiceInvoker().CallService(service =>
service.SendCommand(new CreateOrderCommand()
{
ExpectedVersion = 1,
Id = id,
Address = "This is the address",
Description = "Description1",
OrderItems = new List<OrderItem>()
}));


//var x = await new OrderServiceClient().SendCommand(new CreateOrderCommand()
//{
// ExpectedVersion = 1,
// Id = id,
// Address = "This is the address",
// Description = "Description1",
// OrderItems = new List<OrderItem>()
//});


var y = 54554;

invoker.SendCommand(new RenameOrderCommand()
{
ExpectedVersion = 1,
Id = id,
NewOrderDescription = "CHANGED New Order A"
});
//invoker.SendCommand(new RenameOrderCommand()
//{
// ExpectedVersion = 1,
// Id = id,
// NewOrderDescription = "CHANGED New Order A"
//});

}


static void Main(string[] args)
{
Program p = new Program();
p.Run().Wait();



Console.ReadLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Reflection;
using System.ServiceModel;

using System.Threading.Tasks;
using SachaBarber.CQRS.Demo.Orders.Commands;
using SachaBarber.CQRS.Demo.Orders.Domain.Commands;
using SachaBarber.CQRS.Demo.SharedCore.Exceptions;
Expand All @@ -22,17 +22,17 @@ public OrderService(OrderCommandHandlers commandHandlers)
this.commandHandlers = commandHandlers;
}

public bool SendCommand(Command command)
public async Task<bool> SendCommand(Command command)
{
var meth = (from m in typeof(OrderCommandHandlers).GetMethods(BindingFlags.Public | BindingFlags.Instance)
let prms = m.GetParameters()
where prms.Count() == 1 && prms[0].ParameterType == command.GetType()
select m).FirstOrDefault();
//var meth = (from m in typeof(OrderCommandHandlers).GetMethods(BindingFlags.Public | BindingFlags.Instance)
// let prms = m.GetParameters()
// where prms.Count() == 1 && prms[0].ParameterType == command.GetType()
// select m).FirstOrDefault();

if (meth == null)
throw new BusinessLogicException(string.Format("Handler for {0} could not be found", command.GetType().Name));
//if (meth == null)
// throw new BusinessLogicException(string.Format("Handler for {0} could not be found", command.GetType().Name));

meth.Invoke(commandHandlers, new[] { command });
//meth.Invoke(commandHandlers, new[] { command });
return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions SachaBarber.CQRS.Demo/SachaBarber.CQRS.Demo.Domain/TODO.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
1. We should come up with a new EventStore other than InMemory
2. Move all CQRS stuff into Common dll, and make sure to change app.configs for new
contract interface location, swap it out to use async await codebase for WCF
http://www.dotnetcurry.com/showarticle.aspx?ID=983

2. In the Repository.Save where it Publishes out,
we should have preregistered handlers in main service something like

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ namespace SachaBarber.CQRS.Demo.Orders
public interface IOrderService
{
[OperationContract]
bool SendCommand(Command command);
Task<bool> SendCommand(Command command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SachaBarber.CQRS.Demo.Orders.Commands;

namespace SachaBarber.CQRS.Demo.Orders
{
public partial class OrderServiceClient :
System.ServiceModel.ClientBase<IOrderService>, IOrderService
{

public OrderServiceClient()
{
}

public OrderServiceClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}

public OrderServiceClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}

public OrderServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}

public OrderServiceClient(System.ServiceModel.Channels.Binding binding,
System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}

public System.Threading.Tasks.Task<bool> SendCommand(Command command)
{
return base.Channel.SendCommand(command);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

using SachaBarber.CQRS.Demo.Orders.Commands;
using SachaBarber.CQRS.Demo.SharedCore;
using SachaBarber.CQRS.Demo.SharedCore.Exceptions;
using SachaBarber.CQRS.Demo.SharedCore.Faults;

namespace SachaBarber.CQRS.Demo.Orders
{
public class OrderServiceInvoker : ServiceInvokerBase, IOrderService
public class OrderServiceInvoker
{
public bool SendCommand(Command command)
public TR CallService<TR>(Func<IOrderService, TR> requestAction)
{
return this.CallService<IOrderService, bool>(proxy => proxy.SendCommand(command));
try
{
OrderServiceClient proxy = new OrderServiceClient();
return requestAction(proxy);
}
catch (FaultException<GenericFault> gf)
{
throw new ApplicationException("A FaultException<GenericFault> occured", gf.InnerException);
}
catch (FaultException<BusinessLogicFault> bf)
{
throw new BusinessLogicException(bf.Message);
}
catch (Exception ex)
{
throw new Exception("A Exception occured", ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="Commands\RenameOrderCommand.cs" />
<Compile Include="DTOs\OrderItem.cs" />
<Compile Include="IOrderService.cs" />
<Compile Include="OrderServiceClient.cs" />
<Compile Include="OrderServiceInvoker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="ChannelFactoryManager.cs" />
<Compile Include="Exceptions\BusinessLogicException.cs" />
<Compile Include="ExtensionMethods\CastleExtensions.cs" />
<Compile Include="Faults\BusinessLogicFault.cs" />
<Compile Include="Faults\GenericFault.cs" />
<Compile Include="Faults\IFault.cs" />
<Compile Include="Faults\StandardFaultsAttribute.cs" />
<Compile Include="IOC\LifestyleApplier.cs" />
<Compile Include="ServiceInvokerBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WCF\ErrorHandler.cs" />
<Compile Include="WCF\ErrorHandlerBehaviorExtension.cs" />
Expand Down

0 comments on commit 37f86ce

Please sign in to comment.