Skip to content

Commit

Permalink
Merge pull request #1 from quasarke/master
Browse files Browse the repository at this point in the history
Updating personal fork
  • Loading branch information
seiggy authored Oct 17, 2018
2 parents 18829e6 + 198e362 commit e76491d
Show file tree
Hide file tree
Showing 76 changed files with 809 additions and 522 deletions.
48 changes: 0 additions & 48 deletions Arke.DSL/Step/DslStep.cs

This file was deleted.

84 changes: 84 additions & 0 deletions Arke.DSL/Step/NodeData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections.Generic;
using System.Linq;
using Arke.DSL.Step.Settings;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

namespace Arke.DSL.Step
{
public class NodeData
{
public string Text { get; set; }
public string Category { get; set; }
public int Key { get; set; }
public NodeProperties Properties { get; set; }

[JsonConstructor]
public NodeData(string text, string category, int key, object properties)
{
var settingsFactory = new SettingsFactory();
Key = key;
Text = text;
Category = category;
Properties = settingsFactory.CreateProperties(category, (JObject)properties);
}
}

public abstract class NodeProperties
{
[JsonConverter(typeof(StringEnumConverter))]
public Direction Direction { get; set; }

public virtual NodeProperties ConvertFromJObject(JObject jObject)
{
SetDirection(jObject.GetValue("Direction").Value<string>());
return this;
}

private void SetDirection(string direction)
{
switch (direction)
{
case "Incoming":
Direction = Direction.Incoming;
break;
case "Outgoing":
Direction = Direction.Outgoing;
break;
default:
Direction = Direction.Both;
break;
}
}
}

public class LinkData
{
public int From { get; set; }
public int To { get; set; }
public string FromPort { get; set; }
public string ToPort { get; set; }
}

public class CallFlowDsl
{
public List<NodeData> NodeDataArray { get; set; }
public List<LinkData> LinkDataArray { get; set; }

public Dictionary<int, Step> GetStepsFromDsl()
{
var stepList = new Dictionary<int, Step>();
foreach (var node in NodeDataArray)
{
var step = new Step()
{
NodeData = node,
LinkedSteps = LinkDataArray.AsQueryable().Where(s => s.From == node.Key).ToList()
};
stepList.Add(node.Key, step);
}
return stepList;
}
}
}
16 changes: 0 additions & 16 deletions Arke.DSL/Step/Settings/GenericSettings.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Arke.DSL/Step/Settings/ISettings.cs

This file was deleted.

31 changes: 15 additions & 16 deletions Arke.DSL/Step/Settings/SettingsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ namespace Arke.DSL.Step.Settings
{
public class SettingsFactory
{
public virtual object GetSettings(string stepType)
public NodeProperties CreateProperties(string category, JObject jObject)
{
var settingsName = stepType + "Settings";
var settingsType = AppDomain.CurrentDomain.GetAssemblies()
// Xunit assemblies cause issues during unit tests, so omit from assembly search.
var properties = CreatePropertiesObject(category);
return ((NodeProperties) properties).ConvertFromJObject(jObject);
}

public virtual object CreatePropertiesObject(string category)
{
var propertiesName = category + "Settings";
var propertiesType = AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly => !assembly.FullName.Contains("xunit"))
.SelectMany(assembly => assembly.GetTypes())
.Where(type => typeof(ISettings).IsAssignableFrom(type))
.SingleOrDefault(type => type.Name == settingsName);
.Where(type => typeof(NodeProperties).IsAssignableFrom(type))
.SingleOrDefault(type => type.Name == propertiesName);

if (settingsType == null)
throw new StepNotFoundException($"Step {stepType} is missing from Assembly.");
if (propertiesType == null)
throw new StepNotFoundException($"Step {category} is missing from Assembly");

var settings = ObjectContainer.GetInstance().GetObjectInstance(settingsType);
return settings;
}

public ISettings CopyJObject(string stepType, JObject jObject)
{
var settings = GetSettings(stepType);
return ((ISettings) settings).ConvertFromJObject(jObject);
var property = ObjectContainer.GetInstance().GetObjectInstance(propertiesType);
return property;
}
}
}
26 changes: 26 additions & 0 deletions Arke.DSL/Step/Step.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Arke.DSL.Step.Settings;

namespace Arke.DSL.Step
{
public class Step
{
public NodeData NodeData { get; set; }
public List<LinkData> LinkedSteps { get; set; }

public int GetStepFromConnector(string connectorName)
{
try
{
return LinkedSteps.Single(s => s.FromPort == connectorName).To;
}
catch (Exception)
{
throw new StepNotFoundException($"Connector {connectorName} not found on {NodeData.Key}");
}
}
}
}
2 changes: 1 addition & 1 deletion Arke.DependencyInjection/Arke.DependencyInjection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.4" />
<PackageReference Include="SimpleInjector" Version="4.2.3" />
<PackageReference Include="SimpleInjector" Version="4.3.0" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions Arke.DependencyInjection/ObjectContainer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using SimpleInjector;
using SimpleInjector.Lifestyles;

namespace Arke.DependencyInjection
{
Expand All @@ -12,6 +13,7 @@ public class ObjectContainer
public ObjectContainer()
{
_container = new Container();
_container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
_lifecycleConverter = new SimpleInjectorLifecycleConverter();
}

Expand Down
Loading

0 comments on commit e76491d

Please sign in to comment.