How Do I... Figures

Important: This documentation applies to 1.0 only. The 2.0 documentation is here

Figure 1: httpHandlers configuration element
<configuration>
  <system.web>
    <httpHandlers>
      <add path="AIP.ashx" verb="GET"
           type="DaveSexton.Web.Controls.AutoInputProtectionRequestHandler, DaveSexton.AutoInputProtection" />
    </httpHandlers>
  </system.web>
</configuration>


Figure 2: Register TagPrefix
<%@ Register Namespace="DaveSexton.Web.Controls" Assembly="DaveSexton.AutoInputProtection"
             TagPrefix="dsweb" %>


Figure 3: Basic control declaration
<dsweb:AutoInputProtectionControl runat="server" ID="aip" />


Figure 4: Configuring a default text provider and bitmap provider example
<configuration>
  <configSections>
    <sectionGroup name="dsweb">
      <section name="autoInputProtection"
               type="DaveSexton.Web.Controls.Configuration.AutoInputProtectionSection, DaveSexton.AutoInputProtection" />
    </sectionGroup>
  </configSections>
  <dsweb>
    <autoInputProtection defaultTextProvider="randomtext" defaultBitmapProvider="resource">
      <textProviders>
        <add name="randomtext"
             type="DaveSexton.Web.Controls.RandomCharactersAutoInputProtectionTextProvider, DaveSexton.AutoInputProtection"
             colors="Red,Green,Blue,Brown" fonts="Times New Roman,Arial,Lucida Sans"
             minimumFontSize="20" maximumFontSize="35" />
      </textProviders>
      <bitmapProviders>
        <add name="resource" 
             type="DaveSexton.Web.Controls.ResourceAutoInputProtectionBitmapProvider, DaveSexton.AutoInputProtection"
             minimumCharacterRotationDegrees="-15" maximumCharacterRotationDegrees="15" />
      </bitmapProviders>
    </autoInputProtection>
  </dsweb>
  ...
</configuration>


Figure 5: Configuring a filter provider example
<autoInputProtection>
  ...
  <filters>
    <add name="horizontalbars" 
         type="DaveSexton.Web.Controls.TranslucentBarsOverlayAutoInputProtectionFilterProvider, DaveSexton.AutoInputProtection"
         colors="Orange,Yellow,Fuchsia" />
  </filters>
</autoInputProtection>


Figure 6: Custom text provider example in C#
using System;
using DaveSexton.Web.Controls;
using DaveSexton.Web.Controls.Configuration;

public class RandomNumbersAutoInputProtectionTextProvider : AutoInputProtectionTextProvider
{
  public override string GenerateRandomAutoInputProtectionText()
  {
    return RandomString.Create(MinimumCharacters, MaximumCharacters, 
      CharacterSets.PositiveDigits, null);
  }
}


Figure 7: Custom bitmap provider example in C#
using System;
using DaveSexton.Web.Controls;
using DaveSexton.Web.Controls.Configuration;

public sealed class WhiteBackgroundAutoInputProtectionBitmapProvider
  : PartitionedAutoInputProtectionBitmapProvider
{
  public override AutoInputProtectionBitmap GenerateAutoInputProtectionBitmap(
    string name, System.Drawing.Size size, AutoInputProtectionTextProvider textProvider)
  {
    return GenerateBitmap(size, textProvider);
  }

  public override AutoInputProtectionBitmap GenerateRandomAutoInputProtectionBitmap(
    System.Drawing.Size size, AutoInputProtectionTextProvider textProvider)
  {
    return GenerateBitmap(size, textProvider);
  }
}


Figure 8: Custom filter provider example in C#
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using DaveSexton.Web.Controls.Configuration;

public sealed class CrossHatchAutoInputProtectionFilterProvider
  : AutoInputProtectionFilterProvider
{
  public override bool CanPostProcess
  {
    get { return true; }
  }

  public override bool CanPreProcess
  {
    get { return false; }
  }

  public override void PostProcess(System.Drawing.Graphics graphics, 
    System.Drawing.Size bitmapSize)
  {
    using (HatchBrush brush = new HatchBrush(HatchStyle.DiagonalCross, 
      Color.FromArgb(100, Color.Black), Color.Transparent))
    {
      graphics.FillRectangle(brush, 0, 0, bitmapSize.Width, bitmapSize.Height);
    }
  }

  public override void PreProcess(System.Drawing.Graphics graphics, 
    System.Drawing.Size bitmapSize)
  {
    throw new NotImplementedException();
  }
}

Last edited Apr 2, 2008 at 12:30 PM by davedev, version 5

Comments

No comments yet.