Skip to content

Commit 4e05cdd

Browse files
committed
Refactor: No ReactiveUI in STUN
1 parent 1963ef3 commit 4e05cdd

File tree

8 files changed

+18
-54
lines changed

8 files changed

+18
-54
lines changed

NatTypeTester.ViewModels/RFC3489ViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using System.Net;
1111
using System.Reactive;
12+
using System.Reactive.Linq;
1213
using System.Threading;
1314
using System.Threading.Tasks;
1415

@@ -51,9 +52,16 @@ private async Task TestClassicNatTypeImpl(CancellationToken token)
5152
using var client = new StunClient3489(server.Hostname, server.Port, Result3489.LocalEndPoint, proxy);
5253

5354
Result3489 = client.Status;
54-
await client.Query3489Async();
55+
using (Observable.Interval(TimeSpan.FromSeconds(0.1))
56+
.ObserveOn(RxApp.MainThreadScheduler)
57+
.Subscribe(_ => this.RaisePropertyChanged(nameof(Result3489))))
58+
{
59+
await client.Query3489Async();
60+
}
5561

5662
Result3489.LocalEndPoint = client.LocalEndPoint;
63+
64+
this.RaisePropertyChanged(nameof(Result3489));
5765
}
5866
}
5967
}

NatTypeTester.ViewModels/RFC5780ViewModel.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using System.Net;
1111
using System.Reactive;
12+
using System.Reactive.Linq;
1213
using System.Threading;
1314
using System.Threading.Tasks;
1415

@@ -51,12 +52,19 @@ private async Task DiscoveryNatTypeImpl(CancellationToken token)
5152
using var client = new StunClient5389UDP(server.Hostname, server.Port, Result5389.LocalEndPoint, proxy);
5253

5354
Result5389 = client.Status;
54-
await client.QueryAsync();
55+
using (Observable.Interval(TimeSpan.FromSeconds(0.1))
56+
.ObserveOn(RxApp.MainThreadScheduler)
57+
.Subscribe(_ => this.RaisePropertyChanged(nameof(Result5389))))
58+
{
59+
await client.QueryAsync();
60+
}
5561

5662
var cache = new StunResult5389();
5763
cache.Clone(client.Status);
5864
cache.LocalEndPoint = client.LocalEndPoint;
5965
Result5389 = cache;
66+
67+
this.RaisePropertyChanged(nameof(Result5389));
6068
}
6169
}
6270
}

STUN/Client/StunClient3489.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#if ReactiveUI
2-
using ReactiveUI.Fody.Helpers;
3-
#endif
41
using STUN.DnsClients;
52
using STUN.Enums;
63
using STUN.Message;
@@ -37,9 +34,6 @@ public TimeSpan Timeout
3734

3835
protected readonly IUdpProxy Proxy;
3936

40-
#if ReactiveUI
41-
[Reactive]
42-
#endif
4337
public ClassicStunResult Status { get; } = new();
4438

4539
public StunClient3489(string server, ushort port = 3478, IPEndPoint? local = null, IUdpProxy? proxy = null, IDnsQuery? dnsQuery = null)

STUN/Client/StunClient5389UDP.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#if ReactiveUI
2-
using ReactiveUI.Fody.Helpers;
3-
#endif
41
using STUN.DnsClients;
52
using STUN.Enums;
63
using STUN.Message;
@@ -20,9 +17,6 @@ namespace STUN.Client
2017
/// </summary>
2118
public class StunClient5389UDP : StunClient3489
2219
{
23-
#if ReactiveUI
24-
[Reactive]
25-
#endif
2620
public new StunResult5389 Status { get; } = new();
2721

2822
public StunClient5389UDP(string server, ushort port = 3478, IPEndPoint? local = null, IUdpProxy? proxy = null, IDnsQuery? dnsQuery = null)

STUN/STUN.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
7-
<DefineConstants>TRACE;ReactiveUI</DefineConstants>
87
</PropertyGroup>
98

10-
<ItemGroup>
11-
<PackageReference Include="ReactiveUI.Fody" Version="14.3.10" Condition="$(DefineConstants.Contains('ReactiveUI'))" />
12-
</ItemGroup>
13-
149
</Project>

STUN/StunResult/ClassicStunResult.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
#if ReactiveUI
2-
using ReactiveUI.Fody.Helpers;
3-
#endif
41
using STUN.Enums;
52

63
namespace STUN.StunResult
74
{
85
public class ClassicStunResult : StunResult
96
{
10-
#if ReactiveUI
11-
[Reactive]
12-
#endif
137
public NatType NatType { get; set; } = NatType.Unknown;
148
}
159
}

STUN/StunResult/StunResult.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
#if ReactiveUI
2-
using ReactiveUI;
3-
using ReactiveUI.Fody.Helpers;
4-
#endif
51
using System.Net;
62

73
namespace STUN.StunResult
84
{
95
public abstract class StunResult
10-
#if ReactiveUI
11-
: ReactiveObject
12-
#endif
136
{
14-
#if ReactiveUI
15-
[Reactive]
16-
#endif
177
public IPEndPoint? PublicEndPoint { get; set; }
18-
19-
#if ReactiveUI
20-
[Reactive]
21-
#endif
228
public IPEndPoint? LocalEndPoint { get; set; }
239
}
2410
}

STUN/StunResult/StunResult5389.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1-
#if ReactiveUI
2-
using ReactiveUI.Fody.Helpers;
3-
#endif
41
using STUN.Enums;
52
using System.Net;
63

74
namespace STUN.StunResult
85
{
96
public class StunResult5389 : StunResult
107
{
11-
#if ReactiveUI
12-
[Reactive]
13-
#endif
148
public IPEndPoint? OtherEndPoint { get; set; }
159

16-
#if ReactiveUI
17-
[Reactive]
18-
#endif
1910
public BindingTestResult BindingTestResult { get; set; } = BindingTestResult.Unknown;
2011

21-
#if ReactiveUI
22-
[Reactive]
23-
#endif
2412
public MappingBehavior MappingBehavior { get; set; } = MappingBehavior.Unknown;
2513

26-
#if ReactiveUI
27-
[Reactive]
28-
#endif
2914
public FilteringBehavior FilteringBehavior { get; set; } = FilteringBehavior.Unknown;
3015

3116
public void Clone(StunResult5389 result)

0 commit comments

Comments
 (0)