async Task DoDelete(Entity entity, DeleteBehaviour behaviour) { // Raise deleting event if (!IsSet(behaviour, DeleteBehaviour.BypassDeleting)) { var deletingArgs = new System.ComponentModel.CancelEventArgs(); await Entity.Services.RaiseOnDeleting(entity, deletingArgs); if (deletingArgs.Cancel) { Cache.Remove(entity); return; } } if (SoftDeleteAttribute.IsEnabled(entity.GetType()) && !SoftDeleteAttribute.Context.ShouldByPassSoftDelete()) { SoftDeleteAttribute.MarkDeleted(entity); await GetProvider(entity).Save(entity); } else { await GetProvider(entity).Delete(entity); } }
static void DoDelete(Entity entity, DeleteBehaviour behaviour) { // Raise deleting event if (!IsSet(behaviour, DeleteBehaviour.BypassDeleting)) { var deletingArgs = new System.ComponentModel.CancelEventArgs(); EntityManager.RaiseOnDeleting(entity, deletingArgs); if (deletingArgs.Cancel) { Cache.Current.Remove(entity); return; } } if (SoftDeleteAttribute.IsEnabled(entity.GetType()) && !SoftDeleteAttribute.Context.ShouldByPassSoftDelete()) { // Soft delete: EntityManager.MarkSoftDeleted(entity); GetProvider(entity).Save(entity); } else { GetProvider(entity).Delete(entity); } }
public void Delete(EntityId entityId, DeleteBehaviour deleteBehaviour = DeleteBehaviour.Default) { IEnumerable <IEntityQuad> deletes = DeleteQuads(entityId); if (!_trackChanges) { return; } var deletesGrouped = (from removedQuad in deletes group removedQuad by removedQuad.Graph into g select g).ToList(); if (entityId is BlankId) { foreach (var removed in deletesGrouped) { if (removed.Any(quad => quad.Object.IsBlank || quad.Subject.IsBlank)) { var removedQuads = removed; _changesTracker.Add(new GraphReconstruct(entityId, removed.Key.ToEntityId(), _entityQuads.Where(q => (Equals(q.Graph, removedQuads.Key)) || (q.Graph.Equals(removedQuads.Key))))); } } } else { _changesTracker.Add(new EntityDelete(entityId)); if (deleteBehaviour.HasFlag(DeleteBehaviour.NullifyChildren)) { _entityQuads.RemoveWhereObject(Node.FromEntityId(entityId)); _changesTracker.Add(new RemoveReferences(entityId)); } } }
/// <inheritdoc /> public void Delete(EntityId entityId, DeleteBehaviour deleteBehaviour) { if (entityId == null) { throw new ArgumentNullException("entityId"); } entityId = EnsureAbsoluteEntityId(entityId); _entityStore.Delete(entityId, deleteBehaviour); }
public FolderSettingItemViewModel(SpecificFolderSetting setting) { Path.Value = setting.DirectoryPath; if (setting.Status == SpecificFolderSettingStatus.Initialized) { DaysAge.Value = setting.DayAgeToRemove; DeleteBehaviourID.Value = (int)setting.DirectoriesDeleteBehaviour; DeleteBehaviour.LinkWith(DeleteBehaviourID); } DaysAge.OnModify += SettingsModified; DeleteBehaviourID.OnModify += SettingsModified; }
/// <summary> /// Deletes the specified record from the data repository. /// </summary> public static void Delete(IEntity instance, DeleteBehaviour behaviour) { if (instance == null) { throw new ArgumentNullException("instance"); } var entity = instance as Entity; if (entity == null) { throw new ArgumentException("The type of the specified object to delete does not inherit from {0} class.".FormatWith(typeof(Entity).FullName)); } EnlistOrCreateTransaction(() => DoDelete(entity, behaviour)); Cache.Current.Remove(entity); if (Transaction.Current != null) { Transaction.Current.TransactionCompleted += (s, e) => { Cache.Current.Remove(entity); } } ; if (DbTransactionScope.Root != null) { DbTransactionScope.Root.OnTransactionCompleted(() => Cache.Current.Remove(entity)); } if (!IsSet(behaviour, DeleteBehaviour.BypassLogging)) { if (!(entity is IApplicationEvent) && Config.Get <bool>("Log.Record.Application.Events", defaultValue: true)) { ApplicationEventManager.RecordDelete(entity); } } OnUpdated(new EventArgs <IEntity>(entity)); if (!IsSet(behaviour, DeleteBehaviour.BypassDeleted)) { EntityManager.RaiseOnDeleted(entity); } }
/// <summary> /// Deletes the specified record from the data repository. /// </summary> public async Task Delete(IEntity instance, DeleteBehaviour behaviour) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } var entity = instance as Entity; if (entity == null) { throw new ArgumentException($"The type of the specified object to delete does not inherit from {typeof(Entity).FullName} class."); } await EnlistOrCreateTransaction(async() => await DoDelete(entity, behaviour)); Cache.Current.Remove(entity); if (Transaction.Current != null) { Transaction.Current.TransactionCompleted += (s, e) => { Cache.Current.Remove(entity); } } ; DbTransactionScope.Root?.OnTransactionCompleted(() => Cache.Current.Remove(entity)); if (!IsSet(behaviour, DeleteBehaviour.BypassLogging)) { if (!(entity is IApplicationEvent) && Config.Get("Log.Record:Application:Events", defaultValue: true)) { await ApplicationEventManager.RecordDelete(entity); } } await OnUpdated(entity); if (!IsSet(behaviour, DeleteBehaviour.BypassDeleted)) { await EntityManager.RaiseOnDeleted(entity); } }
/// <summary> /// Deletes the specified record from the data repository. /// </summary> public async Task Delete(IEntity instance, DeleteBehaviour behaviour) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } var entity = instance as Entity; if (entity == null) { throw new ArgumentException($"The type of the specified object to delete does not inherit from {typeof(Entity).FullName} class."); } await EnlistOrCreateTransaction(async() => await DoDelete(entity, behaviour)); Cache.Remove(entity); if (Transaction.Current != null) { Transaction.Current.TransactionCompleted += (s, e) => { Cache.Remove(entity); } } ; DbTransactionScope.Root?.OnTransactionCompleted(() => Cache.Remove(entity)); if (!IsSet(behaviour, DeleteBehaviour.BypassLogging)) { await Audit.LogDelete(entity); } await Updated.Raise(entity); if (!IsSet(behaviour, DeleteBehaviour.BypassDeleted)) { await Entity.Services.RaiseOnDeleted(entity); } }
internal static bool IsSet(DeleteBehaviour setting, DeleteBehaviour behaviour) => (setting & behaviour) == behaviour;
static bool IsSet(DeleteBehaviour setting, DeleteBehaviour behaviour) { return((setting & behaviour) == behaviour); }
bool IsSet(DeleteBehaviour setting, DeleteBehaviour behaviour) => (setting & behaviour) == behaviour;