|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example creates a sample documents structure and workflow objects required for the API examples on the following pages to be executed.
private bool CreateExampleObjects() { // Create a new tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the root node TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us");
if (parent != null) { // Create the API document TreeNode node = TreeNode.New("CMS.MenuItem", tree);
node.DocumentName = "API Example"; node.DocumentCulture = "en-us";
// Insert it to database DocumentHelper.InsertDocument(node, parent, tree);
// Get the default workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("default");
if (workflow != null) { // Get the document data node = DocumentHelper.GetDocument(node, tree);
// Create new workflow scope WorkflowScopeInfo scope = new WorkflowScopeInfo();
// Assign to the default workflow and current site and set starting alias path to the example document scope.ScopeWorkflowID = workflow.WorkflowID; scope.ScopeStartingPath = node.NodeAliasPath; scope.ScopeSiteID = CMSContext.CurrentSiteID;
// Save the scope into the database WorkflowScopeInfoProvider.SetWorkflowScopeInfo(scope);
// Create a new workflow step WorkflowStepInfo step = new WorkflowStepInfo();
// Set its properties step.StepWorkflowID = workflow.WorkflowID; step.StepName = "MyNewWorkflowStep"; step.StepDisplayName = "My new workflow step"; step.StepOrder = 1;
// Save the workflow step WorkflowStepInfoProvider.SetWorkflowStepInfo(step);
// Ensure correct step order WorkflowStepInfoProvider.InitStepOrders(workflow);
return true; } else { apiCreateExampleObjects.ErrorMessage = "The default workflow was not found."; } }
return false; } |
The following example deletes the sample document structure and objects created by the example above.
private bool DeleteExampleObjects() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get the example document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", "en-us");
if (node != null) { // Delete the document DocumentHelper.DeleteDocument(node, tree, true, true, true); }
string where = "ScopeStartingPath LIKE '/API-Example%'";
// Get example workflow scopes DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, null, 0, null);
if (!DataHelper.DataSourceIsEmpty(scopes)) { // Loop through all the scopes in case more identical scopes were accidentally created foreach (DataRow scopeRow in scopes.Tables[0].Rows) { // Create scope info object WorkflowScopeInfo scope = new WorkflowScopeInfo(scopeRow);
// Delete the scope WorkflowScopeInfoProvider.DeleteWorkflowScopeInfo(scope); } }
// Get the default workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("default");
if (workflow != null) { // Get the example step WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("MyNewWorkflowStep", workflow.WorkflowID);
if (step != null) { // Delete the step WorkflowStepInfoProvider.DeleteWorkflowStepInfo(step); } }
return true; } |