Browse Source

集成咚咚启动器

qianyi
shanji 2 years ago
parent
commit
2ca9e5d143
  1. 80
      BBWY.Client/Helpers/PipeHelper.cs
  2. 10
      BBWY.Client/ViewModels/Order/OrderListViewModel.cs
  3. 21
      BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs
  4. 2
      BBWY.Client/Views/MainWindow.xaml

80
BBWY.Client/Helpers/PipeHelper.cs

@ -0,0 +1,80 @@
using BBWY.Common.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BBWY.Client.Helpers
{
public class PipeHelper: IDenpendency
{
public PipeHelper()
{
_pipeServerDictionary = new Dictionary<string, NamedPipeServerStream>();
}
private IDictionary<string, NamedPipeServerStream> _pipeServerDictionary;
public Action<string> ServerReceiveCallback;
private async Task WaitForClientConnectionsAsync(NamedPipeServerStream pipeServer)
{
while (true)
{
await pipeServer.WaitForConnectionAsync().ConfigureAwait(false);
try
{
const int bufferLength = 1024;
var buffer = new byte[bufferLength];
using (var stream = new MemoryStream())
{
while (true)
{
var bytesRead = await pipeServer.ReadAsync(buffer.AsMemory(0, bufferLength), CancellationToken.None).ConfigureAwait(false);
if (bytesRead == 0)
{
break;
}
stream.Write(buffer, 0, bytesRead);
}
stream.Seek(0, SeekOrigin.Begin);
ServerReceiveCallback?.Invoke(Encoding.UTF8.GetString(stream.ToArray()));
}
}
finally
{
pipeServer.Disconnect();
}
}
}
public void CreateServer(string pipeName)
{
var _pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 100, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly);
_ = WaitForClientConnectionsAsync(_pipeServer);
}
public void CloseServer(string pipeName)
{
if (_pipeServerDictionary.TryGetValue(pipeName, out NamedPipeServerStream pipeServer))
{
try
{
pipeServer.Disconnect();
pipeServer.Dispose();
pipeServer.Close();
_pipeServerDictionary.Remove(pipeName);
}
catch (Exception ex)
{
}
}
}
}
}

10
BBWY.Client/ViewModels/Order/OrderListViewModel.cs

@ -1,4 +1,5 @@
using BBWY.Client.APIServices; using BBWY.Client.APIServices;
using BBWY.Client.Helpers;
using BBWY.Client.Models; using BBWY.Client.Models;
using BBWY.Client.Views.Order; using BBWY.Client.Views.Order;
using BBWY.Common.Extensions; using BBWY.Common.Extensions;
@ -157,7 +158,7 @@ namespace BBWY.Client.ViewModels
/// </summary> /// </summary>
public bool IsSDGroup { get => isSDGroup; set { Set(ref isSDGroup, value); } } public bool IsSDGroup { get => isSDGroup; set { Set(ref isSDGroup, value); } }
public OrderListViewModel(OrderService orderService, StatisticsService statisticsService, AfterOrderService afterOrderService, GlobalContext globalContext, ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel) public OrderListViewModel(OrderService orderService, StatisticsService statisticsService, AfterOrderService afterOrderService, GlobalContext globalContext, ChoosePurchaseSchemeViewModel choosePurchaseSchemeViewModel, PipeHelper pipeHelper)
{ {
IsSDGroup = globalContext.User.TeamName == "刷单组"; IsSDGroup = globalContext.User.TeamName == "刷单组";
if (IsSDGroup) if (IsSDGroup)
@ -171,6 +172,7 @@ namespace BBWY.Client.ViewModels
} }
random = new Random(); random = new Random();
this.pipeHelper = pipeHelper;
this.globalContext = globalContext; this.globalContext = globalContext;
this.orderService = orderService; this.orderService = orderService;
this.statisticsService = statisticsService; this.statisticsService = statisticsService;
@ -182,7 +184,7 @@ namespace BBWY.Client.ViewModels
StartDate = DateTime.Now.Date; StartDate = DateTime.Now.Date;
ToDayOrderAchievement = new ToDayOrderAchievement(); ToDayOrderAchievement = new ToDayOrderAchievement();
InitSearchParam(); InitSearchParam();
InitDongDong();
SetOrderStateCommand = new RelayCommand<OrderState?>(SetOrderState); SetOrderStateCommand = new RelayCommand<OrderState?>(SetOrderState);
SearchOrderCommand = new RelayCommand(() => SearchOrderCommand = new RelayCommand(() =>
{ {
@ -1092,8 +1094,8 @@ namespace BBWY.Client.ViewModels
} }
} }
else else
{ {
} }
} }
} }

21
BBWY.Client/ViewModels/Order/OrderListVoewModel_DongDong.cs

@ -0,0 +1,21 @@
using BBWY.Client.Helpers;
using System;
namespace BBWY.Client.ViewModels
{
public partial class OrderListViewModel
{
private PipeHelper pipeHelper;
public void InitDongDong()
{
pipeHelper.ServerReceiveCallback = OnDongDongSendMessage;
pipeHelper.CreateServer("bbwyPipeServer");
}
private void OnDongDongSendMessage(string msg)
{
Console.WriteLine(msg);
}
}
}

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.TeamName}" Margin="5,0,0,0"/>
<TextBlock Text="{Binding GlobalContext.User.Shop.Platform}" 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="{Binding GlobalContext.User.Shop.ShopName}" Margin="5,0,0,0"/>
<TextBlock Text="v10073" Margin="5,0,0,0"/> <TextBlock Text="v10074" Margin="5,0,0,0"/>
</StackPanel> </StackPanel>
</Border> </Border>
<Grid Grid.Row="1"> <Grid Grid.Row="1">

Loading…
Cancel
Save