-
Notifications
You must be signed in to change notification settings - Fork 0
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 #104 from buildersoftdev/v2.1/main
V2.1/main
- Loading branch information
Showing
50 changed files
with
966 additions
and
121 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
9 changes: 8 additions & 1 deletion
9
...ion/XNodeDependencyInjectionExtensions.cs → ...njection/RepositoryInjectionExtensions.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,14 +1,21 @@ | ||
using Buildersoft.Andy.X.Storage.Core.Abstraction.Repository.Connection; | ||
using Buildersoft.Andy.X.Storage.Core.Abstraction.Repository.Consumers; | ||
using Buildersoft.Andy.X.Storage.Core.Repository.Connection; | ||
using Buildersoft.Andy.X.Storage.Core.Repository.Consumers; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Buildersoft.Andy.X.Storage.App.Extensions.DependencyInjection | ||
{ | ||
public static class XNodeDependencyInjectionExtensions | ||
public static class RepositoryInjectionExtensions | ||
{ | ||
public static void AddNodeServiceRepository(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<IXNodeConnectionRepository, XNodeConnectionRepository>(); | ||
} | ||
|
||
public static void AddConsumerConnectionRepository(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<IConsumerConnectionRepository, ConsumerConnectionRepository>(); | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/Storage.Core/Abstraction/Repository/Consumers/IConsumerConnectionRepository.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Buildersoft.Andy.X.Storage.Model.App.Consumers; | ||
|
||
namespace Buildersoft.Andy.X.Storage.Core.Abstraction.Repository.Consumers | ||
{ | ||
public interface IConsumerConnectionRepository | ||
{ | ||
Consumer GetConsumerById(string id); | ||
void AddConsumer(string id, Consumer consumer); | ||
void AddConsumerConnection(string id); | ||
void RemoveConsumer(string id); | ||
void RemoveConsumerConnection(string id); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/Storage.Core/Repository/Consumers/ConsumerConnectionRepository.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using Buildersoft.Andy.X.Storage.Core.Abstraction.Repository.Consumers; | ||
using Buildersoft.Andy.X.Storage.Model.App.Consumers; | ||
|
||
namespace Buildersoft.Andy.X.Storage.Core.Repository.Consumers | ||
{ | ||
public class ConsumerConnectionRepository : IConsumerConnectionRepository | ||
{ | ||
private readonly ConcurrentDictionary<string, Consumer> _consumersConnected; | ||
|
||
public ConsumerConnectionRepository() | ||
{ | ||
_consumersConnected = new ConcurrentDictionary<string, Consumer>(); | ||
} | ||
|
||
public Consumer GetConsumerById(string id) | ||
{ | ||
return _consumersConnected.ContainsKey(id) | ||
? _consumersConnected[id] | ||
: null; | ||
} | ||
|
||
public void AddConsumer(string id, Consumer consumer) | ||
{ | ||
_consumersConnected.TryAdd(id, consumer); | ||
} | ||
|
||
public void AddConsumerConnection(string id) | ||
{ | ||
if (_consumersConnected.ContainsKey(id)) | ||
_consumersConnected[id].Connections.Add(Guid.NewGuid()); | ||
} | ||
|
||
public void RemoveConsumer(string id) | ||
{ | ||
if (!_consumersConnected.ContainsKey(id)) | ||
return; | ||
|
||
if (_consumersConnected[id].Connections.Count == 0) | ||
_consumersConnected.TryRemove(id, out _); | ||
} | ||
|
||
public void RemoveConsumerConnection(string id) | ||
{ | ||
if (!_consumersConnected.ContainsKey(id)) | ||
return; | ||
|
||
if (_consumersConnected[id].Connections.Count != 0) | ||
_consumersConnected[id].Connections.RemoveAt(0); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.