From f8a6249414b2867a9690584804c63fe135e1cae1 Mon Sep 17 00:00:00 2001
From: shanj <18996038927@163.com>
Date: Wed, 1 Feb 2023 20:20:05 +0800
Subject: [PATCH] pjzs 10002
---
BBWY.Client/Views/MainWindow.xaml | 2 +-
PJZS/App.xaml.cs | 35 ++++++++++----------
PJZS/MainWindow.xaml | 2 +-
PJZS/MemoryHelper.cs | 53 +++++++++++++++++++++++++++++++
4 files changed, 73 insertions(+), 19 deletions(-)
create mode 100644 PJZS/MemoryHelper.cs
diff --git a/BBWY.Client/Views/MainWindow.xaml b/BBWY.Client/Views/MainWindow.xaml
index 673f12e8..95d68eeb 100644
--- a/BBWY.Client/Views/MainWindow.xaml
+++ b/BBWY.Client/Views/MainWindow.xaml
@@ -26,7 +26,7 @@
-
+
diff --git a/PJZS/App.xaml.cs b/PJZS/App.xaml.cs
index 8a699cda..bd92d274 100644
--- a/PJZS/App.xaml.cs
+++ b/PJZS/App.xaml.cs
@@ -12,6 +12,7 @@ using PJZS.Models;
using System.Linq;
using System.IO.MemoryMappedFiles;
using System.Diagnostics;
+using Utils;
namespace PJZS
{
@@ -38,13 +39,8 @@ namespace PJZS
//齐越山鸡
userToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNTM1MzMwMzI4ODkyMTQ5NzYwIiwidGVhbUlkIjoiMTUxNjk3NDI1MDU0MjUwMTg4OCIsInNvblRlYW1JZHMiOiIxNDM2Mjg4NTAwMjM1MjQzNTIwIiwiZXhwIjoxNjk0NjY5NjkxfQ.cSwro-7bGwOu92YejH9JhMenTai7Mvf99i2paQCmxIw";
#else
- var uid = e.Args.Count() > 0 ? e.Args.LastOrDefault(args => args.StartsWith("uid:")) : string.Empty;
- if (string.IsNullOrEmpty(uid))
- {
- MessageBox.Show("缺少启动参数", "提示");
- Environment.Exit(0);
- }
- var tokenResult = ReadMMF(uid);
+
+ var tokenResult = ReadMMF();
if (tokenResult.isOk)
userToken = tokenResult.content;
else
@@ -94,19 +90,24 @@ namespace PJZS
throw new NotImplementedException();
}
- public (bool isOk, string content) ReadMMF(string mapname)
+ public (bool isOk, string content) ReadMMF()
{
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/PJZS/MainWindow.xaml b/PJZS/MainWindow.xaml
index c4763bd4..04017908 100644
--- a/PJZS/MainWindow.xaml
+++ b/PJZS/MainWindow.xaml
@@ -27,7 +27,7 @@
-
+
diff --git a/PJZS/MemoryHelper.cs b/PJZS/MemoryHelper.cs
new file mode 100644
index 00000000..f4ce52c1
--- /dev/null
+++ b/PJZS/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;
+ }
+
+ }
+
+ }
+}