Skip to content

Commit

Permalink
添加库定义通讯
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Nov 16, 2023
1 parent d714c6e commit 8c39bad
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion demo/UnoDemo/IpcUno/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project ToolsVersion="15.0">
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageVersion Include="dotnetCampus.Ipc" Version="2.0.0-alpha409" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.2.23479.6" />
Expand Down Expand Up @@ -36,4 +37,4 @@
<PackageVersion Include="Uno.UITest.Helpers" Version="1.1.0-dev.70" />
<PackageVersion Include="Xamarin.UITest" Version="4.3.0" />
</ItemGroup>
</Project>
</Project>
47 changes: 47 additions & 0 deletions demo/UnoDemo/IpcUno/IpcUno/Business/Models/ConnectedPeerModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.ObjectModel;

using dotnetCampus.Ipc.Context;
using dotnetCampus.Ipc.Messages;
using dotnetCampus.Ipc.Pipes;

using Windows.ApplicationModel.Core;
using Windows.UI.Core;

namespace IpcUno.Business.Models
{
public class ConnectedPeerModel
{
public ConnectedPeerModel()
{
Peer = null!;
}

public ConnectedPeerModel(PeerProxy peer)
{
Peer = peer;
peer.MessageReceived += Peer_MessageReceived;
}

private void Peer_MessageReceived(object? sender, IPeerMessageArgs e)
{
var streamReader = new StreamReader(e.Message.Body.ToMemoryStream());
var message = streamReader.ReadToEnd();

_ = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AddMessage(PeerName, message);
});
}

public void AddMessage(string name, string message)
{
MessageList.Add($"{name} {DateTime.Now:yyyy/MM/dd hh:mm:ss.fff}:\r\n{message}");
}

public ObservableCollection<string> MessageList { get; } = new ObservableCollection<string>();

public PeerProxy Peer { get; }

public string PeerName => Peer.PeerName;
}
}
1 change: 1 addition & 0 deletions demo/UnoDemo/IpcUno/IpcUno/IpcUno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="dotnetCampus.Ipc" />
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Uno.Resizetizer" />
<PackageReference Include="CommunityToolkit.Mvvm" />
Expand Down

0 comments on commit 8c39bad

Please sign in to comment.