From 9447a8a09f87d6ea2cb62860021c595386668eec Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 20 Feb 2019 22:55:15 +0200 Subject: A lot of work !!! --- .../Machine Studio Installer.aip | 5 + .../Build/Shortcuts/Machine Emulator.lnk | Bin 1471 -> 1445 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1464 -> 1444 bytes .../Modules/MachineStudio.Dispensers/App.config | 2 +- .../Tango.MachineStudio.ColorLab/app.config | 2 +- .../Modules/Tango.MachineStudio.DB/App.config | 2 +- .../Tango.MachineStudio.DataCapture/app.config | 2 +- .../Tango.MachineStudio.Developer/app.config | 2 +- .../app.config | 2 +- .../Modules/Tango.MachineStudio.Logging/App.config | 2 +- .../Tango.MachineStudio.MachineDesigner/app.config | 2 +- .../Modules/Tango.MachineStudio.RML/App.config | 2 +- .../Tango.MachineStudio.Statistics/App.config | 2 +- .../Modules/Tango.MachineStudio.Storage/app.config | 2 +- .../Tango.MachineStudio.Stubs.csproj | 6 +- .../Modules/Tango.MachineStudio.Stubs/app.config | 2 +- .../Tango.MachineStudio.Stubs/packages.config | 2 +- .../Tango.MachineStudio.Technician/app.config | 2 +- .../Tango.MachineStudio.UsersAndRoles.csproj | 6 +- .../Tango.MachineStudio.UsersAndRoles/app.config | 2 +- .../packages.config | 2 +- .../Web/CheckForUpdatesRequest.cs | 2 +- .../Web/DownloadLatestVersionRequest.cs | 2 +- .../Web/MachineStudioWebClient.cs | 9 +- .../Web/MachineStudioWebClientBase.cs | 14 +- .../Web/UploadCompletedRequest.cs | 2 +- .../Web/UploadVersionRequest.cs | 2 +- .../Tango.MachineStudio.Common/app.config | 2 +- .../Tango.MachineStudio.Publisher.CLI/App.config | 2 +- .../Tango.MachineStudio.Publisher.UI/App.config | 2 +- .../MainWindowVM.cs | 1 + .../Tango.MachineStudio.UI/App.config | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../Tango.Notes/Azure/Test User Credentials.txt | 3 + .../Notes/Tango.Notes/Tango.Notes.csproj | 3 +- .../PPC/Modules/Tango.PPC.Events/app.config | 2 +- .../PPC/Modules/Tango.PPC.Jobs/app.config | 2 +- .../PPC/Modules/Tango.PPC.Logging/app.config | 2 +- .../Modules/Tango.PPC.MachineSettings/app.config | 2 +- .../PPC/Modules/Tango.PPC.Power/app.config | 2 +- .../PPC/Modules/Tango.PPC.Storage/app.config | 2 +- .../MachineSetup/MachineSetupManager.cs | 1 + .../MachineUpdate/MachineUpdateManager.cs | 3 + .../Tango.PPC.Common/Web/CheckForUpdateRequest.cs | 3 +- .../Tango.PPC.Common/Web/DownloadUpdateRequest.cs | 4 +- .../Tango.PPC.Common/Web/MachineSetupRequest.cs | 4 +- .../PPC/Tango.PPC.Common/Web/PPCWebClient.cs | 8 +- .../PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs | 14 +- .../PPC/Tango.PPC.Common/Web/UpdateDBRequest.cs | 4 +- .../Tango.PPC.Common/Web/UploadCompletedRequest.cs | 2 +- .../Tango.PPC.Common/Web/UploadVersionRequest.cs | 2 +- .../Visual_Studio/PPC/Tango.PPC.Common/app.config | 2 +- .../PPC/Tango.PPC.Publisher.UI/App.config | 2 +- Software/Visual_Studio/PPC/Tango.PPC.UI/App.config | 80 +++++++++++ .../PPC/Tango.PPC.WatchDog/App.config | 2 +- .../Tango.BL/ObservablesContextConfiguration.cs | 17 --- .../Tango.BL/ObservablesContextExtension.cs | 13 +- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 6 +- Software/Visual_Studio/Tango.BL/packages.config | 2 +- .../Templates/TangoWebClientCodeFile.cshtml | 15 +- .../Visual_Studio/Tango.Core/Tango.Core.csproj | 6 +- Software/Visual_Studio/Tango.Core/packages.config | 2 +- Software/Visual_Studio/Tango.Emulations/app.config | 2 +- .../Tango.Integration/Tango.Integration.csproj | 6 +- .../Visual_Studio/Tango.Integration/app.config | 2 +- .../Tango.Integration/packages.config | 2 +- .../Tango.Serialization/Tango.Serialization.csproj | 6 +- .../Tango.Serialization/packages.config | 2 +- .../Tango.Settings/Tango.Settings.csproj | 6 +- .../Visual_Studio/Tango.Settings/packages.config | 2 +- .../Visual_Studio/Tango.Stubs/Tango.Stubs.csproj | 6 +- Software/Visual_Studio/Tango.Stubs/app.config | 2 +- Software/Visual_Studio/Tango.Stubs/packages.config | 2 +- Software/Visual_Studio/Tango.TFS/Tango.TFS.csproj | 7 +- Software/Visual_Studio/Tango.TFS/app.config | 2 +- Software/Visual_Studio/Tango.TFS/packages.config | 2 +- .../Tango.Transport/Tango.Transport.csproj | 11 +- .../Tango.Transport/Web/IWebTransportClient.cs | 1 + .../Tango.Transport/Web/InvalidTokenException.cs | 16 +++ .../Tango.Transport/Web/SessionExpiredException.cs | 16 --- .../Tango.Transport/Web/TokenExpiredException.cs | 16 +++ .../Tango.Transport/Web/WebRequestSecureMessage.cs | 13 -- .../Tango.Transport/Web/WebTransportClient.cs | 65 ++++++++- Software/Visual_Studio/Tango.Transport/app.config | 2 +- .../Visual_Studio/Tango.Transport/packages.config | 2 +- .../Visual_Studio/Tango.UnitTesting/App.config | 2 +- .../MachineService/MachineStudio_Controller_TST.cs | 78 +++++++++++ .../MachineService/PPC_Controller_TST.cs | 95 +++++++++++++ .../Tango.UnitTesting/MachineService_TST.cs | 2 +- .../Tango.UnitTesting/Tango.UnitTesting.csproj | 12 +- .../Tango.UnitTesting/Web/JWT_Tokens_TST.cs | 69 ++++++++++ .../Tango.UnitTesting/packages.config | 3 +- .../Tango.Web/Authentication/TokensManager.cs | 6 +- .../Tango.Web/Authentication/WebToken.cs | 151 ++++++++++++++++++++- .../Tango.Web/Authentication/WebTokenResponse.cs | 2 +- .../Tango.Web/Controllers/JsonController.cs | 76 ----------- .../Tango.Web/Controllers/TangoController.cs | 125 +++++++++++++++++ Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 18 ++- Software/Visual_Studio/Tango.Web/TangoWebClient.cs | 82 +++++------ Software/Visual_Studio/Tango.Web/app.config | 6 +- Software/Visual_Studio/Tango.Web/packages.config | 3 +- .../Utilities/Tango.BugReporter/App.config | 2 +- .../Utilities/Tango.MachineEM.UI/App.config | 2 +- .../Utilities/Tango.RemoteRunner.UI/App.config | 2 +- .../Utilities/Tango.Stubs.CLI/App.config | 2 +- .../Tango.Stubs.CLI/Tango.Stubs.CLI.csproj | 6 +- .../Utilities/Tango.Stubs.CLI/packages.config | 2 +- .../Utilities/Tango.Stubs.UI/App.config | 2 +- .../Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj | 6 +- .../Utilities/Tango.Stubs.UI/packages.config | 2 +- .../Utilities/Tango.TransportRouter.UI/App.config | 2 +- .../Utilities/Tango.UITests/App.config | 2 +- .../Utilities/Tango.WebClientGenerator/App.config | 4 +- .../Utilities/Tango.WebClientGenerator/Program.cs | 2 +- .../VSIX/Tango.BuildExtensions/app.config | 2 +- .../Tango.MachineService/App_Start/WebApiConfig.cs | 8 +- .../Controllers/MachineStudioController.cs | 26 ++-- .../Controllers/PPCController.cs | 42 +++--- .../Tango.MachineService/Filters/JwtTokenFilter.cs | 46 +++++++ .../Filters/MachineStudioLoginFilter.cs | 35 ----- .../Tango.MachineService/Filters/PPCLoginFilter.cs | 35 ----- .../Tango.MachineService/MachineServiceConfig.cs | 1 + .../Tango.MachineService.csproj | 12 +- .../Web/Tango.MachineService/Web.config | 9 +- .../Web/Tango.MachineService/packages.config | 3 +- 125 files changed, 1047 insertions(+), 430 deletions(-) create mode 100644 Software/Visual_Studio/Notes/Tango.Notes/Azure/Test User Credentials.txt create mode 100644 Software/Visual_Studio/Tango.Transport/Web/InvalidTokenException.cs delete mode 100644 Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/TokenExpiredException.cs delete mode 100644 Software/Visual_Studio/Tango.Transport/Web/WebRequestSecureMessage.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs delete mode 100644 Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs create mode 100644 Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Filters/JwtTokenFilter.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Filters/PPCLoginFilter.cs (limited to 'Software') diff --git a/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip b/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip index a04ca8748..46b47ce70 100644 --- a/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip +++ b/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip @@ -739,6 +739,7 @@ + @@ -783,6 +784,7 @@ + @@ -804,6 +806,7 @@ + @@ -831,6 +834,8 @@ + + diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 1a45908c4..2edf815e9 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk index cf3225957..6b545ae45 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/MachineStudio.Dispensers/App.config b/Software/Visual_Studio/MachineStudio/Modules/MachineStudio.Dispensers/App.config index 6a9fc2ba2..825aaae9e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/MachineStudio.Dispensers/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/MachineStudio.Dispensers/App.config @@ -12,7 +12,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/app.config index b957f7710..96b77fa8f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/App.config index b67f4c16f..7d3d4b2ec 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/App.config @@ -70,7 +70,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config index d9be669f7..fa31bbb95 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config @@ -68,7 +68,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/app.config index d9be669f7..fa31bbb95 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/app.config @@ -68,7 +68,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config index b957f7710..96b77fa8f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/App.config index f83cf3eb1..f66a052ae 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/App.config @@ -74,7 +74,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/app.config index d9be669f7..fa31bbb95 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/app.config @@ -68,7 +68,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config index 48870dbc1..1f0b571a1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/App.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config index cf8218113..8ea5566ba 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/App.config @@ -70,7 +70,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/app.config index 78d1014dd..354aeba1d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/Tango.MachineStudio.Stubs.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/Tango.MachineStudio.Stubs.csproj index b23f34d86..3c3efdca7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/Tango.MachineStudio.Stubs.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/Tango.MachineStudio.Stubs.csproj @@ -52,8 +52,8 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll - - ..\..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -173,7 +173,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/app.config index b957f7710..96b77fa8f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/packages.config index 8bf2b7b7d..292525e42 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/packages.config @@ -8,5 +8,5 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config index b957f7710..96b77fa8f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj index 897486454..3b14fd13c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/Tango.MachineStudio.UsersAndRoles.csproj @@ -46,8 +46,8 @@ ..\..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll - - ..\..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -210,7 +210,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config index 78d1014dd..354aeba1d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config index 12270c85d..fe4f26e87 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/packages.config @@ -6,5 +6,5 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs index 4f9576f50..84616c607 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs @@ -8,7 +8,7 @@ using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Web { - public class CheckForUpdatesRequest : WebRequestSecureMessage + public class CheckForUpdatesRequest : WebRequestMessage { public String Version { get; set; } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs index d63654726..e0a47041c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs @@ -7,7 +7,7 @@ using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Web { - public class DownloadLatestVersionRequest : WebRequestSecureMessage + public class DownloadLatestVersionRequest : WebRequestMessage { } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs index 02276d641..7938e1a17 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs @@ -15,12 +15,17 @@ namespace Tango.MachineStudio.Common.Web { } - public MachineStudioWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + public MachineStudioWebClient(DeploymentSlot environment, String token) : base(environment, token) { } - public MachineStudioWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + public MachineStudioWebClient(String token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + { + + } + + public MachineStudioWebClient(string address, string token) : base(address, token) { } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs index dc5a14856..62a57ad93 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs @@ -1,7 +1,7 @@ +using System; using System.Threading.Tasks; using Tango.Web; -using Tango.Web.Authentication; namespace Tango.MachineStudio.Common.Web { @@ -16,7 +16,7 @@ namespace Tango.MachineStudio.Common.Web /// /// The environment. /// Existing token. - public MachineStudioWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "MachineStudio", token) + public MachineStudioWebClientBase(DeploymentSlot environment, String token) : base(environment, "MachineStudio", token) { } @@ -30,6 +30,16 @@ namespace Tango.MachineStudio.Common.Web } + /// + /// Initializes a new instance of the class. + /// + /// The service address. + /// Existing token. + public MachineStudioWebClientBase(String address, String token) : base(address, "MachineStudio", token) + { + + } + /// /// Executes the CheckForUpdates action and returns Tango.MachineStudio.Common.Web.CheckForUpdatesResponse. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs index 48f5b2a6e..c85dd3ace 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs @@ -8,7 +8,7 @@ using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Web { - public class UploadCompletedRequest : WebRequestSecureMessage + public class UploadCompletedRequest : WebRequestMessage { public String Token { get; set; } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs index 33577deb2..d27f48648 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs @@ -8,7 +8,7 @@ using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Web { - public class UploadVersionRequest : WebRequestSecureMessage + public class UploadVersionRequest : WebRequestMessage { public String Version { get; set; } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config index d9be669f7..fa31bbb95 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/app.config @@ -68,7 +68,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.CLI/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.CLI/App.config index f08d9fd45..25105196d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.CLI/App.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.CLI/App.config @@ -23,7 +23,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/App.config index 6818e3328..26a23dcd0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/App.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/App.config @@ -71,7 +71,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs index e62f29403..e227c0904 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs @@ -103,6 +103,7 @@ namespace Tango.MachineStudio.Publisher.UI IsFree = false; await _publisher.Publish(); ShowInfo("Version published successfully."); + UpdateVersions(); } catch (Exception ex) { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config index 662ab4bf6..36619a25b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config @@ -74,7 +74,7 @@ --> - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs index f6386cfc9..bceaaf956 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ using System.Runtime.InteropServices; [assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)] [assembly: AssemblyTitle("Tango - Machine Studio")] -[assembly: AssemblyVersion("4.0.8.0")] +[assembly: AssemblyVersion("4.0.7.0")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Notes/Tango.Notes/Azure/Test User Credentials.txt b/Software/Visual_Studio/Notes/Tango.Notes/Azure/Test User Credentials.txt new file mode 100644 index 000000000..c7b78ddf0 --- /dev/null +++ b/Software/Visual_Studio/Notes/Tango.Notes/Azure/Test User Credentials.txt @@ -0,0 +1,3 @@ +TestUser@twine-s.com + +ASJH_asdjkl1234 \ No newline at end of file diff --git a/Software/Visual_Studio/Notes/Tango.Notes/Tango.Notes.csproj b/Software/Visual_Studio/Notes/Tango.Notes/Tango.Notes.csproj index 15e72865b..e2f081fd0 100644 --- a/Software/Visual_Studio/Notes/Tango.Notes/Tango.Notes.csproj +++ b/Software/Visual_Studio/Notes/Tango.Notes/Tango.Notes.csproj @@ -44,6 +44,7 @@ + @@ -55,7 +56,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/app.config index 205fb2c55..cca4bcfd8 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/app.config @@ -52,7 +52,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/app.config index 8c8385399..bce416708 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/app.config @@ -56,7 +56,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Logging/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Logging/app.config index 8ad04b77c..f47375ba5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Logging/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Logging/app.config @@ -48,7 +48,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/app.config index 8c8385399..bce416708 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/app.config @@ -56,7 +56,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Power/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Power/app.config index 392cc7969..15c81fa4b 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Power/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Power/app.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/app.config b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/app.config index 80ba81455..8d7f1b8a7 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/app.config +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/app.config @@ -48,7 +48,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 369248c7b..fa9c95742 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -130,6 +130,7 @@ namespace Tango.PPC.Common.MachineSetup Login(serialNumber).Wait(); MachineSetupRequest request = new MachineSetupRequest(); + request.SerialNumber = serialNumber; MachineSetupResponse setup_response = null; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 8b9aede87..6fd53bce2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -130,6 +130,7 @@ namespace Tango.PPC.Common.MachineUpdate await Login(serialNumber); DownloadUpdateRequest request = new DownloadUpdateRequest(); + request.SerialNumber = serialNumber; DownloadUpdateResponse update_response = null; @@ -298,6 +299,7 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Checking if updates available..."); CheckForUpdateRequest request = new CheckForUpdateRequest(); + request.SerialNumber = serialNumber; request.Version = _app_manager.Version.ToString(); CheckForUpdateResponse update_response = null; @@ -408,6 +410,7 @@ namespace Tango.PPC.Common.MachineUpdate Login(serialNumber).Wait(); UpdateDBRequest request = new UpdateDBRequest(); + request.SerialNumber = serialNumber; UpdateDBResponse update_response = null; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs index 8bb8cde54..b98848e4f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/CheckForUpdateRequest.cs @@ -7,8 +7,9 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class CheckForUpdateRequest : WebRequestSecureMessage + public class CheckForUpdateRequest : WebRequestMessage { + public String SerialNumber { get; set; } public String Version { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateRequest.cs index 20d1da3ec..a32d3d497 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/DownloadUpdateRequest.cs @@ -7,8 +7,8 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class DownloadUpdateRequest : WebRequestSecureMessage + public class DownloadUpdateRequest : WebRequestMessage { - + public String SerialNumber { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupRequest.cs index ce8b2f58d..83bec6b07 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/MachineSetupRequest.cs @@ -7,8 +7,8 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class MachineSetupRequest : WebRequestSecureMessage + public class MachineSetupRequest : WebRequestMessage { - + public String SerialNumber { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs index 5900dd697..4897efc90 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs @@ -15,16 +15,20 @@ namespace Tango.PPC.Common.Web { } - public PPCWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + public PPCWebClient(DeploymentSlot environment, string token) : base(environment, token) { } - public PPCWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + public PPCWebClient(string token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) { } public PPCWebClient() : this(null) { } + + public PPCWebClient(string address, string token) : base(address, token) + { + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs index e5c1beb4a..723e3ffc4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs @@ -1,7 +1,7 @@ +using System; using System.Threading.Tasks; using Tango.Web; -using Tango.Web.Authentication; namespace Tango.PPC.Common.Web { @@ -16,7 +16,7 @@ namespace Tango.PPC.Common.Web /// /// The environment. /// Existing token. - public PPCWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "PPC", token) + public PPCWebClientBase(DeploymentSlot environment, String token) : base(environment, "PPC", token) { } @@ -30,6 +30,16 @@ namespace Tango.PPC.Common.Web } + /// + /// Initializes a new instance of the class. + /// + /// The service address. + /// Existing token. + public PPCWebClientBase(String address, String token) : base(address, "PPC", token) + { + + } + /// /// Executes the MachineSetup action and returns Tango.PPC.Common.Web.MachineSetupResponse. /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdateDBRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdateDBRequest.cs index 4c9714970..f3b4ccb34 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdateDBRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UpdateDBRequest.cs @@ -7,8 +7,8 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class UpdateDBRequest : WebRequestSecureMessage + public class UpdateDBRequest : WebRequestMessage { - + public String SerialNumber { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadCompletedRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadCompletedRequest.cs index f9674f6c5..b51612603 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadCompletedRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadCompletedRequest.cs @@ -8,7 +8,7 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class UploadCompletedRequest : WebRequestSecureMessage + public class UploadCompletedRequest : WebRequestMessage { public String Token { get; set; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadVersionRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadVersionRequest.cs index 68643bfe7..d75a94300 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadVersionRequest.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/UploadVersionRequest.cs @@ -8,7 +8,7 @@ using Tango.Transport.Web; namespace Tango.PPC.Common.Web { - public class UploadVersionRequest : WebRequestSecureMessage + public class UploadVersionRequest : WebRequestMessage { public String Version { get; set; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/app.config b/Software/Visual_Studio/PPC/Tango.PPC.Common/app.config index 976aaf83b..24626938a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/app.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/app.config @@ -56,7 +56,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/App.config b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/App.config index e8039e63f..4b93a7127 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/App.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/App.config @@ -65,7 +65,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config index ea49af905..15a7107bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.config @@ -11,6 +11,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.config b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.config index 85607e5e8..b295bcfda 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.config +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.config @@ -47,7 +47,7 @@ - + diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs index 07c3f5306..04d22a7b6 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs @@ -24,23 +24,6 @@ namespace Tango.BL { Directory.CreateDirectory(FolderPath); var modelStore = new DefaultDbModelStore(FolderPath); - - try - { - modelStore.TryLoad(typeof(ObservablesContext)); - } - catch - { - try - { - Directory.Delete(FolderPath, true); - Thread.Sleep(1000); - Directory.CreateDirectory(FolderPath); - } - catch { } - modelStore = new DefaultDbModelStore(FolderPath); - } - SetModelStore(modelStore); } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index d36113e71..94d751482 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -22,6 +22,7 @@ namespace Tango.BL private List _pending_notifications = new List(); private ObservablesContextAdapter _adapter; private static DataSource _override_datasource; + private DataSource _dataSource; /// /// Initializes a new instance of the class. @@ -38,6 +39,7 @@ namespace Tango.BL /// if set to true will try to connect to an .mdf file. public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true) { + _dataSource = dataSource; Database.SetInitializer(null); Configuration.LazyLoadingEnabled = false; _adapter = new ObservablesContextAdapter(this); @@ -189,6 +191,15 @@ namespace Tango.BL _override_datasource = dataSource; } + /// + /// Gets the current data source. + /// + /// + public DataSource GetDataSource() + { + return _dataSource; + } + /// /// Gets the actual data source (settings or overridden). /// @@ -207,7 +218,7 @@ namespace Tango.BL /// public override string ToString() { - return GetActualDataSource().ToString(); + return GetDataSource().ToString(); } /// diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index c4f672593..6453881f0 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -42,8 +42,8 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll ..\packages\SimpleValidator.0.6.1.0\lib\net40\SimpleValidator.dll @@ -408,7 +408,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.BL/packages.config b/Software/Visual_Studio/Tango.BL/packages.config index 3ed77ec38..408466746 100644 --- a/Software/Visual_Studio/Tango.BL/packages.config +++ b/Software/Visual_Studio/Tango.BL/packages.config @@ -2,7 +2,7 @@ - + diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml index 100171849..7d9ebc075 100644 --- a/Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml @@ -1,10 +1,9 @@ @{ Tango.CodeGeneration.TangoWebClientCodeFile model = Model as Tango.CodeGeneration.TangoWebClientCodeFile; } - +using System; using System.Threading.Tasks; using Tango.Web; -using Tango.Web.Authentication; namespace @(model.Namespace) { @@ -19,7 +18,7 @@ namespace @(model.Namespace) /// /// The environment. /// Existing token. - public @(model.Name)(DeploymentSlot environment, WebToken token) : base(environment, "@(model.ControllerName)", token) + public @(model.Name)(DeploymentSlot environment, String token) : base(environment, "@(model.ControllerName)", token) { } @@ -33,6 +32,16 @@ namespace @(model.Namespace) } + /// + /// Initializes a new instance of the class. + /// + /// The service address. + /// Existing token. + public @(model.Name)(String address, String token) : base(address, "@(model.ControllerName)", token) + { + + } + @foreach (var action in model.Actions) {
diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index c3d685a29..eb80279ef 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -48,8 +48,8 @@ ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -194,7 +194,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Core/packages.config b/Software/Visual_Studio/Tango.Core/packages.config index 53cd4a3c8..28c0e4b9c 100644 --- a/Software/Visual_Studio/Tango.Core/packages.config +++ b/Software/Visual_Studio/Tango.Core/packages.config @@ -4,7 +4,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Emulations/app.config b/Software/Visual_Studio/Tango.Emulations/app.config index 49b6f5ebe..55a256ebb 100644 --- a/Software/Visual_Studio/Tango.Emulations/app.config +++ b/Software/Visual_Studio/Tango.Emulations/app.config @@ -8,7 +8,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 9a7e783ed..8d6d43c02 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -42,8 +42,8 @@ ..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -176,7 +176,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Integration/app.config b/Software/Visual_Studio/Tango.Integration/app.config index 63b19aed7..2ddf77726 100644 --- a/Software/Visual_Studio/Tango.Integration/app.config +++ b/Software/Visual_Studio/Tango.Integration/app.config @@ -12,7 +12,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Integration/packages.config b/Software/Visual_Studio/Tango.Integration/packages.config index dda6ff5f8..56f5092b2 100644 --- a/Software/Visual_Studio/Tango.Integration/packages.config +++ b/Software/Visual_Studio/Tango.Integration/packages.config @@ -3,7 +3,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Serialization/Tango.Serialization.csproj b/Software/Visual_Studio/Tango.Serialization/Tango.Serialization.csproj index 4efa0e255..24c0b4d96 100644 --- a/Software/Visual_Studio/Tango.Serialization/Tango.Serialization.csproj +++ b/Software/Visual_Studio/Tango.Serialization/Tango.Serialization.csproj @@ -33,8 +33,8 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -63,7 +63,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Serialization/packages.config b/Software/Visual_Studio/Tango.Serialization/packages.config index f147efb72..696615a7d 100644 --- a/Software/Visual_Studio/Tango.Serialization/packages.config +++ b/Software/Visual_Studio/Tango.Serialization/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Settings/Tango.Settings.csproj b/Software/Visual_Studio/Tango.Settings/Tango.Settings.csproj index b185b8431..8115619e4 100644 --- a/Software/Visual_Studio/Tango.Settings/Tango.Settings.csproj +++ b/Software/Visual_Studio/Tango.Settings/Tango.Settings.csproj @@ -30,8 +30,8 @@ 4 - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -62,7 +62,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Settings/packages.config b/Software/Visual_Studio/Tango.Settings/packages.config index 92167d083..7ee8c1052 100644 --- a/Software/Visual_Studio/Tango.Settings/packages.config +++ b/Software/Visual_Studio/Tango.Settings/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj b/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj index 1c5865379..828248c9b 100644 --- a/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj +++ b/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj @@ -46,8 +46,8 @@ ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -186,7 +186,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Stubs/app.config b/Software/Visual_Studio/Tango.Stubs/app.config index 0e8167dde..203a0c7bc 100644 --- a/Software/Visual_Studio/Tango.Stubs/app.config +++ b/Software/Visual_Studio/Tango.Stubs/app.config @@ -56,7 +56,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Stubs/packages.config b/Software/Visual_Studio/Tango.Stubs/packages.config index 8a6da5794..d3b5d7780 100644 --- a/Software/Visual_Studio/Tango.Stubs/packages.config +++ b/Software/Visual_Studio/Tango.Stubs/packages.config @@ -4,7 +4,7 @@ - + diff --git a/Software/Visual_Studio/Tango.TFS/Tango.TFS.csproj b/Software/Visual_Studio/Tango.TFS/Tango.TFS.csproj index bc9248040..b69fbfbb1 100644 --- a/Software/Visual_Studio/Tango.TFS/Tango.TFS.csproj +++ b/Software/Visual_Studio/Tango.TFS/Tango.TFS.csproj @@ -161,9 +161,8 @@ ..\packages\Microsoft.VisualStudio.Services.Client.15.112.1\lib\net45\Microsoft.VisualStudio.Services.WebApi.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll - False + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -263,7 +262,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.TFS/app.config b/Software/Visual_Studio/Tango.TFS/app.config index de5386a47..8460dd432 100644 --- a/Software/Visual_Studio/Tango.TFS/app.config +++ b/Software/Visual_Studio/Tango.TFS/app.config @@ -4,7 +4,7 @@ - + diff --git a/Software/Visual_Studio/Tango.TFS/packages.config b/Software/Visual_Studio/Tango.TFS/packages.config index c39c44fe7..d24692072 100644 --- a/Software/Visual_Studio/Tango.TFS/packages.config +++ b/Software/Visual_Studio/Tango.TFS/packages.config @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index bea51be51..2fe525153 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -35,8 +35,8 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -56,6 +56,7 @@ ..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll + @@ -108,16 +109,16 @@ + - + - @@ -147,7 +148,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Transport/Web/IWebTransportClient.cs b/Software/Visual_Studio/Tango.Transport/Web/IWebTransportClient.cs index 8ab0f9305..b1645401a 100644 --- a/Software/Visual_Studio/Tango.Transport/Web/IWebTransportClient.cs +++ b/Software/Visual_Studio/Tango.Transport/Web/IWebTransportClient.cs @@ -9,6 +9,7 @@ namespace Tango.Transport.Web { public interface IWebTransportClient : IDisposable { + String AuthenticationToken { get; set; } Task PostProto(String url, Request request) where Request : class, IMessage where Response : class, IMessage; Task PostJson(String url, Request request) where Request : class, IWebRequestMessage where Response : class, IWebResponseMessage; } diff --git a/Software/Visual_Studio/Tango.Transport/Web/InvalidTokenException.cs b/Software/Visual_Studio/Tango.Transport/Web/InvalidTokenException.cs new file mode 100644 index 000000000..0501c7c9d --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/InvalidTokenException.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class InvalidTokenException : Exception + { + public InvalidTokenException(String message) : base(message) + { + + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs b/Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs deleted file mode 100644 index 7ee553b4a..000000000 --- a/Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Transport.Web -{ - public class SessionExpiredException : Exception - { - public SessionExpiredException(String message) : base(message) - { - - } - } -} diff --git a/Software/Visual_Studio/Tango.Transport/Web/TokenExpiredException.cs b/Software/Visual_Studio/Tango.Transport/Web/TokenExpiredException.cs new file mode 100644 index 000000000..92d7a0fec --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/TokenExpiredException.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class TokenExpiredException : Exception + { + public TokenExpiredException(String message) : base(message) + { + + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/WebRequestSecureMessage.cs b/Software/Visual_Studio/Tango.Transport/Web/WebRequestSecureMessage.cs deleted file mode 100644 index 33644208e..000000000 --- a/Software/Visual_Studio/Tango.Transport/Web/WebRequestSecureMessage.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Transport.Web -{ - public class WebRequestSecureMessage : WebRequestMessage - { - public String AccessToken { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Transport/Web/WebTransportClient.cs b/Software/Visual_Studio/Tango.Transport/Web/WebTransportClient.cs index 188203945..ed2e69468 100644 --- a/Software/Visual_Studio/Tango.Transport/Web/WebTransportClient.cs +++ b/Software/Visual_Studio/Tango.Transport/Web/WebTransportClient.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Net.Http.Headers; +using System.Security.Authentication; using System.Text; using System.Threading.Tasks; using System.Web; @@ -17,11 +19,13 @@ namespace Tango.Transport.Web private HttpClient _httpClient; private static JsonSerializerSettings _settings; + public string AuthenticationToken { get; set; } + static WebTransportClient() { _settings = new JsonSerializerSettings() { - + }; } @@ -30,6 +34,11 @@ namespace Tango.Transport.Web _httpClient = new HttpClient(); } + public WebTransportClient(String authenticationToken) : this() + { + AuthenticationToken = authenticationToken; + } + public Task PostProto(String url, Request request) where Request : class, IMessage where Response : class, IMessage { return Task.Factory.StartNew(() => @@ -38,6 +47,15 @@ namespace Tango.Transport.Web var req = new ByteArrayContent(request.ToByteArray()); req.Headers.Add("Content-Type", "application/x-protobuf"); + if (AuthenticationToken != null) + { + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthenticationToken); + } + else + { + _httpClient.DefaultRequestHeaders.Authorization = null; + } + var response = _httpClient.PostAsync(url, req).Result; var data = response.Content.ReadAsByteArrayAsync().Result; @@ -60,6 +78,16 @@ namespace Tango.Transport.Web { var req = new ByteArrayContent(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request, _settings))); req.Headers.Add("Content-Type", "application/json"); + + if (AuthenticationToken != null) + { + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthenticationToken); + } + else + { + _httpClient.DefaultRequestHeaders.Authorization = null; + } + var response = _httpClient.PostAsync(url, req).Result; var data = response.Content.ReadAsStringAsync().Result; @@ -70,19 +98,48 @@ namespace Tango.Transport.Web catch (HttpRequestException ex) { String message = JObject.Parse(data).GetValue("Message").ToString(); + Exception exception = null; - if (message == "Session Expired.") + try { - throw new SessionExpiredException(ex.Message); + String exceptionMessage = JObject.Parse(data).GetValue("ExceptionMessage").ToString(); + String exceptionType = JObject.Parse(data).GetValue("ExceptionType").ToString(); + String stackTrace = JObject.Parse(data).GetValue("StackTrace").ToString(); + Type type = GetType(exceptionType); + if (type != null) + { + exception = Activator.CreateInstance(type, new object[] { exceptionMessage + "\n" + stackTrace }) as Exception; + } + else + { + exception = new HttpException(exceptionMessage + "\n" + stackTrace); + } + } + catch + { + throw new HttpRequestException(ex.Message + " " + message); } - throw new HttpRequestException(ex.Message + " " + message); + throw exception; } return JsonConvert.DeserializeObject(data); }); } + private static Type GetType(string typeName) + { + var type = Type.GetType(typeName); + if (type != null) return type; + foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) + { + type = a.GetType(typeName); + if (type != null) + return type; + } + return null; + } + public void Dispose() { _httpClient.Dispose(); diff --git a/Software/Visual_Studio/Tango.Transport/app.config b/Software/Visual_Studio/Tango.Transport/app.config index 49b6f5ebe..55a256ebb 100644 --- a/Software/Visual_Studio/Tango.Transport/app.config +++ b/Software/Visual_Studio/Tango.Transport/app.config @@ -8,7 +8,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Transport/packages.config b/Software/Visual_Studio/Tango.Transport/packages.config index a473d73d9..e1a21695a 100644 --- a/Software/Visual_Studio/Tango.Transport/packages.config +++ b/Software/Visual_Studio/Tango.Transport/packages.config @@ -1,7 +1,7 @@  - + diff --git a/Software/Visual_Studio/Tango.UnitTesting/App.config b/Software/Visual_Studio/Tango.UnitTesting/App.config index 525a23acf..1a3af14d9 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/App.config +++ b/Software/Visual_Studio/Tango.UnitTesting/App.config @@ -64,7 +64,7 @@ - + diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs new file mode 100644 index 000000000..8a126df2e --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs @@ -0,0 +1,78 @@ +using System; +using System.Security.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.BL; +using Tango.MachineStudio.Common.Web; +using Tango.Transport.Web; +using System.Linq; + +namespace Tango.UnitTesting.Web +{ + [TestClass] + [TestCategory("Machine Service - Machine Studio")] + public class MachineStudio_Controller_TST + { + private const string address = "http://localhost:51581"; + + [TestMethod] + public void Login_and_check_for_updates() + { + //First test the more primitive web clients. + + IWebTransportClient client = new WebTransportClient(); + + var res1 = client.PostJson($"{address}/api/MachineStudio/Login", new LoginRequest() + { + Email = "TestUser@twine-s.com", + Password = "ASJH_asdjkl1234", + Version = "1.0.0.0" + }).Result; + + String token = res1.AccessToken; + client.AuthenticationToken = token; + + var res2 = client.PostJson($"{address}/api/MachineStudio/CheckForUpdates", new CheckForUpdatesRequest() + { + Version = "1.0.0.0" + }).ConfigureAwait(false).GetAwaiter().GetResult(); + + //Check updates are available.. + Assert.IsTrue(res2.IsUpdateAvailable); + + + //Now check the dedicated machine studio client. + MachineStudioWebClient msClient = new MachineStudioWebClient(address, null); + + //Should throw an exception without login first (no token specified..) + Assert.ThrowsException(() => + { + var res3 = msClient.CheckForUpdates(new CheckForUpdatesRequest() + { + Version = "1.0.0.0" + }).GetAwaiter().GetResult(); + }); + + //Perform a login. + var res4 = msClient.Login(new LoginRequest() + { + Email = "TestUser@twine-s.com", + Password = "ASJH_asdjkl1234", + Version = "1.0.0.0" + }).Result; + + //Validate the data source received. + using (ObservablesContext db = ObservablesContext.CreateDefault(res4.DataSource)) + { + var user = db.Users.Single(x => x.Email.ToLower() == "TestUser@twine-s.com"); + } + + //Check updates are not available.. + var res5 = msClient.CheckForUpdates(new CheckForUpdatesRequest() + { + Version = "100.0.0.0" + }).Result; + + Assert.IsFalse(res5.IsUpdateAvailable); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs new file mode 100644 index 000000000..23ab74f3b --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/PPC_Controller_TST.cs @@ -0,0 +1,95 @@ +using System; +using System.Security.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.BL; +using Tango.Transport.Web; +using System.Linq; +using Tango.PPC.Common.Web; +using Tango.Core.IO; + +namespace Tango.UnitTesting.Web +{ + [TestClass] + [TestCategory("Machine Service - PPC")] + public class PPC_Controller_TST + { + private const string address = "http://localhost:51581"; + + [TestMethod] + public void Login_and_setup() + { + //Now check the dedicated machine studio client. + PPCWebClient client = new PPCWebClient(address, null); + + //Should throw an exception without login first (no token specified..) + Assert.ThrowsException(() => + { + var res1 = client.MachineSetup(new MachineSetupRequest() + { + + }).GetAwaiter().GetResult(); + }); + + //Perform a login with user mode. + var res2 = client.Login(new LoginRequest() + { + Mode = LoginMode.User, + Email = "TestUser@twine-s.com", + Password = "ASJH_asdjkl1234", + }).Result; + + //Should throw exception about serial number not found. + Assert.ThrowsException(() => + { + var res3 = client.Login(new LoginRequest() + { + Mode = LoginMode.Machine, + SerialNumber = "NOT_EXISTING_SERIAL_NUMBER", + }).GetAwaiter().GetResult(); + }); + + //Perform a login with machine mode. + var res4 = client.Login(new LoginRequest() + { + Mode = LoginMode.Machine, + SerialNumber = "0003", + }).Result; + + //Should return setup information + var res5 = client.MachineSetup(new MachineSetupRequest() + { + SerialNumber = "0003", + }).GetAwaiter().GetResult(); + + //Now get DEV data source using the machine studio client in order to validate the setup information. + MachineStudio.Common.Web.MachineStudioWebClient msClient = new MachineStudio.Common.Web.MachineStudioWebClient(address, null); + var res6 = msClient.Login(new MachineStudio.Common.Web.LoginRequest() + { + Email = "TestUser@twine-s.com", + Password = "ASJH_asdjkl1234", + }).Result; + + var dataSource = res6.DataSource; + + using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource)) + { + var machine = db.Machines.Single(x => x.SerialNumber == "0003"); + + Assert.AreEqual(res5.IsDemo, machine.IsDemo); + Assert.AreEqual(res5.OSKey, machine.OsKey); + Assert.AreEqual(res5.SetupActivation, machine.SetupActivation); + Assert.AreEqual(res5.SetupFirmware, machine.SetupFirmware); + Assert.AreEqual(res5.SetupFPGA, machine.SetupFpga); + Assert.AreEqual(res5.SetupRemoteAssistance, machine.SetupRemoteAssistance); + Assert.AreEqual(res5.SetupUWF, machine.SetupUwf); + } + + + var tempFile = TemporaryManager.Default.CreateFile(); + StorageBlobDownloader downloader = new StorageBlobDownloader(res5.BlobAddress, tempFile); + downloader.Download().Wait(); + + tempFile.Delete(); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs index ababd1793..455a45895 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs @@ -59,7 +59,7 @@ namespace Tango.UnitTesting tokensManager.Validate(recent_token); - Assert.ThrowsException(() => tokensManager.Validate(token1)); + Assert.ThrowsException(() => tokensManager.Validate(token1)); } } } diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 9ebc45dfc..445992b64 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -56,18 +56,23 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + ..\packages\JWT.5.0.0\lib\net46\JWT.dll + True + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -96,6 +101,7 @@ + @@ -108,6 +114,8 @@ + + diff --git a/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs new file mode 100644 index 000000000..ff698f18f --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs @@ -0,0 +1,69 @@ +using JWT; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Web.Authentication; + +namespace Tango.UnitTesting.Web +{ + [TestClass] + [TestCategory("Web")] + public class JWT_Tokens_TST + { + private class TokenObject + { + public String Name { get; set; } + public int Age { get; set; } + } + + [TestMethod] + public void Test_JWT_Tokens_Read_Write_Validation() + { + string secret = "GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk"; + + //Create new web token with embedded object. Expiration in 2 seconds. + var webToken = WebToken.CreateNew(secret, new TokenObject() + { + Name = "Roy", + Age = 35 + + }, DateTime.UtcNow.AddSeconds(2)); + + //Get the actual string token. + String token = webToken.AccessToken; + + //Validate the string token using the secret. + WebToken.Validate(secret, token); + + //Read the token payload (Expiration, Issued, Embedded Object).. + var read_web_token = WebToken.FromToken(token); + + //Validate the token again using the web token instance (Just to see if the method is working..) + read_web_token.Validate(secret); + + //Validate the token payload reading.. + Assert.AreEqual(read_web_token.Expiration.Value.ToString("hh:mm"), webToken.Expiration.Value.ToString("hh:mm")); + Assert.AreEqual(read_web_token.Issued.ToString("hh:mm"), webToken.Issued.ToString("hh:mm")); + Assert.AreEqual(read_web_token.Object.Name, webToken.Object.Name); + Assert.AreEqual(read_web_token.Object.Age, webToken.Object.Age); + + //Ensure token validation fails when messing with the token string. + Assert.ThrowsException(() => + { + WebToken.Validate(secret, token.Substring(0, token.Length - 1) + "0"); + }); + + //Wait for the token to expire... + Thread.Sleep(2000); + + //Ensure the token validation fails with 'token expired'. + Assert.ThrowsException(() => read_web_token.Validate(secret)); + } + + + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/packages.config b/Software/Visual_Studio/Tango.UnitTesting/packages.config index 9b8d6e793..0528c7ef0 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/packages.config +++ b/Software/Visual_Studio/Tango.UnitTesting/packages.config @@ -4,9 +4,10 @@ + - + diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs index 890d69d53..5829bfca3 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -48,8 +48,8 @@ namespace Tango.Web.Authentication Value = tokenObject, WebToken = new WebToken() { - AccessToken = token, - Expiration = DateTime.UtcNow.Add(ExpirationTime) + //AccessToken = token, + //Expiration = DateTime.UtcNow.Add(ExpirationTime) }, }; @@ -73,7 +73,7 @@ namespace Tango.Web.Authentication if (DateTime.UtcNow > _tokens[token].WebToken.Expiration) { _tokens.Remove(token); - throw new SessionExpiredException("Session Expired."); + throw new TokenExpiredException("Session Expired."); } return _tokens[token].Value; diff --git a/Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs b/Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs index 71ec6eb0b..14fc49942 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs @@ -1,6 +1,12 @@ -using System; +using JWT; +using JWT.Algorithms; +using JWT.Builder; +using JWT.Serializers; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; +using System.Security.Claims; using System.Text; using System.Threading.Tasks; @@ -8,7 +14,146 @@ namespace Tango.Web.Authentication { public class WebToken { - public DateTime Expiration { get; set; } - public String AccessToken { get; set; } + public DateTime Issued { get; protected set; } + public DateTime? Expiration { get; protected set; } + public String AccessToken { get; protected set; } + + public WebToken() + { + + } + + public static WebToken CreateNew(String secret, DateTime? expiration = null) + { + DateTime issued = DateTime.UtcNow; + + var builder = new JwtBuilder() + .WithAlgorithm(new HMACSHA256Algorithm()) + .WithSecret(secret) + .IssuedAt(issued); + + if (expiration != null) + { + builder = builder.ExpirationTime(expiration.Value); + } + + builder = builder.AddClaim("object", null); + + return new WebToken() + { + AccessToken = builder.Build(), + Expiration = expiration, + Issued = issued, + }; + } + + public static void Validate(String secret, String token) + { + var json = new JwtBuilder() + .WithSecret(secret) + .MustVerifySignature() + .Decode(token); + } + + public void Validate(String secret) + { + var json = new JwtBuilder() + .WithSecret(secret) + .MustVerifySignature() + .Decode(AccessToken); + } + + public static WebToken FromToken(String token) + { + WebToken webToken = new WebToken(); + + var payload = new JwtBuilder() + .WithValidator(null) + .Decode>(token); + + webToken.AccessToken = token; + + if (payload.ContainsKey("exp")) + { + long exp = long.Parse(payload["exp"].ToString()); + webToken.Expiration = ConvertEpochToDateTime(exp); + } + + if (payload.ContainsKey("iat")) + { + long iat = long.Parse(payload["iat"].ToString()); + webToken.Issued = ConvertEpochToDateTime(iat); + } + + return webToken; + } + + protected static DateTime ConvertEpochToDateTime(long seconds) + { + var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + return epoch.AddSeconds(seconds); + } + } + + public class WebToken : WebToken where T : class + { + public T Object { get; protected set; } + + private WebToken() + { + + } + + public static WebToken CreateNew(String secret, T obj = null, DateTime? expiration = null) + { + DateTime issued = DateTime.UtcNow; + + var builder = new JwtBuilder() + .WithAlgorithm(new HMACSHA256Algorithm()) + .WithSecret(secret) + .IssuedAt(issued); + + if (expiration != null) + { + builder = builder.ExpirationTime(expiration.Value); + } + + builder = builder.AddClaim("object", obj); + + return new WebToken() + { + AccessToken = builder.Build(), + Expiration = expiration, + Issued = issued, + Object = obj, + }; + } + + public static new WebToken FromToken(String token) + { + WebToken webToken = new WebToken(); + + var payload = new JwtBuilder() + .WithValidator(null) + .Decode>(token); + + webToken.AccessToken = token; + + if (payload.ContainsKey("exp")) + { + long exp = long.Parse(payload["exp"].ToString()); + webToken.Expiration = ConvertEpochToDateTime(exp); + } + + if (payload.ContainsKey("iat")) + { + long iat = long.Parse(payload["iat"].ToString()); + webToken.Issued = ConvertEpochToDateTime(iat); + } + + webToken.Object = JsonConvert.DeserializeObject(payload["object"].ToString()); + + return webToken; + } } } diff --git a/Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs b/Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs index 17ac6636f..190a47cc2 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs @@ -9,6 +9,6 @@ namespace Tango.Web.Authentication { public class WebTokenResponse : WebResponseMessage { - public WebToken WebToken { get; set; } + public String AccessToken { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs deleted file mode 100644 index 1fae9cccc..000000000 --- a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Authentication; -using System.Threading; -using System.Threading.Tasks; -using System.Web; -using System.Web.Http; -using System.Web.Http.Controllers; -using Tango.Logging; - -namespace Tango.Web.Controllers -{ - public class JsonController : ApiController - { - protected LogManager LogManager { get; private set; } - - public JsonController() - { - LogManager = LogManager.Default; - } - - public override async Task ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken) - { - string controllerName = String.Empty; - string actionName = String.Empty; - - try - { - var routeData = HttpContext.Current.Request.RequestContext.RouteData; - actionName = routeData.Values["action"].ToString(); - controllerName = routeData.Values["controller"].ToString(); - } - catch { } - - try - { - String request = String.Empty; - - try - { - request = context.Request.Content.ReadAsStringAsync().Result; - } - catch {} - - LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}"); - - var result = await base.ExecuteAsync(context, cancellationToken); - return result; - } - catch (Exception ex) - { - LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}."); - - HttpStatusCode code = HttpStatusCode.InternalServerError; - - if (ex is ArgumentException) - { - code = HttpStatusCode.BadRequest; - } - else if (ex is AuthenticationException) - { - code = HttpStatusCode.Unauthorized; - } - -#if DEBUG - throw new HttpResponseException(Request.CreateErrorResponse(code, ex.ToString())); -#else - throw new HttpResponseException(Request.CreateErrorResponse(code, ex.FlattenMessage())); -#endif - } - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs new file mode 100644 index 000000000..854d1cf96 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Controllers/TangoController.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using Tango.Logging; +using Tango.Transport.Web; +using Tango.Web.Authentication; + +namespace Tango.Web.Controllers +{ + public class TangoController : ApiController + { + protected LogManager LogManager { get; private set; } + + public TangoController() + { + LogManager = LogManager.Default; + } + + public override async Task ExecuteAsync(HttpControllerContext context, CancellationToken cancellationToken) + { + string controllerName = String.Empty; + string actionName = String.Empty; + + try + { + var routeData = HttpContext.Current.Request.RequestContext.RouteData; + actionName = routeData.Values["action"].ToString(); + controllerName = routeData.Values["controller"].ToString(); + } + catch { } + + try + { + String request = String.Empty; + + try + { + request = context.Request.Content.ReadAsStringAsync().Result; + } + catch { } + + LogManager.Log($"Request Received on {controllerName + "/" + actionName}: \n{request}"); + + OnRequestArrived(context.Request); + + var result = await base.ExecuteAsync(context, cancellationToken); + return result; + } + catch (Exception ex) + { + LogManager.Log(ex, $"An error occurred while processing the request message on {controllerName + "/" + actionName}."); + + HttpStatusCode code = HttpStatusCode.InternalServerError; + + if (ex is ArgumentException) + { + code = HttpStatusCode.BadRequest; + } + else if (ex is AuthenticationException || ex is TokenExpiredException) + { + code = HttpStatusCode.Unauthorized; + } + + var httpException = new HttpResponseException(Request.CreateErrorResponse(code, ex)); + +#if DEBUG + throw httpException; +#else + //Remove Stack trace + var expandedException = httpException.Response.Content as System.Net.Http.ObjectContent; + + if (expandedException != null) + { + var expandedExceptionValues = expandedException.Value as HttpError; + + if (expandedExceptionValues != null) + { + expandedExceptionValues["StackTrace"] = "StackTrace not provided."; + } + } +#endif + + + throw httpException; + } + } + + protected virtual void OnRequestArrived(HttpRequestMessage request) + { + //Do nothing. + } + } + + public class TangoController : TangoController where T : class + { + public WebToken RequestToken { get; set; } + + protected override void OnRequestArrived(HttpRequestMessage request) + { + base.OnRequestArrived(request); + + var authorizationHeader = request.Headers.Authorization; + + if (authorizationHeader != null && authorizationHeader.Parameter != null) + { + try + { + RequestToken = WebToken.FromToken(authorizationHeader.Parameter); + } + catch (Exception ex) + { + throw new HttpParseException("Could not parse the provided token embedded object.", ex); + } + } + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 56711df28..961ec04e8 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -48,6 +48,9 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + ..\packages\JWT.5.0.0\lib\net46\JWT.dll + ..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.6\lib\net45\Microsoft.AI.Agent.Intercept.dll @@ -186,13 +189,14 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll @@ -257,7 +261,7 @@ - + @@ -268,8 +272,12 @@ - - + + Designer + + + Designer + diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs index bb943533a..42a9d801c 100644 --- a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs +++ b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs @@ -15,8 +15,8 @@ namespace Tango.Web private bool _disposed; private TLoginRequest _lastLoginRequest; - private DeploymentSlot _environment; - public DeploymentSlot Environment + private DeploymentSlot? _environment; + public DeploymentSlot? Environment { get { return _environment; } set @@ -31,26 +31,40 @@ namespace Tango.Web } } + public String Address { get; set; } public String Controller { get; private set; } + public String Token { get; private set; } public WebToken WebToken { get; private set; } public bool IsAuthenticated { get; private set; } public TangoWebClient(DeploymentSlot environment, String controller) { + _client = new WebTransportClient(); Controller = controller; Environment = environment; - _client = new WebTransportClient(); } - public TangoWebClient(DeploymentSlot environment, String controller, WebToken token) : this(environment, controller) + public TangoWebClient(DeploymentSlot environment, String controller, String token) : this(environment, controller) { - WebToken = token; + Token = token; + } + + public TangoWebClient(String address, String controller, String token) + { + _client = new WebTransportClient(); + Address = address; + Controller = controller; + Token = token; } public async Task Login(TLoginRequest request) { var response = await _client.PostJson(GetActionAddress("Login"), request); - WebToken = response.WebToken; + Token = response.AccessToken; + _client.AuthenticationToken = Token; + + WebToken = WebToken.FromToken(Token); + _lastLoginRequest = request; IsAuthenticated = true; return response; @@ -58,27 +72,11 @@ namespace Tango.Web protected virtual async Task Post(String action, TRequest request) where TRequest : class, IWebRequestMessage where TResponse : class, IWebResponseMessage { - bool has_own_token = false; - - if (request is WebRequestSecureMessage) + if (IsAuthenticated) { - has_own_token = (request as WebRequestSecureMessage).AccessToken != null; - - if (!has_own_token) + if (DateTime.UtcNow >= WebToken.Expiration) { - if (IsAuthenticated) - { - if (DateTime.UtcNow >= WebToken.Expiration) - { - await Login(_lastLoginRequest); - } - } - else - { - throw new AuthenticationException("This tango web client has not been authenticated with the service. Please use the login method to authenticate."); - } - - (request as WebRequestSecureMessage).AccessToken = WebToken.AccessToken; + await Login(_lastLoginRequest); } } @@ -87,28 +85,15 @@ namespace Tango.Web var response = await _client.PostJson(GetActionAddress(action), request); return response; } - catch (SessionExpiredException) + catch (TokenExpiredException) { - if (!has_own_token) + try { - try - { - await Login(_lastLoginRequest); - - if (request is WebRequestSecureMessage) - { - (request as WebRequestSecureMessage).AccessToken = WebToken.AccessToken; - } - - var response = await _client.PostJson(GetActionAddress(action), request); - return response; - } - catch - { - throw; - } + await Login(_lastLoginRequest); + var response = await _client.PostJson(GetActionAddress(action), request); + return response; } - else + catch { throw; } @@ -126,7 +111,14 @@ namespace Tango.Web protected virtual String GetServiceAddress() { - return Environment.ToAddress() + $"/api/{Controller}/"; + if (Environment != null) + { + return Environment.Value.ToAddress() + $"/api/{Controller}/"; + } + else + { + return Address + $"/api/{Controller}/"; + } } public virtual void Dispose() diff --git a/Software/Visual_Studio/Tango.Web/app.config b/Software/Visual_Studio/Tango.Web/app.config index 63664236a..bc38de989 100644 --- a/Software/Visual_Studio/Tango.Web/app.config +++ b/Software/Visual_Studio/Tango.Web/app.config @@ -8,7 +8,7 @@ - + @@ -30,6 +30,10 @@ + + + + diff --git a/Software/Visual_Studio/Tango.Web/packages.config b/Software/Visual_Studio/Tango.Web/packages.config index cb6027500..0a940a2ea 100644 --- a/Software/Visual_Studio/Tango.Web/packages.config +++ b/Software/Visual_Studio/Tango.Web/packages.config @@ -3,6 +3,7 @@ + @@ -29,7 +30,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.BugReporter/App.config b/Software/Visual_Studio/Utilities/Tango.BugReporter/App.config index 1955443c4..09c4c4217 100644 --- a/Software/Visual_Studio/Utilities/Tango.BugReporter/App.config +++ b/Software/Visual_Studio/Utilities/Tango.BugReporter/App.config @@ -7,7 +7,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/App.config b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/App.config index eba7ddbbd..ef214165a 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/App.config @@ -63,7 +63,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/App.config b/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/App.config index 3275d5443..862732d18 100644 --- a/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/App.config @@ -59,7 +59,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/App.config b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/App.config index 6b464734d..45f745b55 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/App.config @@ -11,7 +11,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Tango.Stubs.CLI.csproj b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Tango.Stubs.CLI.csproj index 3f63a6f0d..102c64cb7 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Tango.Stubs.CLI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Tango.Stubs.CLI.csproj @@ -41,8 +41,8 @@ ..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll - - ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -93,7 +93,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/packages.config b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/packages.config index 2ec46e138..93113a56a 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/packages.config +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/packages.config @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.config b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.config index 02866ad95..e060dcc60 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.config @@ -191,7 +191,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj index 9d6a8b15e..0cff0bf07 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj @@ -52,8 +52,8 @@ ..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll - - ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -189,7 +189,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/packages.config b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/packages.config index 7725c864a..b064d7f85 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/packages.config +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/packages.config @@ -5,5 +5,5 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.TransportRouter.UI/App.config b/Software/Visual_Studio/Utilities/Tango.TransportRouter.UI/App.config index 23bbb5aa7..45b81480f 100644 --- a/Software/Visual_Studio/Utilities/Tango.TransportRouter.UI/App.config +++ b/Software/Visual_Studio/Utilities/Tango.TransportRouter.UI/App.config @@ -59,7 +59,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/App.config b/Software/Visual_Studio/Utilities/Tango.UITests/App.config index ff7bf1461..f2a26c582 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/App.config +++ b/Software/Visual_Studio/Utilities/Tango.UITests/App.config @@ -62,7 +62,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config index d748e2305..f74b85d15 100644 --- a/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config +++ b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config @@ -7,7 +7,7 @@ - + @@ -27,7 +27,7 @@ - + diff --git a/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs index e95f57344..d645f0e5e 100644 --- a/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs @@ -23,7 +23,7 @@ namespace Tango.WebClientGenerator GenerateWebClient("Tango.MachineStudio.Common.Web", "MachineStudioWebClientBase", PathHelper.GetSolutionFolder() + @"\MachineStudio\Tango.MachineStudio.Common\Web"); } - private static void GenerateWebClient(String nameSpace, String name, String path) where TLoginRequest : WebRequestMessage where TLoginResponse : WebTokenResponse where TController : JsonController + private static void GenerateWebClient(String nameSpace, String name, String path) where TLoginRequest : WebRequestMessage where TLoginResponse : WebTokenResponse where TController : TangoController { TangoWebClientCodeFile model = new TangoWebClientCodeFile(); model.Namespace = nameSpace; diff --git a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/app.config b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/app.config index 49b6f5ebe..55a256ebb 100644 --- a/Software/Visual_Studio/VSIX/Tango.BuildExtensions/app.config +++ b/Software/Visual_Studio/VSIX/Tango.BuildExtensions/app.config @@ -8,7 +8,7 @@ - + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs index 0a63e9acb..73265328c 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/App_Start/WebApiConfig.cs @@ -22,10 +22,10 @@ namespace Tango.MachineService defaults: new { id = RouteParameter.Optional }); config.Formatters.Insert(0, new ProtoBufFormatter()); - config.Formatters.Insert(1, new JsonNetFormatter(new JsonSerializerSettings() - { - PreserveReferencesHandling = PreserveReferencesHandling.All, - })); + //config.Formatters.Insert(1, new JsonNetFormatter(new JsonSerializerSettings() + //{ + // PreserveReferencesHandling = PreserveReferencesHandling.All, + //})); } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 054c8d781..467b6ae28 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -24,12 +24,15 @@ using Tango.MachineService.Filters; namespace Tango.MachineService.Controllers { - public class MachineStudioController : JsonController + public class MachineStudioController : TangoController { private static List _pendingUploads; private ActiveDirectoryManager _ad_manager; - public static TokensManager TokensManager { get; set; } + public class TokenObject + { + public String UserGuid { get; set; } + } #region Constructors @@ -38,8 +41,6 @@ namespace Tango.MachineService.Controllers ///
static MachineStudioController() { - TokensManager = new TokensManager(); - TokensManager.ExpirationTime = TimeSpan.FromDays(10); _pendingUploads = new List(); } @@ -61,11 +62,13 @@ namespace Tango.MachineService.Controllers /// The request. /// [HttpPost] - [MachineStudioLoginFilter] + [JwtTokenFilter] public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) { LogManager.Log("Request received..."); + var userID = RequestToken.Object.UserGuid; + CheckForUpdatesResponse response = new CheckForUpdatesResponse(); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) @@ -103,7 +106,7 @@ namespace Tango.MachineService.Controllers /// The request. /// [HttpPost] - [MachineStudioLoginFilter] + [JwtTokenFilter] public DownloadLatestVersionResponse DownloadLatestVersion(DownloadLatestVersionRequest request) { LogManager.Log("Request received..."); @@ -138,14 +141,14 @@ namespace Tango.MachineService.Controllers /// New version must be greater than latest version. /// Invalid user credentials. [HttpPost] - [MachineStudioLoginFilter] + [JwtTokenFilter] public UploadVersionResponse UploadVersion(UploadVersionRequest request) { UploadVersionResponse response = new UploadVersionResponse(); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - String userID = TokensManager.GetTokenObject(request.AccessToken); + String userID = RequestToken.Object.UserGuid; var user = new UserBuilder(db).Set(userID).WithRolesAndPermissions().Build(); @@ -195,7 +198,7 @@ namespace Tango.MachineService.Controllers /// /// Invalid Token. [HttpPost] - [MachineStudioLoginFilter] + [JwtTokenFilter] public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) { MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); @@ -347,7 +350,10 @@ namespace Tango.MachineService.Controllers Password = request.Password, }, - WebToken = TokensManager.GetOrCreate(user.Guid), + AccessToken = WebToken.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject() + { + UserGuid = user.Guid, + }, DateTime.UtcNow.AddDays(1)).AccessToken, VersionChangeRequired = versionChangeRequired, RequiredVersion = requiredVersion, }; diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 70d64be51..912d2e5e9 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -26,30 +26,22 @@ using Tango.MachineService.Filters; namespace Tango.MachineService.Controllers { - public class PPCController : JsonController + public class PPCController : TangoController { private static List _pendingUploads; private ActiveDirectoryManager _ad_manager; - public class TokenObject : IEquatable + public class TokenObject { public LoginMode Mode { get; set; } public String UserGuid { get; set; } public String MachineGuid { get; set; } - - public bool Equals(TokenObject other) - { - return UserGuid == other.UserGuid || MachineGuid == MachineGuid; - } } - public static TokensManager TokensManager { get; set; } - #region Constructors static PPCController() { - TokensManager = new TokensManager(); _pendingUploads = new List(); } @@ -62,8 +54,8 @@ namespace Tango.MachineService.Controllers #region Setup & Update - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public MachineSetupResponse MachineSetup(MachineSetupRequest request) { MachineSetupResponse response = new MachineSetupResponse(); @@ -73,7 +65,7 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { db.Configuration.LazyLoadingEnabled = false; - String machine_guid = TokensManager.GetTokenObject(request.AccessToken).MachineGuid; + String machine_guid = RequestToken.Object.MachineGuid; var machine = db.Machines.SingleOrDefault(x => x.Guid == machine_guid); @@ -136,8 +128,8 @@ namespace Tango.MachineService.Controllers return response; } - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public DownloadUpdateResponse MachineUpdate(DownloadUpdateRequest request) { DownloadUpdateResponse response = new DownloadUpdateResponse(); @@ -145,7 +137,7 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { db.Configuration.LazyLoadingEnabled = false; - String machine_guid = TokensManager.GetTokenObject(request.AccessToken).MachineGuid; + String machine_guid = RequestToken.Object.MachineGuid; var machine = db.Machines.SingleOrDefault(x => x.Guid == machine_guid); @@ -195,15 +187,15 @@ namespace Tango.MachineService.Controllers return response; } - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public CheckForUpdateResponse CheckForUpdate(CheckForUpdateRequest request) { CheckForUpdateResponse response = new CheckForUpdateResponse(); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - String machine_guid = TokensManager.GetTokenObject(request.AccessToken).MachineGuid; + String machine_guid = RequestToken.Object.MachineGuid; var machine = db.Machines.SingleOrDefault(x => x.Guid == machine_guid); @@ -227,8 +219,8 @@ namespace Tango.MachineService.Controllers return response; } - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public UpdateDBResponse UpdateDB(UpdateDBRequest request) { UpdateDBResponse response = new UpdateDBResponse(); @@ -236,7 +228,7 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - String machine_guid = TokensManager.GetTokenObject(request.AccessToken).MachineGuid; + String machine_guid = RequestToken.Object.MachineGuid; var machine = db.Machines.SingleOrDefault(x => x.Guid == machine_guid); @@ -301,8 +293,8 @@ namespace Tango.MachineService.Controllers return response; } - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public UploadVersionResponse UploadVersion(UploadVersionRequest request) { UploadVersionResponse response = new UploadVersionResponse(); @@ -315,7 +307,7 @@ namespace Tango.MachineService.Controllers db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - var user_guid = TokensManager.GetTokenObject(request.AccessToken).UserGuid; + var user_guid = RequestToken.Object.UserGuid; var user = new UserBuilder(db).Set(user_guid).WithRolesAndPermissions().Build(); @@ -369,8 +361,8 @@ namespace Tango.MachineService.Controllers return response; } - [PPCLoginFilter] [HttpPost] + [JwtTokenFilter] public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) { PPCPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); @@ -439,11 +431,11 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Domain user found but the database entry validation failed."); } - response.WebToken = TokensManager.GetOrCreate(new TokenObject() + response.AccessToken = WebToken.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject() { Mode = LoginMode.User, UserGuid = user.Guid, - }); + }).AccessToken; } else if (request.Mode == LoginMode.Machine) { @@ -454,11 +446,11 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Invalid serial number."); } - response.WebToken = TokensManager.GetOrCreate(new TokenObject() + response.AccessToken = WebToken.CreateNew(MachineServiceConfig.JWT_TOKEN_SECRET, new TokenObject() { Mode = LoginMode.Machine, MachineGuid = machine.Guid, - }); + }).AccessToken; } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Filters/JwtTokenFilter.cs b/Software/Visual_Studio/Web/Tango.MachineService/Filters/JwtTokenFilter.cs new file mode 100644 index 000000000..4cf22cc43 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Filters/JwtTokenFilter.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Filters; +using Tango.Transport.Web; +using Tango.Web.Authentication; + +namespace Tango.MachineService.Filters +{ + public class JwtTokenFilter : ActionFilterAttribute + { + public override void OnActionExecuting(HttpActionContext actionContext) + { + var authorizationHeader = actionContext.Request.Headers.Authorization; + + if (authorizationHeader != null && authorizationHeader.Parameter != null) + { + try + { + WebToken.Validate(MachineServiceConfig.JWT_TOKEN_SECRET, authorizationHeader.Parameter); + } + catch (JWT.TokenExpiredException) + { + throw new TokenExpiredException("Token expired."); + } + catch (JWT.SignatureVerificationException) + { + throw new InvalidTokenException("Invalid token."); + } + } + else + { + throw new AuthenticationException("No token specified."); + } + + base.OnActionExecuting(actionContext); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs b/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs deleted file mode 100644 index dfa78f0a0..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Authentication; -using System.Web; -using System.Web.Http; -using System.Web.Http.Controllers; -using System.Web.Http.Filters; -using Tango.Transport.Web; - -namespace Tango.MachineService.Filters -{ - public class MachineStudioLoginFilter : ActionFilterAttribute - { - public override void OnActionExecuting(HttpActionContext actionContext) - { - var json = actionContext.Request.Content.ReadAsStringAsync().Result; - WebRequestSecureMessage msg = JsonConvert.DeserializeObject(json); - - try - { - Controllers.MachineStudioController.TokensManager.Validate(msg.AccessToken); - } - catch (Exception ex) - { - throw new HttpResponseException(actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex)); - } - - base.OnActionExecuting(actionContext); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Filters/PPCLoginFilter.cs b/Software/Visual_Studio/Web/Tango.MachineService/Filters/PPCLoginFilter.cs deleted file mode 100644 index 322023b7d..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Filters/PPCLoginFilter.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Authentication; -using System.Web; -using System.Web.Http; -using System.Web.Http.Controllers; -using System.Web.Http.Filters; -using Tango.Transport.Web; - -namespace Tango.MachineService.Filters -{ - public class PPCLoginFilter : ActionFilterAttribute - { - public override void OnActionExecuting(HttpActionContext actionContext) - { - var json = actionContext.Request.Content.ReadAsStringAsync().Result; - WebRequestSecureMessage msg = JsonConvert.DeserializeObject(json); - - try - { - Controllers.PPCController.TokensManager.Validate(msg.AccessToken); - } - catch (Exception ex) - { - throw new HttpResponseException(actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex)); - } - - base.OnActionExecuting(actionContext); - } - } -} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs index 289fb08e2..a6aa71944 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -12,5 +12,6 @@ namespace Tango.MachineService public static String TANGO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(TANGO_VERSIONS_CONTAINER)].ToString(); public static String MACHINE_STUDIO_VERSIONS_CONTAINER => ConfigurationManager.AppSettings[nameof(MACHINE_STUDIO_VERSIONS_CONTAINER)].ToString(); public static bool ENFORCE_MACHINE_STUDIO_VERSION => bool.Parse(ConfigurationManager.AppSettings[nameof(ENFORCE_MACHINE_STUDIO_VERSION)].ToString()); + public static String JWT_TOKEN_SECRET => ConfigurationManager.AppSettings[nameof(JWT_TOKEN_SECRET)].ToString(); } } \ 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 038849c72..6dbbe49ab 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -56,6 +56,9 @@ ..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + ..\..\packages\JWT.5.0.0\lib\net46\JWT.dll + @@ -161,8 +164,8 @@ ..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.WmiEnum.dll - - ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll @@ -275,8 +278,7 @@ - - + @@ -379,7 +381,7 @@ False - + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 72c56b38f..fb10e615e 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -16,16 +16,17 @@ - + - - + + +