Bagikan melalui


InventoryContext Class

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

The InventoryContext class provides the Inventory Management functionality.

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

Syntax

'Declaration
Public Class InventoryContext _
    Inherits CatalogObjectBase
'Usage
Dim instance As InventoryContext
public class InventoryContext : CatalogObjectBase
public ref class InventoryContext : public CatalogObjectBase
public class InventoryContext extends CatalogObjectBase

Remarks

You can use this class to create, delete, edit and get inventory catalogs from the inventory system. This class also allows you to import and export inventory catalogs to and from xml files and manage the inventory quantity deltas.

The InventoryContext cannot be created directly. An instance of the InventoryContext class can be obtained from the InventoryContext property. An instance of the InventoryContext object can be obtained in two modes depending on how the CatalogContext class was initialized. These modes are:

  • Web service mode, where calls to the inventory system are made using the web service.

  • Site agent mode, where calls to the inventory system are made using the site name.

A valid instance of the InventoryContext class will be returned only if:

  • The site has the Inventory resource and the enableInventorySystem attribute in web.config is set to true.

  • The site has the Inventory resource and the ignoreInventorySystem parameter on the CatalogSiteAgent is set to false.

The members in the InventoryContext class provides methods which allow creating, deleting, and retrieving inventory catalogs. The Inventory catalogs are used to store and retrieve inventory information for product catalogs in the catalog system. This information can be created, update, deleted and retrieved by methods in the InventoryContext, InventoryCatalog and InventorySku classes.

Examples

This example demonstrates how to obtain the InventoryContext object using the URL of the catalog web service and using the site name.

using System;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Catalog;
using Microsoft.CommerceServer.Inventory;
namespace InventorySamples
{
  class InventorySample {
    // Gets the InventoryContext using the URL of the catalog web service.
    public InventoryContext GetInventoryContextInAgentMode()
    {
      CatalogServiceAgent serviceAgent = new CatalogServiceAgent("https://localhost/CatalogWebService/CatalogWebService.asmx");
      CatalogContext catalogContext = CatalogContext.Create(serviceAgent);
      return catalogContext.InventoryContext;
    }
    // Gets the Inventory context by using the name of the commerce server site.
    public InventoryContext GetInventoryContextInServerMode()
    {
      CatalogSiteAgent siteAgent = new CatalogSiteAgent();
      siteAgent.AuthorizationMode = AuthorizationMode.ThreadContext;
      siteAgent.AuthorizationPolicyPath = @"c:\ABC\catalogauthorizationstore.xml";
      siteAgent.IgnoreInventorySystem = false;
      siteAgent.SiteName = "CsharpSite";
      CatalogContext catalogContext = CatalogContext.Create(siteAgent);
      return catalogContext.InventoryContext;
    }
  }
}

Inheritance Hierarchy

System..::.Object
  Microsoft.CommerceServer.Catalog..::.CatalogObjectBase
    Microsoft.CommerceServer.Inventory..::.InventoryContext

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

InventoryContext Members

Microsoft.CommerceServer.Inventory Namespace