IWebEventCustomEvaluator.CanFire(WebBaseEvent, RuleFiringRecord) Method

Definition

Evaluates whether an event should be raised.

C#
public bool CanFire(System.Web.Management.WebBaseEvent raisedEvent, System.Web.Management.RuleFiringRecord record);

Parameters

raisedEvent
WebBaseEvent

The event to raise.

record
RuleFiringRecord

The RuleFiringRecord containing information about the event.

Returns

true if the event should be raised; otherwise, false.

Examples

The following code example shows a custom implementation of the CanFire method.

C#
// Implements the IWebEventCustomEvaluator.CanFire 
// method. It is called by the ASP.NET if this custom
// type is configured in the profile
// element of the healthMonitoring section.
public bool CanFire(
    System.Web.Management.WebBaseEvent e, 
    RuleFiringRecord rule)
{

    bool fireEvent;
    string lastFired = rule.LastFired.ToString();
    string timesRaised = rule.TimesRaised.ToString();

    // Fire every other event raised.
    fireEvent =
        (rule.TimesRaised % 2 == 0) ? true : false;

    if (fireEvent)
    {
        firingRecordInfo =
            string.Format("Event last fired: {0}",
            lastFired) +
            string.Format(". Times raised: {0}",
            timesRaised);
    }
    else
        firingRecordInfo =
          string.Format(
           "Event not fired. Times raised: {0}",
           timesRaised);

    return fireEvent;
}

Remarks

If the custom event evaluator returns true, the event is raised and then processed by the associated provider.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1