The following extended example demonstrates the power available using the Active Channel Server objects in an ASP environment to allow users to select personalized channel subscriptions.
The Active Channel Server comes with two ASP related COM objects that are tailored to servicing requests for the generation of CDF streams from data stored in project objects. These objects are the CDFGenHelper and the CDFGenerator objects. Besides being able to generate the CDF streams, the actual output can be tailored by specifying a list of GUID values that identify various channels for inclusion or exclusion in the returned CDF stream. The example presented here demonstrates how to go about presenting a list of channel selections to the end user so that they may select only the channels they wish to receive. Once they have selected their channels, they are redirected to an ASP page that will generate the CDF stream using their choices. Note that in this example, the user never actually makes a request for a file with the extension .cdf. The CDF stream is generated dynamically within the ASP page and returned to the client browser. The browser receives the appropriate content-type HTTP header for CDF streams and therefore interprets the stream as channel information.
Setting up the Channel Title List
Assume we have a page that presents a simple form the user can use to select channels from a project. The GUID values and channel titles could be placed in the Application collection for reference by the selector page. Here's how we could do this in the Global.Asa file. Note that this method is static, and the application would have to be reloaded to update the list of titles and channel GUID values after any modification to the project channel data. For the purposes of this example, assume a simple set of channels that are currently not being refreshed: one top-level, and a few in the subchannels collection. The code below could be placed in a Global.Asa file to store the list of channel titles and GUID values for a project. To make the process more dynamic, this code could be altered and placed in an ASP page and would then be created freshly from the project whenever run. In that case, one could store the Titles and GUIDs in a Session ASP object.
Global.Asa
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER>
Sub Application_OnStart
Set IDispHelper = CreateObject("Push.CDFGenHelper")
IDispHelper.Load("Project1")
Set Application("Project1") = IDispHelper
' get the project out to get guids and titles
Set IDispProject = IDispHelper.Project
' add guid=title key/value pairs to a dictionary
Set ChannelTitles = CreateObject("Scripting.Dictionary")
ChannelTitles(IDispProject.Channel.GUID) = IDispProject.Channel.Title
For each channel in IDispProject.Channel.subchannels
ChannelTitles(channel.GUID) = channel.Title
Next
Set IDispProject = nothing 'remove this reference
Set Application("Channel Titles") = ChannelTitles
…
End Sub
</SCRIPT>
Channel Selection Page
Now the user could navigate to a page in the application and view the channel choices available from the project.
Selection.asp
<HTML>
<HEAD>
<TITLE>Select Only the Channels You Want</TITLE>
</HEAD>
<BODY>
Select The Channels You'd Like to Subscribe to:<br>
<FORM METHOD="POST" ACTION="addthem.asp">
<% For Each Key in Application("Channel Titles")
Response.write("<INPUT TYPE=\"CheckBox\" Name=\"ChanSelection\" VALUE=\""
& Key & "\">" & Application("Channel Titles")(key) & "<br>")
%>
<INPUT TYPE=SUBMIT>
</FORM>
</HTML>
Adding the Channel Choices to the Membership Directory
Now we can store the choices in the Membership Directory Service for later use. the hypothetical file called "addthem.asp" is listed below that adds the channels to the user's directory data. At the end of the script we can redirect them to a CDF-generating ASP page so that they receive their chosen channel selections.
addthem.asp
<%
' Get the directory property name used to hold the channel selections
' and style from the CDFGenHelper. Its in the Application collection
Application("Helper").GetSelectionListPropName( ListProp, StyleProp)
' Create the user's AUO
const AUOClass = "membership.userobjects"
Set IDispUserObjects=Server.CreateObject(AUOClass)
' add the guid list to the user's data
' The Form collection should have a nice array of values
' from the checkbox.
IDispUserObjects.PutEx 2, ListProp,(Request.Form("ChanSelection"))
IDispUserObjects.Put StyleProp, 0 ' inclusive list
IDispUserObjects.SetInfo
Set IDispUserObjects = nothing
Response.Clear
Response.Redirect = "generateCDF.asp"
Response.end
%>
Sending the Personalized CDF Stream
Once the user has chosen which channels to subscribe to, a script can be used to generate the personalized channel content so that it may be delivered. An hypothetical file called "DynGenerateCDF.asp" could be something like that listed below. This script actually generates the custom CDF string for the user using their selections stored in the Membership directory database. In the first code example, the CDFGenHelper object was added to the Application collection under the name "Project1". This interface is referred to using this name when the Run method is invoked below.
DynGenerateCDF.asp
<% Set ICDFGenerator = Server.CreateObject("Push.CDFGenerator")
ICDFGenerator.Run "Project1"
%>
The response returned to the user on request would have the CDF mime type set, so the client browser would interpret the stream as CDF and ask the user if they want to add the channel information to their list of channels. The channels presented would only consist of the channels they selected.