Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Fix issue on Flow Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroa committed Dec 4, 2014
1 parent 6153d57 commit bfd3217
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Client/Flows/ClientProtocolFlowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public ClientProtocolFlowProvider (ITopicEvaluator topicEvaluator, IRepositoryPr
{
}

protected override IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ()
protected override IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ()
{
var flows = new Dictionary<ProtocolFlowType, IProtocolFlow>();

Expand Down
20 changes: 14 additions & 6 deletions src/Portable/Flows/ProtocolFlowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ namespace Hermes.Flows
{
public abstract class ProtocolFlowProvider : IProtocolFlowProvider
{
protected readonly IDictionary<ProtocolFlowType, IProtocolFlow> flows;
protected readonly ITopicEvaluator topicEvaluator;
protected readonly IRepositoryProvider repositoryProvider;
protected readonly ProtocolConfiguration configuration;

IDictionary<ProtocolFlowType, IProtocolFlow> flows;

protected ProtocolFlowProvider (ITopicEvaluator topicEvaluator,
IRepositoryProvider repositoryProvider,
ProtocolConfiguration configuration)
{
this.topicEvaluator = topicEvaluator;
this.repositoryProvider = repositoryProvider;
this.configuration = configuration;

this.flows = this.GetFlows ();
}

protected abstract IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ();
protected abstract IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ();

protected abstract bool IsValidPacketType (PacketType packetType);

Expand All @@ -40,7 +39,7 @@ public IProtocolFlow GetFlow (PacketType packetType)
var flow = default (IProtocolFlow);
var flowType = packetType.ToFlowType();

if (!this.flows.TryGetValue (flowType, out flow)) {
if (!this.GetFlows().TryGetValue (flowType, out flow)) {
var error = string.Format (Resources.ProtocolFlowProvider_UnknownPacketType, packetType);

throw new ProtocolException (error);
Expand All @@ -51,13 +50,22 @@ public IProtocolFlow GetFlow (PacketType packetType)

public T GetFlow<T> () where T : class
{
var pair = this.flows.FirstOrDefault (f => f.Value is T);
var pair = this.GetFlows().FirstOrDefault (f => f.Value is T);

if (pair.Equals (default (KeyValuePair<ProtocolFlowType, IProtocolFlow>))) {
return default (T);
}

return pair.Value as T;
}

private IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows()
{
if (this.flows == default (IDictionary<ProtocolFlowType, IProtocolFlow>)) {
this.flows = this.InitializeFlows ();
}

return this.flows;
}
}
}
2 changes: 1 addition & 1 deletion src/Server/Flows/ServerProtocolFlowProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ServerProtocolFlowProvider (IConnectionProvider connectionProvider,
this.connectionProvider = connectionProvider;
}

protected override IDictionary<ProtocolFlowType, IProtocolFlow> GetFlows ()
protected override IDictionary<ProtocolFlowType, IProtocolFlow> InitializeFlows ()
{
var flows = new Dictionary<ProtocolFlowType, IProtocolFlow>();

Expand Down

0 comments on commit bfd3217

Please sign in to comment.