Skip to content

Commit d64aac9

Browse files
committed
Continue to flesh out integraion points
1 parent d81ba79 commit d64aac9

File tree

9 files changed

+113
-8
lines changed

9 files changed

+113
-8
lines changed

IntegrationEngine.ConsoleHost/IntegrationJobs/CarReport/CarMailMessageJob.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IntegrationEngine.Core.Jobs;
1+
using IntegrationEngine.ConsoleHost.IntegrationPoints;
2+
using IntegrationEngine.Core.Jobs;
23
using IntegrationEngine.Core.Mail;
34
using System;
45
using System.Collections.Generic;
@@ -11,6 +12,16 @@ public class CarMailMessageJob : IMailJob, IParameterizedJob
1112
public IMailClient MailClient { get; set; }
1213
public IDictionary<string, string> Parameters { get; set; }
1314

15+
public CarMailMessageJob()
16+
{
17+
}
18+
19+
public CarMailMessageJob(IFooMailClient mailClient)
20+
: this()
21+
{
22+
MailClient = mailClient;
23+
}
24+
1425
public void Run()
1526
{
1627
var mailMessage = new MailMessage();

IntegrationEngine.ConsoleHost/IntegrationPoints/FooMailClient.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
using System;
22
using IntegrationEngine.Core.Mail;
3+
using IntegrationEngine.Core.Configuration;
34

45
namespace IntegrationEngine.ConsoleHost.IntegrationPoints
56
{
7+
//[IntegrationPointConfiguration("FooMailClient")]
68
public class FooMailClient : MailClient
7-
{}
9+
{
10+
public FooMailClient(IMailConfiguration mailConfiguration)
11+
{
12+
MailConfiguration = mailConfiguration;
13+
}
14+
}
815
}
9-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using IntegrationEngine.Core.Mail;
3+
using IntegrationEngine.Core.Configuration;
4+
5+
namespace IntegrationEngine.ConsoleHost.IntegrationPoints
6+
{
7+
//[IntegrationPointConfiguration("FooMailClient")]
8+
public interface IFooMailClient : IMailClient
9+
{
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace IntegrationEngine.Core.Configuration
8+
{
9+
[AttributeUsage(AttributeTargets.Class)]
10+
public class IntegrationPointConfigurationAttribute : Attribute
11+
{
12+
public string Name { get; set; }
13+
14+
//public IntegrationPointConfigurationAttribute(string name)
15+
//{
16+
// Name = name;
17+
//}
18+
}
19+
}

IntegrationEngine.Core/IntegrationEngine.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="Jobs\ILogJob.cs" />
9090
<Compile Include="Jobs\IMailJob.cs" />
9191
<Compile Include="Jobs\IntegrationJobRunFailureException.cs" />
92+
<Compile Include="Configuration\IntegrationPointConfigurationAttribute.cs" />
9293
<Compile Include="Jobs\IParameterizedJob.cs" />
9394
<Compile Include="Jobs\ISqlJob.cs" />
9495
<Compile Include="Jobs\SqlJob.cs" />

IntegrationEngine/EngineHostCompositionRoot.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public void Configure(IList<Assembly> assembliesWithJobs)
4242
LoadConfiguration();
4343
SetupLogging();
4444
RegisterIntegrationPoints();
45+
RegisterIntegrationJobs();
4546
SetupRScriptRunner();
4647
SetupElasticsearchRepository();
47-
SetupEngineScheduler();
4848
SetupThreadedListenerManager();
49+
SetupEngineScheduler();
4950
SetupWebApi();
5051
}
5152

@@ -76,10 +77,13 @@ public void RegisterIntegrationPoints()
7677
Container.RegisterType<INestSerializer, NestSerializer>();
7778
Container.RegisterType<Elasticsearch.Net.Connection.ITransport, Elasticsearch.Net.Connection.Transport>();
7879
Container.RegisterType<IConnectionSettingsValues, ConnectionSettings>();
80+
//Container.RegisterType<IMailConfiguration, MailConfiguration>();
7981
foreach (var config in EngineConfiguration.IntegrationPoints.Mail) {
8082
Container.RegisterInstance<IMailConfiguration>(config.IntegrationPointName, config);
8183
Container.RegisterType<IMailClient, MailClient>(config.IntegrationPointName, new InjectionConstructor(config));
8284
}
85+
var mailClientConfig = Container.Resolve<IMailConfiguration>("FooMailClient");
86+
8387
foreach (var config in EngineConfiguration.IntegrationPoints.Elasticsearch) {
8488
Container.RegisterInstance<IElasticsearchConfiguration>(config.IntegrationPointName, config);
8589
var serverUri = new UriBuilder(config.Protocol, config.HostName, config.Port).Uri;
@@ -100,6 +104,52 @@ public void RegisterIntegrationPoints()
100104
}
101105
}
102106

107+
public void RegisterIntegrationJobs()
108+
{
109+
foreach (var jobType in IntegrationJobTypes)
110+
{
111+
// Register the Types with the Container
112+
// Register a constructor with the Container
113+
// Need to know which constructor should be used.
114+
// If it has no constructor, assume default constructor
115+
// If it has one constructor, then use that constructor
116+
// If it has two or more constructors use the first one with arguments
117+
var constructorCount = jobType.GetConstructors().Count();
118+
if (constructorCount <= 1)
119+
{
120+
Container.RegisterType(jobType);
121+
continue;
122+
}
123+
//else if (constructorCount >= 2)
124+
//{
125+
var parameters = jobType.GetConstructors().Single(x => x.GetParameters().Any()).GetParameters();
126+
// Resolve the integration point type (in parameters).
127+
// Configure the integration point type with a configuration, based on the parameter name.
128+
var resolvedParameters = new List<ResolvedParameter>();
129+
foreach (var parameterInfo in parameters)
130+
{
131+
var parameterType = parameterInfo.ParameterType; // The type of integration point (e.g. IElasticClient)
132+
var parameterName = parameterInfo.ParameterType.Name; // The name of the configuration endpoint (e.g. "MyElasticClient")
133+
134+
if (typeof(IMailClient).IsAssignableFrom(parameterType))
135+
{
136+
// Register the integration point.
137+
// To register the integration point, the parameters of the type's constructor must be known.
138+
// To make this happen, an integration point must have a constructor that takes a configuration object parameter.
139+
//var configName = parameterType.GetCustomAttribute<IntegrationPointConfigurationAttribute>().Name;
140+
//var config = Container.Resolve<IMailConfiguration>(parameterName);
141+
//Container.RegisterType(parameterType, new InjectionConstructor(config));
142+
143+
//Container.RegisterType<IMailClient, MailClient>(config.IntegrationPointName, new InjectionConstructor(config));
144+
Container.RegisterType(parameterType, typeof(MailClient));
145+
resolvedParameters.Add(new ResolvedParameter(parameterType, parameterName));
146+
}
147+
}
148+
var objectArray = resolvedParameters.Cast<object>().ToArray();
149+
Container.RegisterType(jobType, new InjectionConstructor(objectArray));
150+
}
151+
}
152+
103153
public void SetupThreadedListenerManager()
104154
{
105155
var config = Container.Resolve<IRabbitMQConfiguration>("DefaultRabbitMQ");

IntegrationEngine/MessageQueue/RabbitMQListener.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
using RabbitMQ.Client.Events;
1212
using System;
1313
using System.Collections.Generic;
14+
using System.ComponentModel;
1415
using System.IO;
1516
using System.Linq;
1617
using System.Reflection;
1718
using System.Text;
1819
using System.Threading;
20+
using Microsoft.Practices.Unity;
1921

2022
namespace IntegrationEngine.MessageQueue
2123
{
@@ -63,8 +65,9 @@ public void Listen(CancellationToken cancellationToken)
6365
if (IntegrationJobTypes != null && !IntegrationJobTypes.Any())
6466
continue;
6567
var type = IntegrationJobTypes.FirstOrDefault(t => t.FullName.Equals(message.JobType));
66-
var integrationJob = Activator.CreateInstance(type) as IIntegrationJob;
67-
// integrationJob = AutoWireJob(integrationJob, type);
68+
//var integrationJob = Activator.CreateInstance(type) as IIntegrationJob;
69+
//integrationJob = AutoWireJob(integrationJob, type);
70+
var integrationJob = ContainerSingleton.GetContainer().Resolve(type) as IIntegrationJob;
6871
if (integrationJob != null)
6972
{
7073
if (integrationJob is IParameterizedJob)

IntegrationEngine/Scheduler/IntegrationJobDispatcherJob.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public IntegrationJobDispatcherJob()
1616
public virtual void Execute(IJobExecutionContext context)
1717
{
1818
var map = context.MergedJobDataMap;
19-
if (map.ContainsKey("MessageQueueClient") &&
19+
if (map.ContainsKey("Dispatcher") &&
2020
map.ContainsKey("IntegrationJob") &&
2121
map.ContainsKey("Parameters"))
2222
{
23-
var dispatcher = map.Get("Dispatcher") as IDispatcher;
2423
var parameters = map.Get("Parameters") as IDictionary<string, string>;
24+
var dispatcher = map.Get("Dispatcher") as IDispatcher;
2525
dispatcher.Dispatch(map.Get("IntegrationJob"), parameters);
2626
}
2727
}

configuration/IntegrationEngine.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"IntegrationPointName": "DefaultMail",
1414
"HostName": "localhost",
1515
"Port": 25
16+
}, {
17+
"IntegrationPointName": "FooMailClient",
18+
"HostName": "localhost",
19+
"Port": 25
1620
}],
1721
"RabbitMQ": [{
1822
"IntegrationPointName": "DefaultRabbitMQ",

0 commit comments

Comments
 (0)