public void should_ignore_field_if_column_not_exists_and_optional_is_set() { IDataReader reader = GetDataReader(); Mock .Arrange(() => reader.FieldCount) .Returns(1); Mock .Arrange(() => reader.GetName(0)) .Returns("name2"); Mock .Arrange(() => reader.GetOrdinal("name2")) .Returns(1); Mock .Arrange(() => reader.GetString(0)) .Throws <ArgumentException>(); var mapper = new DataReaderMapperBuilder <IgnoreType>( "should_ignore_field_if_column_not_exists_and_optional_is_set") .Map(x => x.Name, "nohros", true) .Build(); try { IgnoreType type = mapper.Map(reader); Assert.That(type.Name, Is.Null); } catch { Assert.Fail("Should not throws any exception"); } }
public void should_map_field_if_column_exists_and_optional_is_set() { IDataReader reader = GetDataReader(); Mock .Arrange(() => reader.FieldCount) .Returns(1); Mock .Arrange(() => reader.GetName(0)) .Returns("name"); Mock .Arrange(() => reader.GetOrdinal("name")) .Returns(0); Mock .Arrange(() => reader.GetString(0)) .Returns("nohros"); var mapper = new DataReaderMapperBuilder <IgnoreType>( "should_map_field_if_column_exists_and_optional_is_set") .Map(x => x.Name, "name", true) .Build(); IgnoreType type = mapper.Map(reader); Assert.That(type.Name, Is.EqualTo("nohros")); }
public static IgnoreType ParseIgnoreRuleType(this string ruleType) { IgnoreType enumResult = IgnoreType.None; Enum.TryParse(ruleType, out enumResult); return(enumResult); }
public async Task Remove(IgnoreType ignoreType, ulong ignoreId, [Remainder] string allowedString) { var collection = _mongo.GetCollection <AllowString>(Context.Client); var allows = await collection.GetIgnoresAsync(Context.Guild.Id); if (!allows.Any(a => a.GuildId == Context.Guild.Id && a.IgnoreType == ignoreType && a.IgnoredId == ignoreId && a.AllowedString.Equals(allowedString, StringComparison.OrdinalIgnoreCase))) { if (await ValidateUlong(Context, ignoreType, ignoreId)) { var allow = allows.First(a => a.GuildId == Context.Guild.Id && a.IgnoreType == ignoreType && a.IgnoredId == ignoreId && a.AllowedString.Equals(allowedString, StringComparison.OrdinalIgnoreCase)); await collection.DeleteAsync(allow); await ReplyAsync( $":white_check_mark: String `{allowedString}` will no longer be whitelisted for `{ignoreType} {ignoreId}`"); } else { await ReplyAsync($"Input {ignoreId} is not a valid {ignoreType}"); } } else { await ReplyAsync("A matching entry is not existent"); } }
public Ignore(ulong guildId, IgnoreType ignoreType, ulong ignoredId, BlockType blockType) { GuildId = guildId; IgnoreType = ignoreType; IgnoredId = ignoredId; BlockType = blockType; }
private string UpdateQuery <T>(string updateFields = null) { var properties = new List <string>(); foreach (var p in typeof(T).GetProperties()) { var pAttr = (QueryIgnoreAttribute[])p.GetCustomAttributes(typeof(QueryIgnoreAttribute), false); if (pAttr.Length > 0) { IgnoreType ignoreType = pAttr[0].Ignore; if (ignoreType == IgnoreType.All || ignoreType == IgnoreType.Update || ignoreType == IgnoreType.InsertAndUpdate) { continue; } } if (updateFields == null) { properties.Add(p.Name); } else if (updateFields.Contains(p.Name)) { properties.Add(p.Name); } } var propQueries = string.Join(", ", properties.Select(p => $"{p} = @{p}")); return($@" UPDATE `{DbName}` SET {propQueries} WHERE `Id` = @Id" .Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty));; }
public void IgnoreFileOrDirectory(int?index, IgnoreType ignoreType, Side side) { Duplicate duplicate = (index != null && index >= 0) ? model.Duplicates[index.Value] : inspectingDuplicate; IgnoreSide ignoreAction = new IgnoreSide(this, duplicate, ignoreType, side); Do(ignoreAction); }
private async Task <bool> ValidateUlong(ICommandContext context, IgnoreType ignoreType, ulong ignoreId) { switch (ignoreType) { case IgnoreType.User: var user = await context.Guild.GetUserAsync(ignoreId); return(user != null); case IgnoreType.Channel: var channel = await context.Guild.GetChannelAsync(ignoreId); return(channel != null); case IgnoreType.Role: var role = context.Guild.GetRole(ignoreId); return(role != null); case IgnoreType.All: var auser = await context.Guild.GetUserAsync(ignoreId); var achannel = await context.Guild.GetChannelAsync(ignoreId); var arole = context.Guild.GetRole(ignoreId); return(auser != null || achannel != null || arole != null); default: throw new ArgumentOutOfRangeException(nameof(ignoreType), ignoreType, null); } }
public AllowString(ulong guildId, IgnoreType ignoreType, ulong ignoredId, string allowedString) { GuildId = guildId; IgnoreType = ignoreType; IgnoredId = ignoredId; AllowedString = allowedString ?? throw new ArgumentNullException(nameof(allowedString)); }
public async Task <IEnumerable <Ignore> > GetAllAsync(IGuild guild, IgnoreType ignoreType) { if (guild == null) { throw new ArgumentNullException(nameof(guild)); } return(await GetAllAsync(guild.Id, ignoreType)); }
public IEnumerable <Ignore> GetAll(IGuild guild, IgnoreType ignoreType) { if (guild == null) { throw new ArgumentNullException(nameof(guild)); } return(GetAll(guild.Id, ignoreType)); }
public Ignore(ulong guildId, IgnoreType ignoreType, ulong ignoredId, BlockType blockType, string ignroedString = null) { GuildId = guildId; IgnoreType = ignoreType; IgnoredId = ignoredId; BlockType = blockType; IgnoredString = ignroedString; }
public IgnoreSide(DuplicatesFormController controller, Duplicate duplicate, IgnoreType ignoreType, Side ignoreSide) : base(controller) { this.duplicate = duplicate; this.ignoreType = ignoreType; this.ignoreSide = ignoreSide; this.duplicateIndexInList = controller.model.Duplicates.IndexOf(duplicate); string file = ignoreSide == Side.Left ? duplicate.File1Path : duplicate.File2Path; this.ignorePath = ignoreType == IgnoreType.Directory ? Path.GetDirectoryName(file) : file; }
public void SetAttackInfo(AttackInfo attackInfo, IgnoreType ignore = IgnoreType.IgnoreFloor) { _ = attackInfo ?? throw new System.ArgumentNullException(nameof(attackInfo)); if (hitSet == null) { hitSet = new HashSet <GameObject>(); } this.attackInfo = attackInfo; this.ignore = ignore; hitCount = 0; isActive = true; }
private string InsertQuery <T>() { var properties = new List <string>(); foreach (var p in typeof(T).GetProperties()) { var pAttr = (QueryIgnoreAttribute[])p.GetCustomAttributes(typeof(QueryIgnoreAttribute), false); if (pAttr.Length > 0) { IgnoreType ignoreType = pAttr[0].Ignore; if (ignoreType == IgnoreType.All || ignoreType == IgnoreType.Insert || ignoreType == IgnoreType.InsertAndUpdate) { continue; } } properties.Add(p.Name); } var propRight = "@" + properties.Aggregate((i, j) => $"{i}, @{j}"); var propLeft = string.Join(", ", properties); return($"INSERT INTO `{DbName}` ({propLeft}) Values({propRight})".Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty));; }
private void IgnoreInput(int count, Keys key, char chr) { _inputIgnoreCount = count; _inputIgnoreKey = key; _inputIgnoreChar = chr; if (key == Keys.None && chr == '\0') { _inputIgnoreType = IgnoreType.All; } else if (key != Keys.None && chr == '\0') { _inputIgnoreType = IgnoreType.Keys; } else if (key == Keys.None && chr != '\0') { _inputIgnoreType = IgnoreType.Characters; } else { _inputIgnoreType = IgnoreType.KeyCharcter; } }
/// <summary> /// Constructor. /// </summary> public IgnoreAttribute() { IgnoreType = IgnoreType.All; }
public IEnumerable <Ignore> GetAll(ulong guildId, IgnoreType ignoreType) => Context.Ignores.Where(ignore => ignore.GuildId == guildId && ignore.IgnoreType == ignoreType);
public string GetIgnorePos(string key, IgnoreType type) { string pos = null; switch (type) { case IgnoreType.Ignore1: report2Ignore.TryGetValue(key, out pos); break; case IgnoreType.Ignore2: report3Ignore.TryGetValue(key, out pos); break; default: break; } return pos; }
public void SetIgnoreListType(IgnoreType type) => IgnoreListType = type;
public async Task <IEnumerable <Ignore> > GetAllAsync(ulong guildId, IgnoreType ignoreType) => await Context.Ignores.Where(ignore => ignore.GuildId == guildId && ignore.IgnoreType == ignoreType).ToListAsync();
/// <summary> Specify which action is to be ignored (persistence or hydration) the default is both.</summary> /// /// <param name="ignoreType"> Type of the ignore. </param> public IgnoreAttribute(IgnoreType ignoreType) { IgnoreType = ignoreType; }
/// <summary> /// 构造函数 /// </summary> /// <param name="ignoreType"></param> /// <param name="sameActionName"></param> public IgnoreAuthorityAttribute(IgnoreType ignoreType, string sameActionName) { IgnoreType = ignoreType; SameActionName = sameActionName; }
/// <summary> /// 构造函数 /// </summary> /// <param name="ignoreType"></param> public IgnoreAuthorityAttribute(IgnoreType ignoreType) { IgnoreType = ignoreType; }
public async Task <IHttpActionResult> UpdateOneIgnore(string id, bool ignore, IgnoreType type) { var article = await _dbContext.Articles.FindAsync(id); if (article == null) { return(NotFound()); } var userId = User.Identity.GetUserId(); if (userId != article.PrincipalId) { return(Unauthorized()); } switch (type) { case IgnoreType.Like: article.IgnoreNewLikes = ignore; break; case IgnoreType.Comment: article.IgnoreNewComments = ignore; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } await _dbContext.SaveChangesAsync(); return(Ok()); }
public static IEnumerable <Ignore> GetIgnoreType(this IEnumerable <Ignore> ignores, IgnoreType type) => ignores.Where(i => i.IgnoreType == type || i.IgnoreType == IgnoreType.All);