diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-15 21:13:45 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-15 21:13:45 +0200 |
| commit | 8d1933f305e8fb4aa4cc7633fa02c419d77766ff (patch) | |
| tree | 780c92eda81022afe1dca6838416ab44480776bf /Software/Visual_Studio/Web | |
| parent | 7b5a8bd0e4dbe8f1955a06c720380760ccb67ebd (diff) | |
| download | Tango-8d1933f305e8fb4aa4cc7633fa02c419d77766ff.tar.gz Tango-8d1933f305e8fb4aa4cc7633fa02c419d77766ff.zip | |
External bridge improvements.
Diffstat (limited to 'Software/Visual_Studio/Web')
| -rw-r--r-- | Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs index d5ce0d145..a09cd7954 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs @@ -41,6 +41,8 @@ namespace Tango.MachineService.Hubs public void RegisterMachine(MachineInfo machineInfo) { _externalBridges.RemoveAll(x => x.MachineInfo.SerialNumber == machineInfo.SerialNumber); + _sessions.RemoveAll(x => x.ExternalBridge.ConnectionID == Context.ConnectionId); + _externalBridges.Add(new ExternalBridgeInfo() { MachineInfo = machineInfo, @@ -51,6 +53,7 @@ namespace Tango.MachineService.Hubs public void UnregisterMachine() { _externalBridges.RemoveAll(x => x.ConnectionID == Context.ConnectionId); + _sessions.RemoveAll(x => x.ExternalBridge.ConnectionID == Context.ConnectionId); } public List<MachineInfo> GetAvailableMachines() @@ -64,6 +67,13 @@ namespace Tango.MachineService.Hubs if (externalBridge != null) { + var existingSession = GetSession(); + + if (existingSession != null) + { + _sessions.Remove(existingSession); + } + MachineSession session = new MachineSession(); session.ControllerConnectionID = Context.ConnectionId; session.ExternalBridge = externalBridge; @@ -75,16 +85,6 @@ namespace Tango.MachineService.Hubs return null; } - //public void NotifySessionCreated() - //{ - // var session = _sessions.SingleOrDefault(x => x.ReceiverConnectionID == Context.ConnectionId); - - // if (session != null) - // { - // Clients.Client(session.ControllerConnectionID).SessionCreated(); - // } - //} - public void JoinSession(String sessionID) { var session = _sessions.SingleOrDefault(x => x.SessionID == sessionID); @@ -98,7 +98,41 @@ namespace Tango.MachineService.Hubs public void Write(List<byte[]> dataCollection) { - var session = _sessions.SingleOrDefault(x => x.ReceiverConnectionID == Context.ConnectionId || x.ControllerConnectionID == Context.ConnectionId); + var connectionID = GetOtherSideConnectionID(); + + if (connectionID != null) + { + Clients.Client(connectionID).DataAvailable(dataCollection); + } + } + + public void LeaveSession() + { + var connectionID = GetOtherSideConnectionID(); + ClearSession(); + Clients.Client(connectionID).OnSessionClosed(); + } + + public override Task OnDisconnected(bool stopCalled) + { + _externalBridges.RemoveAll(x => x.ConnectionID == Context.ConnectionId); + _sessions.RemoveAll(x => x.ControllerConnectionID == Context.ConnectionId || x.ReceiverConnectionID == Context.ConnectionId || x.ExternalBridge.ConnectionID == Context.ConnectionId); + return base.OnDisconnected(stopCalled); + } + + private void ClearSession() + { + _sessions.RemoveAll(x => x.ControllerConnectionID == Context.ConnectionId || x.ReceiverConnectionID == Context.ConnectionId); + } + + private MachineSession GetSession() + { + return _sessions.SingleOrDefault(x => x.ReceiverConnectionID == Context.ConnectionId || x.ControllerConnectionID == Context.ConnectionId); + } + + private String GetOtherSideConnectionID() + { + var session = GetSession(); if (session != null) { @@ -113,15 +147,10 @@ namespace Tango.MachineService.Hubs connectionID = session.ReceiverConnectionID; } - Clients.Client(connectionID).DataAvailable(dataCollection); + return connectionID; } - } - public override Task OnDisconnected(bool stopCalled) - { - _externalBridges.RemoveAll(x => x.ConnectionID == Context.ConnectionId); - _sessions.RemoveAll(x => x.ControllerConnectionID == Context.ConnectionId || x.ReceiverConnectionID == Context.ConnectionId); - return base.OnDisconnected(stopCalled); + return null; } } }
\ No newline at end of file |
