|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|