The ContentStore object is the centerpiece of the CSAPI. This is the object that creates all communication sessions.
The ContentStore object should only be created once per CMS instance within your application's app domain.
For integration with the CMS application, we can easily retrieve the ContentStore from the Common object:
CMS_Common common = CMS_Common.GetCommonInstance(context.Request.RequestContext); IContentStore contentStore = common.ContentStore;
For an individual desktop or web application that doesn't live in CMS app domain, create the Common object like in the following sample. It need only be created once in your app domain.
IContentStore contentStore = new ContentStore("http://cms.yourfirm.com/testsite1/contentstore", "d:\IGX_Sites\cms\90\testsite1\App_Data\xml");
An operating user is necessary to create an communication channel and read or write data from Content Store.
For intergration with CMS application, the current user can be retrieved from the Common object:
CMS_Common common = CMS_Common.GetCommonInstance(context.Request.RequestContext); IReadonlyUser currentUser = common.CurrentUser;
For an individual desktop or web application that doesn't live in the CMS app domain, provide this user's ID.
IReadonlyUser currentUser = store.GetStartingUser(@"yourfirm\youruserid");
The CSAPI is a session-based, transaction-oriented API. All CSAPI objects must scoped within the session in which they were created or retrieved. Change-tracking is automatically performed on these objects.
UserSession objects are based on IDisposable, and the best way to create them is with "using" statements.
To open a read-only session, where changes will not be saved on the objects:
using (IUserSession session = store.OpenReadSession(currentUser))
{
......
}
To open a write session, where changes will be automatically saved on the objects upon end of a "using" statement:
using (IUserSession session = store.OpenWriteSession(currentUser))
{
......
}