/// <summary> /// Deletes workflow scope. Called when the "Delete scope" button is pressed. /// Expects the CreateWorkflowScope method to be run first. /// </summary> private bool DeleteWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Get the workflow's scopes DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID); if (!DataHelper.DataSourceIsEmpty(scopes)) { // Create the scope info object WorkflowScopeInfo deleteScope = new WorkflowScopeInfo(scopes.Tables[0].Rows[0]); // Delete the workflow scope WorkflowScopeInfoProvider.DeleteWorkflowScopeInfo(deleteScope); return(true); } else { // No scope was found apiDeleteWorkflowScope.ErrorMessage = "The scope was not found."; } } return(false); }
/// <summary> /// Gets and updates workflow scope. Called when the "Get and update scope" button is pressed. /// Expects the CreateWorkflowScope method to be run first. /// </summary> private bool GetAndUpdateWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Get the workflow's scopes InfoDataSet <WorkflowScopeInfo> scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID); if (!DataHelper.DataSourceIsEmpty(scopes)) { // Create the scope info object WorkflowScopeInfo updateScope = scopes.First <WorkflowScopeInfo>(); // Update the properties - the scope will include all cultures and document types updateScope.ScopeCultureID = 0; updateScope.ScopeClassID = 0; // Save the changes WorkflowScopeInfoProvider.SetWorkflowScopeInfo(updateScope); return(true); } else { // No scope was found apiGetAndUpdateWorkflowScope.ErrorMessage = "The scope was not found."; } } return(false); }
/// <summary> /// Creates workflow scope. Called when the "Create scope" button is pressed. /// Expects the "CreateWorkflow" method to be run first. /// </summary> private bool CreateWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Create new workflow scope object WorkflowScopeInfo newScope = new WorkflowScopeInfo(); // Get the site default culture from settings string cultureCode = SettingsKeyInfoProvider.GetStringValue(SiteContext.CurrentSiteName + ".CMSDefaultCultureCode"); CultureInfo culture = CultureInfoProvider.GetCultureInfo(cultureCode); // Get root document type class ID int classID = DataClassInfoProvider.GetDataClassInfo("CMS.Root").ClassID; // Set the properties newScope.ScopeStartingPath = "/"; newScope.ScopeCultureID = culture.CultureID; newScope.ScopeClassID = classID; newScope.ScopeWorkflowID = workflow.WorkflowID; newScope.ScopeSiteID = SiteContext.CurrentSiteID; // Save the workflow scope WorkflowScopeInfoProvider.SetWorkflowScopeInfo(newScope); return(true); } return(false); }
/// <summary> /// Deletes workflow scope. Called when the "Delete scope" button is pressed. /// Expects the CreateWorkflowScope method to be run first. /// </summary> private bool DeleteWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow", WorkflowTypeEnum.Approval); if (workflow != null) { // Get the workflow's scopes InfoDataSet <WorkflowScopeInfo> scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID); if (!DataHelper.DataSourceIsEmpty(scopes)) { // Create the scope info object WorkflowScopeInfo deleteScope = scopes.First <WorkflowScopeInfo>(); // Delete the workflow scope WorkflowScopeInfoProvider.DeleteWorkflowScopeInfo(deleteScope); return(true); } else { // No scope was found apiDeleteWorkflowScope.ErrorMessage = "The scope was not found."; } } return(false); }
/// <summary> /// Deletes the workflow scope(s). Called when the "Delete workflow scope" button is pressed. /// Expects the "CreateWorkflowScope" method to be run first. /// </summary> private bool DeleteWorkflowScope() { // Prepare parameters string where = "ScopeStartingPath LIKE '/API-Example%'"; string orderBy = null; int topN = 0; string columns = null; DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns); 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 scope.Delete(); } return(true); } return(false); }
/// <summary> /// Deletes the workflow scope(s) and culture assignments used for this example. Called when the "Delete objects" button is pressed. /// Expects the "CreateExampleObjects" method to be run first. /// </summary> private bool DeleteObjects() { CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); // Remove the example culture from the site CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, CMSContext.CurrentSiteID); // Prepare parameters string where = "ScopeStartingPath LIKE '/API-Example%'"; string orderBy = null; int topN = 0; string columns = null; DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns); 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 scope.Delete(); } return(true); } return(false); }
/// <summary> /// Publishes document. /// </summary> /// <param name="node">Node to publish</param> /// <param name="wm">Workflow manager</param> /// <returns>Whether node is already published</returns> private bool Publish(TreeNode node, WorkflowManager wm) { string pathCulture = HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")"); WorkflowStepInfo currentStep = wm.GetStepInfo(node); bool alreadyPublished = (currentStep == null) || currentStep.StepIsPublished; if (!alreadyPublished) { using (CMSActionContext ctx = new CMSActionContext() { LogEvents = false }) { // Remove possible checkout if (node.DocumentCheckedOutByUserID > 0) { TreeProvider.ClearCheckoutInformation(node); node.Update(); } } // Publish document currentStep = wm.PublishDocument(node, null); } // Document is already published, check if still under workflow if (alreadyPublished && (currentStep != null) && currentStep.StepIsPublished) { WorkflowScopeInfo wsi = wm.GetNodeWorkflowScope(node); if (wsi == null) { DocumentHelper.ClearWorkflowInformation(node); VersionManager vm = VersionManager.GetInstance(node.TreeProvider); vm.RemoveWorkflow(node); } } // Document already published if (alreadyPublished) { AddLog(string.Format(ResHelper.GetString("content.publishedalready"), pathCulture)); } else if ((currentStep == null) || !currentStep.StepIsPublished) { AddError(string.Format(ResHelper.GetString("content.PublishWasApproved"), pathCulture)); return(true); } else { // Add log record AddLog(pathCulture); } return(false); }
/// <summary> /// Deletes the workflow scope, workflow step and the document used for this example. Called when the "Delete example objects" button is pressed. /// Expects the "CreateExampleObjects" method to be run first. /// </summary> 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); }
private void Apply() { var path = Node.NodeAliasPath; var scope = new WorkflowScopeInfo { ScopeStartingPath = path, ScopeExcludeChildren = radDocument.Checked, ScopeWorkflowID = ValidationHelper.GetInteger(ucWorkflow.Value, 0), ScopeSiteID = SiteContext.CurrentSiteID }; scope.Insert(); ScriptHelper.RegisterStartupScript(this, typeof(string), "CloseApplyWorkflowDialog", ScriptHelper.GetScript("RefreshParent();CloseDialog();")); }
/// <summary> /// Publishes document. /// </summary> /// <param name="node">Node to publish</param> /// <param name="currentStep">Current workflow step</param> /// <returns>TRUE if operation fails</returns> private bool Publish(TreeNode node, WorkflowStepInfo currentStep) { string pathCulture = HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")"); bool alreadyPublished = (currentStep == null) || currentStep.StepIsPublished; if (!alreadyPublished) { var workflow = node.WorkflowManager.GetNodeWorkflow(node); if (workflow != null && workflow.IsApproval && currentStep.StepIsArchived) { node.CreateNewVersion(); } // Publish document currentStep = node.WorkflowManager.PublishDocument(node); } // Document is already published, check if still under workflow if (alreadyPublished && (currentStep != null) && currentStep.StepIsPublished) { WorkflowScopeInfo wsi = node.WorkflowManager.GetNodeWorkflowScope(node); if (wsi == null) { VersionManager vm = VersionManager.GetInstance(node.TreeProvider); vm.RemoveWorkflow(node); } } // Document already published if (alreadyPublished) { AddLog(string.Format(ResHelper.GetString("content.publishedalready"), pathCulture)); } else if ((currentStep == null) || !currentStep.StepIsPublished) { AddError(string.Format(ResHelper.GetString("content.PublishWasApproved"), pathCulture)); return(true); } else { // Add log record AddLog(pathCulture); } return(false); }
/// <summary> /// Gets the default workflow "Versioning without workflow" and creates new workflow scope. /// Called when the "Create scope" button is pressed. /// </summary> private bool CreateWorkflowScope() { WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("versioningWithoutWorkflow"); if (workflow != null) { // Create new workflow scope and set its properties WorkflowScopeInfo scope = new WorkflowScopeInfo() { ScopeWorkflowID = workflow.WorkflowID, ScopeStartingPath = "/API-Example/%", ScopeSiteID = SiteContext.CurrentSiteID }; // Save the scope into the database WorkflowScopeInfoProvider.SetWorkflowScopeInfo(scope); return(true); } return(false); }
/// <summary> /// Publishes document. /// </summary> /// <param name="node">Node to publish</param> /// <param name="wm">Workflow manager</param> /// <param name="currentStep">Current workflow step</param> /// <returns>Whether node is already published</returns> private static bool Publish(TreeNode node, WorkflowManager wm, WorkflowStepInfo currentStep) { bool toReturn = true; if (currentStep != null) { // For archive step start new version if (currentStep.StepName.ToLower() == "archived") { VersionManager vm = new VersionManager(node.TreeProvider); currentStep = vm.CheckOut(node, node.IsPublished, true); vm.CheckIn(node, null, null); } // Approve until the step is publish while ((currentStep != null) && (currentStep.StepName.ToLower() != "published")) { currentStep = wm.MoveToNextStep(node, string.Empty); toReturn = false; } // Document is already published, check if still under workflow if (toReturn && (currentStep.StepName.ToLower() == "published")) { WorkflowScopeInfo wsi = wm.GetNodeWorkflowScope(node); if (wsi == null) { DocumentHelper.ClearWorkflowInformation(node); VersionManager vm = new VersionManager(node.TreeProvider); vm.RemoveWorkflow(node); } } } return(toReturn); }
/// <summary> /// Gets and updates workflow scope. Called when the "Get and update scope" button is pressed. /// Expects the CreateWorkflowScope method to be run first. /// </summary> private bool GetAndUpdateWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Get the workflow's scopes DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID); if (!DataHelper.DataSourceIsEmpty(scopes)) { // Create the scope info object WorkflowScopeInfo updateScope = new WorkflowScopeInfo(scopes.Tables[0].Rows[0]); // Update the properties - the scope will include all cultures and document types updateScope.ScopeCultureID = 0; updateScope.ScopeClassID = 0; // Save the changes WorkflowScopeInfoProvider.SetWorkflowScopeInfo(updateScope); return true; } else { // No scope was found apiGetAndUpdateWorkflowScope.ErrorMessage = "The scope was not found."; } } return false; }
/// <summary> /// Deletes the workflow scope(s) and culture assignments used for this example. Called when the "Delete objects" button is pressed. /// Expects the "CreateExampleObjects" method to be run first. /// </summary> private bool DeleteObjects() { CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); // Remove the example culture from the site CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, CMSContext.CurrentSiteID); // Prepare parameters string where = "ScopeStartingPath LIKE '/API-Example%'"; string orderBy = null; int topN = 0; string columns = null; DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns); 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 scope.Delete(); } return true; } return false; }
/// <summary> /// Assigns another culture to the current site, then creates the document structure and workflow scope needed for this example. Called when the "Create example objects" button is pressed. /// </summary> private bool CreateExampleObjects() { // Add a new culture to the current site CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, CMSContext.CurrentSiteID); // 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 example folder TreeNode node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "API Example"; node.DocumentCulture = "en-us"; // Insert it to database DocumentHelper.InsertDocument(node, parent, tree); parent = node; // Create the Source folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Source"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Create the Target folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Target"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Get the default workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("default"); if (workflow != null) { // Get the example folder data node = DocumentHelper.GetDocument(parent, 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); return true; } else { apiCreateExampleObjects.ErrorMessage = "The default workflow was not found."; } } return false; }
/// <summary> /// Saves data of edited workflow scope from TextBoxes into DB. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // finds whether required fields are not empty string result = new Validator().NotEmpty(pathElem.Value, GetString("Development-Workflow_Scope_Edit.RequiresStartingAliasPath")).Result; string className = ValidationHelper.GetString(selectClassNames.Value, ALL_DOCTYPES); int classId = 0; if (className != ALL_DOCTYPES) { // Get class ID DataClassInfo dci = DataClassInfoProvider.GetDataClass(className); classId = dci.ClassID; } if (result == string.Empty) { if (WorkflowScopeId > 0) { if (CurrentScopeInfo != null) { if (!pathElem.Value.ToString().StartsWith("/")) { pathElem.Value = "/" + pathElem.Value; } CurrentScopeInfo.ScopeStartingPath = pathElem.Value.ToString().Trim(); CurrentScopeInfo.ScopeClassID = classId; CurrentScopeInfo.ScopeID = WorkflowScopeId; CurrentScopeInfo.ScopeCultureID = ValidationHelper.GetInteger(cultureSelector.Value, 0); WorkflowScopeInfoProvider.SetWorkflowScopeInfo(CurrentScopeInfo); lblInfo.Visible = true; lblInfo.Text = GetString("General.ChangesSaved"); } } else { if (workflowId > 0) { if (siteId > 0) { if (!pathElem.Value.ToString().StartsWith("/")) { pathElem.Value = "/" + pathElem.Value; } WorkflowScopeInfo wsi = new WorkflowScopeInfo(); wsi.ScopeStartingPath = pathElem.Value.ToString().Trim(); wsi.ScopeClassID = classId; wsi.ScopeCultureID = ValidationHelper.GetInteger(cultureSelector.Value, 0); wsi.ScopeSiteID = siteId; wsi.ScopeWorkflowID = workflowId; try { WorkflowScopeInfoProvider.SetWorkflowScopeInfo(wsi); URLHelper.Redirect("Workflow_Scope_Edit.aspx?scopeid=" + wsi.ScopeID + "&saved=1"); } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; } } else { lblError.Visible = true; lblError.Text = GetString("Development-Workflow_Scope_Edit.NoSiteIdGiven"); } } else { lblError.Visible = true; lblError.Text = GetString("Development-Workflow_Scope_Edit.NoDocumentTypeGiven"); } } } else { lblError.Visible = true; lblError.Text = result; } }
/// <summary> /// Saves data of edited workflow scope from TextBoxes into DB. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string path = pathElem.Value.ToString().Trim(); // Find whether required fields are not empty string result = new Validator().NotEmpty(path, GetString("Development-Workflow_Scope_Edit.RequiresStartingAliasPath")).Result; // Prepare path for further validation if (result == string.Empty) { // Ensure slash at the beginning if (!path.StartsWithCSafe("/")) { path = "/" + path; } string className = ValidationHelper.GetString(selectClassNames.Value, ALL_DOCTYPES); int classId = 0; if (className != ALL_DOCTYPES) { // Get class ID DataClassInfo dci = DataClassInfoProvider.GetDataClass(className); classId = dci.ClassID; } if (WorkflowScopeId > 0) { if (CurrentScopeInfo != null) { if (rbChildren.Checked) { CurrentScopeInfo.ScopeStartingPath = TreePathUtils.EnsureSingleNodePath(path).TrimEnd('/') + "/%"; CurrentScopeInfo.ScopeExcludeChildren = false; } else { CurrentScopeInfo.ScopeStartingPath = TreePathUtils.EnsureSingleNodePath(path); CurrentScopeInfo.ScopeExcludeChildren = rbDoc.Checked; } CurrentScopeInfo.ScopeClassID = classId; CurrentScopeInfo.ScopeID = WorkflowScopeId; CurrentScopeInfo.ScopeExcluded = rbExcluded.Checked; CurrentScopeInfo.ScopeMacroCondition = cbCondition.Text; CurrentScopeInfo.ScopeCultureID = ValidationHelper.GetInteger(cultureSelector.Value, 0); WorkflowScopeInfoProvider.SetWorkflowScopeInfo(CurrentScopeInfo); ShowChangesSaved(); } } else { if (workflowId > 0) { if (siteId > 0) { WorkflowScopeInfo wsi = new WorkflowScopeInfo(); if (rbChildren.Checked) { wsi.ScopeStartingPath = TreePathUtils.EnsureSingleNodePath(path).TrimEnd('/') + "/%"; wsi.ScopeExcludeChildren = false; } else { wsi.ScopeStartingPath = TreePathUtils.EnsureSingleNodePath(path); wsi.ScopeExcludeChildren = rbDoc.Checked; } wsi.ScopeClassID = classId; wsi.ScopeCultureID = ValidationHelper.GetInteger(cultureSelector.Value, 0); wsi.ScopeExcluded = rbExcluded.Checked; wsi.ScopeMacroCondition = cbCondition.Text; wsi.ScopeSiteID = siteId; wsi.ScopeWorkflowID = workflowId; WorkflowScopeInfoProvider.SetWorkflowScopeInfo(wsi); URLHelper.Redirect("Workflow_Scope_Edit.aspx?scopeid=" + wsi.ScopeID + "&saved=1"); } else { ShowError(GetString("Development-Workflow_Scope_Edit.NoSiteIdGiven")); } } else { ShowError(GetString("Development-Workflow_Scope_Edit.NoDocumentTypeGiven")); } } pathElem.Value = path; } else { ShowError(result); } }
/// <summary> /// Gets the default workflow "Versioning without workflow" and creates new workflow scope. /// Called when the "Create scope" button is pressed. /// </summary> private bool CreateWorkflowScope() { WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("versioningWithoutWorkflow"); if (workflow != null) { // Create new workflow scope and set its properties WorkflowScopeInfo scope = new WorkflowScopeInfo() { ScopeWorkflowID = workflow.WorkflowID, ScopeStartingPath = "/API-Example/%", ScopeSiteID = SiteContext.CurrentSiteID }; // Save the scope into the database WorkflowScopeInfoProvider.SetWorkflowScopeInfo(scope); return true; } return false; }
/// <summary> ///Creates the document, workflow scope and step needed for this example. Called when the "Create example objects" button is pressed. /// </summary> private bool CreateExampleObjects() { // Create a new tree provider TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); // Get the root node TreeNode parent = tree.SelectSingleNode(SiteContext.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 = SiteContext.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; }
/// <summary> ///Creates the document, workflow scope and step needed for this example. Called when the "Create example objects" button is pressed. /// </summary> 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); }
/// <summary> /// Assigns another culture to the current site, then creates the document structure and workflow scope needed for this example. Called when the "Create example objects" button is pressed. /// </summary> private bool CreateExampleObjects() { // Add a new culture to the current site CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, CMSContext.CurrentSiteID); // 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 example folder TreeNode node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "API Example"; node.DocumentCulture = "en-us"; // Insert it to database DocumentHelper.InsertDocument(node, parent, tree); parent = node; // Create the Source folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Source"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Create the Target folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Target"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Get the default workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("default"); if (workflow != null) { // Get the example folder data node = DocumentHelper.GetDocument(parent, 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); return(true); } else { apiCreateExampleObjects.ErrorMessage = "The default workflow was not found."; } } return(false); }
/// <summary> /// Deletes workflow scope. Called when the "Delete scope" button is pressed. /// Expects the CreateWorkflowScope method to be run first. /// </summary> private bool DeleteWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Get the workflow's scopes DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(workflow.WorkflowID); if (!DataHelper.DataSourceIsEmpty(scopes)) { // Create the scope info object WorkflowScopeInfo deleteScope = new WorkflowScopeInfo(scopes.Tables[0].Rows[0]); // Delete the workflow scope WorkflowScopeInfoProvider.DeleteWorkflowScopeInfo(deleteScope); return true; } else { // No scope was found apiDeleteWorkflowScope.ErrorMessage = "The scope was not found."; } } return false; }
/// <summary> /// Creates workflow scope. Called when the "Create scope" button is pressed. /// Expects the "CreateWorkflow" method to be run first. /// </summary> private bool CreateWorkflowScope() { // Get the workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow"); if (workflow != null) { // Create new workflow scope object WorkflowScopeInfo newScope = new WorkflowScopeInfo(); // Get the site default culture from settings string cultureCode = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode"); CultureInfo culture = CultureInfoProvider.GetCultureInfo(cultureCode); // Get root document type class ID int classID = DataClassInfoProvider.GetDataClass("CMS.Root").ClassID; // Set the properties newScope.ScopeStartingPath = "/"; newScope.ScopeCultureID = culture.CultureID; newScope.ScopeClassID = classID; newScope.ScopeWorkflowID = workflow.WorkflowID; newScope.ScopeSiteID = CMSContext.CurrentSiteID; // Save the workflow scope WorkflowScopeInfoProvider.SetWorkflowScopeInfo(newScope); return true; } return false; }
/// <summary> /// Deletes the workflow scope, workflow step and the document used for this example. Called when the "Delete example objects" button is pressed. /// Expects the "CreateExampleObjects" method to be run first. /// </summary> private bool DeleteExampleObjects() { TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); // Get the example document TreeNode node = tree.SelectSingleNode(SiteContext.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; }
/// <summary> /// Deletes the workflow scope(s). Called when the "Delete workflow scope" button is pressed. /// Expects the "CreateWorkflowScope" method to be run first. /// </summary> private bool DeleteWorkflowScope() { // Prepare parameters string where = "ScopeStartingPath LIKE '/API-Example%'"; string orderBy = null; int topN = 0; string columns = null; DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns); 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 scope.Delete(); } return true; } return false; }