From 178e25e4dba37decbcbc389955539997e0321df7 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 31 Jul 2020 19:28:46 +0300 Subject: Fixed total dye time formating on PPC and MS. --- .../Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs index 302c50e8e..30b2c83fd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -97,7 +97,7 @@ namespace Tango.MachineStudio.UI.ViewModels { var jobRuns = await db.JobRuns.Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync(); - TotalMachineWorkTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); + TotalMachineWorkTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours(); int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); TotalMachineMeters = $"{meters.ToString("N0")} meters"; -- cgit v1.3.1 From 67770063ff1a1c5c522e3bc29f442c42eb6dc521 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 23 Aug 2020 01:55:05 +0300 Subject: Fixed issue with Bson DateTime serialization. Added bug reports insights annotations. --- .../Modules/Tango.FSE.Firmware/Views/LogsView.xaml | 2 +- .../Modules/Tango.FSE.Insights/Themes/Generic.xaml | 80 +++++++++++++++++++++- .../ViewModels/InsightsViewVM.cs | 31 +++++++-- .../Tango.FSE.Insights/Views/InsightsView.xaml | 8 +-- .../Tango.FSE.PPCConsole/Views/LogsView.xaml | 2 +- .../FSE/Tango.FSE.Common/BugReporting/Bug.cs | 15 ++++ .../Tango.FSE.Common/BugReporting/IBugReporter.cs | 8 +++ .../Tango.FSE.Common/Insights/InsightsPackage.cs | 3 + .../Tango.FSE.Common/Insights/InsightsReadyBug.cs | 14 ++++ .../FSE/Tango.FSE.Common/Tango.FSE.Common.csproj | 1 + .../BugReporting/DefaultBugReporter.cs | 47 +++++++++++++ .../Insights/DefaultInsightsProvider.cs | 22 ++++++ .../ViewModels/MainViewVM.cs | 4 ++ .../Tango.TFS/TeamFoundationServiceClient.cs | 48 +++++++++++++ Software/Visual_Studio/Tango.TFS/WorkItem.cs | 2 + .../Tango.Transport/GenericMessageSerializer.cs | 64 +++++++++++++++-- 16 files changed, 331 insertions(+), 20 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyBug.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Firmware/Views/LogsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Firmware/Views/LogsView.xaml index 85f36de75..4d7f9f814 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Firmware/Views/LogsView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Firmware/Views/LogsView.xaml @@ -44,7 +44,7 @@ | - + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml index cf9c18b68..5426ba4ea 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Themes/Generic.xaml @@ -5,6 +5,7 @@ xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:commonInsights="clr-namespace:Tango.FSE.Common.Insights;assembly=Tango.FSE.Common" xmlns:ML="clr-namespace:Tango.FSE.Insights.ML" + xmlns:bugs="clr-namespace:Tango.FSE.Common.BugReporting;assembly=Tango.FSE.Common" xmlns:views="clr-namespace:Tango.FSE.Insights.Views" xmlns:local="clr-namespace:Tango.FSE.Diagnostics.Themes"> @@ -18,7 +19,7 @@ # Time: - + @@ -136,4 +137,81 @@ + + + + + + + Title: + + + Area: + + + Time: + + + Author: + + + Assigned To: + + + + Description + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs index b36ef163a..6ef92e525 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/ViewModels/InsightsViewVM.cs @@ -183,9 +183,11 @@ namespace Tango.FSE.Insights.ViewModels #region Commands - public RelayCommand PeekApplicationLogsCommand { get; set; } + public RelayCommand PeekApplicationLogsCommand { get; set; } - public RelayCommand PeekFirmwareLogsCommand { get; set; } + public RelayCommand PeekFirmwareLogsCommand { get; set; } + + public RelayCommand OpenBugReportCommand { get; set; } public RelayCommand AnalyzeCommand { get; set; } @@ -205,8 +207,9 @@ namespace Tango.FSE.Insights.ViewModels VisibleCharts = new ObservableCollection(); Annotations = new AnnotationCollection(); GetInsightsCommand = new RelayCommand(GetInsights, () => IsFree); - PeekApplicationLogsCommand = new RelayCommand(PeekAnnotationApplicationLogs); - PeekFirmwareLogsCommand = new RelayCommand(PeekAnnotationFirmwareLogs); + PeekApplicationLogsCommand = new RelayCommand(PeekAnnotationApplicationLogs); + PeekFirmwareLogsCommand = new RelayCommand(PeekAnnotationFirmwareLogs); + OpenBugReportCommand = new RelayCommand(OpenAnnotationBugReport); AnalyzeCommand = new RelayCommand(Analyze, () => InsightsPackage != null); } @@ -492,7 +495,7 @@ namespace Tango.FSE.Insights.ViewModels { var y = 0.05; - foreach (var insight in package.Events.Cast().Concat(package.Statuses).OrderBy(x => x.Time)) + foreach (var insight in package.Events.Cast().Concat(package.Statuses).Concat(package.Bugs).OrderBy(x => x.Time)) { CustomAnnotation annotation = new CustomAnnotation(); annotation.X1 = insight.Time.ToLocalTime(); @@ -509,6 +512,11 @@ namespace Tango.FSE.Insights.ViewModels annotation.Content = status; annotation.ContentTemplate = Application.Current.Resources["InsightStatusTemplate"] as DataTemplate; } + else if (insight is InsightsReadyBug bug) + { + annotation.Content = bug; + annotation.ContentTemplate = Application.Current.Resources["InsightBugTemplate"] as DataTemplate; + } Annotations.Add(annotation); @@ -525,7 +533,7 @@ namespace Tango.FSE.Insights.ViewModels #region Logs Peeking - private async void PeekAnnotationFirmwareLogs(InsightsReadyEvent ev) + private async void PeekAnnotationFirmwareLogs(InsightReadyBase ev) { using (NotificationProvider.PushTaskItem("Peeking firmware logs...")) { @@ -534,7 +542,7 @@ namespace Tango.FSE.Insights.ViewModels } } - private async void PeekAnnotationApplicationLogs(InsightsReadyEvent ev) + private async void PeekAnnotationApplicationLogs(InsightReadyBase ev) { using (NotificationProvider.PushTaskItem("Peeking application logs...")) { @@ -545,6 +553,15 @@ namespace Tango.FSE.Insights.ViewModels #endregion + #region Bug Report + + private void OpenAnnotationBugReport(InsightsReadyBug bug) + { + Process.Start(bug.Bug.URL); + } + + #endregion + #region Event Handlers private async void MachineProvider_MachineConnected(object sender, Common.Connection.MachineConnectedEventArgs e) diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Views/InsightsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Views/InsightsView.xaml index 65246662e..a0b8909fc 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Views/InsightsView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Insights/Views/InsightsView.xaml @@ -133,7 +133,7 @@ - + - + - + @@ -164,7 +164,7 @@ - + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/Views/LogsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/Views/LogsView.xaml index fe2c205f1..d78cfd311 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/Views/LogsView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/Views/LogsView.xaml @@ -44,7 +44,7 @@ | - + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/Bug.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/Bug.cs index 667c1fd90..57e9fc0fe 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/Bug.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/Bug.cs @@ -18,6 +18,11 @@ namespace Tango.FSE.Common.BugReporting /// public String URL { get; set; } + /// + /// Gets or sets the creation date. + /// + public DateTime CreatedDate { get; set; } + /// /// Gets or sets the bug type. /// @@ -53,6 +58,16 @@ namespace Tango.FSE.Common.BugReporting /// public TeamMember AssignedTo { get; set; } + /// + /// Gets or sets the team member who created the bug. + /// + public TeamMember CreatedBy { get; set; } + + /// + /// Gets or sets the actual logged in user. + /// + public String LoggedInUser { get; set; } + /// /// Gets or sets the area. /// diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/IBugReporter.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/IBugReporter.cs index e0bafdb54..fbbaf84e3 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/IBugReporter.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/BugReporting/IBugReporter.cs @@ -30,5 +30,13 @@ namespace Tango.FSE.Common.BugReporting /// /// Task ShowBugReportDialog(); + + /// + /// Gets the connected machine bugs. + /// + /// The start date. + /// The end date. + /// + Task> GetConnectedMachineBugs(DateTime start, DateTime end); } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs index 25e375b4c..3f57a50d9 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsPackage.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.FSE.Common.BugReporting; using Tango.Insights; namespace Tango.FSE.Common.Insights @@ -13,12 +14,14 @@ namespace Tango.FSE.Common.Insights public List Frames { get; set; } public List Events { get; set; } public List Statuses { get; set; } + public List Bugs { get; set; } public InsightsPackage() { Frames = new List(); Events = new List(); Statuses = new List(); + Bugs = new List(); } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyBug.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyBug.cs new file mode 100644 index 000000000..977fb1582 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Insights/InsightsReadyBug.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.FSE.Common.BugReporting; + +namespace Tango.FSE.Common.Insights +{ + public class InsightsReadyBug : InsightReadyBase + { + public Bug Bug { get; set; } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj index 64a165530..b89d30f82 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj @@ -228,6 +228,7 @@ + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs index a99752091..978a03f05 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs @@ -104,6 +104,8 @@ namespace Tango.FSE.UI.BugReporting var tempFolder = TemporaryManager.CreateFolder(); item.Title = bug.Title; + item.Description = bug.Description; + item.LoggedInUser = AuthenticationProvider.CurrentUser.Email; if (bug.Area != null) { @@ -586,5 +588,50 @@ namespace Tango.FSE.UI.BugReporting } } } + + public async Task> GetConnectedMachineBugs(DateTime start, DateTime end) + { + List list = new List(); + + if (!MachineProvider.IsConnected) + { + LogManager.Log("Could not get connected machine bugs while machine is not connected.", LogCategory.Warning); + return new List(); + } + + try + { + if (!_isInitialized) + { + await Initialize(); + } + + var workItems = await _tfsClient.GetWorkItemsForMachine(Project, MachineProvider.Machine.SerialNumber); + + if (workItems.Count > 0) + { + return workItems.Where(x => x.CreatedDate >= start && x.CreatedDate <= end).Select(x => new Bug() + { + Area = x.Area, + AssignedTo = x.AssignedTo, + CreatedBy = x.CreatedBy, + Comments = x.Comment, + CreatedDate = x.CreatedDate, + Description = x.Description, + StepsToReproduce = x.StepsToReproduce, + Title = x.Title, + LoggedInUser = x.LoggedInUser, + Type = BugType.PPC, + URL = $"https://twinetfs.visualstudio.com/Tango/_workitems/edit/{x.ID}" + }).ToList(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not get machine work items from VSTS."); + } + + return list; + } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs index a4958f25d..5b17bd5e0 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Insights/DefaultInsightsProvider.cs @@ -4,9 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.Core; using Tango.Core.DI; using Tango.FSE.BL; +using Tango.FSE.Common.Authentication; +using Tango.FSE.Common.BugReporting; using Tango.FSE.Common.Connection; using Tango.FSE.Common.FileSystem; using Tango.FSE.Common.Insights; @@ -22,12 +25,18 @@ namespace Tango.FSE.UI.Insights private IMachineProvider MachineProvider { get; set; } + [TangoInject] + private IAuthenticationProvider AuthenticationProvider { get; set; } + [TangoInject] private IFileSystemProvider FileSystemProvider { get; set; } [TangoInject] private FSEServicesContainer Services { get; set; } + [TangoInject] + public IBugReporter BugReporter { get; set; } + public DefaultInsightsProvider(IMachineProvider machineProvider) { MachineProvider = machineProvider; @@ -133,6 +142,19 @@ namespace Tango.FSE.UI.Insights }); } + if (AuthenticationProvider.CurrentUser.HasPermission(Permissions.FSE_ModifyBugReport)) + { + try + { + var bugs = BugReporter.GetConnectedMachineBugs(startDateUTC, endTimeUTC).Result; + package.Bugs = bugs.Select(bug => new InsightsReadyBug() { Time = bug.CreatedDate, Bug = bug }).ToList(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error retrieving connected machine bugs for insights."); + } + } + handler.RaiseCompleted(package); } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 0e02d779f..6ddfee545 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -600,6 +600,10 @@ namespace Tango.MachineStudio.UI.ViewModels Intent = config.Intent, UserName = AuthenticationProvider.CurrentUser.Contact.FullName, RequireSafetyLevelOperations = config.RequireSafetyOperations + }, new PMR.Integration.ConfigureProtocolRequest() + { + EnableCompression = true, + GenericProtocol = PMR.Integration.GenericMessageProtocol.Bson }); _reconnectionMachine = machine; diff --git a/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs b/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs index 766f2da1e..27e92b740 100644 --- a/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs +++ b/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs @@ -37,6 +37,7 @@ namespace Tango.TFS public const String EMBEDDED_VERSION = "Custom.EmbeddedVersion"; public const String MACHINE_SN = "Custom.MachineSN"; public const String ENVIRONMENT = "Custom.Environment"; + public const String LOGGED_IN_USER = "Custom.LoggedInUser"; } #endregion @@ -415,6 +416,16 @@ namespace Tango.TFS }); } + if (workItem.LoggedInUser != null) + { + patchDocument.Add(new JsonPatchOperation + { + Operation = Operation.Add, + Path = GetExtensionFieldNameForWrite(ExtensionFields.LOGGED_IN_USER), + Value = workItem.LoggedInUser, + }); + } + var resultWorkItem = witClient.CreateWorkItemAsync(patchDocument, project.Name, workItem.Type.ToString(), bypassRules: true).Result; workItem.ID = resultWorkItem.Id.Value; @@ -544,6 +555,28 @@ namespace Tango.TFS }); } + public Task> GetWorkItemsForMachine(Project project, String serialNumber) + { + return Task.Factory.StartNew>(() => + { + var connection = CreateConnection(); + + var projCollection = new TfsTeamProjectCollection(new Uri(CollectionURL), connection.Credentials); + var store = projCollection.GetService(); + + WorkItemCollection queryResults = store.Query($"Select [Id] From WorkItems Where {ExtensionFields.MACHINE_SN} = '{serialNumber}' And [Work Item Type] = 'Bug'"); + var ids = queryResults.OfType().Where(x => x.Project.Name == project.Name).ToList().Select(x => x.Id).ToList(); + + if (ids.Count == 0) return new List(); + + WorkItemTrackingHttpClient witClient = connection.GetClient(); + + var items = witClient.GetWorkItemsAsync(ids).Result; + + return items.Select(x => ConvertToWorkItem(project, x)).ToList(); + }); + } + /// /// Sets the state of the work item. /// @@ -789,6 +822,21 @@ namespace Tango.TFS workItem.SystemInformation = TryGetField(item.Fields, ExtensionFields.SYSTEM_INFO).ToString(); } + if (item.Fields.ContainsKey(ExtensionFields.LOGGED_IN_USER)) + { + workItem.LoggedInUser = TryGetField(item.Fields, ExtensionFields.LOGGED_IN_USER).ToString(); + } + + if (item.Fields.ContainsKey(ExtensionFields.MACHINE_SN)) + { + workItem.MachineSerialNumber = TryGetField(item.Fields, ExtensionFields.MACHINE_SN).ToString(); + } + + if (item.Fields.ContainsKey(ExtensionFields.ENVIRONMENT)) + { + workItem.Environment = TryGetField(item.Fields, ExtensionFields.ENVIRONMENT).ToString(); + } + workItem.Comment = TryGetField(item.Fields, GetFieldNameForRead(CoreField.History)).ToString(); return workItem; diff --git a/Software/Visual_Studio/Tango.TFS/WorkItem.cs b/Software/Visual_Studio/Tango.TFS/WorkItem.cs index ef80fc217..35c2f8669 100644 --- a/Software/Visual_Studio/Tango.TFS/WorkItem.cs +++ b/Software/Visual_Studio/Tango.TFS/WorkItem.cs @@ -197,6 +197,8 @@ namespace Tango.TFS set { _comment = value; RaisePropertyChangedAuto(); } } + public String LoggedInUser { get; set; } + public bool IsBuildVersionValid { get diff --git a/Software/Visual_Studio/Tango.Transport/GenericMessageSerializer.cs b/Software/Visual_Studio/Tango.Transport/GenericMessageSerializer.cs index 50c4221ab..bb483e19a 100644 --- a/Software/Visual_Studio/Tango.Transport/GenericMessageSerializer.cs +++ b/Software/Visual_Studio/Tango.Transport/GenericMessageSerializer.cs @@ -1,9 +1,11 @@ using Google.Protobuf; using Newtonsoft.Json; using Newtonsoft.Json.Bson; +using Newtonsoft.Json.Serialization; using ProtoBuf; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -16,8 +18,61 @@ namespace Tango.Transport { public static class GenericMessageSerializer { + private class DateTimeConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return typeof(DateTime) == objectType + || typeof(DateTime?) == objectType; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var dateTimeOffset = (DateTime)value; + // Serialize DateTimeOffset as round-trip formatted string + serializer.Serialize(writer, dateTimeOffset.ToString("O")); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Date) + return null; + + DateTime dt; + + var dateWithOffset = (String)reader.Value; + + if (String.IsNullOrEmpty(dateWithOffset)) + return null; + + if (DateTime.TryParseExact(dateWithOffset, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dt)) + return dt; + + return null; + } + + } + + private class DateTimeContractResolver : DefaultContractResolver + { + protected override JsonContract CreateContract(Type objectType) + { + var contract = base.CreateContract(objectType); + + if (objectType == typeof(DateTime) || objectType == typeof(DateTime?)) + contract.Converter = new DateTimeConverter(); + + return contract; + } + } + + private static JsonSerializer _serializer; + static GenericMessageSerializer() { + _serializer = new JsonSerializer() { ContractResolver = new DateTimeContractResolver() }; + _serializer.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind; + ProtoBuf.Meta.RuntimeTypeModel.Default.AutoAddMissingTypes = true; ProtoBuf.Meta.RuntimeTypeModel.Default.AutoAddProtoContractTypesOnly = false; ProtoBuf.Meta.RuntimeTypeModel.Default.InferTagFromNameDefault = true; @@ -158,8 +213,7 @@ namespace Tango.Transport MemoryStream ms = new MemoryStream(); using (BsonWriter writer = new BsonWriter(ms)) { - JsonSerializer serializer = new JsonSerializer(); - serializer.Serialize(writer, obj); + _serializer.Serialize(writer, obj); return ms.ToArray(); } } @@ -169,8 +223,7 @@ namespace Tango.Transport MemoryStream ms = new MemoryStream(data); using (BsonReader reader = new BsonReader(ms)) { - JsonSerializer serializer = new JsonSerializer(); - Object obj = serializer.Deserialize(reader, type); + Object obj = _serializer.Deserialize(reader, type); return obj; } } @@ -180,8 +233,7 @@ namespace Tango.Transport MemoryStream ms = new MemoryStream(data); using (BsonReader reader = new BsonReader(ms)) { - JsonSerializer serializer = new JsonSerializer(); - T obj = serializer.Deserialize(reader); + T obj = _serializer.Deserialize(reader); return obj; } } -- cgit v1.3.1 From 07173155f536396f80501839b336adac76c90f7b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 25 Aug 2020 02:49:54 +0300 Subject: Removed all application event logging from MS. --- .../Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs | 4 ++-- .../Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs | 8 ++++---- .../StudioApplication/DefaultStudioApplicationManager.cs | 2 +- .../Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs index bbe5432e9..bb9608f6b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs @@ -382,7 +382,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels using (_notification.PushTaskItem("Starting Recording...")) { Recorder.Start(); - _eventLogger.Log(EventTypes.RECORDING_STARTED, "Recording Started..."); + //_eventLogger.Log(EventTypes.RECORDING_STARTED, "Recording Started..."); _recordingBarItem.Push(); } @@ -398,7 +398,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels await Recorder.Stop(); _recordingBarItem.Pop(); - _eventLogger.Log(EventTypes.RECORDING_STOPPED, "Recording Stopped..."); + //_eventLogger.Log(EventTypes.RECORDING_STOPPED, "Recording Stopped..."); } String recordingName = _notification.ShowTextInput("Enter recording name", "Recording name"); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index f1a205f5d..613b443df 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -194,10 +194,10 @@ namespace Tango.MachineStudio.Common.EventLogging /// The events. private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable events) { - foreach (var ev in events) - { - Log(String.Format("Event '{0}' resolved.", ev.EventType.Name)); - } + //foreach (var ev in events) + //{ + // Log(String.Format("Event '{0}' resolved.", ev.EventType.Name)); + //} } #endregion diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index ed5f8b394..56f2a2bc0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -293,7 +293,7 @@ namespace Tango.MachineStudio.UI.StudioApplication var eventLogger = TangoIOC.Default.GetInstance(); if (eventLogger != null) { - eventLogger.Log(EventTypes.APPLICATION_TERMINATED, "Application Terminated!"); + //eventLogger.Log(EventTypes.APPLICATION_TERMINATED, "Application Terminated!"); eventLogger.FlushAll(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 97ff894df..f4645ecf2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -263,7 +263,7 @@ namespace Tango.MachineStudio.UI.ViewModels return; } - _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); + //_eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); _navigationManager.NavigateTo(NavigationView.MainView); -- cgit v1.3.1 From 810bbfab7a812a0d9f0e46ff60d45280594a6716 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 8 Oct 2020 05:07:41 +0300 Subject: Implemented auto reconnection for USB on MS. --- .../DefaultStudioApplicationManager.cs | 4 +- .../Tango.MachineStudio.UI.csproj | 6 +- .../ViewModels/MainViewVM.cs | 81 +++++++++++++--------- 3 files changed, 55 insertions(+), 36 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 56f2a2bc0..feed9e193 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -132,8 +132,6 @@ namespace Tango.MachineStudio.UI.StudioApplication { if (e == Transport.TransportComponentState.Disconnected || e == Transport.TransportComponentState.Failed) { - bool reconnect = ConnectedMachine is IExternalBridgeSecureClient; - ConnectedMachine = null; if (e == Transport.TransportComponentState.Failed) @@ -147,7 +145,7 @@ namespace Tango.MachineStudio.UI.StudioApplication ConnectionLostViewVM vm = new ConnectionLostViewVM() { Exception = failed_reason, - AutoReconnect = reconnect, + AutoReconnect = true, }; InvokeUI(() => diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 78125cd8c..3783b54f8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -434,6 +434,10 @@ {63561e19-ff5a-414b-a5ef-e30711543e1d} Tango.Emulations + + {99081c0e-065c-4d68-bf60-f82330cca02d} + Tango.Git + {4206ac58-3b57-4699-8835-90bf6db01a61} Tango.Integration @@ -676,7 +680,7 @@ if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)Roslyn\" - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 6ddfee545..4f8c8a9b1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -58,8 +58,9 @@ namespace Tango.MachineStudio.UI.ViewModels private IEventLogger _eventLogger; private MachineStudioSettings _settings; private MachineStudioWebClient _machineStudioWebClient; - private IExternalBridgeSecureClient _reconnectionMachine; + private IExternalBridgeClient _reconnectionMachine; private MachineLoginViewVM _reconnectionMachineConfig; + private bool _lastUploadHardwareConfigLocal; /// /// Gets or sets the current loaded module. @@ -350,9 +351,16 @@ namespace Tango.MachineStudio.UI.ViewModels ApplicationManager.ReconnectionRequired += ApplicationManager_ReconnectionRequired; } - private void ApplicationManager_ReconnectionRequired(object sender, EventArgs e) + private async void ApplicationManager_ReconnectionRequired(object sender, EventArgs e) { - ConnectToMachineSecure(_reconnectionMachine, _reconnectionMachineConfig); + if (_reconnectionMachine is IExternalBridgeSecureClient client) + { + ConnectToMachineSecure(client, _reconnectionMachineConfig); + } + else + { + await ConnectToMachineLocal(_reconnectionMachine, _reconnectionMachine.Machine, _lastUploadHardwareConfigLocal); + } } private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable e) @@ -486,41 +494,15 @@ namespace Tango.MachineStudio.UI.ViewModels { if (vm.SelectedMachine != null) { - using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) - { - try - { - await x.SelectedMachine.Connect(); - x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; - ApplicationManager.SetConnectedMachine(x.SelectedMachine); - - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _settings.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; - _settings.Save(); - - if (x.UploadHardwareConfiguration) - { - UploadHardwareConfiguration(false); - } - } - catch (Exception ex) - { - LogManager.Log(ex); - - _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); - - } - - InvalidateRelayCommands(); - } + await ConnectToMachineLocal(x.SelectedMachine, vm.SelectedMachine, x.UploadHardwareConfiguration); } }); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); }); } else @@ -585,6 +567,41 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); } + private async Task ConnectToMachineLocal(IExternalBridgeClient client, Machine machine, bool uploadHardwareConfig) + { + using (NotificationProvider.PushTaskItem("Connecting to " + client.ToString() + "...")) + { + try + { + _reconnectionMachine = client; + + await client.Connect(); + client.SerialNumber = machine.SerialNumber; + ApplicationManager.SetConnectedMachine(client); + + PostMessage(new MachineConnectionChangedMessage() { Machine = client }); + _settings.LastVirtualMachineSerialNumber = machine.SerialNumber; + _settings.Save(); + + _lastUploadHardwareConfigLocal = uploadHardwareConfig; + + if (uploadHardwareConfig) + { + UploadHardwareConfiguration(false); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); + + } + + InvalidateRelayCommands(); + } + } + private async void ConnectToMachineSecure(IExternalBridgeSecureClient machine, MachineLoginViewVM config) { using (NotificationProvider.PushTaskItem("Connecting to machine " + machine.ToString() + "...")) -- cgit v1.3.1