This repository was archived by the owner on Feb 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathServiceRemoting.cs
More file actions
93 lines (83 loc) · 3.18 KB
/
ServiceRemoting.cs
File metadata and controls
93 lines (83 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting.Client;
using Microsoft.ServiceFabric.Services.Remoting.V2.FabricTransport.Client;
using ServiceFabric.Logging.Extensions;
using ServiceFabric.Remoting.CustomHeaders;
namespace ServiceFabric.Logging.Remoting
{
/// <summary>
/// Helper class for remoting calls
/// </summary>
[Obsolete("Use the ProxyFactoryProvider class")]
public class ServiceRemoting : IServiceRemoting
{
private readonly ILogger _logger;
/// <summary>
/// Creates a new instance
/// </summary>
/// <param name="logger">An <see cref="ILogger"/> instance used to log a service call</param>
public ServiceRemoting(ILogger logger)
{
_logger = logger;
}
/// <inheritdoc/>
public async Task<TResult> CallAsync<TService, TResult>(
CustomHeaders customHeaders,
Uri uri,
Expression<Func<TService, Task<TResult>>> callMethod) where TService : IService
{
var proxyFactory = new ServiceProxyFactory(c => new ExtendedServiceRemotingClientFactory(new FabricTransportServiceRemotingClientFactory(remotingCallbackMessageHandler: c), customHeaders));
var service = proxyFactory.CreateServiceProxy<TService>(uri);
var success = true;
var stopwatch = Stopwatch.StartNew();
var started = DateTime.Now;
try
{
return await callMethod.Compile().Invoke(service);
}
catch (Exception exception)
{
success = false;
_logger.LogError(ServiceFabricEvent.Exception, exception, exception.Message);
throw;
}
finally
{
stopwatch.Stop();
_logger.LogDependency(callMethod, started, stopwatch.Elapsed, success);
}
}
/// <inheritdoc/>
public async Task CallAsync<TService>(
CustomHeaders customHeaders,
Uri uri,
Expression<Func<TService, Task>> callMethod) where TService : IService
{
var proxyFactory = new ServiceProxyFactory(c => new ExtendedServiceRemotingClientFactory(new FabricTransportServiceRemotingClientFactory(remotingCallbackMessageHandler: c), customHeaders));
var service = proxyFactory.CreateServiceProxy<TService>(uri);
var success = true;
var stopwatch = Stopwatch.StartNew();
var started = DateTime.Now;
try
{
await callMethod.Compile().Invoke(service);
}
catch (Exception exception)
{
success = false;
_logger.LogError(ServiceFabricEvent.Exception, exception, exception.Message);
throw;
}
finally
{
stopwatch.Stop();
_logger.LogDependency(callMethod, started, stopwatch.Elapsed, success);
}
}
}
}