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.Service.../Connected.ServiceModel.Clie.../TableSchemaMiddleware.cs

56 lines
1.8 KiB

using Connected.Annotations;
using Connected.Data.Schema;
using Connected.Entities.Annotations;
using Connected.Entities.Storage;
using Connected.Interop;
using Connected.Middleware;
using Connected.ServiceModel.Client.Data.Remote;
using Connected.ServiceModel.Client.Data.Schema;
using Connected.ServiceModel.Client.Net;
using Connected.ServiceModel.Data;
namespace Connected.ServiceModel.Client.Data;
[Priority(2)]
internal sealed class TableSchemaMiddleware : MiddlewareComponent, ISchemaMiddleware
{
public TableSchemaMiddleware(IMiddlewareService middleware, IStorageProvider storage, RemoteTableService remote, IConnectedServer connected)
{
Storage = storage;
Remote = remote;
Connected = connected;
}
private IStorageProvider Storage { get; }
private RemoteTableService Remote { get; }
private IConnectedServer Connected { get; }
public Type ConnectionType => typeof(TableDataConnection);
public string DefaultConnectionString { get; private set; } = default!;
protected override async Task OnInitialize()
{
DefaultConnectionString = await Connected.SelectUrl(new ConnectedServerUrlArgs { Kind = ConnectedUrlKind.TableStorage });
}
public async Task<bool> IsEntitySupported(Type entityType)
{
await Task.CompletedTask;
/*
* This middleware supports all ITableEntity<> entities.
*/
return entityType.ImplementsInterface(typeof(ITableEntity<>));
}
public async Task Synchronize(Type entity, ISchema schema)
{
await Synchronize(schema, DefaultConnectionString);
}
private async Task Synchronize(ISchema schema, string connectionString)
{
var args = new SchemaExecutionContext(schema, Remote);
if (string.IsNullOrWhiteSpace(schema.Type) || string.Equals(schema.Type, SchemaAttribute.SchemaTypeTable, StringComparison.OrdinalIgnoreCase))
await new TableSynchronize().Execute(args);
}
}