You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Services/DistributedService.cs

41 lines
985 B

2 years ago
using Connected.Net;
using Connected.Net.Server;
using Connected.ServiceModel;
namespace Connected.Services;
public abstract class DistributedService : Service
{
public DistributedService(IContext context) : base(context)
{
if (context is null)
throw new ArgumentNullException(null, nameof(context));
EndpointServer = context.GetService<IEndpointServer>();
if (EndpointServer is null)
throw new NullReferenceException(nameof(IEndpointServer));
Http = context.GetService<IHttpService>();
if (Http is null)
throw new NullReferenceException(nameof(IHttpService));
}
private IEndpointServer EndpointServer { get; }
protected async Task<string> ParseUrl(string relativePath)
{
if (await IsServer())
throw new InvalidOperationException(SR.ErrNoServer);
return $"{EndpointServer.ServerUrl}/{relativePath.Trim('/')}";
}
protected IHttpService Http { get; }
protected async Task<bool> IsServer()
{
return await EndpointServer.IsServer();
}
}