Skip to content

Instantly share code, notes, and snippets.

View gurmitteotia's full-sized avatar

Gurmit Teotia gurmitteotia

View GitHub Profile
[WorkflowDescription("1.0")]
public class ExpenseWorkflow : Workflow
{
public ExpenseWorkflow()
{
ScheduleChildWorkflow<ApproveExpense>()
.OnCompletion(e=>e.WaitForAnySignal("Accepted", "Rejected"));
ScheduleLambda("SubmitToAccount").AfterLambda("ApproveExpense")
.When(_=>Signal("Accepted").IsTriggered());
@gurmitteotia
gurmitteotia / WaitForAnySignal.cs
Created February 4, 2019 17:41
WaitForAnySignal
[WorkflowDescription("1.0")]
public class ExpenseWorkflow : Workflow
{
public ExpenseWorkflow()
{
ScheduleLambda("ApproveExpense")
.OnCompletion(e=>e.WaitForAnySignal("Accepted", "Rejected"))
.WithInput(_=>new{Id}); //Send workflow id to lambda functions to send signals to this workflow.
ScheduleLambda("SubmitToAccount").AfterLambda("ApproveExpense")
//IDataContext.cs
public interface IDataContext
{
DbSet<T> Collection<T>() where T : class;
void SaveChanges();
}
//DataContext.cs
public class DataContext : IDataContext
{
private readonly DbContext _dbContext;
public class GenericRepository : IRepository
{
private readonly IDataContext _dataContext;
public GenericRepository(IDataContext dataContext)
{
_dataContext = dataContext;
}
public void Attach<T>(T entity) where T : class
{
_dataContext.Collection<T>().Attach(entity);
@gurmitteotia
gurmitteotia / Part1_IRepository.cs
Last active March 5, 2018 18:06
Part 1. IRepository
public interface IRepository
{
void Attach<T>(T entity) where T : class;
void Add<T>(T entity) where T : class;
void Delete<T>(T entity) where T : class;
T FindByKey<T>(object key) where T : class;
IQueryable<T> GetAll<T>() where T : class;
void Save();
}
@gurmitteotia
gurmitteotia / POOP style not code.cs
Created November 27, 2016 14:19
Poop style meeting application
//interface to read meetings from file
internal interface IMeetingFileParser
{
IEnumerable<Meeting> ParseMeetings(string filePath);
}
internal class CsvMeetingFileParser : IMeetingFileParser
{
private readonly IFileReader _fileReader;
public CsvMeetingFileParser(IFileReader fileReader)
{
@gurmitteotia
gurmitteotia / functinal_trait.cs
Created November 27, 2016 14:15
Function trait oop meeting program
public static MeetingFile Csv(string path)
{
var meetingLines = File.ReadAllLines(path).Skip(1).Select(line => new MeetingLine(line));
return new MeetingFile(meetingLines.Select(ml=>ml.Meeting).ToArray());
}
@gurmitteotia
gurmitteotia / oop_meeting_app.cs
Last active February 5, 2018 18:14
OOP style meeting application
public class CsvMeetingFile
{
private readonly string _filePath;
public CsvMeetingFile(string filePath)
{
_filePath = filePath;
}
public IEnumerable<Meeting> Meetings()
{
var meetingLines = File.ReadAllLines(_filePath).Skip(1).Select(line => new MeetingLine(line));
@gurmitteotia
gurmitteotia / GenericRepository.cs
Created August 25, 2015 12:54
Final generic repository implementation
public class GenericRepository : IRepository
{
private readonly IDataContext _dataContext;
public GenericRepository(IDataContext dataContext)
{
_dataContext = dataContext;
}
public void Attach<T>(T entity) where T : class
{
_dataContext.Collection<T>().Attach(entity);
@gurmitteotia
gurmitteotia / IRepository.cs
Created August 20, 2015 16:41
Part 2- Repository implementation using specification
public interface IRepository
{
void Attach<T>(T entity) where T : class;
void Add<T>(T entity) where T : class;
void Delete<T>(T entity) where T : class;
T FindByKey<T>(object key) where T : class;