diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-14 18:39:02 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-14 18:39:02 +0200 |
| commit | 0791a0ee675d6bddd54233bc9511cd6c01ce3a88 (patch) | |
| tree | 3c1e7747cd750f286a3d235c11827f8ad90d99a1 /Software/Visual_Studio/Web | |
| parent | 0d5f3fff32d8c17dbd0d33d86cffe20704a74271 (diff) | |
| download | Tango-0791a0ee675d6bddd54233bc9511cd6c01ce3a88.tar.gz Tango-0791a0ee675d6bddd54233bc9511cd6c01ce3a88.zip | |
Working on external bridge signalR
Diffstat (limited to 'Software/Visual_Studio/Web')
3 files changed, 110 insertions, 23 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs new file mode 100644 index 000000000..564ff4831 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs @@ -0,0 +1,104 @@ +using Microsoft.AspNet.SignalR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Web; +using Tango.Integration.ExternalBridge.Web; + +namespace Tango.MachineService.Hubs +{ + public class ExternalBridgeHub : Hub + { + private static List<RegisteredMachine> _machines; + private static List<MachineSession> _sessions; + + public class RegisteredMachine + { + public String ConnectionID { get; set; } + public MachineInfo MachineInfo { get; set; } + } + + public class MachineSession + { + public String ControllerConnectionID { get; set; } + public RegisteredMachine RegisteredMachine { get; set; } + } + + static ExternalBridgeHub() + { + _machines = new List<RegisteredMachine>(); + _sessions = new List<MachineSession>(); + } + + public class ExternalBridgeSession + { + public String ClientA { get; set; } + public String ClientB { get; set; } + } + + public void Test(String msg) + { + this.Clients.Caller.Test(msg); + } + + public int Calc(int a, int b) + { + return a + b; + } + + public void RegisterMachine(MachineInfo machineInfo) + { + _machines.RemoveAll(x => x.MachineInfo.SerialNumber == machineInfo.SerialNumber); + _machines.Add(new RegisteredMachine() + { + MachineInfo = machineInfo, + ConnectionID = Context.ConnectionId, + }); + } + + public void UnregisterMachine() + { + _machines.RemoveAll(x => x.ConnectionID == Context.ConnectionId); + } + + public List<MachineInfo> GetAvailableMachines() + { + return _machines.Select(x => x.MachineInfo).ToList(); + } + + public void Connect(String serialNumber) + { + var registeredMachine = _machines.SingleOrDefault(x => x.MachineInfo.SerialNumber == serialNumber); + + if (registeredMachine != null) + { + MachineSession session = new MachineSession(); + session.ControllerConnectionID = Context.ConnectionId; + session.RegisteredMachine = registeredMachine; + _sessions.Add(session); + } + } + + public void Write(byte[] data) + { + var session = _sessions.SingleOrDefault(x => x.ControllerConnectionID == Context.ConnectionId || x.RegisteredMachine.ConnectionID == Context.ConnectionId); + + if (session != null) + { + String connectionID = String.Empty; + + if (session.ControllerConnectionID == Context.ConnectionId) + { + connectionID = session.RegisteredMachine.ConnectionID; + } + else + { + connectionID = session.ControllerConnectionID; + } + + Clients.Client(connectionID).DataAvailable(data); + } + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/MainHub.cs b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/MainHub.cs deleted file mode 100644 index a17661f78..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/MainHub.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.AspNet.SignalR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Hubs -{ - public class MainHub : Hub - { - public void Test(String msg) - { - this.Clients.Caller.Test(msg); - } - - public int Calc(int a, int b) - { - return a + b; - } - } -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index 3ae2c9483..e916f01e6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -307,7 +307,7 @@ <Compile Include="Controllers\DownloadsController.cs" /> <Compile Include="Controllers\AccountController.cs" /> <Compile Include="Filters\JwtTokenFilter.cs" /> - <Compile Include="Hubs\MainHub.cs" /> + <Compile Include="Hubs\ExternalBridgeHub.cs" /> <Compile Include="MachineServiceConfig.cs" /> <Compile Include="Controllers\MachineStudioController.cs" /> <Compile Include="Models\DownloadModel.cs" /> @@ -388,6 +388,10 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.Integration\Tango.Integration.csproj"> + <Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project> + <Name>Tango.Integration</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.Logging\Tango.Logging.csproj"> <Project>{BC932DBD-7CDB-488C-99E4-F02CF441F55E}</Project> <Name>Tango.Logging</Name> @@ -452,7 +456,7 @@ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
