Skip to content

Commit 4e01804

Browse files
committed
Replace ConcurrentList with BCL collections.
1 parent 11ac3a7 commit 4e01804

6 files changed

Lines changed: 33 additions & 290 deletions

File tree

Server/Components/Devices/ChatCard.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ private async Task HandleChatMessageReceived(ChatReceivedMessage message)
6868

6969
if (message.DidDisconnect)
7070
{
71-
session.ChatHistory.Add(new ChatHistoryItem()
71+
session.ChatHistory.Enqueue(new ChatHistoryItem()
7272
{
7373
Message = $"{Session.DeviceName} disconnected.",
7474
Origin = ChatHistoryItemOrigin.System
7575
});
7676
}
7777
else
7878
{
79-
session.ChatHistory.Add(new ChatHistoryItem()
79+
session.ChatHistory.Enqueue(new ChatHistoryItem()
8080
{
8181
Message = message.MessageText,
8282
Origin = ChatHistoryItemOrigin.Device
@@ -110,7 +110,7 @@ private async Task EvaluateInputKeypress(KeyboardEventArgs args)
110110

111111
await CircuitConnection.SendChat(_inputText, $"{Session.DeviceId}");
112112

113-
Session.ChatHistory.Add(new ChatHistoryItem()
113+
Session.ChatHistory.Enqueue(new ChatHistoryItem()
114114
{
115115
Origin = ChatHistoryItemOrigin.Self,
116116
Message = _inputText

Server/Components/Devices/ChatFrame.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private async Task HandleChatMessageReceived(ChatReceivedMessage message)
6666
IsExpanded = true
6767
};
6868

69-
newChat.ChatHistory.Add(new ChatHistoryItem()
69+
newChat.ChatHistory.Enqueue(new ChatHistoryItem()
7070
{
7171
Message = message.MessageText,
7272
Origin = ChatHistoryItemOrigin.Device

Server/Services/ToastService.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Remotely.Server.Enums;
22
using Remotely.Server.Models;
3-
using Remotely.Shared.Primitives;
43
using System;
4+
using System.Collections;
5+
using System.Collections.Concurrent;
6+
using System.Collections.Generic;
7+
using System.Linq;
58
using System.Timers;
69

710
namespace Remotely.Server.Services;
@@ -10,7 +13,7 @@ public interface IToastService
1013
{
1114
event EventHandler OnToastsChanged;
1215

13-
ConcurrentList<Toast> Toasts { get; }
16+
IEnumerable<Toast> Toasts { get; }
1417
void ShowToast(
1518
string message,
1619
int expirationMillisecond = 3000,
@@ -26,8 +29,20 @@ void ShowToast2(
2629

2730
public class ToastService : IToastService
2831
{
32+
private readonly object _lock = new();
33+
private readonly List<Toast> _toasts = new();
2934
public event EventHandler? OnToastsChanged;
30-
public ConcurrentList<Toast> Toasts { get; } = new();
35+
36+
public IEnumerable<Toast> Toasts
37+
{
38+
get
39+
{
40+
lock (_lock)
41+
{
42+
return _toasts.ToArray();
43+
}
44+
}
45+
}
3146

3247
public void ShowToast(string message,
3348
int expirationMillisecond = 3000,
@@ -46,7 +61,10 @@ public void ShowToast(string message,
4661
TimeSpan.FromMilliseconds(expirationMillisecond),
4762
styleOverrides);
4863

49-
Toasts.Add(toastModel);
64+
lock (_lock)
65+
{
66+
_toasts.Add(toastModel);
67+
}
5068

5169
OnToastsChanged?.Invoke(this, EventArgs.Empty);
5270

@@ -56,7 +74,10 @@ public void ShowToast(string message,
5674
};
5775
removeToastTimer.Elapsed += (s, e) =>
5876
{
59-
Toasts.Remove(toastModel);
77+
lock (_lock)
78+
{
79+
_toasts.Remove(toastModel);
80+
}
6081
OnToastsChanged?.Invoke(this, EventArgs.Empty);
6182
removeToastTimer.Dispose();
6283
};

Shared/Primitives/ConcurrentList.cs

Lines changed: 0 additions & 198 deletions
This file was deleted.

Shared/ViewModels/ChatSession.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Remotely.Shared.Primitives;
2-
using System;
1+
using System;
2+
using System.Collections.Concurrent;
33

44
namespace Remotely.Shared.ViewModels;
55

66
public class ChatSession
77
{
8-
public ConcurrentList<ChatHistoryItem> ChatHistory { get; } = new();
8+
public ConcurrentQueue<ChatHistoryItem> ChatHistory { get; } = new();
99
public string? DeviceId { get; set; }
1010
public string? DeviceName { get; set; }
1111
public string ExpandedClass => IsExpanded ? "expanded" : "";

Tests/Shared.Tests/ConcurrentListTests.cs

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)