-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
demo/UnoDemo/IpcUno/IpcUno/Business/Models/ConnectedPeerModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters