Browse Source

10076

qianyi
shanji 2 years ago
parent
commit
91bdcf957a
  1. 25
      BBWY.Client/App.xaml.cs
  2. 53
      BBWY.Client/Helpers/MemoryHelper.cs
  3. 2
      BBWY.Client/Views/MainWindow.xaml

25
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)
{

53
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
{
/// <summary>
/// 获取token
/// </summary>
/// <returns></returns>
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;
}
}
}
}

2
BBWY.Client/Views/MainWindow.xaml

@ -26,7 +26,7 @@
<!--<TextBlock Text="{Binding GlobalContext.User.TeamName}" Margin="5,0,0,0"/>
<TextBlock Text="{Binding GlobalContext.User.Shop.Platform}" Margin="5,0,0,0"/>-->
<TextBlock Text="{Binding GlobalContext.User.Shop.ShopName}" Margin="5,0,0,0"/>
<TextBlock Text="v10075" Margin="5,0,0,0"/>
<TextBlock Text="v10076" Margin="5,0,0,0"/>
</StackPanel>
</Border>
<Grid Grid.Row="1">

Loading…
Cancel
Save