Code to Support the ContentSelector Object

The following code shows how to initialize the Content Selection Framework (CSF), set up the CacheManager object and the Expression Evaluator, create an advertising pipeline, and configure the context for CSF ads.

The Global.asa file should include the following code:

<SCRIPT LANGUAGE=VBSCRIPT RUNAT=Server>

option explicit

' Initialize the Content Selection Framework.
Sub Application_OnStart

    ' Modify sConnStr to point to a valid Campaigns database.
    ' The Campaigns database can be created either by unpacking a site,
    ' such as blank.pup, or by running the campaign database creation
    ' scripts in the C:/Program Files/Microsoft Commerce Server/Site
    ' Create directory.
    const sConnStr = "provider=SQLOLEDB;Data Source=(local);Initial
    Catalog=Retail_commerce;Integrated Security='SSPI';"

    Dim oPipe, dCSFAdsContext
    Dim oExpressionEval, oCacheManager, dCacheConfig

    ' Set up CacheManager object.
    Set dCacheConfig = CreateObject("Commerce.Dictionary")
    dCacheConfig.ConnectionString = sConnStr   
    Set oCacheManager = CreateObject("Commerce.CacheManager")
    oCacheManager.LoaderProgId("Ads") = "Commerce.CSFLoadAdvertisements"
    Set oCacheManager.LoaderConfig("Ads") = dCacheConfig
    oCacheManager.RefreshInterval("Ads") = 15 * 60 ' 15 minutes

    ' Create the Expression Evaluator and connect it to the database.
    Set oExpressionEval = CreateObject("Commerce.ExpressionEvaluator")
    Call oExpressionEval.Connect(sConnStr)

    ' Create CSF advertising context, a dictionary.
    Set dCSFAdsContext = CreateObject("Commerce.Dictionary")

    ' Create an advertising pipeline and add it to the context.
    Set oPipe = CreateObject("Commerce.OrderPipeline")
    ' Load the pipeline configuration
    oPipe.LoadPipe(Server.MapPath("Advertising.pcf"))
    ' Store a reference to the pipeline object in the Context
    ' dictionary.
    Set dCSFAdsContext("pipeline") = oPipe

    ' Other context configuration for CSF ads.
    dCSFAdsContext("RedirectUrl") = ".\redir.asp"
    ' Add a reference to an expression evaluator to the Context
    Set dCSFAdsContext("Evaluator") = oExpressionEval
    ' InitCacheManager, a routine that would appear elsewhere in the
    ' global.asa, returns a reference to a CacheManager object.
    Set dCSFAdsContext("CacheManager") = oCacheManager
    dCSFAdsContext("CacheName") = "Ads"

    ' Store a reference to the dCSFAdsContext dictionary in the
    ' Application collection.
    Set Application("CSFAdsContext") = dCSFAdsContext
End Sub

</SCRIPT>

Copyright © 2005 Microsoft Corporation.
All rights reserved.