다음을 통해 공유


Creating an Instance of a Custom Resource

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

When a new resource is being added for management within Commerce Server Manager you must add new rows to the ResourceProps, Resources, and SiteResources tables in the Administration database (MSCS_Admin). Taken together, new rows in these tables define a particular instance of a new resource. This enables Commerce Server Manager to display the new resource in the correct location in the scope-pane hierarchy.

These three tables should only be modified by using the administration objects GlobalConfig2FreeThreaded and SiteConfigFreeThreaded. Do not modify them directly in SQL Server Enterprise Manager (SQL Server 2000), SQL Server Management Studio (SQL Server 2005), or using SQL scripts.

For more information about the columns of the various resource tables in the Administration database, see ResourceProps Table, Resources Table, and SiteResources Table, respectively.

Depending on whether the new resource is a global resource or a site resource, a different mechanism is used to instantiate the schema definition values that you already added to the SystemProps and ExtendedProps tables into these three tables. For information about how to add the schema definition values to these two tables, see Defining the Schema for a Custom Resource.

The following code shows how to add a new resource to the site resources of a particular site within Commerce Server Manager.

Note

The string "MyCustomResourceClass" must match the corresponding s_ClassName value in the SystemProps table in order to determine the correct resource schema definition.

sSiteName = "MySite"
sResourceName = "MyCustomResource"
sResourceClassName = "MyCustomResourceClass"

' Initialize the SiteConfig object to the selected site.
Dim SiteConfig
Set SiteConfig = CreateObject("Microsoft.CommerceServer.Interop.Configuration.SiteConfigFreeThreaded")
SiteConfig.Initialize sSiteName

' Instantiate your custom resource to the resource tables.
SiteConfig.CreateComponentConfig sResourceName, sResourceClassName

' Here are some examples of how to set values for your resource
' regardless of whether they are one of the basic properties defined
' in the Resources table or extended properties (that are specific to your
' custom resource defined in the ResourceProps table.
SiteConfig.Fields.Item(sResourceName).Value.Fields.Item("s_Description").Value = "This is my custom resource."
SiteConfig.Fields.Item(sResourceName).Value.Fields.Item("f_ResourceFlags").Value = 2

' You must save changes that were made in the object in order
' to persist those changes to the database tables.
SiteConfig.SaveConfig
Set SiteConfig = Nothing

To add a new resource to the global resources within Commerce Server Manager, you only have to change the example as follows (significant changes are shown in bold font):

Note

The string "MyCustomGlobalResourceClass" must match the corresponding s_ClassName value in the SystemProps table in order to determine the correct resource schema definition.

sResourceName = "MyCustomGlobalResource"
sResourceClassName = "MyCustomGlobalResourceClass"

' Initialize the GlobalConfig object.
Dim GlobalConfig
Set GlobalConfig = CreateObject("Microsoft.CommerceServer.Interop.Configuration.GlobalConfig2FreeThreaded")
GlobalConfig.Initialize    ' no site name

' Instantiate your custom global resource to the resource tables.
GlobalConfig.CreateServiceConfig sResourceName, sResourceClassName

' Here are some examples of how to set values for your resource
' regardless of whether they are one of the basic properties defined
' in the Resources table or extended properties (that are specific to your
' custom resource defined in the ResourceProps table.
GlobalConfig.Fields.Item(sResourceName).Value.Fields.Item("s_Description").Value = _
    "This is my custom global resource."
GlobalConfig.Fields.Item(sResourceName).Value.Fields.Item("f_ResourceFlags").Value = _
    GlobalConfig.Fields.Item(sResourceName).Value.Fields.Item("f_ResourceFlags").Value Or _
    &H00000002

' You must save changes that were made in the object in order
' to persist those changes to the database tables.
GlobalConfig.SaveConfig
Set GlobalConfig = Nothing

See Also

Other Resources

Resource Tables in the Administration Database

Defining the Schema for a Custom Resource

Adding a Custom Resource