/// <summary> /// Manage events associated with the schema customization state. /// The primary function of schema customization is to reassociate /// schema customizations when a schema is deleted and recreated. /// Therefore, the data is maintained outside the transacted store /// and must be updated with events to remain consistent across /// undo and redo operations. /// </summary> /// <param name="eventManager">The <see cref="ModelingEventManager"/> to attach /// to. The assumption is that this is called for state change events on document /// loaded.</param> /// <param name="store">The <see cref="Store"/> used to retrieve type information.</param> /// <param name="action">The action to take (add or remove the handler)</param> public static void ManageModelingEventHandlers(ModelingEventManager eventManager, Store store, EventHandlerAction action) { DomainDataDirectory dataDir = store.DomainDataDirectory; eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Column.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(ColumnPropertyChanged), action); eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Table.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(TablePropertyChanged), action); eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Schema.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(SchemaPropertyChanged), action); eventManager.AddOrRemoveHandler(dataDir.FindDomainRole(TableContainsColumn.ColumnDomainRoleId), new EventHandler <RolePlayerOrderChangedEventArgs>(ColumnOrderChanged), action); }
/// <summary> /// Manages <see cref="EventHandler{TEventArgs}"/>s in the <see cref="Store"/> for <see cref="ORMBaseShape"/>s. /// </summary> /// <param name="store">The <see cref="Store"/> for which the <see cref="EventHandler{TEventArgs}"/>s should be managed.</param> /// <param name="eventManager">The <see cref="ModelingEventManager"/> used to manage the <see cref="EventHandler{TEventArgs}"/>s.</param> /// <param name="action">The <see cref="EventHandlerAction"/> that should be taken for the <see cref="EventHandler{TEventArgs}"/>s.</param> public static void ManageEventHandlers(Store store, ModelingEventManager eventManager, EventHandlerAction action) { DomainDataDirectory dataDirectory = store.DomainDataDirectory; DomainClassInfo classInfo = dataDirectory.FindDomainClass(ORMBaseShape.DomainClassId); DomainPropertyInfo propertyInfo = dataDirectory.FindDomainProperty(UpdateCounterDomainPropertyId); eventManager.AddOrRemoveHandler(propertyInfo, new EventHandler <ElementPropertyChangedEventArgs>(UpdateRequiredEvent), action); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementAddedEventArgs>(ShapeAddedEvent), action); classInfo = dataDirectory.FindDomainClass(PresentationViewsSubject.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementDeletedEventArgs>(ShapeDeletedEvent), action); }
private Dictionary <Type, Type> ParseList(string list, Dictionary <Type, Type> cache) { if (list.Length != 0) { Dictionary <Type, Type> retVal = cache; if (retVal == null) { retVal = new Dictionary <Type, Type>(); } if (retVal.Count == 0) { //synchronize the cache with the string DomainDataDirectory dataDir = Store.DomainDataDirectory; string[] typeNames = list.Split(new char[] { ListDelimiter }, StringSplitOptions.RemoveEmptyEntries); int typeCount = typeNames.Length; for (int i = 0; i < typeCount; ++i) { DomainClassInfo classInfo; if (null != (classInfo = dataDir.FindDomainClass(typeNames[i]))) { retVal.Add(classInfo.ImplementationClass, null); } } } return(retVal); } return(cache); }
private static Dictionary<DomainClassInfo, object> BuildCustomSerializationOmissions(Store store) { Dictionary<DomainClassInfo, object> retVal = new Dictionary<DomainClassInfo, object>(); DomainDataDirectory dataDir = store.DomainDataDirectory; retVal[dataDir.FindDomainRelationship(ParentShapeContainsNestedChildShapes.DomainClassId)] = null; retVal[dataDir.FindDomainRelationship(PresentationViewsSubject.DomainClassId)] = null; retVal[dataDir.FindDomainClass(BarkerEntityShape.DomainClassId)] = null; return retVal; }
void IModelingEventSubscriber.ManageModelingEventHandlers(ModelingEventManager eventManager, EventSubscriberReasons reasons, EventHandlerAction action) { if (0 != (reasons & EventSubscriberReasons.SurveyQuestionEvents)) { Store store = Store; DomainDataDirectory dataDirectory = store.DomainDataDirectory; DomainClassInfo classInfo = dataDirectory.FindDomainClass(Diagram.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementAddedEventArgs>(DiagramAddedEvent), action); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementDeletedEventArgs>(DiagramRemovedEvent), action); DomainPropertyInfo propertyInfo = dataDirectory.FindDomainProperty(Diagram.NameDomainPropertyId); eventManager.AddOrRemoveHandler(propertyInfo, new EventHandler <ElementPropertyChangedEventArgs>(DiagramRenamedEvent), action); } }
/// <summary> /// Manages <see cref="EventHandler{TEventArgs}"/>s in the <see cref="Store"/> during activation and /// deactivation. /// </summary> /// <param name="store">The <see cref="Store"/> for which the <see cref="EventHandler{TEventArgs}"/>s should be managed.</param> /// <param name="action">The <see cref="EventHandlerAction"/> that should be taken for the <see cref="EventHandler{TEventArgs}"/>s.</param> private void ManageStoreEvents(Store store, EventHandlerAction action) { if (store == null || store.Disposed) { return; // bail out } DomainDataDirectory dataDirectory = store.DomainDataDirectory; ModelingEventManager eventManager = ModelingEventManager.GetModelingEventManager(store); DomainClassInfo classInfo = dataDirectory.FindDomainClass(ReferenceModeKind.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementPropertyChangedEventArgs>(ReferenceModeKindChangeEvent), action); classInfo = dataDirectory.FindDomainClass(CustomReferenceMode.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementPropertyChangedEventArgs>(CustomReferenceModeChangeEvent), action); classInfo = dataDirectory.FindDomainRelationship(ModelHasReferenceMode.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementAddedEventArgs>(CustomReferenceModeAddEvent), action); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementDeletedEventArgs>(CustomReferenceModeRemoveEvent), action); classInfo = dataDirectory.FindDomainRelationship(ReferenceModeHasReferenceModeKind.DomainClassId); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <RolePlayerChangedEventArgs>(ReferenceModeHasKindChangeEvent), action); }
/// <summary> /// Iterates through the domain and finds the specific name usage using it's <see cref="NameUsageIdentifierAttribute"/> /// </summary> /// <param name="store"></param> /// <param name="identifier">String representing the <see cref="NameUsageIdentifierAttribute"/> of the desired NameUsage</param> /// <returns></returns> public static DomainClassInfo TranslateFromNameUsageIdentifier(Store store, string identifier) { DomainDataDirectory dataDir = store.DomainDataDirectory; DomainClassInfo classInfo = dataDir.FindDomainClass(NameUsage.DomainClassId); DomainClassInfo retVal = null; string[] identifierPieces = identifier.Split(new char[] { '.', ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < identifierPieces.Length; ++i) { IList <DomainClassInfo> childInfos = classInfo.LocalDescendants; int count = childInfos.Count; int j = 0; string identifierPiece = identifierPieces[i]; for (; j < count; ++j) { bool match = false; DomainClassInfo childInfo = childInfos[j]; if (childInfo.Name == identifierPiece) { match = true; } else { object[] customAttributes = childInfo.ImplementationClass.GetCustomAttributes(typeof(NameUsageIdentifierAttribute), false); if (customAttributes != null && customAttributes.Length != 0) { match = ((NameUsageIdentifierAttribute)customAttributes[0]).Name == identifierPiece; } } if (match) { classInfo = childInfo; retVal = classInfo; break; } } if (j == count) { return(null); } } return(retVal); }
/// <summary> /// Required override. Attach handlers for tracking the current diagram. /// </summary> protected override void ManageEventHandlers(Store store, ModelingEventManager eventManager, EventHandlerAction action) { store = Utility.ValidateStore(store); if (store == null) { return; } DomainDataDirectory dataDirectory = store.DomainDataDirectory; DomainClassInfo classInfo = dataDirectory.FindDomainClass(typeof(Diagram)); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementAddedEventArgs>(DiagramAddedEvent), action); eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementDeletedEventArgs>(DiagramRemovedEvent), action); eventManager.AddOrRemoveHandler(dataDirectory.FindDomainProperty(Diagram.NameDomainPropertyId), new EventHandler <ElementPropertyChangedEventArgs>(DiagramNameChangedEvent), action); eventManager.AddOrRemoveHandler(new EventHandler <ElementEventsEndedEventArgs>(ElementEventsEnded), action); myStore = (action == EventHandlerAction.Add) ? store : null; myDiagramSetChanged = true; AdjustVisibility(false, false); }
/// <summary> /// We cannot use anonymous delegates in ManageEventHandlers to respond to add/remove /// of relationships because the instance would change each time, making it impossible /// to remove the event handler from the watch list on a store. These are built once /// for each store, which can theoretically have different sets of note owners from /// other stores, depending on the loaded extensions. This finds all embedding relationships /// that contain an element of the <typeparamref name="NoteType"/> or any descendants of /// this type. /// </summary> private NoteRoleAndHandler[] GetOwningRelationshipHandlers(Store store, bool forceCreate) { Dictionary <object, object> storeBag = store.PropertyBag; object key = typeof(NoteType); object handlersAsObject; NoteRoleAndHandler[] handlers; if (storeBag.TryGetValue(key, out handlersAsObject) && null != (handlers = handlersAsObject as NoteRoleAndHandler[])) { return(handlers); } else if (!forceCreate) { return(null); } List <NoteRoleAndHandler> handlersList = new List <NoteRoleAndHandler>(); DomainDataDirectory dataDir = store.DomainDataDirectory; DomainClassInfo classInfo = dataDir.FindDomainClass(typeof(NoteType)); ReadOnlyCollection <DomainClassInfo> descendants = classInfo.AllDescendants; int descendantCount = descendants.Count; for (int descendantIndex = -1; descendantIndex < descendantCount;) { foreach (DomainRoleInfo noteRole in classInfo.LocalDomainRolesPlayed) { if (noteRole.DomainRelationship.IsEmbedding) { handlersList.Add(new NoteRoleAndHandler(this, noteRole)); } } ++descendantIndex; if (descendantIndex == descendantCount) { break; } classInfo = descendants[descendantIndex]; } handlers = handlersList.ToArray(); storeBag[key] = handlers; return(handlers); }
private IEnumerable <ModelElement> ExtractElements(IDataObject data) { if (data != null) { if (data.GetDataPresent(typeof(ElementGroupPrototype))) { ElementGroupPrototype groupPrototype = (ElementGroupPrototype)data.GetData(typeof(ElementGroupPrototype)); if (groupPrototype != null) { IElementDirectory elementDir = Store.ElementDirectory; foreach (ProtoElement proto in groupPrototype.RootProtoElements) { ModelElement element; if (null != (element = elementDir.FindElement(proto.ElementId))) { yield return(element); } } } } else { Store store = Store; DomainDataDirectory dataDirectory = store.DomainDataDirectory; foreach (string possibleClassName in data.GetFormats(false)) { DomainClassInfo classInfo; DomainClassInfo elementClassInfo; ModelElement element; if (null != (classInfo = dataDirectory.FindDomainClass(possibleClassName)) && null != (element = data.GetData(possibleClassName) as ModelElement) && element.Store == store && ((elementClassInfo = element.GetDomainClass()) == classInfo || elementClassInfo.IsDerivedFrom(classInfo))) { yield return(element); } } } } }