/// <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> /// 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> /// 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; } }