Skip to content

Commit

Permalink
Merge pull request #820 from Cysharp/feature/CleanupCodes
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
mayuki authored Aug 13, 2024
2 parents 7524748 + 09198c5 commit 4f63800
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 224 deletions.
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
src/MagicOnion.HttpGateway/Swagger/SwaggerUI/* linguist-vendored
src/MagicOnion.HttpGateway/Swagger/SwaggerUI/* linguist-vendored
*.csproj text
*.props text
*.targets text
*.cs text
*.xml text
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageVersion Include="Grpc.Net.Client" Version="$(GrpcVersion)" />
<PackageVersion Include="MemoryPack" Version="$(MemoryPackVersion)" />
<PackageVersion Include="MessagePack" Version="$(MessagePackVersion)" />
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics" Version="8.0.0" />
<PackageVersion Include="Multicaster" Version="$(MulticasterVersion)" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public class StreamingHubClientOptions
public TimeSpan? ClientHeartbeatTimeout { get; }
public Action<ServerHeartbeatEvent>? OnServerHeartbeatReceived { get; }
public Action<ClientHeartbeatEvent>? OnClientHeartbeatResponseReceived { get; }
#if NET8_0_OR_GREATER
#if NON_UNITY
public TimeProvider? TimeProvider { get; }
#endif

public StreamingHubClientOptions(string? host, CallOptions callOptions, IMagicOnionSerializerProvider serializerProvider, IMagicOnionClientLogger logger)
#if NET8_0_OR_GREATER
#if NON_UNITY
: this(host, callOptions, serializerProvider, logger, default, default, default, default, default)
#else
: this(host, callOptions, serializerProvider, logger, default, default, default, default)
#endif
{
}

#if NET8_0_OR_GREATER
#if NON_UNITY
public StreamingHubClientOptions(string? host, CallOptions callOptions, IMagicOnionSerializerProvider serializerProvider, IMagicOnionClientLogger logger, TimeSpan? clientHeartbeatInterval, TimeSpan? clientHeartbeatTimeout, Action<ServerHeartbeatEvent>? onServerHeartbeatReceived, Action<ClientHeartbeatEvent>? onClientHeartbeatResponseReceived,TimeProvider? timeProvider)
#else
public StreamingHubClientOptions(string? host, CallOptions callOptions, IMagicOnionSerializerProvider serializerProvider, IMagicOnionClientLogger logger, TimeSpan? clientHeartbeatInterval, TimeSpan? clientHeartbeatTimeout, Action<ServerHeartbeatEvent>? onServerHeartbeatReceived, Action<ClientHeartbeatEvent>? onClientHeartbeatResponseReceived)
Expand All @@ -51,7 +51,7 @@ public StreamingHubClientOptions(string? host, CallOptions callOptions, IMagicOn
ClientHeartbeatTimeout = clientHeartbeatTimeout;
OnServerHeartbeatReceived = onServerHeartbeatReceived;
OnClientHeartbeatResponseReceived = onClientHeartbeatResponseReceived;
#if NET8_0_OR_GREATER
#if NON_UNITY
TimeProvider = timeProvider;
#endif
}
Expand All @@ -62,29 +62,29 @@ public static StreamingHubClientOptions CreateWithDefault(string? host = default
public StreamingHubClientOptions WithHost(string? host)
=> new(host, CallOptions, SerializerProvider, Logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
public StreamingHubClientOptions WithCallOptions(CallOptions callOptions)
=> new(Host, callOptions, SerializerProvider, Logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
public StreamingHubClientOptions WithSerializerProvider(IMagicOnionSerializerProvider serializerProvider)
=> new(
Host, CallOptions, serializerProvider, Logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
public StreamingHubClientOptions WithLogger(IMagicOnionClientLogger logger)
=> new(Host, CallOptions, SerializerProvider, logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
Expand All @@ -97,7 +97,7 @@ public StreamingHubClientOptions WithLogger(IMagicOnionClientLogger logger)
public StreamingHubClientOptions WithClientHeartbeatInterval(TimeSpan? interval)
=> new(Host, CallOptions, SerializerProvider, Logger
, interval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
Expand All @@ -110,7 +110,7 @@ public StreamingHubClientOptions WithClientHeartbeatInterval(TimeSpan? interval)
public StreamingHubClientOptions WithClientHeartbeatTimeout(TimeSpan? timeout)
=> new(Host, CallOptions, SerializerProvider, Logger
, ClientHeartbeatInterval, timeout, OnServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
Expand All @@ -123,7 +123,7 @@ public StreamingHubClientOptions WithClientHeartbeatTimeout(TimeSpan? timeout)
public StreamingHubClientOptions WithServerHeartbeatReceived(Action<ServerHeartbeatEvent>? onServerHeartbeatReceived)
=> new(Host, CallOptions, SerializerProvider, Logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, onServerHeartbeatReceived, OnClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);
Expand All @@ -136,12 +136,12 @@ public StreamingHubClientOptions WithServerHeartbeatReceived(Action<ServerHeartb
public StreamingHubClientOptions WithClientHeartbeatResponseReceived(Action<ClientHeartbeatEvent>? onClientHeartbeatResponseReceived)
=> new(Host, CallOptions, SerializerProvider, Logger
, ClientHeartbeatInterval, ClientHeartbeatTimeout, OnServerHeartbeatReceived, onClientHeartbeatResponseReceived
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider
#endif
);

#if NET8_0_OR_GREATER
#if NON_UNITY
/// <summary>
/// Sets a <see cref="TimeProvider"/>
/// </summary>
Expand Down Expand Up @@ -199,7 +199,7 @@ protected StreamingHubClientBase(string serviceName, TReceiver receiver, CallInv
}

// call immediately after create.
public async Task __ConnectAndSubscribeAsync(CancellationToken cancellationToken)
internal async Task __ConnectAndSubscribeAsync(CancellationToken cancellationToken)
{
var syncContext = SynchronizationContext.Current; // capture SynchronizationContext.
var callResult = callInvoker.AsyncDuplexStreamingCall(duplexStreamingConnectMethod, options.Host, options.CallOptions);
Expand Down Expand Up @@ -279,7 +279,7 @@ async Task StartSubscribe(SynchronizationContext? syncContext, Task<bool> firstM
options.OnClientHeartbeatResponseReceived,
syncContext,
cancellationTokenSource.Token
#if NET8_0_OR_GREATER
#if NON_UNITY
, options.TimeProvider ?? TimeProvider.System
#endif
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class StreamingHubClientHeartbeatManager : IDisposable
readonly Action<ClientHeartbeatEvent>? onClientHeartbeatResponseReceived;
readonly SynchronizationContext? synchronizationContext;
readonly ChannelWriter<StreamingHubPayload> writer;
#if NET8_0_OR_GREATER
#if NON_UNITY
readonly TimeProvider timeProvider;
#endif

Expand All @@ -77,7 +77,7 @@ public StreamingHubClientHeartbeatManager(
Action<ClientHeartbeatEvent>? onClientHeartbeatResponseReceived,
SynchronizationContext? synchronizationContext,
CancellationToken shutdownToken
#if NET8_0_OR_GREATER
#if NON_UNITY
, TimeProvider timeProvider
#endif
)
Expand All @@ -94,7 +94,7 @@ CancellationToken shutdownToken
this.onClientHeartbeatResponseReceived = onClientHeartbeatResponseReceived;
this.synchronizationContext = synchronizationContext;
this.shutdownTokenSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken, timeoutTokenSource.Token);
#if NET8_0_OR_GREATER
#if NON_UNITY
this.timeProvider = timeProvider;
#endif
}
Expand Down Expand Up @@ -177,7 +177,7 @@ SendOrPostCallback ProcessClientHeartbeatResponseCore(Action<ClientHeartbeatEven
}

var now =
#if NET8_0_OR_GREATER
#if NON_UNITY
timeProvider.GetUtcNow();
#else
DateTimeOffset.UtcNow;
Expand Down Expand Up @@ -215,7 +215,7 @@ StreamingHubPayload BuildClientHeartbeatMessage(short clientSequence)
using var buffer = ArrayPoolBufferWriter.RentThreadStaticWriter();

var now =
#if NET8_0_OR_GREATER
#if NON_UNITY
timeProvider.GetUtcNow();
#else
DateTimeOffset.UtcNow;
Expand Down
4 changes: 4 additions & 0 deletions src/MagicOnion.Client/MagicOnion.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<PackageReference Include="System.Threading.Channels" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Bcl.TimeProvider" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" />
<PackageReference Include="PolySharp">
Expand Down
Loading

0 comments on commit 4f63800

Please sign in to comment.