protected void btnSave_Click(object sender, EventArgs e) { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (moState == null) { MetaClass stateClass = StateMachineUtil.GetObjectRoleStateMetaClass(ClassName); moState = new MetaObject(stateClass); } MetaObjectPropertyCollection properties = moState.Properties; properties[StateMachineUtil.RoleField].Value = mo.PrimaryKeyId.Value; properties[StateMachineUtil.StateMachineField].Value = StateMachineId; properties[StateMachineUtil.StateField].Value = StateId; for (int i = 0; i < rights.Count; i++) { string rightName = rights[i].ToString(); properties[rightName].Value = ((CheckControl)checkControls[i]).Value; } moState.Save(); // Closing window if (RefreshButton == String.Empty) { CHelper.CloseItAndRefresh(Response); } else // Dialog Mode { CHelper.CloseItAndRefresh(Response, RefreshButton); } }
private void BindData() { principal.BindData(mc.Fields[principalField]); principal.Value = PrincipalId; principal.ReadOnly = true; MetaObject mo = Mediachase.Ibn.Data.Services.Security.GetGlobalAceByPrincipal(mc, PrincipalId); MetaObject moState = StateMachineUtil.GetGlobalAclStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (moState == null) { moState = mo; } if (moState != null) { MetaObjectPropertyCollection properties = moState.Properties; for (int i = 0; i < rights.Count; i++) { string rightName = rights[i].ToString(); ((CheckControl)checkControls[i]).Value = (int)properties[rightName].Value; } } }
protected void MainGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.CommandName == "Reset") { int roleId = int.Parse(MainGrid.DataKeys[int.Parse(e.CommandArgument.ToString(), CultureInfo.InvariantCulture)].Value.ToString()); StateMachineUtil.UnregisterObjectRole(mc.Name, roleId, int.Parse(StateMachineList.SelectedValue, CultureInfo.InvariantCulture), int.Parse(StateList.SelectedValue, CultureInfo.InvariantCulture)); } CHelper.AddToContext("RebindPage", "true"); }
/// <summary> /// Creates a simple IStateMachine that should transition from it's start state to another state /// </summary> protected override void Execute() { var allStates = new List <IState>(); var transitions = new List <ITransition>(); //start state var startState = new State("startState"); allStates.Add(StateMachineUtil.MakeDebugState(startState)); //state 2 var state2 = new State("state2"); allStates.Add(StateMachineUtil.MakeDebugState(state2)); //transitions var transition = new Transition(startState, state2, new List <ICriteria>() { new ConsoleCriteria() }, new List <IProcess>() { new TimerProcess(2) }); transitions.Add(StateMachineUtil.MakeDebugTransition(transition)); var stateMachine = new AI.StateMachine.StateMachine(startState, allStates, transitions); stateMachine.Start(); //simulate the update loop DateTime lastUpdate = DateTime.Now; int loopCnt = 0; do { ConsoleUtil.WriteLine("Update Loop #" + loopCnt, ConsoleColor.Green); stateMachine.Update((DateTime.Now - lastUpdate).TotalSeconds); lastUpdate = DateTime.Now; loopCnt++; Console.WriteLine("Enter x to abort update loop"); } while (!Console.ReadLine().Equals("x")); }
private void BindData() { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (mo != null) { txtName.Text = mo.Properties["RoleName"].Value.ToString(); } if (moState != null) { MetaObjectPropertyCollection properties = moState.Properties; for (int i = 0; i < states.Count; i++) { string stateName = states[i].ToString(); ((CheckControl)checkControls[i]).Value = (int)properties[stateName].Value; } } }
private void BindData() { MetaObject mo = Mediachase.Ibn.Data.Services.RoleManager.GetObjectRole(mc, RoleName); MetaObject moState = StateMachineUtil.GetObjectRoleStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (mo != null) { string roleName = mo.Properties["RoleName"].Value.ToString(); RoleNameLabel.Text = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()); if (mo.Properties["ClassName"].Value != null) { string className = (string)mo.Properties["ClassName"].Value; if (className.Contains("::")) { string[] s = new string[] { "::" }; className = className.Split(s, StringSplitOptions.None)[0]; RoleNameLabel.Text = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", RoleNameLabel.Text, CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName)); } } } if (moState == null) { moState = mo; } MetaObjectPropertyCollection properties = moState.Properties; if (moState != null) { for (int i = 0; i < rights.Count; i++) { string rightName = rights[i].ToString(); ((CheckControl)checkControls[i]).Value = (int)properties[rightName].Value; } } }
protected void btnSave_Click(object sender, EventArgs e) { MetaObject mo = Mediachase.Ibn.Data.Services.Security.GetGlobalAceByPrincipal(mc, PrincipalId); MetaObject moState = StateMachineUtil.GetGlobalAclStateItem(ClassName, mo.PrimaryKeyId.Value, StateMachineId, StateId); if (moState == null) { MetaClass stateClass = StateMachineUtil.GetGlobalAclStateMetaClass(ClassName); moState = new MetaObject(stateClass); moState.Properties[StateMachineUtil.GlobalAclField].Value = mo.PrimaryKeyId.Value; moState.Properties[StateMachineUtil.StateMachineField].Value = StateMachineId; moState.Properties[StateMachineUtil.StateField].Value = StateId; // Rights foreach (string rightName in Mediachase.Ibn.Data.Services.Security.GetRegisteredRights(ClassName)) { moState.Properties[rightName].Value = mo.Properties[rightName].Value; } } for (int i = 0; i < states.Count; i++) { string stateName = states[i].ToString(); moState.Properties[stateName].Value = ((CheckControl)checkControls[i]).Value; } moState.Save(); // Closing window if (RefreshButton == String.Empty) { CHelper.CloseItAndRefresh(Response); } else // Dialog Mode { CHelper.CloseItAndRefresh(Response, RefreshButton); } }
private void BindGrid() { if (sm == null) { sm = new Mediachase.Ibn.Data.Services.StateMachine(mc, int.Parse(ddlStateMachine.SelectedValue)); } // DataTable structure DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add(principalColumn, typeof(string)); MetaObject moState = StateMachineManager.GetState(mc, int.Parse(ddlState.SelectedValue)); string fromState = moState.Properties["Name"].Value.ToString(); foreach (State state in sm.States) { StateTransition st = sm.FindTransition(fromState, state.Name); if (st != null) { dt.Columns.Add(state.Name, typeof(string)); } } dt.Columns.Add(editColumn, typeof(string)); // Fill data DataRow dr; foreach (MetaObject mo in Mediachase.Ibn.Data.Services.Security.GetGlobalAcl(mc.Name)) { int principalId = (PrimaryKeyId)mo.Properties["PrincipalId"].Value; dr = dt.NewRow(); dr[principalColumn] = CHelper.GetUserName(principalId); MetaObject obj = StateMachineUtil.GetGlobalAclStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(ddlStateMachine.SelectedValue), int.Parse(ddlState.SelectedValue)); for (int i = 1; i < grdMain.Columns.Count - 1; i++) { BoundField rightsField = grdMain.Columns[i] as BoundField; if (rightsField != null) { string fieldName = rightsField.DataField; if (obj != null) { dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value); } else { dr[fieldName] = CHelper.GetPermissionImage((int)Mediachase.Ibn.Data.Services.Security.Rights.None); } } } string url = String.Format("javascript:ShowWizard("{7}?ClassName={0}&btn={1}&PrincipalId={2}&SmId={3}&StateId={4}", {5}, {6});", mc.Name, Page.ClientScript.GetPostBackEventReference(btnRefresh, ""), principalId, ddlStateMachine.SelectedValue, ddlState.SelectedValue, dialogWidth, dialogHeight, ResolveClientUrl("~/Apps/Security/Pages/Admin/GlobalRoleAclStateTransitionEdit.aspx")); dr[editColumn] = String.Format("<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString()); dt.Rows.Add(dr); } grdMain.DataSource = dt; grdMain.DataBind(); }
private void BindGrid() { // DataTable structure DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add(idColumn, typeof(string)); dt.Columns.Add(roleColumn, typeof(string)); dt.Columns.Add(isInheritedColumn, typeof(bool)); CustomTableRow[] classRights = CustomTableRow.List(SqlContext.Current.Database.Tables[Mediachase.Ibn.Data.Services.Security.BaseRightsTableName], FilterElement.EqualElement("ClassOnly", 1)); foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name)) { // Check for Class Right (ex. Create) bool isClassRight = false; string rightUid = right.BaseRightUid.ToString(); foreach (CustomTableRow r in classRights) { if (r["BaseRightUid"].ToString() == rightUid) { isClassRight = true; break; } } if (isClassRight) { continue; } dt.Columns.Add(right.RightName, typeof(string)); } dt.Columns.Add(editColumn, typeof(string)); dt.Columns.Add(resetColumn, typeof(string)); // Fill data DataRow dr; foreach (MetaObject mo in Mediachase.Ibn.Data.Services.RoleManager.GetObjectRoleItems(mc.Name)) { string roleName = mo.Properties["RoleName"].Value.ToString(); dr = dt.NewRow(); dr[idColumn] = mo.PrimaryKeyId; dr[roleColumn] = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()); if (mo.Properties["ClassName"].Value != null) { string className = (string)mo.Properties["ClassName"].Value; if (className.Contains("::")) { string[] s = new string[] { "::" }; className = className.Split(s, StringSplitOptions.None)[0]; } dr[roleColumn] += String.Format(CultureInfo.InvariantCulture, " ({0})", CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName)); } bool isInhereted = false; MetaObject obj = StateMachineUtil.GetObjectRoleStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(StateMachineList.SelectedValue, CultureInfo.InvariantCulture), int.Parse(StateList.SelectedValue, CultureInfo.InvariantCulture)); if (obj == null) { obj = mo; isInhereted = true; } for (int i = 1; i < MainGrid.Columns.Count - 2; i++) { BoundField rightsField = MainGrid.Columns[i] as BoundField; if (rightsField != null) { string fieldName = rightsField.DataField; dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value, isInhereted); } } dr[isInheritedColumn] = isInhereted; string url = String.Format(CultureInfo.InvariantCulture, "javascript:ShowWizard("{7}?ClassName={0}&btn={1}&Role={2}&SmId={3}&StateId={4}", {5}, {6});", mc.Name, Page.ClientScript.GetPostBackEventReference(RefreshButton, ""), roleName, StateMachineList.SelectedValue, StateList.SelectedValue, dialogWidth, editDialogHeight, ResolveClientUrl("~/Apps/Security/Pages/Admin/ObjectRoleStateEdit.aspx")); dr[editColumn] = String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString()); dt.Rows.Add(dr); } MainGrid.DataSource = dt; MainGrid.DataBind(); }
private void BindGrid() { // DataTable structure DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add(idColumn, typeof(string)); dt.Columns.Add(principalColumn, typeof(string)); dt.Columns.Add(isInheritedColumn, typeof(bool)); foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name)) { dt.Columns.Add(right.RightName, typeof(string)); } dt.Columns.Add(editColumn, typeof(string)); dt.Columns.Add(resetColumn, typeof(string)); // Fill data DataRow dr; foreach (MetaObject mo in Mediachase.Ibn.Data.Services.Security.GetGlobalAcl(mc.Name)) { int principalId = (PrimaryKeyId)mo.Properties["PrincipalId"].Value; dr = dt.NewRow(); dr[idColumn] = mo.PrimaryKeyId.Value; dr[principalColumn] = CHelper.GetUserName(principalId); bool isInhereted = false; MetaObject obj = StateMachineUtil.GetGlobalAclStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(StateMachineList.SelectedValue), int.Parse(StateList.SelectedValue)); if (obj == null) { obj = mo; isInhereted = true; } dr[isInheritedColumn] = isInhereted; for (int i = 1; i < MainGrid.Columns.Count - 2; i++) { BoundField rightsField = MainGrid.Columns[i] as BoundField; if (rightsField != null) { string fieldName = rightsField.DataField; dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value, isInhereted); } } string url = String.Format(CultureInfo.InvariantCulture, "javascript:ShowWizard("{7}?ClassName={0}&btn={1}&PrincipalId={2}&SmId={3}&StateId={4}", {5}, {6});", mc.Name, Page.ClientScript.GetPostBackEventReference(RefreshButton, ""), principalId, StateMachineList.SelectedValue, StateList.SelectedValue, dialogWidth, dialogHeight, ResolveClientUrl("~/Apps/Security/Pages/Admin/GlobalRoleAclStateEdit.aspx")); dr[editColumn] = String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString()); dt.Rows.Add(dr); } MainGrid.DataSource = dt; MainGrid.DataBind(); }
private void Start() { instance = this; }