-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cc6cef
commit 1be5a81
Showing
6 changed files
with
124 additions
and
0 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,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Ntlx.Server.Net; | ||
using Ntlx.Server.Sessions; | ||
using Ntlx.Server.Formatters; | ||
using Ntlx.Server.Collections.Generic; | ||
|
||
namespace Ntlx.Server.Dispatcher | ||
{ | ||
public class Dispatcher | ||
{ | ||
private Gateway gateway; | ||
|
||
private SessionManager sessionManager = new SessionManager(); | ||
|
||
private IDictionary<string, IFormatter> formatters = new ThreadSafeDictionary<string, IFormatter>(); | ||
|
||
|
||
public Dispatcher(Gateway gateway) | ||
{ | ||
this.gateway = gateway; | ||
gateway.OpenConnection += OpenConnection; | ||
gateway.CloseConnection += CloseConnection; | ||
} | ||
|
||
|
||
private void OpenConnection(object sender, ConnectionOpenEventArgs e) | ||
{ | ||
sessionManager.AddSession(new Session(e.Connection.Id)); | ||
e.Connection.Received += ReceivedData; | ||
e.Formatter.DeserializedMessage += DeserializedMessage; | ||
formatters[e.Connection.Id] = e.Formatter; | ||
} | ||
|
||
private void CloseConnection(object sender, ConnectionCloseEventArgs e) | ||
{ | ||
e.Connection.Received -= ReceivedData; | ||
formatters[e.Connection.Id].DeserializedMessage -= DeserializedMessage; | ||
formatters.Remove(e.Connection.Id); | ||
sessionManager.RemoveSession(e.Connection.Id); | ||
} | ||
|
||
private void ReceivedData(object sender, ConnectionBufferEventArgs e) | ||
{ | ||
formatters[e.Connection.Id].WriteMessage(e.Buffer, e.Offset, e.Count); | ||
} | ||
|
||
private void DeserializedMessage(object sender, EventArgs e) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Ntlx.Server.Formatters | ||
{ | ||
public interface IFormatter | ||
{ | ||
void WriteMessage(byte[] buffer, int offset, int count); | ||
|
||
event EventHandler DeserializedMessage; | ||
|
||
byte[] SerializeMessage(object obj); | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Ntlx.Server.Sessions | ||
{ | ||
public class Session | ||
{ | ||
public string Id | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public Session(string id) | ||
{ | ||
Id = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Ntlx.Server.Collections.Generic; | ||
|
||
namespace Ntlx.Server.Sessions | ||
{ | ||
public class SessionManager | ||
{ | ||
private IDictionary<string, Session> sessions = new ThreadSafeDictionary<string, Session>(); | ||
|
||
|
||
public void AddSession(Session session) | ||
{ | ||
|
||
} | ||
|
||
public void RemoveSession(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
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