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