Skip to content

Commit

Permalink
Fixed naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPuckett2G3 committed Jul 2, 2020
1 parent fcd1a79 commit ff96bb5
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 78 deletions.
42 changes: 21 additions & 21 deletions IFTTT.Tests/TestVarious.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TestVarious
private const string LogicalPassingOrFailingGroup = "Logical Passing OR Failing Test Group";
private const string FailingGroup = "Failing Test Group";

static IFTTTExpressionGroup GetExpressionGroupA()
static ExpressionGroup GetExpressionGroupA()
{
var person = new Person
{
Expand All @@ -22,12 +22,12 @@ static IFTTTExpressionGroup GetExpressionGroupA()
Age = 40
};

var expression1 = new IFTTTPropertyExpression<string>(person, nameof(person.FirstName), EqualityOperator.NotEquals, "Doe");
var expression2 = new IFTTTPropertyExpression<string>(person, nameof(person.LastName), EqualityOperator.NotEquals, null);
var expression3 = new IFTTTPropertyExpression<int>(person, nameof(person.Age), EqualityOperator.Equals, 40);
var allExpressions = new List<IFTTTExpression> { expression1, expression2, expression3 };
var expression1 = new PropertyExpression<string>(person, nameof(person.FirstName), EqualityOperator.NotEquals, "Doe");
var expression2 = new PropertyExpression<string>(person, nameof(person.LastName), EqualityOperator.NotEquals, null);
var expression3 = new PropertyExpression<int>(person, nameof(person.Age), EqualityOperator.Equals, 40);
var allExpressions = new List<Expression> { expression1, expression2, expression3 };

var expressionGroup = new IFTTTExpressionGroup
var expressionGroup = new ExpressionGroup
{
Name = PassingGroup,
Circuit = Circuit.Series,
Expand All @@ -37,7 +37,7 @@ static IFTTTExpressionGroup GetExpressionGroupA()

return expressionGroup;
}
static IFTTTExpressionGroup GetExpressionGroupB()
static ExpressionGroup GetExpressionGroupB()
{
var person = new Person
{
Expand All @@ -46,12 +46,12 @@ static IFTTTExpressionGroup GetExpressionGroupB()
Age = 40
};

var expression1 = new IFTTTPropertyExpression<string>(person, nameof(person.FirstName), EqualityOperator.NotEquals, "John");
var expression2 = new IFTTTPropertyExpression<string>(person, nameof(person.LastName), EqualityOperator.NotEquals, null);
var expression3 = new IFTTTPropertyExpression<int>(person, nameof(person.Age), EqualityOperator.Equals, 40);
var allExpressions = new List<IFTTTExpression> { expression1, expression2, expression3 };
var expression1 = new PropertyExpression<string>(person, nameof(person.FirstName), EqualityOperator.NotEquals, "John");
var expression2 = new PropertyExpression<string>(person, nameof(person.LastName), EqualityOperator.NotEquals, null);
var expression3 = new PropertyExpression<int>(person, nameof(person.Age), EqualityOperator.Equals, 40);
var allExpressions = new List<Expression> { expression1, expression2, expression3 };

var expressionGroup = new IFTTTExpressionGroup
var expressionGroup = new ExpressionGroup
{
Name = FailingGroup,
Circuit = Circuit.Series,
Expand All @@ -70,15 +70,15 @@ public void TestExpressionGroupsLogic()
//Arrange
var expressionGroupA = GetExpressionGroupA(); //Meant to pass
var expressionGroupB = GetExpressionGroupB(); //Meant to fail
var allGroups = new IFTTTExpressionGroup
var allGroups = new ExpressionGroup
{
Name = LogicalPassingOrFailingGroup,
ExpressionGroups = new List<IFTTTExpressionGroup> { expressionGroupA, expressionGroupB },
ExpressionGroups = new List<ExpressionGroup> { expressionGroupA, expressionGroupB },
LogicalOperator = LogicalOperator.Or //Passes if one or the other.
};

var traceLogger = new TraceExpressionLogger();
var expressionProcessor = new IFTTTExpressionProcessor(traceLogger);
var expressionProcessor = new ExpressionProcessor(traceLogger);

//Act
var result = expressionProcessor.ProcessExpressionGroup(allGroups);
Expand All @@ -94,14 +94,14 @@ public void TestTriggers()

//Arrange

var triggers = new List<IFTTTTrigger>
var triggers = new List<Trigger>
{
new IFTTTTrigger
new Trigger
{
ListForGroupName = PassingGroup,
TriggerGroupName = FailingGroup
},
new IFTTTTrigger
new Trigger
{
ListForGroupName = FailingGroup,
TriggerGroupName = LogicalPassingOrFailingGroup
Expand All @@ -112,11 +112,11 @@ public void TestTriggers()
var expressionGroupB = GetExpressionGroupB(); //Meant to fail

var traceLogger = new TraceExpressionLogger();
var expressionProcessor = new IFTTTExpressionProcessor(traceLogger);
var actor = new IFTTTExpressionTriggerProcessor(expressionProcessor)
var expressionProcessor = new ExpressionProcessor(traceLogger);
var actor = new ExpressionTriggerProcessor(expressionProcessor)
{
Triggers = triggers,
ExpressionGroups = new IFTTTExpressionGroup[] { expressionGroupA, expressionGroupB }
ExpressionGroups = new ExpressionGroup[] { expressionGroupA, expressionGroupB }
};

//Act
Expand Down
6 changes: 3 additions & 3 deletions IFTTT.Tests/TraceExpressionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace IFTTT.Tests
{
public class TraceExpressionLogger : IFTTTLogger
public class TraceExpressionLogger : IExpressionLogger
{
private const string NullString = "Null";

public Task LogAsync(IFTTTExpression expression, bool expressionResult) => Task.Run(() =>
public Task LogAsync(Expression expression, bool expressionResult) => Task.Run(() =>
{
Trace.WriteLine($"Expression:\t\t\t\t{expression.ExpressionA ?? NullString} {expression.EqualityOperator} {expression.ExpressionB ?? NullString} = {expressionResult}");
});

public Task LogAsync(IFTTTExpressionGroup group, bool expressionResult) => Task.Run(() =>
public Task LogAsync(ExpressionGroup group, bool expressionResult) => Task.Run(() =>
{
Trace.WriteLine($"Expression Group:\t\t{group.Name} = {expressionResult}");
});
Expand Down
11 changes: 11 additions & 0 deletions IFTTT/Interfaces/IExpressionLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using IFTTT.Models;
using System.Threading.Tasks;

namespace IFTTT.Interfaces
{
public interface IExpressionLogger
{
Task LogAsync(Expression expression, bool expressionResult);
Task LogAsync(ExpressionGroup group, bool expressionResult);
}
}
15 changes: 15 additions & 0 deletions IFTTT/Interfaces/IExpressionProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using IFTTT.Constants;
using IFTTT.Models;
using System;
using System.Collections.Generic;

namespace IFTTT.Interfaces
{
public interface IExpressionProcessor
{
event EventHandler<ExpressionGroup> ExpressionGroupPassed;
bool ProcessExpression(Expression expression);
bool ProcessExpressionGroup(ExpressionGroup expressionGroup);
bool ProcessExpressions(IEnumerable<Expression> expressions, bool isShorted, Circuit circuit);
}
}
11 changes: 0 additions & 11 deletions IFTTT/Interfaces/IFTTTExpressionLogger.cs

This file was deleted.

15 changes: 0 additions & 15 deletions IFTTT/Interfaces/IIFTTTExpressionProcessor.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IFTTT.Models
{
public class IFTTTExpression
public class Expression
{
public object ExpressionA { get; set; }
public EqualityOperator EqualityOperator { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

namespace IFTTT.Models
{
public class IFTTTExpressionGroup
public class ExpressionGroup
{
private static int counter;
public IFTTTExpressionGroup()
public ExpressionGroup()
{
counter++;
if (string.IsNullOrEmpty(Name)) Name = $"{nameof(IFTTTExpressionGroup)}:{counter}";
if (string.IsNullOrEmpty(Name)) Name = $"{nameof(ExpressionGroup)}:{counter}";
}

public string Name { get; set; }

public Circuit Circuit { get; set; } = Circuit.Series;
public bool IsShorted { get; set; } = true;
public IEnumerable<IFTTTExpression> Expressions { get; set; }
public IEnumerable<Expression> Expressions { get; set; }
public LogicalOperator LogicalOperator { get; set; } = LogicalOperator.And;
public IEnumerable<IFTTTExpressionGroup> ExpressionGroups { get; set; }
public IEnumerable<ExpressionGroup> ExpressionGroups { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace IFTTT.Models
{
public class IFTTTPropertyExpression<T> : IFTTTTypeExpression<T>
public class PropertyExpression<T> : TypeExpression<T>
{
private static IEnumerable<PropertyInfo> propertyInfos;

public IFTTTPropertyExpression(object obj, string propertyName, EqualityOperator equalityOperator, T value)
public PropertyExpression(object obj, string propertyName, EqualityOperator equalityOperator, T value)
{
Owner = obj;
PropertyName = propertyName;
Expand Down
2 changes: 1 addition & 1 deletion IFTTT/Models/IFTTTTrigger.cs → IFTTT/Models/Trigger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace IFTTT.Models
{
public class IFTTTTrigger
public class Trigger
{
public string ListForGroupName { get; set; }
public string TriggerGroupName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace IFTTT.Models
{
public class IFTTTTypeExpression<T> : IFTTTExpression
public class TypeExpression<T> : Expression
{
public new T ExpressionA
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

namespace IFTTT.Processors
{
public class IFTTTExpressionProcessor : IIFTTTExpressionProcessor
public class ExpressionProcessor : IExpressionProcessor
{
private const int MaxDegreesOfParallism = 8;
private readonly IFTTTLogger expressionLogger;
public event EventHandler<IFTTTExpressionGroup> ExpressionGroupPassed;
private readonly IExpressionLogger expressionLogger;
public event EventHandler<ExpressionGroup> ExpressionGroupPassed;

public IFTTTExpressionProcessor(IFTTTLogger expressionLogger = null)
public ExpressionProcessor(IExpressionLogger expressionLogger = null)
{
this.expressionLogger = expressionLogger;
}

public bool ProcessExpressionGroup(IFTTTExpressionGroup expressionGroup)
public bool ProcessExpressionGroup(ExpressionGroup expressionGroup)
{
bool boolean = ProcessExpressions(expressionGroup.Expressions, expressionGroup.IsShorted, expressionGroup.Circuit);
if (expressionGroup.IsShorted && !boolean) return boolean;
Expand All @@ -41,7 +41,7 @@ public bool ProcessExpressionGroup(IFTTTExpressionGroup expressionGroup)
return boolean;
}

public bool ProcessExpressions(IEnumerable<IFTTTExpression> expressions, bool isShorted, Circuit circuit)
public bool ProcessExpressions(IEnumerable<Expression> expressions, bool isShorted, Circuit circuit)
{
var boolean = true; //Always assume true to start.
if (!(expressions?.Any() ?? false)) return boolean;
Expand All @@ -68,7 +68,7 @@ public bool ProcessExpressions(IEnumerable<IFTTTExpression> expressions, bool is
return boolean;
}

public bool ProcessExpression(IFTTTExpression expression)
public bool ProcessExpression(Expression expression)
{
bool result;
switch (expression.EqualityOperator)
Expand All @@ -86,7 +86,7 @@ public bool ProcessExpression(IFTTTExpression expression)
return result;
}

private bool ProcessLogicalParallel(IFTTTExpressionGroup expressionGroup, bool boolean)
private bool ProcessLogicalParallel(ExpressionGroup expressionGroup, bool boolean)
{
switch (expressionGroup.LogicalOperator)
{
Expand All @@ -102,7 +102,7 @@ private bool ProcessLogicalParallel(IFTTTExpressionGroup expressionGroup, bool b
return boolean;
}

private bool ProcessLogicalSeries(IFTTTExpressionGroup expressionGroup, bool boolean)
private bool ProcessLogicalSeries(ExpressionGroup expressionGroup, bool boolean)
{
switch (expressionGroup.LogicalOperator)
{
Expand All @@ -118,9 +118,9 @@ private bool ProcessLogicalSeries(IFTTTExpressionGroup expressionGroup, bool boo
return boolean;
}

private bool ProcessExpressionGroupInSeries(IFTTTExpressionGroup expressionGroup, bool boolean)
private bool ProcessExpressionGroupInSeries(ExpressionGroup expressionGroup, bool boolean)
{
foreach (var group in expressionGroup.ExpressionGroups ?? Enumerable.Empty<IFTTTExpressionGroup>())
foreach (var group in expressionGroup.ExpressionGroups ?? Enumerable.Empty<ExpressionGroup>())
{
boolean = ProcessExpressionGroup(group) && boolean;
if (expressionGroup.IsShorted && !boolean) break;
Expand All @@ -129,7 +129,7 @@ private bool ProcessExpressionGroupInSeries(IFTTTExpressionGroup expressionGroup
return boolean;
}

private bool ProcessExpressionGroupInParallel(IFTTTExpressionGroup expressionGroup, bool boolean)
private bool ProcessExpressionGroupInParallel(ExpressionGroup expressionGroup, bool boolean)
{
if (!(expressionGroup.ExpressionGroups?.Any() ?? false)) return boolean;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using IFTTT.Interfaces;
using IFTTT.Models;
using System.Collections.Generic;
using System.Linq;

namespace IFTTT.Processors
{
public class IFTTTExpressionTriggerProcessor
public class ExpressionTriggerProcessor
{
private readonly IIFTTTExpressionProcessor expressionProcessor;
private readonly IExpressionProcessor expressionProcessor;

public IFTTTExpressionTriggerProcessor(IIFTTTExpressionProcessor expressionProcessor)
public ExpressionTriggerProcessor(IExpressionProcessor expressionProcessor)
{
this.expressionProcessor = expressionProcessor;
this.expressionProcessor.ExpressionGroupPassed += ExpressionProcessor_ExpressionGroupPassed;
}

public IEnumerable<IFTTTTrigger> Triggers { get; set; }
public IEnumerable<IFTTTExpressionGroup> ExpressionGroups { get; set; }
public IEnumerable<Trigger> Triggers { get; set; }
public IEnumerable<ExpressionGroup> ExpressionGroups { get; set; }

private void ExpressionProcessor_ExpressionGroupPassed(object sender, IFTTTExpressionGroup e)
private void ExpressionProcessor_ExpressionGroupPassed(object sender, ExpressionGroup e)
{
var trigger = Triggers.FirstOrDefault(x => x.ListForGroupName == e.Name);
if (trigger != null)
Expand Down

0 comments on commit ff96bb5

Please sign in to comment.