Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp CoreIpc [ROBO-3791] #106

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
reduce surface area
- decommission the duplication of IClient methods in Message
  • Loading branch information
eduard-dumitru committed Dec 9, 2024
commit d17ec528b815d7658da8127e3d7a779761e387d2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<int> MultiplySimple(int x, int y)

public async Task<int> Multiply(int x, int y, Message message = default!)
{
var arithmetic = message.GetCallback<IArithmetic>();
var arithmetic = message.Client.GetCallback<IArithmetic>();

int result = 0;
for (int i = 0; i < x; i++)
Expand All @@ -32,7 +32,7 @@ public async Task<int> Multiply(int x, int y, Message message = default!)
}
public async Task<bool> TestMessage(Message<int> message)
{
var arithmetic = message.GetCallback<IArithmetic>();
var arithmetic = message.Client.GetCallback<IArithmetic>();
return await arithmetic.SendMessage(message);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Playground/Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public sealed class Server(ClientRegistry clients) : Contracts.IServerOperations
{
public async Task<bool> Register(Message? m = null)
{
var clientOps = m!.GetCallback<Contracts.IClientOperations>();
var clientOps2 = m.GetCallback<Contracts.IClientOperations2>();
var clientOps = m!.Client.GetCallback<Contracts.IClientOperations>();
var clientOps2 = m.Client.GetCallback<Contracts.IClientOperations2>();

var added = clients.Add(new(clientOps, clientOps2));

Expand Down
5 changes: 1 addition & 4 deletions src/UiPath.CoreIpc/Wire/Dtos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ namespace UiPath.Ipc;
public class Message
{
[JsonIgnore]
public IClient Client { get; set; }
public IClient Client { get; set; } = null!;
[JsonIgnore]
public TimeSpan RequestTimeout { get; set; }
public TCallbackInterface GetCallback<TCallbackInterface>() where TCallbackInterface : class =>
Client.GetCallback<TCallbackInterface>();
public void ImpersonateClient(Action action) => Client.Impersonate(action);
}
public class Message<TPayload> : Message
{
Expand Down
4 changes: 2 additions & 2 deletions src/UiPath.Ipc.Tests/Services/ComputingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<bool> Wait(TimeSpan duration, CancellationToken ct = default)
public async Task<string> GetCallbackThreadName(TimeSpan waitOnServer, Message message = null!, CancellationToken cancellationToken = default)
{
await Task.Delay(waitOnServer);
return await message.GetCallback<IComputingCallback>().GetThreadName();
return await message.Client.GetCallback<IComputingCallback>().GetThreadName();
}

public async Task<ComplexNumber> AddComplexNumberList(IReadOnlyList<ComplexNumber> numbers)
Expand All @@ -47,7 +47,7 @@ public async Task<ComplexNumber> AddComplexNumberList(IReadOnlyList<ComplexNumbe

public async Task<int> MultiplyInts(int x, int y, Message message = null!)
{
var callback = message.GetCallback<IComputingCallbackBase>();
var callback = message.Client.GetCallback<IComputingCallbackBase>();

var result = 0;
for (int i = 0; i < y; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/UiPath.Ipc.Tests/Services/Robot/Pals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal sealed class Callback<T> where T : class
public Callback(Message message)
{
Client = message.Client;
_callback = message.GetCallback<T>();
_callback = message.Client.GetCallback<T>();
}

public void Invoke(Func<T, Task> call) => InvokeAsync(call).TraceError();
Expand Down
6 changes: 3 additions & 3 deletions src/UiPath.Ipc.Tests/Services/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task FireAndForget(TimeSpan wait)
{
try
{
_ = await message.GetCallback<IUnregisteredCallback>().SomeMethod();
_ = await message.Client.GetCallback<IUnregisteredCallback>().SomeMethod();
return null;
}
catch (Exception ex)
Expand Down Expand Up @@ -75,8 +75,8 @@ public async Task<Stream> Download(string s, CancellationToken ct = default)

public async Task<int> AddIncrement(int x, int y, Message message = null!)
{
var sum = await message.GetCallback<IComputingCallbackBase>().AddInts(x, y);
var result = await message.GetCallback<IArithmeticCallback>().Increment(sum);
var sum = await message.Client.GetCallback<IComputingCallbackBase>().AddInts(x, y);
var result = await message.Client.GetCallback<IArithmeticCallback>().Increment(sum);
return result;
}
}