public override void Restore() { if (Target != null) { Type targetType = Target.GetType(); PropertyInfo pI = targetType.GetProperty(PropertyName); if (pI != null) { if (pI.CanWrite) { pI.SetValue(Target, PropertyValue, null); } else if (Target is IDeletable && PropertyName == "IsDeleted") { IDeletable deletable = (IDeletable)Target; if ((bool)PropertyValue == true) { deletable.Delete(); } else { deletable.Undelete(); } } } } }
public OrderController(ICreatable <Order> _creatable, IDeletable _deletable, IUpdatable <Order> _updatable, IReadable <Order> _readable) { creatable = _creatable; deletable = _deletable; updatable = _updatable; readable = _readable; }
public void DeleteSelected(bool noWarning) { if (noWarning || MessageBox.Show("Delete", "Delete?", MessageBoxButtons.OKCancel) == DialogResult.OK) { List <IDeletable> hitlist = new List <IDeletable>(); foreach (Control c in this.Controls) { ISelectable selectable = c as ISelectable; if (selectable != null) { if (selectable.IsSelected()) { IDeletable deleteme = selectable as IDeletable; if (deleteme != null) { hitlist.Add(deleteme); } } } } foreach (IDeletable item in hitlist) { item.Delete(); } } }
public void ShouldNotBeDeleted_When_Entity_Null_Fails_Assertion() { // Arrange IDeletable entity = null; // Act & Assert Should.Throw <ShouldAssertException>(() => entity.ShouldNotBeDeleted()); }
public void AllowDeletion_WhenCalled_AssertDeletableIsTrue() { IDeletable sut = CreateSut(); sut.AllowDeletion(); Assert.That(sut.Deletable, Is.True); }
public void ShouldNotBeDeletedBy_DeletedBy_When_Entity_Null_Fails_Assertion() { // Arrange IDeletable entity = null; // Act & Assert Should.Throw <ShouldAssertException>(() => entity.ShouldNotBeDeletedBy(deletedBy: Build <UserStub>())); }
public void ShouldBeDeletedBy_DeletedById_When_Entity_Null_Fails_Assertion() { // Arrange IDeletable entity = null; // Act & Assert Should.Throw <ShouldAssertException>(() => entity.ShouldBeDeletedBy(deletedById: Random.Long())); }
/// <summary> /// Removes <see cref="IMessage" /> after a timeout /// </summary> /// <param name="message">Message to remove</param> /// <param name="timeout">Timeout to remove message</param> /// <returns></returns> private static async Task RemoveAfterTimeout(this IDeletable message, int timeout = 10000) { await Task.Delay(timeout); await message.DeleteAsync(new RequestOptions { RetryMode = RetryMode.RetryRatelimit }); await Task.CompletedTask; }
public void DisallowDeletion_WhenCalled_AssertDeletableIsFalse() { IDeletable sut = CreateSut(); sut.DisallowDeletion(); Assert.That(sut.Deletable, Is.False); }
public void Execute(Entity entity) { IDeletable del = entity as IDeletable; if (del != null) { del.Delete(); } }
public static Task DeleteAfterTimeSpan(this IDeletable message, TimeSpan timeSpan) { return(Task.Delay(timeSpan).ContinueWith(async _ => { if (message != null) { await message?.DeleteAsync(); } })); }
public bool Remove(IDeletable entity) { bool isDeleted = entity is IDeletable; if (!isDeleted) { throw new Exception("This Item Is Not Deletable"); } return(BaseRepository.Remove(entity)); }
public ProductController(ISaveChange _saveChange, ICreatable <Product> _creatable, IDeletable _deletable, IUpdatable <Product> _updatable, IReadable <Product> _readable) { //productService = _productService; //review_RatingService = _review_RatingService; creatable = _creatable; deletable = _deletable; updatable = _updatable; readable = _readable; saveChange = _saveChange; }
public virtual bool Remove(IDeletable entity) { bool isDeleteable = entity is IDeletable; if (!isDeleteable) { throw new Exception("This Item is not Deleteable!"); } return(_repository.Remove(entity)); }
public virtual bool Remove(IDeletable entity) { bool IsDeletable = entity is IDeletable; if (!IsDeletable) { throw new Exception("This Item Is Not Deletable"); } return(BaseRepository.Remove((IDeletable)entity)); }
public static bool TryDeleteAsync(this IDeletable deletable, RequestOptions options = null) { try { deletable.DeleteAsync(options); return(true); } catch { return(false); } }
public static void SetDeletable(this IDeletable deletable, bool canDelete) { NullGuard.NotNull(deletable, nameof(deletable)); if (canDelete) { deletable.AllowDeletion(); return; } deletable.DisallowDeletion(); }
public LoanService( ILoanRepository repository, IDeletable <Loan> delete, IFindableId <Loan> findableId, ILoadAll <Loan> loadAll, ICreatable <Loan> creatable) { _repository = repository; _delete = delete; _findableId = findableId; _loadAll = loadAll; _creatable = creatable; }
public FriendService( IUpdatableRepository <Friend> updatableRepository, IDeletable <Friend> deletable, IFindableId <Friend> findableId, ILoadAll <Friend> loadAll, ICreatable <Friend> creatable) { _updatableRepository = updatableRepository; _deletable = deletable; _findableId = findableId; _loadAll = loadAll; _creatable = creatable; }
public static async Task <bool> TryDeleteAsync(this IDeletable deletable, RequestOptions options = null) { try { await deletable.DeleteAsync(options).ConfigureAwait(false); return(true); } catch { return(false); } }
public void MarkForDeletion(IDeletable resource) { if (_disposed) { throw new ObjectDisposedException(nameof(AutoCleanup), "The environment has already been cleaned up"); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } _cleanupList.Add(resource); }
public void ShouldBeDeletable_WhenValueIsNotNullAndDeletableGetterReturnsNull_ThrowsIntranetValidationException() { IObjectValidator sut = CreateSut(); IDeletable deletable = null; Type validatingType = GetType(); string validatingField = _fixture.Create <string>(); IntranetValidationException result = Assert.Throws <IntranetValidationException>(() => sut.ShouldBeDeletable(_fixture.Create <object>(), async obj => await Task.Run(() => deletable), validatingType, validatingField)); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ValueShouldReferToDeletableEntity)); Assert.That(result.ValidatingType, Is.EqualTo(validatingType)); Assert.That(result.ValidatingField, Is.EqualTo(validatingField)); Assert.That(result.InnerException, Is.Null); }
private static async Task HandleMessage(IDeletable messageParam) { if (!(messageParam is SocketUserMessage message)) { return; } if (message.Author.IsBot) { return; } var ctx = new ShardedCommandContext(_client, message); // don't handle anything in dms if (ctx.IsPrivate) { return; } var guildSettings = await _database.GetSettings(ctx.Guild.Id); // automod // command handling var argPos = 0; if (!( // in case people forget message.HasMentionPrefix(_client.CurrentUser, ref argPos) // custom prefix || message.HasStringPrefix(guildSettings.Prefix, ref argPos) ) ) { return; } Logger.Debug("Processing command {Command} from {GuildId}", message.Content, ctx.Guild.Id); var result = await _commands.ExecuteAsync(ctx, argPos, _services); if (!result.IsSuccess && result.ErrorReason != "Unknown command.") { await ctx.Channel.SendMessageAsync( LocalizationProvider.Instance._("bot.error.errorOccurred", guildSettings.Language, Constants.ErrorEmoji, result.ErrorReason) + "\n" + LocalizationProvider.Instance._("bot.error.docs", guildSettings.Language, Constants.InfoEmoji, "notarealdomain://selenium.bot/docs/")); } }
/// <inheritdoc /> public async Task UnConfigureGuildAsync(IGuild guild) { var config = await ModerationConfigRepository.ReadAsync(guild.Id); if (config != null) { IDeletable muteRole = guild.Roles.FirstOrDefault(x => x.Id == config.MuteRoleId); if (muteRole != null) { await muteRole.DeleteAsync(); } await ModerationConfigRepository.DeleteAsync(config.GuildId); } }
public GameService( IUpdatableRepository <Game> updatableRepository, IDeletable <Game> deletable, IFindableId <Game> findableId, ILoadAll <Game> loadAll, ICreatable <Game> creatable, ILoadBy <Game> loadByEntityService) { _updatableRepository = updatableRepository; _deletable = deletable; _findableId = findableId; _loadAll = loadAll; _creatable = creatable; _loadBy = loadByEntityService; }
async Task <bool> canDeleteAsync(IDeletable deletable) { var user = await getCurrentUserOrNullAsync(); if (user == null || user.Status.State != ProfileState.ACTIVE) { return(false); } else { return(await isNotDeletedAsync(deletable) && !deletable.IsDeleted && user.Role >= Role.MODERATOR); } }
public IValidator ShouldBeDeletable <TValue, TDeletable>(TValue value, Func <TValue, Task <TDeletable> > deletableGetter, Type validatingType, string validatingField, bool allowNull = false) where TDeletable : IDeletable { NullGuard.NotNull(deletableGetter, nameof(deletableGetter)) .NotNull(validatingType, nameof(validatingType)) .NotNullOrWhiteSpace(validatingField, nameof(validatingField)); if (Equals(value, null) && allowNull) { return(this); } if (Equals(value, null)) { throw new IntranetExceptionBuilder(ErrorCode.ValueCannotBeNull, validatingField) .WithValidatingType(validatingType) .WithValidatingField(validatingField) .Build(); } Exception innerException = null; try { IDeletable deletable = deletableGetter(value).GetAwaiter().GetResult(); if (deletable != null && deletable.Deletable) { return(this); } } catch (AggregateException aggregateException) { aggregateException.Handle(exception => { innerException = exception; return(true); }); } catch (Exception exception) { innerException = exception; } IIntranetExceptionBuilder intranetExceptionBuilder = new IntranetExceptionBuilder(ErrorCode.ValueShouldReferToDeletableEntity, validatingField) .WithValidatingType(validatingType) .WithValidatingField(validatingField); throw (innerException == null ? intranetExceptionBuilder : intranetExceptionBuilder.WithInnerException(innerException)).Build(); }
public UserAuthenticationProvider( ITranslate<User, UserAccount> translateDataUserToUserAccount, IRetrievable<ByUserEmail, User> retrieveUserByEmail, IBulkRetrievable<ByEncodedUserId, UserAuthentication> retrieveAllUserAuthenticationByEncodedUserId, IUpdatable<UserAuthentication> userAuthUpdater, ICreatable<UserAuthentication> userAuthCreator, IPasswords passwords, IDeletable<UserAuthentication> userAuthDeleter) { _translateDataUserToUserAccount = translateDataUserToUserAccount; _retrieveUserByEmail = retrieveUserByEmail; _retrieveAllUserAuthenticationByEncodedUserId = retrieveAllUserAuthenticationByEncodedUserId; _userAuthUpdater = userAuthUpdater; _userAuthCreator = userAuthCreator; _passwords = passwords; _userAuthDeleter = userAuthDeleter; }
public virtual void OnCollisionEnter2D(Collision2D collision) { IDeletable deletable = collision.gameObject.GetComponent(typeof(IDeletable)) as IDeletable; if (deletable != null) { bool deleted = deletable.Delete(parent); if (deleted) { parent.Despawn(); } } else { parent.Despawn(); } }
protected virtual async Task <IHttpActionResult> DeleteAndSaveAsync(IDeletable obj) { obj.Deleted = true; obj.DeletedAt = DateTimeOffset.UtcNow; try { await Context.SaveChangesAsync(); } catch (Exception) { Trace.TraceError("Error marking object as deleted in db."); throw; } return(Ok()); }
/// <inheritdoc /> public async Task UnConfigureGuildAsync(IGuild guild) { foreach (var mapping in await ModerationMuteRoleMappingRepository .SearchBriefsAsync(new ModerationMuteRoleMappingSearchCriteria() { GuildId = guild.Id, IsDeleted = false, })) { IDeletable muteRole = guild.Roles.FirstOrDefault(x => x.Id == mapping.MuteRoleId); if (muteRole != null) { await muteRole.DeleteAsync(); } await ModerationMuteRoleMappingRepository.TryDeleteAsync(mapping.Id, DiscordClient.CurrentUser.Id); } }
public UserAccountProvider( IUserAuthenticationProvider userAuthProvider, ICreatable<User> userCreator, IRetrievable<ByUserId, User> userGetByUserId, IRetrievable<ByUserEmail, User> retrieveUserByEmail, IDeletable<User> userDeleter, IUpdatable<User> userUpdater, ITranslate<User, UserAccount> translateDataUserToUserAccount, ISystemTime systemTime) { _userAuthProvider = userAuthProvider; _userCreator = userCreator; _userGetByUserId = userGetByUserId; _retrieveUserByEmail = retrieveUserByEmail; _userDeleter = userDeleter; _userUpdater = userUpdater; _translateDataUserToUserAccount = translateDataUserToUserAccount; _systemTime = systemTime; }