private void ContextMenuDeletePageClick(object sender, EventArgs e) { Diagram diagram = ContextMenuStrip.SelectedDiagram; if (diagram != null) { Store store = diagram.Store; using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.DiagramCommandDeletePage.Replace("&", ""))) { // UNDONE: MSBUG This rule should not be doing anything if the parent is deleted. // Causes diagram deletion to crash VS bool turnedOffLineRoutingRule = false; Type ruleType = typeof(Diagram).Assembly.GetType("Microsoft.VisualStudio.Modeling.Diagrams.LineRoutingRule"); RuleManager ruleManager = store.RuleManager; try { if (ruleType != null) { ruleManager.DisableRule(ruleType); turnedOffLineRoutingRule = true; } diagram.Delete(); t.Commit(); } finally { if (turnedOffLineRoutingRule) { ruleManager.EnableRule(ruleType); } } } } }
public void DisableDiagramRules() { RuleManager ruleManager = Store.RuleManager; ruleManager.DisableRule(typeof(FixUpAllDiagrams)); ruleManager.DisableRule(typeof(DecoratorPropertyChanged)); ruleManager.DisableRule(typeof(ConnectorRolePlayerChanged)); ruleManager.DisableRule(typeof(CompartmentItemAddRule)); ruleManager.DisableRule(typeof(CompartmentItemDeleteRule)); ruleManager.DisableRule(typeof(CompartmentItemRolePlayerChangeRule)); ruleManager.DisableRule(typeof(CompartmentItemRolePlayerPositionChangeRule)); ruleManager.DisableRule(typeof(CompartmentItemChangeRule)); }
void bwDisable_DoWork(object sender, DoWorkEventArgs e) { var rm = new RuleManager(entityName, service); var deactivatedItems = new List <ListViewItem>(); foreach (ListViewItem item in (ListView.SelectedListViewItemCollection)e.Argument) { var rule = (Entity)item.Tag; rm.DisableRule(rule.Id); deactivatedItems.Add(item); } e.Result = deactivatedItems; }
/// <summary> /// Reverses the binarization process performed by <see cref="BinarizeUnary"/>. Typically used when /// <paramref name="binarizedUnaryFactRoleCollection"/> no longer qualifies as the roles for a /// binarized unary <see cref="FactType"/>. /// </summary> private static void DebinarizeUnary(LinkedElementCollection <RoleBase> binarizedUnaryFactRoleCollection, bool deleteImplicitBooleanRole, INotifyElementAdded notifyAdded) { // UNDONE: We need to make sure the debinarization happens BEFORE the implied Objectification rules run on the binarized unary FactType. // The default implied role is the second one, walk the collection backwards int roleCount = binarizedUnaryFactRoleCollection.Count; for (int i = roleCount - 1; i >= 0; --i) { Role implicitBooleanRole; ObjectType implicitBooleanValueType; if (null != (implicitBooleanRole = binarizedUnaryFactRoleCollection[i].Role) && null != (implicitBooleanValueType = implicitBooleanRole.RolePlayer) && implicitBooleanValueType.IsImplicitBooleanValue) { // Delete the implicit boolean value type (which will also remove any value constraints on it) // Note that changes to IsImplicitBooleanValue are intentionally blocked so that the // deleted implied ValueType can be identified as such by events as well as rules. // implicitBooleanValueType.IsImplicitBooleanValue = false; bool ruleDisabled = false; RuleManager ruleManager = null; try { if (notifyAdded == null) { ruleManager = implicitBooleanRole.Store.RuleManager; ruleManager.DisableRule(typeof(ObjectTypePlaysRoleDeletedRuleClass)); ruleDisabled = true; } if (deleteImplicitBooleanRole) { // We delete the role first so that rules do not // try to recreate and implied fact type for this rule // if it is part of an objectified FactType. implicitBooleanRole.Delete(); --roleCount; if (!implicitBooleanValueType.IsDeleted) { // The Objectification.RolePlayerDeletingRule rule will delet this automatically implicitBooleanValueType.Delete(); } } else { implicitBooleanValueType.Delete(); } } finally { if (ruleDisabled) { ruleManager.EnableRule(typeof(ObjectTypePlaysRoleDeletedRuleClass)); } } // Clear implied constraints for (int j = 0; j < roleCount; ++j) { Role role = binarizedUnaryFactRoleCollection[j] as Role; if (role != null) { if (role != implicitBooleanRole) { role.Name = ""; // Role cardinality is for unary fact types only, eliminate // it if we switch away. role.Cardinality = null; } UniquenessConstraint singleRoleAlethicUniquenessConstraint = role.SingleRoleAlethicUniquenessConstraint; if (singleRoleAlethicUniquenessConstraint != null) { // Delete the uniqueness constraint singleRoleAlethicUniquenessConstraint.Delete(); } // UNDONE: We are using open-world assumption now //MandatoryConstraint simpleMandatoryConstraint = role.SimpleMandatoryConstraint; //if (simpleMandatoryConstraint != null && simpleMandatoryConstraint.Modality == ConstraintModality.Alethic) //{ // // Delete the simple mandatory constraint (for closed-world assumption), if present // simpleMandatoryConstraint.Delete(); //} } } break; } } }