/// <summary> /// Sets the callback URL of the ActionMenu. It represents the service url with correct parameters for the actions. /// </summary> private void SetServiceUrl() { var scParams = GetReplacedScenarioParameters(); var context = UITools.FindContextInfo(this, ContextInfoID); var path = !String.IsNullOrEmpty(ContextInfoID) ? context.Path : NodePath; var encodedReturnUrl = Uri.EscapeDataString(PortalContext.Current.RequestedUri.PathAndQuery); var encodedParams = Uri.EscapeDataString(scParams ?? string.Empty); if (String.IsNullOrEmpty(path)) { path = GetPathFromContentView(this); } if (string.IsNullOrEmpty(path)) { this.Visible = false; return; } this.Content = Content.Load(path); //Pre-check action count. If empty, hide the action menu. if (CheckActionCount) { var sc = ScenarioManager.GetScenario(Scenario, scParams); var actionCount = 0; if (sc != null) { actionCount = sc.GetActions(this.Content, PortalContext.Current.RequestedUri.PathAndQuery).Count(); } if (actionCount < 2 && string.Equals(Scenario, "new", StringComparison.CurrentCultureIgnoreCase)) { ClickDisabled = true; } else if (actionCount == 0) { this.Visible = false; return; } } //Pre-check required permissions var permissions = ActionFramework.GetRequiredPermissions(RequiredPermissions); if (permissions.Count > 0 && !SecurityHandler.HasPermission(NodeHead.Get(path), permissions.ToArray())) { this.Visible = false; return; } var encodedPath = HttpUtility.UrlEncode(path); ServiceUrl = String.Format("/SmartAppHelper.mvc/GetActions?path={0}&scenario={1}&back={2}¶meters={3}", encodedPath, Scenario, encodedReturnUrl, encodedParams); }
public void AppModel_Scenario_ResolveNotSingleton() { Test(() => { var instance1 = ScenarioManager.GetScenario("TestScenario2"); var instance2 = ScenarioManager.GetScenario("TestScenario2"); Assert.AreNotSame(instance1, instance2); }); }
//================================================================ Helper methods private void SetParameters() { if (ActionListView == null) { return; } ActionListView.ItemDataBound += ActionListView_ItemDataBound; ActionListView.DataSource = null; //refresh NodePath by contextinfo id if (!string.IsNullOrEmpty(ContextInfoID)) { var context = UITools.FindContextInfo(this, ContextInfoID); if (context != null) { var path = context.Path; if (!string.IsNullOrEmpty(path)) { NodePath = path; } } } if (!string.IsNullOrEmpty(NodePath)) { var actions = new List <ActionBase>(); if (string.IsNullOrEmpty(Scenario)) { actions = ActionFramework.GetActions(ContentRepository.Content.Load(NodePath), Scenario, PortalContext.Current.RequestedUri.PathAndQuery).ToList(); } else { var scParams = GetReplacedScenarioParameters(); var sc = ScenarioManager.GetScenario(Scenario, scParams); if (sc != null) { actions = sc.GetActions(ContentRepository.Content.Load(NodePath), PortalContext.Current.RequestedUri.PathAndQuery).ToList(); } } ActionListView.DataSource = actions.Count > 0 ? actions : null; } else if (!string.IsNullOrEmpty(ActionName) && !string.IsNullOrEmpty(ContentPathList)) { var actions = GetActionListFromPathList(); ActionListView.DataSource = actions.Count > 0 ? actions : null; } ActionListView.DataBind(); }
public void AppModel_Scenario_GenericIsSingleton() { Test(() => { var parentPath = "/Root/(apps)/GenericContent"; var appPath = parentPath + "/tempapp"; // create at least one app with a scenario RepositoryTools.CreateStructure(parentPath, "SystemFolder"); var tempAppContent = RepositoryTools.CreateStructure(appPath, "Application") ?? Content.Load(appPath); var tempApp = (Application)tempAppContent.ContentHandler; tempApp.Scenario = "SC1,SC2"; tempApp.Save(SavingMode.KeepVersion); try { // Get first generic scenario var genericScenario = ApplicationStorage.Instance.ScenarioNames .Select(ScenarioManager.GetScenario) .Where(s => s != null) .FirstOrDefault(s => s.GetType() == typeof(GenericScenario)); // The test method is invalid if there is no any generic scenario if (genericScenario == null) { Assert.Inconclusive(); } // Test var instance1 = ScenarioManager.GetScenario(genericScenario.Name); var instance2 = ScenarioManager.GetScenario(genericScenario.Name); Assert.AreSame(instance1, instance2); } finally { // cleanup tempAppContent.ForceDelete(); } }); }
public void AppModel_Scenario_GenericIsSingleton() { Test(() => { // Get first generic scenario var genericScenario = ApplicationStorage.Instance.ScenarioNames .Select(ScenarioManager.GetScenario) .Where(s => s != null) .FirstOrDefault(s => s.GetType() == typeof(GenericScenario)); // The test method is invalid if there is no any generic scenario if (genericScenario == null) { Assert.Inconclusive(); } // Test var instance1 = ScenarioManager.GetScenario(genericScenario.Name); var instance2 = ScenarioManager.GetScenario(genericScenario.Name); Assert.AreSame(instance1, instance2); }); }
public ActionResult GetActions(string path, string scenario, string back, string parameters) { path = HttpUtility.UrlDecode(path); scenario = HttpUtility.UrlDecode(scenario); parameters = HttpUtility.UrlDecode(parameters); //this line caused an error in back url encoding (multiple back //parameters when the user goes deep, through multiple actions) //back = HttpUtility.UrlDecode(back); var actions = new List <ActionBase>(); var sc = ScenarioManager.GetScenario(scenario, parameters); if (sc != null) { var context = SNCR.Content.Load(path); actions = sc.GetActions(context, back).ToList(); } return(Json(actions, JsonRequestBehavior.AllowGet)); }
public GenericScenario GetScenario(string name, string parameters) { return(ScenarioManager.GetScenario(name, HttpContext.Current.Request.QueryString.ToString())); }
public async Task <List <Scenario> > GetScenario(GetScenarioInput Parameters) { return(await ScenarioManager.GetScenario(Parameters)); }
protected override void Render(HtmlTextWriter writer) { //render nothing if the action does not exist if (Action == null) { return; } var actionClickable = true; if (CheckActionCount) { var am = ActionMenu.FindContainerActionMenu(this); List <ActionBase> scActions = null; var scenario = string.Empty; if (am != null) { scenario = am.Scenario; if (!string.IsNullOrEmpty(scenario)) { var sc = ScenarioManager.GetScenario(scenario, am.GetReplacedScenarioParameters()); if (sc != null) { scActions = sc.GetActions(Content.Load(ContextPath), PortalContext.Current.RequestedUri.PathAndQuery).ToList(); } } } if (scActions != null) { if (scActions.Count > 1) { actionClickable = false; } else if (scActions.Count == 1 && string.Equals(scenario, "new", StringComparison.CurrentCultureIgnoreCase) && string.Equals(this.ActionName, "add", StringComparison.CurrentCultureIgnoreCase)) { //change action to the single "New" action found in the parent menu _action = scActions.First(); _actionChecked = true; this.Text = this.Text + " " + _action.Text; } } } if (actionClickable) { var claction = Action as ClientAction; if (claction != null && claction.Callback != null) { NavigateUrl = "javascript:"; this.Attributes["onclick"] = claction.Callback; } else { NavigateUrl = Action.Uri; } } this.CssClass += (string.IsNullOrEmpty(this.CssClass) ? "" : " ") + "sn-actionlinkbutton"; if (Action.Forbidden) { this.CssClass += " sn-disabled"; this.Enabled = false; this.NavigateUrl = string.Empty; } base.Render(writer); }