Share via


CatalogSiteAgent Class

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

The CatalogSiteAgent class contains configuration for a connection directly to a Commerce Server site's catalog database. This class cannot be inherited.

Namespace:  Microsoft.CommerceServer.Catalog
Assembly:  Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)

Syntax

'Declaration
Public NotInheritable Class CatalogSiteAgent
'Usage
Dim instance As CatalogSiteAgent
public sealed class CatalogSiteAgent
public ref class CatalogSiteAgent sealed
public final class CatalogSiteAgent

Remarks

The CatalogSiteAgent class contains configuration for a connection directly to a Commerce Server site's catalog database.

The SiteName is used to find the connection string to connect to the database and also to find the authorization configuration.

Examples

public CatalogContext GetCatalogContext()
{
  CatalogContext catalogContext = null;
  CatalogServiceAgent catalogServiceAgent = null;

  try
  {
    if (config.InitializationMode == ConnectionMode.Agent)
    {//AGENT MODE
      if ((config.UserName == null) || (config.UserName.Equals(
        Environment.GetEnvironmentVariable("USERDOMAIN") + @"\" +
          Environment.GetEnvironmentVariable("USERNAME"))))
      {
        // Default case when nothing is specified
        // Uses the user's default credentials when anonymous is not allowed
        catalogServiceAgent = new CatalogServiceAgent(config.WebServiceURL, ServiceAgent.DefaultAuthMethods);

        catalogContext = CatalogContext.Create(catalogServiceAgent);
      }
      else if (config.UserName != null)
      {
        // Create custom
        CredentialCache credentials = new CredentialCache();
        NetworkCredential networkCredential = new NetworkCredential();
        //create new uri with web service url
        System.Uri uri = new System.Uri(config.WebServiceURL);

        //add the user name, password, and domain to the network credential
        int index = config.UserName.IndexOf(@"\");
        networkCredential.UserName = config.UserName.Substring(index + 1);
        networkCredential.Password = config.Password;
        networkCredential.Domain = config.UserName.Substring(1, index - 1);

        //add the network credential to the credential cache collection
        credentials.Add(uri, "NTLM", networkCredential);

        catalogServiceAgent = new CatalogServiceAgent(config.WebServiceURL, ServiceAgent.DefaultAuthMethods);
        catalogServiceAgent.Credentials = credentials;

        catalogContext = CatalogContext.Create(catalogServiceAgent);
      }
      else
        throw new System.InvalidOperationException("Cannot perform this operation without initialization");
    }
    else
    {//INPROC MODE
      CatalogSiteAgent csa = new CatalogSiteAgent();
      csa.AuthorizationMode = config.AuthorizationMode;
      csa.AuthorizationPolicyPath = config.AzManXmlFileStore;
      csa.IgnoreInventorySystem = config.IgnoreInventorySystem;
      csa.SiteName = config.SiteName;
      catalogContext = CatalogContext.Create(csa);
    }
  }
  catch (Exception e)
  {
    Console.WriteLine("Error getting CatalogContext: " + e.Message);
    throw e;
  }
  if (catalogContext != null)
    inventoryContext = catalogContext.InventoryContext;
  return catalogContext;
}

Inheritance Hierarchy

System..::.Object
  Microsoft.CommerceServer.Catalog..::.CatalogSiteAgent

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

CatalogSiteAgent Members

Microsoft.CommerceServer.Catalog Namespace