From 91bdcf957ab4fdfa7d75249d9ca8a6a7c6f3f10e Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 1 Feb 2023 20:12:29 +0800 Subject: [PATCH] 10076 --- BBWY.Client/App.xaml.cs | 25 +++++++++----- BBWY.Client/Helpers/MemoryHelper.cs | 53 +++++++++++++++++++++++++++++ BBWY.Client/Views/MainWindow.xaml | 2 +- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 BBWY.Client/Helpers/MemoryHelper.cs diff --git a/BBWY.Client/App.xaml.cs b/BBWY.Client/App.xaml.cs index bb9da2a8..efed654d 100644 --- a/BBWY.Client/App.xaml.cs +++ b/BBWY.Client/App.xaml.cs @@ -16,6 +16,7 @@ using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Windows; +using Utils; namespace BBWY.Client { @@ -161,17 +162,23 @@ namespace BBWY.Client public (bool isOk, string content) ReadMMF(string mapname) { + try { - using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname)) - { - using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite)) - { - StreamReader reader = new StreamReader(mmfStream); - string jwt = reader.ReadToEnd().Replace("\0", "").TrimEnd(); - return (true, jwt); - } - } + var token = MemoryHelper.GetMemoryToken(); + if (string.IsNullOrEmpty(token)) + return (false, "token为空"); + else + return (true, token); + //using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname)) + //{ + // using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite)) + // { + // StreamReader reader = new StreamReader(mmfStream); + // string jwt = reader.ReadToEnd().Replace("\0", "").TrimEnd(); + // return (true, jwt); + // } + //} } catch (Exception ex) { diff --git a/BBWY.Client/Helpers/MemoryHelper.cs b/BBWY.Client/Helpers/MemoryHelper.cs new file mode 100644 index 00000000..f4ce52c1 --- /dev/null +++ b/BBWY.Client/Helpers/MemoryHelper.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.MemoryMappedFiles; +using System.IO.Pipes; +using System.Text; +using System.Windows; + +namespace Utils +{ + public class MemoryHelper + { + /// + /// 获取token + /// + /// + public static string GetMemoryToken() + { + try + { + string pipeId = Environment.GetCommandLineArgs()[1]; + //创建输入类型匿名管道 + using (PipeStream pipeClient = new AnonymousPipeClientStream(PipeDirection.In, pipeId)) + { + using (StreamReader sr = new StreamReader(pipeClient)) + { + string temp; + + do + { + temp = sr.ReadLine(); + } + while (!temp.StartsWith("SYNC")); + + + while ((temp = sr.ReadLine()) != null) + { + return temp; + } + } + } + + return string.Empty; + } + catch (Exception ex) + { + return string.Empty; + } + + } + + } +} diff --git a/BBWY.Client/Views/MainWindow.xaml b/BBWY.Client/Views/MainWindow.xaml index d5973b3a..673f12e8 100644 --- a/BBWY.Client/Views/MainWindow.xaml +++ b/BBWY.Client/Views/MainWindow.xaml @@ -26,7 +26,7 @@ - +