-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from luca-domenichini/master
Prerelease 2023-12-15
- Loading branch information
Showing
49 changed files
with
633 additions
and
387 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
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
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
namespace SmartIOT.Connector.Core.Factory | ||
namespace SmartIOT.Connector.Core.Factory; | ||
|
||
public class ConnectorFactory : IConnectorFactory | ||
{ | ||
public class ConnectorFactory : IConnectorFactory | ||
{ | ||
private readonly List<IConnectorFactory> _factories = new List<IConnectorFactory>(); | ||
private readonly List<IConnectorFactory> _factories = new List<IConnectorFactory>(); | ||
|
||
public void Add(IConnectorFactory factory) | ||
{ | ||
_factories.Add(factory); | ||
} | ||
|
||
public void Add(IConnectorFactory factory) | ||
{ | ||
_factories.Add(factory); | ||
} | ||
public void AddRange(IList<IConnectorFactory> connectorFactories) | ||
{ | ||
_factories.AddRange(connectorFactories); | ||
} | ||
public bool Any(Func<IConnectorFactory, bool> predicate) | ||
{ | ||
return _factories.Any(x => predicate(x)); | ||
} | ||
public void AddRange(IList<IConnectorFactory> connectorFactories) | ||
{ | ||
_factories.AddRange(connectorFactories); | ||
} | ||
|
||
public IConnector? CreateConnector(string connectionString) | ||
{ | ||
return _factories.Select(x => x.CreateConnector(connectionString)) | ||
.FirstOrDefault(x => x != null); | ||
} | ||
public bool Any(Func<IConnectorFactory, bool> predicate) | ||
{ | ||
return _factories.Exists(x => predicate(x)); | ||
} | ||
|
||
} | ||
public IConnector? CreateConnector(string connectionString) | ||
{ | ||
return _factories.Select(x => x.CreateConnector(connectionString)) | ||
.FirstOrDefault(x => x != null); | ||
} | ||
} |
55 changes: 24 additions & 31 deletions
55
Core/SmartIOT.Connector.Core/Factory/DeviceDriverFactory.cs
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 |
---|---|---|
@@ -1,41 +1,34 @@ | ||
using SmartIOT.Connector.Core.Conf; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SmartIOT.Connector.Core.Factory | ||
{ | ||
public class DeviceDriverFactory : IDeviceDriverFactory | ||
{ | ||
private readonly List<IDeviceDriverFactory> _factories = new List<IDeviceDriverFactory>(); | ||
namespace SmartIOT.Connector.Core.Factory; | ||
|
||
public void Add(IDeviceDriverFactory factory) | ||
{ | ||
_factories.Add(factory); | ||
} | ||
public class DeviceDriverFactory : IDeviceDriverFactory | ||
{ | ||
private readonly List<IDeviceDriverFactory> _factories = new List<IDeviceDriverFactory>(); | ||
|
||
public void AddRange(IList<IDeviceDriverFactory> deviceDriverFactories) | ||
{ | ||
_factories.AddRange(deviceDriverFactories); | ||
} | ||
public void Add(IDeviceDriverFactory factory) | ||
{ | ||
_factories.Add(factory); | ||
} | ||
|
||
public bool Any() => _factories.Any(); | ||
public void AddRange(IList<IDeviceDriverFactory> deviceDriverFactories) | ||
{ | ||
_factories.AddRange(deviceDriverFactories); | ||
} | ||
|
||
public bool Any(Func<object, bool> predicate) => _factories.Any(predicate); | ||
public bool Any() => _factories.Count > 0; | ||
|
||
public IDeviceDriver? CreateDriver(DeviceConfiguration deviceConfiguration) | ||
{ | ||
foreach (var factory in _factories) | ||
{ | ||
var d = factory.CreateDriver(deviceConfiguration); | ||
if (d != null) | ||
return d; | ||
} | ||
public bool Any(Func<object, bool> predicate) => _factories.Exists(x => predicate.Invoke(x)); | ||
|
||
return null; | ||
} | ||
public IDeviceDriver? CreateDriver(DeviceConfiguration deviceConfiguration) | ||
{ | ||
foreach (var factory in _factories) | ||
{ | ||
var d = factory.CreateDriver(deviceConfiguration); | ||
if (d != null) | ||
return d; | ||
} | ||
|
||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.