-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed the simplified RfcContext constructor (4.x) (#45)
bad design decision - keep it straight is it was in past and use one constructor instead added a ConnectionBuilder to fluent build options for connection and runtime.
- Loading branch information
Showing
6 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using LanguageExt; | ||
|
||
namespace Dbosoft.YaNco | ||
{ | ||
public class ConnectionBuilder | ||
{ | ||
private readonly IDictionary<string, string> _connectionParam; | ||
private StartProgramDelegate _startProgramDelegate; | ||
private Action<RfcRuntimeConfigurer> _configureRuntime = (c) => {}; | ||
private Func<IDictionary<string, string>, IRfcRuntime, EitherAsync<RfcErrorInfo,IConnection>> | ||
_connectionFactory = Connection.Create; | ||
|
||
public ConnectionBuilder(IDictionary<string, string> connectionParam) | ||
{ | ||
_connectionParam = connectionParam; | ||
} | ||
|
||
public ConnectionBuilder ConfigureRuntime(Action<RfcRuntimeConfigurer> configure) | ||
{ | ||
_configureRuntime = configure; | ||
return this; | ||
} | ||
|
||
public ConnectionBuilder WithStartProgramCallback(StartProgramDelegate startProgramDelegate) | ||
{ | ||
_startProgramDelegate = startProgramDelegate; | ||
return this; | ||
} | ||
|
||
public ConnectionBuilder UseFactory( | ||
Func<IDictionary<string, string>, IRfcRuntime, EitherAsync<RfcErrorInfo, IConnection>> factory) | ||
{ | ||
_connectionFactory = factory; | ||
return this; | ||
} | ||
|
||
public Func<EitherAsync<RfcErrorInfo, IConnection>> Build() | ||
{ | ||
var runtimeConfigurer = new RfcRuntimeConfigurer(); | ||
_configureRuntime(runtimeConfigurer); | ||
var runtime = runtimeConfigurer.Create(); | ||
|
||
if(_startProgramDelegate == null) | ||
return () => _connectionFactory(_connectionParam, runtime); | ||
|
||
|
||
return () => (from c in _connectionFactory(_connectionParam, runtime) | ||
from _ in c.AllowStartOfPrograms(_startProgramDelegate) | ||
select c); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Dbosoft.YaNco; | ||
using Dbosoft.YaNco.TypeMapping; | ||
|
||
public class RfcMappingConfigurer | ||
{ | ||
private Func<IEnumerable<Type>, IEnumerable<Type>,IFieldMapper> | ||
_mappingFactory = RfcRuntime.CreateDefaultFieldMapper; | ||
|
||
private readonly List<Type> _fromRfcMappingTypes = new List<Type>(); | ||
private readonly List<Type> _toRfcMappingTypes = new List<Type>(); | ||
|
||
public RfcMappingConfigurer UseFactory(Func<IEnumerable<Type>, IEnumerable<Type>, IFieldMapper> factory) | ||
{ | ||
_mappingFactory = factory; | ||
return this; | ||
} | ||
|
||
public RfcMappingConfigurer AddToRfcMapper(Type mapper) | ||
{ | ||
_toRfcMappingTypes.Add(mapper); | ||
return this; | ||
} | ||
|
||
public RfcMappingConfigurer AddFromRfcMapper(Type mapper) | ||
{ | ||
_fromRfcMappingTypes.Add(mapper); | ||
return this; | ||
} | ||
|
||
internal IFieldMapper Create() | ||
{ | ||
return _mappingFactory(_fromRfcMappingTypes, _toRfcMappingTypes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Dbosoft.YaNco; | ||
using Dbosoft.YaNco.TypeMapping; | ||
|
||
namespace Dbosoft.YaNco | ||
{ | ||
public class RfcRuntimeConfigurer | ||
{ | ||
private Func<ILogger, IFieldMapper, IRfcRuntime> | ||
_runtimeFactory = (logger, mapper) => new RfcRuntime(logger, mapper); | ||
|
||
private ILogger _logger; | ||
private Action<RfcMappingConfigurer> _configureMapping = (m) => { }; | ||
|
||
public RfcRuntimeConfigurer WithLogger(ILogger logger) | ||
{ | ||
_logger = logger; | ||
return this; | ||
} | ||
|
||
|
||
public RfcRuntimeConfigurer ConfigureMapping(Action<RfcMappingConfigurer> configure) | ||
{ | ||
_configureMapping = configure; | ||
return this; | ||
} | ||
|
||
public RfcRuntimeConfigurer UseFactory(Func<ILogger, IFieldMapper, IRfcRuntime> factory) | ||
{ | ||
_runtimeFactory = factory; | ||
return this; | ||
} | ||
|
||
internal IRfcRuntime Create() | ||
{ | ||
var mappingConfigurer = new RfcMappingConfigurer(); | ||
_configureMapping(mappingConfigurer); | ||
var mapping = mappingConfigurer.Create(); | ||
|
||
return _runtimeFactory(_logger, mapping); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters