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 !!! --- Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.config | 2 +- .../MachineStudio/Tango.MachineStudio.UI/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') 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 -- cgit v1.3.1 From 64b768178dc9e64293a52c1b6d2631709af9502a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 24 Feb 2019 13:38:47 +0200 Subject: Removed all refresh tokens use :/ --- .../Build/Shortcuts/Machine Emulator.lnk | Bin 1530 -> 1445 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1581 -> 1516 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1529 -> 1444 bytes .../Build/Shortcuts/Stubs Execution GUI.lnk | Bin 1547 -> 1462 bytes .../Build/Shortcuts/Transport Router.lnk | Bin 1578 -> 1493 bytes .../Properties/AssemblyInfo.cs | 2 +- .../MachineService/MachineStudio_Controller_TST.cs | 2 +- .../Tango.UnitTesting/Web/JWT_Tokens_TST.cs | 2 - .../ExtensionMethods/CloudTableExtensions.cs | 14 +++--- .../Tango.Web/Security/RefreshTokenEntity.cs | 24 --------- .../Tango.Web/Security/RenewTokenRequest.cs | 14 ------ .../Tango.Web/Security/RenewTokenResponse.cs | 14 ------ .../Visual_Studio/Tango.Web/Security/WebToken.cs | 34 +++++++++---- .../Tango.Web/Security/WebTokenResponse.cs | 1 - Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 3 -- Software/Visual_Studio/Tango.Web/TangoWebClient.cs | 21 +------- .../Controllers/MachineStudioController.cs | 21 -------- .../Security/RefreshTokenEncoder.cs | 8 +-- .../Security/RefreshTokenEntity.cs | 55 +++++++++++++++++++++ .../Security/RefreshTokensManager.cs | 16 ++++-- .../Tango.MachineService.csproj | 3 +- 21 files changed, 107 insertions(+), 127 deletions(-) delete mode 100644 Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs delete mode 100644 Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs delete mode 100644 Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEntity.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 20ad50570..82d25f5cb 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/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index a1eb6ae58..34b13a9c4 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.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 37b68bcf8..2d58f55bf 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/Build/Shortcuts/Stubs Execution GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk index 0b46f425e..41d0606ed 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk index 04c0b9bb2..a4d815d5a 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk and b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk differ 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 bceaaf956..f313e9073 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.7.0")] +[assembly: AssemblyVersion("4.0.9.0")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs index 56a57ab92..21ab16307 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService/MachineStudio_Controller_TST.cs @@ -12,7 +12,7 @@ namespace Tango.UnitTesting.MachineService [TestCategory("Machine Service - Machine Studio")] public class MachineStudio_Controller_TST { - private const string address = "http://localhost:51581"; + private const string address = "http://localhost:1111"; [TestMethod] public void Login_and_check_for_updates() diff --git a/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs index d696a627c..6f97e1c4e 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Web/JWT_Tokens_TST.cs @@ -63,7 +63,5 @@ namespace Tango.UnitTesting.Web //Ensure the token validation fails with 'token expired'. Assert.ThrowsException(() => read_web_token.Validate(secret)); } - - } } diff --git a/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs index 43c4804d3..ffffe6950 100644 --- a/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs +++ b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs @@ -15,10 +15,10 @@ public static class CloudTableExtensions /// Partition key - i.e., last name /// Row key - i.e., first name /// A Task object - public static async Task GetEntityAsync(this CloudTable table, string partitionKey, string rowKey) where T : class, ITableEntity + public static T GetEntity(this CloudTable table, string partitionKey, string rowKey) where T : class, ITableEntity { TableOperation retrieveOperation = TableOperation.Retrieve(partitionKey, rowKey); - TableResult result = await table.ExecuteAsync(retrieveOperation); + TableResult result = table.Execute(retrieveOperation); T customer = result.Result as T; return customer; } @@ -33,7 +33,7 @@ public static class CloudTableExtensions /// The sample table name /// The entity to insert or merge /// A Task object - public static async Task InsertOrUpdateEntityAsync(this CloudTable table, T entity) where T : class, ITableEntity + public static T InsertOrUpdateEntity(this CloudTable table, T entity) where T : class, ITableEntity { if (entity == null) { @@ -41,10 +41,10 @@ public static class CloudTableExtensions } // Create the InsertOrReplace table operation - TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); + TableOperation insertOrMergeOperation = TableOperation.InsertOrReplace(entity); // Execute the operation. - TableResult result = await table.ExecuteAsync(insertOrMergeOperation); + TableResult result = table.Execute(insertOrMergeOperation); T insertedCustomer = result.Result as T; return insertedCustomer; @@ -56,7 +56,7 @@ public static class CloudTableExtensions /// Sample table name /// Entity to delete /// A Task object - public static async Task DeleteEntityAsync(this CloudTable table, T deleteEntity) where T : class, ITableEntity + public static void DeleteEntity(this CloudTable table, T deleteEntity) where T : class, ITableEntity { if (deleteEntity == null) { @@ -64,6 +64,6 @@ public static class CloudTableExtensions } TableOperation deleteOperation = TableOperation.Delete(deleteEntity); - await table.ExecuteAsync(deleteOperation); + table.Execute(deleteOperation); } } diff --git a/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs b/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs deleted file mode 100644 index 839027ca1..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.WindowsAzure.Storage.Table; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Web.Security -{ - public class RefreshTokenEntity : TableEntity - { - /// - /// Initializes a new instance of the class. - /// - public RefreshTokenEntity() - { - - } - - public String RefreshToken { get; set; } - public String AccessToken { get; set; } - public DateTime Expiration { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs b/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs deleted file mode 100644 index 213cd3afd..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.Web.Security -{ - public class RenewTokenRequest : WebRequestMessage - { - public String RefreshToken { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs b/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs deleted file mode 100644 index 76c381852..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.Web.Security -{ - public class RenewTokenResponse : WebTokenResponse - { - - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/WebToken.cs b/Software/Visual_Studio/Tango.Web/Security/WebToken.cs index 006ed9de7..7aa4860ab 100644 --- a/Software/Visual_Studio/Tango.Web/Security/WebToken.cs +++ b/Software/Visual_Studio/Tango.Web/Security/WebToken.cs @@ -38,12 +38,15 @@ namespace Tango.Web.Security builder = builder.ExpirationTime(expiration.Value); } + String refreshToken = Guid.NewGuid().ToString(); + builder = builder.AddClaim("object", null); + builder = builder.AddClaim("refresh-token", refreshToken); return new WebToken() { AccessToken = builder.Build(), - RefreshToken = Guid.NewGuid().ToString(), + RefreshToken = refreshToken, Expiration = expiration, Issued = issued, }; @@ -65,11 +68,10 @@ namespace Tango.Web.Security .Decode(AccessToken); } - public WebToken Renew(String secret, String token) + public WebToken Renew(String secret) { - WebToken webToken = WebToken.FromToken(token); - var newToken = CreateNew(secret, DateTime.UtcNow.Add(webToken.Expiration.Value - webToken.Issued)); - newToken.RefreshToken = webToken.RefreshToken; + var newToken = CreateNew(secret, DateTime.UtcNow.Add(Expiration.Value - Issued)); + newToken.RefreshToken = RefreshToken; return newToken; } @@ -95,6 +97,11 @@ namespace Tango.Web.Security webToken.Issued = ConvertEpochToDateTime(iat); } + if (payload.ContainsKey("refresh-token")) + { + webToken.RefreshToken = payload["refresh-token"].ToString(); + } + return webToken; } @@ -128,12 +135,15 @@ namespace Tango.Web.Security builder = builder.ExpirationTime(expiration.Value); } + String refreshToken = Guid.NewGuid().ToString(); + builder = builder.AddClaim("object", obj); + builder = builder.AddClaim("refresh-token", refreshToken); return new WebToken() { AccessToken = builder.Build(), - RefreshToken = Guid.NewGuid().ToString(), + RefreshToken = refreshToken, Expiration = expiration, Issued = issued, Object = obj, @@ -162,16 +172,20 @@ namespace Tango.Web.Security webToken.Issued = ConvertEpochToDateTime(iat); } + if (payload.ContainsKey("refresh-token")) + { + webToken.RefreshToken = payload["refresh-token"].ToString(); + } + webToken.Object = JsonConvert.DeserializeObject(payload["object"].ToString()); return webToken; } - public new WebToken Renew(String secret, String token) + public new WebToken Renew(String secret) { - WebToken webToken = WebToken.FromToken(token); - var newToken = WebToken.CreateNew(secret, webToken.Object, DateTime.UtcNow.Add(webToken.Expiration.Value - webToken.Issued)); - newToken.RefreshToken = webToken.RefreshToken; + var newToken = WebToken.CreateNew(secret, Object, DateTime.UtcNow.Add(Expiration.Value - Issued)); + newToken.RefreshToken = RefreshToken; return newToken; } } diff --git a/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs b/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs index 8c8f2f096..e68305fbb 100644 --- a/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs +++ b/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs @@ -10,6 +10,5 @@ namespace Tango.Web.Security public class WebTokenResponse : WebResponseMessage { public String AccessToken { get; set; } - public String RefreshToken { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 621014496..b16473a96 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -248,9 +248,6 @@ GlobalVersionInfo.cs - - - diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs index 08fc19099..1d2f9fc8e 100644 --- a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs +++ b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs @@ -70,29 +70,13 @@ namespace Tango.Web return response; } - private async Task Renew() - { - var response = await _client.PostJson(GetActionAddress("Renew"), new RenewTokenRequest() - { - RefreshToken = WebToken.RefreshToken, - }); - - Token = response.AccessToken; - _client.AuthenticationToken = Token; - - WebToken = WebToken.FromToken(Token); - - IsAuthenticated = true; - } - protected virtual async Task Post(String action, TRequest request) where TRequest : class, IWebRequestMessage where TResponse : class, IWebResponseMessage { if (IsAuthenticated) { if (DateTime.UtcNow >= WebToken.Expiration) { - await Renew(); - //await Login(_lastLoginRequest); + await Login(_lastLoginRequest); } } @@ -105,8 +89,7 @@ namespace Tango.Web { try { - //await Login(_lastLoginRequest); - await Renew(); + await Login(_lastLoginRequest); var response = await _client.PostJson(GetActionAddress(action), request); return response; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 324878f25..29cc067d6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -366,27 +366,6 @@ namespace Tango.MachineService.Controllers }; } - [HttpPost] - [JwtTokenFilter(allowExpired: true)] - public RenewTokenResponse Renew(RenewTokenRequest request) - { - RefreshTokensManager manager = new RefreshTokensManager(); - var entity = manager.GetToken(request.RefreshToken); - - if (entity.AccessToken != RequestToken.AccessToken) - { - throw new AuthenticationException("Invalid access token and refresh token combination."); - } - - var newToken = RequestToken.Renew(MachineServiceConfig.JWT_TOKEN_SECRET, entity.AccessToken); - - return new RenewTokenResponse() - { - AccessToken = entity.AccessToken, - RefreshToken = entity.RefreshToken, - }; - } - #endregion } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEncoder.cs b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEncoder.cs index 3948ae1c4..896788ffc 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEncoder.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEncoder.cs @@ -11,16 +11,16 @@ namespace Tango.MachineService.Security { public String Encode(T obj) { - String str = obj.ToJsonString(); + String json = JsonConvert.SerializeObject(obj); Rfc2898Cryptographer crypt = new Rfc2898Cryptographer(); - return crypt.Encrypt(str); + return crypt.Encrypt(json); } public T Decode(String token) { Rfc2898Cryptographer crypt = new Rfc2898Cryptographer(); - String str = crypt.Decrypt(token); - return JsonConvert.DeserializeObject(str); + String json = crypt.Decrypt(token); + return JsonConvert.DeserializeObject(json); } } } \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEntity.cs b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEntity.cs new file mode 100644 index 000000000..2788799aa --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEntity.cs @@ -0,0 +1,55 @@ +using Microsoft.WindowsAzure.Storage.Table; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineService.Security +{ + public class RefreshTokenEntity : TableEntity where T : class + { + /// + /// Initializes a new instance of the class. + /// + public RefreshTokenEntity() + { + + } + + + public RefreshTokenEntity(String identity, String accessToken, String refreshToken, DateTime expiration, T obj) + { + PartitionKey = MachineServiceConfig.REFRESH_TOKENS_TABLE_PARTITION; + + Identity = identity; + AccessToken = accessToken; + RefreshToken = refreshToken; + Expiration = expiration; + + RefreshTokenEncoder encoder = new RefreshTokenEncoder(); + Object = encoder.Encode(obj); + } + + [IgnoreProperty] + public String RefreshToken + { + get { return RowKey; } + set { RowKey = value; } + } + + public String Identity { get; set; } + + public String AccessToken { get; set; } + + public DateTime Expiration { get; set; } + + public String Object { get; set; } + + public T GetObject() + { + RefreshTokenEncoder encoder = new RefreshTokenEncoder(); + return encoder.Decode(RefreshToken); + } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokensManager.cs b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokensManager.cs index 5cc206c63..06796c41e 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokensManager.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokensManager.cs @@ -7,7 +7,7 @@ using Tango.Web.Storage; namespace Tango.MachineService.Security { - public class RefreshTokensManager + public class RefreshTokensManager where T : class { private TableStorageManager _manager; @@ -16,16 +16,22 @@ namespace Tango.MachineService.Security _manager = new TableStorageManager(); } - public RefreshTokenEntity GetToken(String refreshToken) + public RefreshTokenEntity GetToken(String refreshToken) { var table = _manager.GetTable(MachineServiceConfig.REFRESH_TOKENS_TABLE_NAME); - return table.GetEntityAsync(MachineServiceConfig.REFRESH_TOKENS_TABLE_PARTITION, refreshToken).Result; + return table.GetEntity>(MachineServiceConfig.REFRESH_TOKENS_TABLE_PARTITION, refreshToken); } - public RefreshTokenEntity InsertOrUpdate(RefreshTokenEntity refreshTokenEntity) + public RefreshTokenEntity InsertOrUpdate(RefreshTokenEntity refreshTokenEntity) { var table = _manager.GetTable(MachineServiceConfig.REFRESH_TOKENS_TABLE_NAME); - return table.InsertOrUpdateEntityAsync(refreshTokenEntity).Result; + return table.InsertOrUpdateEntity(refreshTokenEntity); + } + + public void DeleteToken(RefreshTokenEntity entity) + { + var table = _manager.GetTable(MachineServiceConfig.REFRESH_TOKENS_TABLE_NAME); + table.DeleteEntity(entity); } } } \ 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 22be33277..bf0c15541 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -291,6 +291,7 @@ + @@ -375,7 +376,7 @@ True 51581 / - http://localhost:51581/ + http://localhost:1111/ False False -- cgit v1.3.1 From 2248c386c45aa0b1f2d077907424b6fdbcc0d53c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 24 Feb 2019 20:26:44 +0200 Subject: Machine Studio v4.0.9 PPC v1.0.3 --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Machine Studio Installer.aip | 104 +++++++++- .../Build/Shortcuts/Machine Emulator.lnk | Bin 1445 -> 1471 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1532 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1444 -> 1464 bytes .../ViewModels/FirmwareUpgradeViewVM.cs | 32 ++- .../Views/FirmwareUpgradeView.xaml | 3 +- .../Tango.Emulations/Emulators/MachineEmulator.cs | 2 +- .../Tango.Transport/TransportMessageBase.cs | 5 + .../Tango.Transport/TransporterBase.cs | 216 ++++++++++++--------- 11 files changed, 256 insertions(+), 106 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 19a7f9e56..a64750021 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 71bdb175e..762885218 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ 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 c55783488..2937817c5 100644 --- a/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip +++ b/Software/Visual_Studio/Advanced Installer Projects/Machine Studio Installer.aip @@ -66,9 +66,17 @@ + + + + + + + + @@ -98,13 +106,13 @@ + - @@ -114,7 +122,9 @@ + + @@ -123,6 +133,7 @@ + @@ -130,8 +141,11 @@ + + + @@ -143,13 +157,18 @@ + + + + + @@ -176,6 +195,7 @@ + @@ -192,15 +212,23 @@ + + + + + + + + @@ -208,19 +236,25 @@ + + + + + + @@ -273,19 +307,26 @@ + + + + - + + + + - + @@ -313,7 +354,7 @@ - + @@ -328,12 +369,21 @@ + + + + + + + + + @@ -380,6 +430,7 @@ + @@ -388,6 +439,7 @@ + @@ -412,7 +464,9 @@ + + @@ -421,6 +475,7 @@ + @@ -430,8 +485,11 @@ + + + @@ -443,13 +501,18 @@ + + + + + @@ -484,6 +547,7 @@ + @@ -500,16 +564,24 @@ + + + + + + + + @@ -517,10 +589,12 @@ + + @@ -529,10 +603,14 @@ + + + + @@ -667,18 +745,32 @@ + + + + + + + + + + + + + + @@ -772,8 +864,6 @@ - - @@ -834,8 +924,8 @@ - + diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 82d25f5cb..fb11f4b31 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/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index d8c2c376b..053449ca5 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.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 2d58f55bf..21aad3ff2 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/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs index e54c28e17..e45c29f73 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -61,6 +61,7 @@ namespace Tango.MachineStudio.UI.ViewModels if (_dfu) { UploadTFP = false; + DFUAndTFP = false; } } } @@ -76,10 +77,29 @@ namespace Tango.MachineStudio.UI.ViewModels if (_uploadTFP) { DFU = false; + DFUAndTFP = false; } } } + private bool _dfuAndTFP; + + public bool DFUAndTFP + { + get { return _dfuAndTFP; } + set + { + _dfuAndTFP = value; RaisePropertyChangedAuto(); + + if (_dfuAndTFP) + { + DFU = false; + UploadTFP = false; + } + } + } + + public RelayCommand SelectCommand { get; set; } public RelayCommand UpgradeCommand { get; set; } @@ -131,13 +151,17 @@ namespace Tango.MachineStudio.UI.ViewModels { IsFree = false; - if (UploadTFP) + if (DFU) { - _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU; } - else + else if (UploadTFP) { - _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU; + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.TFP_PACKAGE; + } + else if (DFUAndTFP) + { + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; } _stream = new FileStream(SelectedFile, FileMode.Open); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml index 9acd0386a..976c3866a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml @@ -66,7 +66,8 @@ DFU - DFU & Package + TFP Package + DFU & Package diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 020456bf1..f1d9487ff 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -46,7 +46,7 @@ namespace Tango.Emulations.Emulators public bool Canceled { get; set; } } - private const int MAX_CHUNK_LENGTH = 1024 * 10; + private const int MAX_CHUNK_LENGTH = 4000; private StartDiagnosticsRequest _diagnosticsRequest; private bool _cancelJob; private List _motorJoggingRequestTypes; diff --git a/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs b/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs index 8ef9aee5f..4e80dc2e6 100644 --- a/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs @@ -32,6 +32,11 @@ namespace Tango.Transport /// public Func Serialize { get; set; } + /// + /// Gets or sets the activate timeout callback. + /// + public Action ActivateTimeout { get; set; } + /// /// Gets or sets the message. /// diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs index 03188b71f..fe7d8a249 100644 --- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs @@ -329,20 +329,24 @@ namespace Tango.Transport TaskCompletionSource source = new TaskCompletionSource(); TransportMessage message = new TransportMessage(container.Token, request, TransportMessageDirection.Request, () => container.ToByteArray(), source); - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - - if (!source.Task.IsCompleted) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request task exception...", LogCategory.Debug); - source.SetException(ex); - } - }, timeout != null ? timeout.Value : RequestTimeout); + if (!source.Task.IsCompleted) + { + TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request task exception...", LogCategory.Debug); + source.SetException(ex); + } + + }, timeout != null ? timeout.Value : RequestTimeout); + }; + + EnqueueMessageOut(message); return source.Task; } @@ -399,20 +403,25 @@ namespace Tango.Transport TaskCompletionSource source = new TaskCompletionSource(); TransportMessage message = new TransportMessage(container.Token, container, TransportMessageDirection.Request, () => container.ToByteArray(), source); - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - - if (!source.Task.IsCompleted) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + container.Type + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request task exception...", LogCategory.Debug); - source.SetException(ex); - } - }, timeout != null ? timeout.Value : RequestTimeout); + if (!source.Task.IsCompleted) + { + TimeoutException ex = new TimeoutException("Request message: " + container.Type + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request task exception...", LogCategory.Debug); + source.SetException(ex); + } + + }, timeout != null ? timeout.Value : RequestTimeout); + + }; + + EnqueueMessageOut(message); return source.Task; } @@ -489,20 +498,26 @@ namespace Tango.Transport IsContinuous = true, ContinuesResponseSubject = subject, }; - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - if (!message.AtLeastOneResponseReceived) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request exception...", LogCategory.Debug); - message.SetException(ex); - } - }, timeout != null ? timeout.Value : RequestTimeout); + if (!message.AtLeastOneResponseReceived) + { + TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request exception...", LogCategory.Debug); + message.SetException(ex); + } + + }, timeout != null ? timeout.Value : RequestTimeout); + + }; + + EnqueueMessageOut(message); return subject.AsObservable(); } @@ -524,20 +539,24 @@ namespace Tango.Transport TaskCompletionSource> source = new TaskCompletionSource>(); TransportMessage> message = new TransportMessage>(request.Container.Token, request, TransportMessageDirection.Request, () => Encoder.Encode(request), source); - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - - if (!source.Task.IsCompleted) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + typeof(Request).Name + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request task exception...", LogCategory.Debug); - source.SetException(ex); - } - }, timeout != null ? timeout.Value : RequestTimeout); + if (!source.Task.IsCompleted) + { + TimeoutException ex = new TimeoutException("Request message: " + typeof(Request).Name + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request task exception...", LogCategory.Debug); + source.SetException(ex); + } + + }, timeout != null ? timeout.Value : RequestTimeout); + }; + + EnqueueMessageOut(message); return source.Task; } @@ -569,44 +588,48 @@ namespace Tango.Transport IsContinuous = true, ContinuesResponseSubject = subject, }; - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - - if (!message.AtLeastOneResponseReceived) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + typeof(Request).Name + " had timed out after " + (firstTimeout != null ? firstTimeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request exception...", LogCategory.Debug); - message.SetException(ex); - } - if (continousTimeout != null) - { - Task.Factory.StartNew(async () => + if (!message.AtLeastOneResponseReceived) + { + TimeoutException ex = new TimeoutException("Request message: " + typeof(Request).Name + " had timed out after " + (firstTimeout != null ? firstTimeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request exception...", LogCategory.Debug); + message.SetException(ex); + } + + if (continousTimeout != null) { - while (!message.Completed) + Task.Factory.StartNew(async () => { - await Task.Delay(continousTimeout.Value).ContinueWith((y) => + while (!message.Completed) { - if (!message.Completed) + await Task.Delay(continousTimeout.Value).ContinueWith((y) => { - if (DateTime.Now - message.LastResponseTime > continousTimeout.Value) + if (!message.Completed) { - TimeoutException ex = new TimeoutException("Continuous request message: " + typeof(Request).Name + " had failed to provide a response for a period of " + (continousTimeout.Value.TotalSeconds) + " seconds and has timed out."); - LogManager.Log(ex); - LogManager.Log("Setting request exception...", LogCategory.Debug); - message.SetException(ex); - return; + if (DateTime.Now - message.LastResponseTime > continousTimeout.Value) + { + TimeoutException ex = new TimeoutException("Continuous request message: " + typeof(Request).Name + " had failed to provide a response for a period of " + (continousTimeout.Value.TotalSeconds) + " seconds and has timed out."); + LogManager.Log(ex); + LogManager.Log("Setting request exception...", LogCategory.Debug); + message.SetException(ex); + return; + } } - } - }); - } - }); - } + }); + } + }); + } + + }, firstTimeout != null ? firstTimeout.Value : RequestTimeout); + }; - }, firstTimeout != null ? firstTimeout.Value : RequestTimeout); + EnqueueMessageOut(message); return subject.AsObservable(); } @@ -635,44 +658,48 @@ namespace Tango.Transport IsContinuous = true, ContinuesResponseSubject = subject, }; - EnqueueMessageOut(message); - TimeoutTask.StartNew(() => + message.ActivateTimeout = () => { - - if (!message.AtLeastOneResponseReceived) + TimeoutTask.StartNew(() => { - TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); - LogManager.Log(ex); - LogManager.Log("Setting request exception...", LogCategory.Debug); - message.SetException(ex); - } - if (continuousTimeout != null) - { - Task.Factory.StartNew(async () => + if (!message.AtLeastOneResponseReceived) { - while (!message.Completed) + TimeoutException ex = new TimeoutException("Request message: " + requestName + " had timed out after " + (timeout != null ? timeout.Value.TotalSeconds : RequestTimeout.TotalSeconds) + " seconds."); + LogManager.Log(ex); + LogManager.Log("Setting request exception...", LogCategory.Debug); + message.SetException(ex); + } + + if (continuousTimeout != null) + { + Task.Factory.StartNew(async () => { - await Task.Delay(continuousTimeout.Value).ContinueWith((y) => + while (!message.Completed) { - if (!message.Completed) + await Task.Delay(continuousTimeout.Value).ContinueWith((y) => { - if (DateTime.Now - message.LastResponseTime > continuousTimeout.Value) + if (!message.Completed) { - TimeoutException ex = new TimeoutException("Continuous request message: " + requestName + " had failed to provide a response for a period of " + (continuousTimeout.Value.TotalSeconds) + " seconds and has timed out."); - LogManager.Log(ex); - LogManager.Log("Setting request exception...", LogCategory.Debug); - message.SetException(ex); - return; + if (DateTime.Now - message.LastResponseTime > continuousTimeout.Value) + { + TimeoutException ex = new TimeoutException("Continuous request message: " + requestName + " had failed to provide a response for a period of " + (continuousTimeout.Value.TotalSeconds) + " seconds and has timed out."); + LogManager.Log(ex); + LogManager.Log("Setting request exception...", LogCategory.Debug); + message.SetException(ex); + return; + } } - } - }); - } - }); - } + }); + } + }); + } - }, timeout != null ? timeout.Value : RequestTimeout); + }, timeout != null ? timeout.Value : RequestTimeout); + }; + + EnqueueMessageOut(message); return subject.AsObservable(); } @@ -853,6 +880,9 @@ namespace Tango.Transport } Adapter.Write(message.Serialize()); + + message.ActivateTimeout?.Invoke(); + LogManager.Log("Message sent on adapter: " + Adapter.Address + "...", LogCategory.Debug, message.Message); } else -- cgit v1.3.1