Skip to content

Instantly share code, notes, and snippets.

@trbngr
Created July 9, 2015 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trbngr/2fa60d9e2bc3dc0a5a2b to your computer and use it in GitHub Desktop.
Save trbngr/2fa60d9e2bc3dc0a5a2b to your computer and use it in GitHub Desktop.
Mini Akka Helper DSL
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyCompany
{
using Akka;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
public interface IIndexUsers
{
}
public class CreateAccount : ICommand
{
public Guid AccountId { get; private set; }//;
public String UserName { get; private set; }//;
[JsonConstructor()]
private CreateAccount()
{
}
public CreateAccount(Guid accountId, String userName)
{
this.AccountId = accountId;
this.UserName = userName;
}
public virtual CreateAccount Clone(Guid accountId = default(Guid), String userName = default(String))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
String localUserName = userName;
if ((userName == default(String)))
{
localUserName = this.UserName;
}
return new CreateAccount(localAccountId, localUserName);
}
}
public class AccountCreated : IEvent, IIndexUsers
{
public Guid AccountId { get; private set; }//;
public String UserName { get; private set; }//;
public DateTime Date { get; private set; }//;
[JsonConstructor()]
private AccountCreated()
{
}
public AccountCreated(Guid accountId, String userName, DateTime date)
{
this.AccountId = accountId;
this.UserName = userName;
this.Date = date;
}
public virtual AccountCreated Clone(Guid accountId = default(Guid), String userName = default(String), DateTime date = default(DateTime))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
String localUserName = userName;
if ((userName == default(String)))
{
localUserName = this.UserName;
}
DateTime localDate = date;
if ((date == default(DateTime)))
{
localDate = this.Date;
}
return new AccountCreated(localAccountId, localUserName, localDate);
}
}
public class UpdateAccount : ICommand
{
public Guid AccountId { get; private set; }//;
public String UserName { get; private set; }//;
[JsonConstructor()]
private UpdateAccount()
{
}
public UpdateAccount(Guid accountId, String userName)
{
this.AccountId = accountId;
this.UserName = userName;
}
public virtual UpdateAccount Clone(Guid accountId = default(Guid), String userName = default(String))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
String localUserName = userName;
if ((userName == default(String)))
{
localUserName = this.UserName;
}
return new UpdateAccount(localAccountId, localUserName);
}
}
public class AccountUpdated : IEvent, IIndexUsers
{
public Guid AccountId { get; private set; }//;
public String UserName { get; private set; }//;
public DateTime Date { get; private set; }//;
[JsonConstructor()]
private AccountUpdated()
{
}
public AccountUpdated(Guid accountId, String userName, DateTime date)
{
this.AccountId = accountId;
this.UserName = userName;
this.Date = date;
}
public virtual AccountUpdated Clone(Guid accountId = default(Guid), String userName = default(String), DateTime date = default(DateTime))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
String localUserName = userName;
if ((userName == default(String)))
{
localUserName = this.UserName;
}
DateTime localDate = date;
if ((date == default(DateTime)))
{
localDate = this.Date;
}
return new AccountUpdated(localAccountId, localUserName, localDate);
}
}
public class LogInUser : ICommand
{
public Guid AccountId { get; private set; }//;
[JsonConstructor()]
private LogInUser()
{
}
public LogInUser(Guid accountId)
{
this.AccountId = accountId;
}
public virtual LogInUser Clone(Guid accountId = default(Guid))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
return new LogInUser(localAccountId);
}
}
public class UserLoggedIn : IEvent
{
public Guid AccountId { get; private set; }//;
public DateTime Date { get; private set; }//;
[JsonConstructor()]
private UserLoggedIn()
{
}
public UserLoggedIn(Guid accountId, DateTime date)
{
this.AccountId = accountId;
this.Date = date;
}
public virtual UserLoggedIn Clone(Guid accountId = default(Guid), DateTime date = default(DateTime))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
DateTime localDate = date;
if ((date == default(DateTime)))
{
localDate = this.Date;
}
return new UserLoggedIn(localAccountId, localDate);
}
}
public class LogOutUser : ICommand
{
public Guid AccountId { get; private set; }//;
[JsonConstructor()]
private LogOutUser()
{
}
public LogOutUser(Guid accountId)
{
this.AccountId = accountId;
}
public virtual LogOutUser Clone(Guid accountId = default(Guid))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
return new LogOutUser(localAccountId);
}
}
public class UserLoggedOut : IEvent
{
public Guid AccountId { get; private set; }//;
public DateTime Date { get; private set; }//;
[JsonConstructor()]
private UserLoggedOut()
{
}
public UserLoggedOut(Guid accountId, DateTime date)
{
this.AccountId = accountId;
this.Date = date;
}
public virtual UserLoggedOut Clone(Guid accountId = default(Guid), DateTime date = default(DateTime))
{
Guid localAccountId = accountId;
if ((accountId == default(Guid)))
{
localAccountId = this.AccountId;
}
DateTime localDate = date;
if ((date == default(DateTime)))
{
localDate = this.Date;
}
return new UserLoggedOut(localAccountId, localDate);
}
}
}
namespace MyCompany;
commands are ICommand;
events are IEvent;
state AccountViewState
marker IIndexUsers
const accountId is Guid;
const date is DateTime
const userName is string
command CreateAccount(accountId, userName)
event AccountCreated(accountId, userName, date)
markas IIndexUsers
tell AccountViewState
command UpdateAccount(accountId, userName)
event AccountUpdated(accountId, userName, date)
markas IIndexUsers
tell AccountViewState
command LogInUser(accountId)
event UserLoggedIn(accountId, date)
tell AccountViewState
command LogOutUser(accountId)
event UserLoggedOut(accountId, date)
tell AccountViewState
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyCompany
{
using Akka;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
public abstract class AccountViewState
{
private bool Receive(object message)
{
return message.Match()
.With<AccountCreated>(When)
.With<AccountUpdated>(When)
.With<UserLoggedIn>(When)
.With<UserLoggedOut>(When)
.WasHandled;
}
protected abstract void When(AccountCreated message);
protected abstract void When(AccountUpdated message);
protected abstract void When(UserLoggedIn message);
protected abstract void When(UserLoggedOut message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment