/// <summary> /// Creates a new object from the underlying failing query. /// </summary> /// <param name="underlyingFailingQuery">The underlying failing query dataset.</param> /// <param name="penaltyInfo">The penalty info.</param> /// <remarks> /// Yes, this is code duplication with BgpRestApiController and a common base-class would make sense design-wise (is-a FailingQuery). /// But this has been added later and the underlying classes are Entity Framework Database Models. /// I'm simply scared of modifying them to have a common base class. Not sure if EF migration framework is able to handle this. /// </remarks> public RssiFailingQueryWithPenaltyInfo(RssiFailingQuery underlyingFailingQuery, ISingleFailureInfo penaltyInfo) { if (underlyingFailingQuery == null) { throw new ArgumentNullException(nameof(underlyingFailingQuery), "The underlying failing query data is null"); } this.AffectedHosts = underlyingFailingQuery.AffectedHosts; this.ErrorInfo = underlyingFailingQuery.ErrorInfo; this.Subnet = underlyingFailingQuery.Subnet; this.TimeStamp = underlyingFailingQuery.TimeStamp; this.PenaltyInfo = underlyingFailingQuery.PenaltyInfo; if (penaltyInfo != null) { // only replacing the object that has potentially been retrieved from database // if we have a more recent one directly from handler. if (this.PenaltyInfo == null) { // we have not penalty info -> unconditionally set the new one this.PenaltyInfo = penaltyInfo; } else if (this.PenaltyInfo.LastOccurance <= penaltyInfo.LastOccurance) { // we have a penalty info -> only set if new one is newer or same this.PenaltyInfo = penaltyInfo; } } }
/// <summary> /// Initialize for the given type and entity string with the given penalty info. /// </summary> /// <param name="entityType">The type of the entity.</param> /// <param name="entity">The name of the entity (e.g. an IP address or a subnet in CIDR).</param> /// <param name="penaltyInfo">The associated penalty info.</param> public SingleFailureInfoWithEntity(EntityType entityType, string entity, ISingleFailureInfo penaltyInfo) { this.entityType = entityType; this.entity = entity ?? string.Empty; this.penaltyInfo = penaltyInfo ?? throw new ArgumentNullException(nameof(penaltyInfo), "The penalty info is null"); }