diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-24 16:47:42 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-24 16:47:42 +0300 |
| commit | 9b40c8f1474459b3db83fb89ccbd0810142f3222 (patch) | |
| tree | 5ee680edaf2c406085dbaa16b939f338aaae747a /Software/Visual_Studio | |
| parent | a749f032ba876742415c75a001894422f19cf146 (diff) | |
| download | Tango-9b40c8f1474459b3db83fb89ccbd0810142f3222.tar.gz Tango-9b40c8f1474459b3db83fb89ccbd0810142f3222.zip | |
FSE Log Viewer Custom Protocol.
Diffstat (limited to 'Software/Visual_Studio')
8 files changed, 216 insertions, 19 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/StartupArgsHelper.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/StartupArgsHelper.cs index 77bc7204b..81709e89f 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/StartupArgsHelper.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Helpers/StartupArgsHelper.cs @@ -9,18 +9,19 @@ namespace Tango.FSE.Common.Helpers { public static class StartupArgsHelper { - private static String FROM_WEB_PREFIX = "tango.fse:%5C%5C"; - public static String[] CleanArgsFromWeb(String[] args) { if (args != null && args.Length == 1) //Check for web custom protocol { - if (args[0].StartsWith(FROM_WEB_PREFIX)) + var match = Regex.Match(args[0], "%5C%5C(.+)"); + var groups = match.Groups.OfType<Group>().ToList(); + if (groups.Count == 2) { List<String> cleanArgs = new List<string>(); - String full = args[0].Replace(FROM_WEB_PREFIX, String.Empty).Replace("%20", " "); - String[] splitted = full.Split(' '); + String encodedData = groups[1].Value; + String decodedData = DecodeBase64String(encodedData); + String[] splitted = decodedData.Split(' '); foreach (var item in splitted) { @@ -33,5 +34,17 @@ namespace Tango.FSE.Common.Helpers return args; } + + public static String EncodeBase64String(String text) + { + var plainTextBytes = Encoding.UTF8.GetBytes(text); + return Convert.ToBase64String(plainTextBytes).Replace("=", "-"); + } + + public static String DecodeBase64String(String base64) + { + var base64EncodedBytes = Convert.FromBase64String(base64.Replace("-", "=")); + return Encoding.UTF8.GetString(base64EncodedBytes); + } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/App.xaml.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/App.xaml.cs index 05f20d822..82c2b0e4d 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/App.xaml.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/App.xaml.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; +using Newtonsoft.Json; +using System; using System.Linq; -using System.Threading.Tasks; +using System.Text.RegularExpressions; +using System.Threading; using System.Windows; +using ZetaIpc.Runtime.Client; namespace Tango.FSE.LogViewer.UI { @@ -13,5 +13,31 @@ namespace Tango.FSE.LogViewer.UI /// </summary> public partial class App : Application { + private static Mutex mutex = new Mutex(true, "{8F6F0AC4-B9A1-45fd-A8CF-TANGLOGVIEWR}"); + + public const int FILE_ASSPCIATION_PORT = 8989; + + protected override void OnStartup(StartupEventArgs e) + { + if (e.Args != null && e.Args.Length > 0) + { + if (mutex.WaitOne(TimeSpan.Zero, true)) + { + //This is the first instance. Do nothing... + mutex.ReleaseMutex(); + } + else + { + var ipcClient = new IpcClient(); + ipcClient.Initialize(FILE_ASSPCIATION_PORT); + ipcClient.Send(JsonConvert.SerializeObject(new ArgsObject() { Args = e.Args.ToList() })); + Thread.Sleep(1000); + Environment.Exit(0); + return; + } + } + + base.OnStartup(e); + } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ArgsObject.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ArgsObject.cs new file mode 100644 index 000000000..28afe02d9 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ArgsObject.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.LogViewer.UI +{ + public class ArgsObject + { + public List<String> Args { get; set; } + + public ArgsObject() + { + Args = new List<string>(); + } + } +} diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj index 5f72b9307..b66c33d7c 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj @@ -58,6 +58,7 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition> + <Compile Include="ArgsObject.cs" /> <Compile Include="Converters\PolygonTabToPointCollectionConverter.cs" /> <Compile Include="LogViewerViewModel.cs" /> <Compile Include="ViewModelLocator.cs" /> @@ -138,6 +139,12 @@ <PackageReference Include="MaterialDesignThemes"> <Version>3.0.1</Version> </PackageReference> + <PackageReference Include="Newtonsoft.Json"> + <Version>9.0.1</Version> + </PackageReference> + <PackageReference Include="ZetaIpc"> + <Version>1.0.0.9</Version> + </PackageReference> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs index 6513fa2d2..40d86bc32 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -12,12 +13,14 @@ using Tango.Core.Commands; using Tango.FSE.Common.Helpers; using Tango.Integration.Logging; using Tango.Logging; +using ZetaIpc.Runtime.Server; namespace Tango.FSE.LogViewer.UI.ViewModels { public class LayoutViewVM : LogViewerViewModel { private ICollectionView _view; + private IpcServer _ipcServer; public ObservableCollection<LogFileTabViewVM> LogFiles { get; set; } @@ -48,6 +51,7 @@ namespace Tango.FSE.LogViewer.UI.ViewModels SaveAsLogFileCommand = new RelayCommand(SaveAsLogFile); ExitCommand = new RelayCommand(ExitApplication); + _ipcServer = new IpcServer(); Application.Current.MainWindow.ContentRendered += MainWindow_ContentRendered; } @@ -223,7 +227,63 @@ namespace Tango.FSE.LogViewer.UI.ViewModels private void OnApplicationReady(List<string> args) { - + try + { + LogManager.Log("Starting file association IPC service..."); + _ipcServer.Start(App.FILE_ASSPCIATION_PORT); + _ipcServer.ReceivedRequest += _ipcServer_ReceivedRequest; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting file association IPC service. Another instance of the application might already be running..."); + } + + HandleStartupArgs(args); + } + + private void _ipcServer_ReceivedRequest(object sender, ReceivedRequestEventArgs e) + { + try + { + e.Handled = true; + var argsObject = JsonConvert.DeserializeObject<ArgsObject>(e.Request); + + InvokeUI(() => + { + if (Application.Current.MainWindow.WindowState == WindowState.Minimized) + { + Application.Current.MainWindow.WindowState = WindowState.Normal; + } + Application.Current.MainWindow.Activate(); + HandleStartupArgs(argsObject.Args); + }); + } + catch (Exception ex) + { + LogManager.Log(ex); + } + } + + private async void HandleStartupArgs(List<string> args) + { + if (args.Count == 3 && args[0] == "-remote") + { + MessageBox.Show($"TODO: Load From Remote, Type: {args[1]}, Work ID: {args[2]}"); + } + else + { + foreach (var file in args) + { + try + { + if (File.Exists(file)) + { + await OpenLogFile(file); + } + } + catch { } + } + } } } } 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 978a03f05..0203527b9 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/DefaultBugReporter.cs @@ -20,6 +20,7 @@ using Tango.FSE.Common.BugReporting; using Tango.FSE.Common.Connection; using Tango.FSE.Common.Connectivity; using Tango.FSE.Common.FSEApplication; +using Tango.FSE.Common.Helpers; using Tango.FSE.Common.Logging; using Tango.FSE.Common.Notifications; using Tango.FSE.Common.RemoteDesktop; @@ -161,6 +162,10 @@ namespace Tango.FSE.UI.BugReporting item.Type = WorkItemType.Bug; item.Environment = AuthenticationProvider.CurrentEnvironment.Description; + bool hasPPCLogs = false; + bool hasFirmwareLogs = false; + bool hasFSELogs = false; + FileLogger appFileLogger = LogManager.Default.RegisteredLoggers.FirstOrDefault(x => x.GetType() == typeof(FileLogger)) as FileLogger; if (appFileLogger != null) @@ -177,6 +182,8 @@ namespace Tango.FSE.UI.BugReporting FilePath = appLogFile.Path, Name = Path.GetFileName(file), }); + + hasFSELogs = true; } } @@ -218,6 +225,8 @@ namespace Tango.FSE.UI.BugReporting FilePath = ppcLogFilePath, Name = ppcLogFile.Name }); + + hasPPCLogs = true; } } catch (Exception ex) @@ -242,6 +251,8 @@ namespace Tango.FSE.UI.BugReporting FilePath = embeddedLogFilePath, Name = embeddedLogFile.Name }); + + hasFirmwareLogs = true; } } catch (Exception ex) @@ -353,7 +364,7 @@ namespace Tango.FSE.UI.BugReporting html = reader.ReadToEnd(); } - item.SystemInformation = CodeGeneration.Helper.Parse(html, sysModel); + item.SystemInformation = String.Empty; item.StepsToReproduce = String.Format("<div style=\"white-space:pre\">{0}</div>", item.StepsToReproduce); LogManager.Log("Uploading work item..."); @@ -361,6 +372,41 @@ namespace Tango.FSE.UI.BugReporting bug.URL = $"https://twinetfs.visualstudio.com/Tango/_workitems/edit/{workItem.ID}"; + if (hasFSELogs) + { + String encodedData = StartupArgsHelper.EncodeBase64String($"-remote FSE {workItem.ID}"); + sysModel.Actions.Add(new ActionModel() + { + Name = "Open FSE logs on Log Viewer", + Link = $@"Tango.FSE.LogViewer:\\{encodedData}", + }); + } + + if (hasPPCLogs) + { + String encodedData = StartupArgsHelper.EncodeBase64String($"-remote PPC {workItem.ID}"); + sysModel.Actions.Add(new ActionModel() + { + Name = "Open FSE logs on Log Viewer", + Link = $@"Tango.FSE.LogViewer:\\{encodedData}", + }); + } + + if (hasFirmwareLogs) + { + String encodedData = StartupArgsHelper.EncodeBase64String($"-remote Embedded {workItem.ID}"); + sysModel.Actions.Add(new ActionModel() + { + Name = "Open Firmware logs on Log Viewer", + Link = $@"Tango.FSE.LogViewer:\\{encodedData}", + }); + } + + String systemInformation = CodeGeneration.Helper.Parse(html, sysModel); + + LogManager.Log("Updating work item system information..."); + workItem = _tfsClient.UpdateWorkItemSystemInfo(Project, item, systemInformation).Result; + LogManager.Log("Deleting temporary folder..."); tempFolder.Delete(); diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/SystemInformationTemplate.cshtml b/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/SystemInformationTemplate.cshtml index 46a295c25..22f57bd98 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/SystemInformationTemplate.cshtml +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/BugReporting/SystemInformationTemplate.cshtml @@ -52,12 +52,16 @@ @if (vm.Actions.Count > 0) { - <div style="font-size:16pt;text-decoration:underline;margin-top:10px">Actions</div> + <div style="font-size:16pt;text-decoration:underline;margin-top:10px;margin-bottom:10px">Actions</div> <div> - @foreach (Tango.FSE.UI.BugReporting.ActionModel action in vm.Actions) - { - <a href="@action.Link">@action.Name</a> - } + <ul> + @foreach (Tango.FSE.UI.BugReporting.ActionModel action in vm.Actions) + { + <li> + <a href="@action.Link">@action.Name</a> + </li> + } + </ul> </div> } diff --git a/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs b/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs index a47b109b0..ed18241fb 100644 --- a/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs +++ b/Software/Visual_Studio/Tango.TFS/TeamFoundationServiceClient.cs @@ -602,7 +602,7 @@ namespace Tango.TFS { File.Delete(tempPath); } - catch {} + catch { } }); handler.Name = attachement.Name; @@ -670,6 +670,29 @@ namespace Tango.TFS }); } + public Task<WorkItem> UpdateWorkItemSystemInfo(Project project, WorkItem item, String systemInfo) + { + return Task.Factory.StartNew<WorkItem>(() => + { + var connection = CreateConnection(); + + WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>(); + + var patchDocument = new JsonPatchDocument(); + + patchDocument.Add(new JsonPatchOperation + { + Operation = Operation.Replace, + Path = GetExtensionFieldNameForWrite(ExtensionFields.SYSTEM_INFO), + Value = systemInfo, + }); + + var updatedItem = witClient.UpdateWorkItemAsync(patchDocument, item.ID).Result; + + return ConvertToWorkItem(project, updatedItem); + }); + } + /// <summary> /// Adds a comment to the work item discussion. /// </summary> |
