internal static DataProviderMetaData Generate(Type type) { var tableName = TableNameAttribute.GetTableName(type); return(new DataProviderMetaData(type) { BaseClassTypesInOrder = GetParents(type), DrivedClassTypes = GetDrivedClasses(type), Properties = GetProperties(type).ToArray(), Schema = SchemaAttribute.GetSchema(type), TableName = tableName, TableAlias = tableName, IsSoftDeleteEnabled = SoftDeleteAttribute.IsEnabled(type, inherit: false) }); }
internal async Task Import(ReplicateDataMessage message) { if (message.CreationUtc < RefreshRequestUtc?.Subtract(TimeSyncTolerance)) { // Ignore this. We will receive a full table after this anyway. Log.Info("Ignored importing expired ReplicateDataMessage " + message.DeduplicationId + " because it's older the last refresh request."); return; } if (message.IsClearSignal) { Log.Debug($"Received Clear Signal for {message.TypeFullName}"); await Database.GetAccess(DomainType).ExecuteNonQuery($"truncate table {SchemaAttribute.GetSchema(DomainType).WithSuffix(".")}{TableNameAttribute.GetTableName(DomainType)}"); return; } Log.Debug($"Beginning to import ReplicateDataMessage for {message.TypeFullName}:\n{message.Entity}\n\n"); IEntity entity; try { entity = await Deserialize(message.Entity); } catch (Exception ex) { Log.Error(ex, "Failed to deserialize a message of :> " + message.TypeFullName + " message : " + message.Entity); throw; } try { if (message.ToDelete) { if (await Endpoint.OnDeleting(message, entity)) { await Database.Delete(entity); await Endpoint.OnDeleted(message, entity); } } else { var mode = entity.IsNew ? SaveMode.Insert : SaveMode.Update; if (mode == SaveMode.Update && !await IsActuallyChanged(entity)) { return; } if (!await Endpoint.OnSaving(message, entity, mode)) { return; } var bypass = SaveBehaviour.BypassAll; if (Config.Get("Database:Audit:EnableForEndpointDataReplication", defaultValue: false)) { bypass &= ~SaveBehaviour.BypassLogging; } await Database.Save(entity, bypass); await GlobalEntityEvents.OnInstanceSaved(new GlobalSaveEventArgs(entity, mode)); await Endpoint.OnSaved(message, entity, mode); Log.Debug("Saved the " + entity.GetType().FullName + " " + entity.GetId()); } } catch (Exception ex) { Log.Error(ex, "Failed to import."); throw; } }