private void OnChangedAttributeEvent(ISessionInformation session, ISessionContext log, ChangePropertyValueEvent cmd, Dictionary <Identity, IModelElement> notifications) { DebugContract.Requires(session); DebugContract.Requires(log); DebugContract.Requires(cmd); if (!Equals(cmd.OldValue, cmd.Value)) { var ctx = new EventContext <ChangePropertyValueEvent>(session, cmd); try { _attributeChanged.OnNext(ctx); } catch (Exception ex) { NotifyEventError(log, ex); } IModelElement mel; if (notifications.TryGetValue(cmd.Id, out mel)) { var propertyName = cmd.PropertyName; NotifyPropertyChanged(mel, propertyName); } } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Send all validations message raises during the session. /// </summary> /// <param name="session"> /// . /// </param> /// <param name="result"> /// The result. /// </param> ///------------------------------------------------------------------------------------------------- public void NotifyMessages(ISessionInformation session, ISessionResult result) { Contract.Requires(session, "session"); Contract.Requires(result, "result"); _messageOccurs.OnNext(result); if (session.IsReadOnly) { return; } foreach (var mel in PrepareNotificationList(session).Values) { var den = mel as IDataErrorNotifier; if (den != null) { den.NotifyDataErrors(result); } } }
/// <summary> /// Send events when the session end (correctly or not) /// </summary> /// <param name="session"></param> /// <param name="log"></param> void IEventNotifier.NotifySessionCompleted(ISessionInformation session, ISessionContext log) { DebugContract.Requires(session, "session"); DebugContract.Requires(log, "log"); if (!session.Events.Any(e => String.Compare(e.Domain, _domainModel.Name, StringComparison.OrdinalIgnoreCase) == 0 && (e.ExtensionName == null || e.ExtensionName == _domainModel.ExtensionName))) { return; } try { _sessionCompleting.OnNext(session); } catch (Exception ex) { NotifyEventError(log, ex); } // Si la session s'est terminée anormalement, aucun autre événement n'est envoyé if (!session.IsAborted && (session.Mode & SessionMode.SkipNotifications) != SessionMode.SkipNotifications) { var notifiedProperties = new HashSet <Identity>(); var notifications = PrepareNotificationList(session); foreach (var ev in session.Events.Where(e => String.Compare(e.Domain, _domainModel.Name, StringComparison.OrdinalIgnoreCase) == 0)) { // Utiliser plutot le eventbus // this._eventDispatcher.HandleEvent(ev); try { if (ev is AddEntityEvent) { _elementAdded.OnNext(new EventContext <AddEntityEvent>(session, (AddEntityEvent)ev)); } else if (ev is AddRelationshipEvent) { var evt = (AddRelationshipEvent)ev; _relationshipAdded.OnNext(new EventContext <AddRelationshipEvent>(session, evt)); var relationshipSchema = session.Store.GetSchemaRelationship(evt.SchemaId, false); if (relationshipSchema != null && (relationshipSchema.Schema.Behavior & DomainBehavior.Observable) == DomainBehavior.Observable) { IModelElement mel; if (notifications.TryGetValue(evt.StartId, out mel) && relationshipSchema.StartPropertyName != null) { var key = mel.Id.CreateAttributeIdentity(relationshipSchema.StartPropertyName); if (notifiedProperties.Add(key)) { NotifyPropertyChanged(mel, relationshipSchema.StartPropertyName); } } if (notifications.TryGetValue(evt.EndId, out mel) && relationshipSchema.EndPropertyName != null) { var key = mel.Id.CreateAttributeIdentity(relationshipSchema.EndPropertyName); if (notifiedProperties.Add(key)) { NotifyPropertyChanged(mel, relationshipSchema.EndPropertyName); } } } } else if (ev is RemoveRelationshipEvent) { var evt = (RemoveRelationshipEvent)ev; _relationshipRemoved.OnNext(new EventContext <RemoveRelationshipEvent>(session, evt)); var relationshipSchema = session.Store.GetSchemaRelationship(evt.SchemaId, false); if (relationshipSchema != null && (relationshipSchema.Schema.Behavior & DomainBehavior.Observable) == DomainBehavior.Observable) { IModelElement mel; if (notifications.TryGetValue(evt.StartId, out mel) && relationshipSchema.StartPropertyName != null) { var key = mel.Id.CreateAttributeIdentity(relationshipSchema.StartPropertyName); if (notifiedProperties.Add(key)) { NotifyPropertyChanged(mel, relationshipSchema.StartPropertyName); } } if (notifications.TryGetValue(evt.EndId, out mel) && relationshipSchema.EndPropertyName != null) { var key = mel.Id.CreateAttributeIdentity(relationshipSchema.EndPropertyName); if (notifiedProperties.Add(key)) { NotifyPropertyChanged(mel, relationshipSchema.EndPropertyName); } } } } else if (ev is RemoveEntityEvent) { _elementRemoved.OnNext(new EventContext <RemoveEntityEvent>(session, (RemoveEntityEvent)ev)); } else if (ev is RemovePropertyEvent) { _attributeRemoved.OnNext(new EventContext <RemovePropertyEvent>(session, (RemovePropertyEvent)ev)); } else if (ev is ChangePropertyValueEvent) { var cmd = (ChangePropertyValueEvent)ev; OnChangedAttributeEvent(session, log, cmd, notifications); } else if (ev is AddSchemaEntityEvent) { _metadataAdded.OnNext(new EventContext <AddSchemaEntityEvent>(session, (AddSchemaEntityEvent)ev)); } else if (ev is AddSchemaRelationshipEvent) { _relationshipMetadataAdded.OnNext(new EventContext <AddSchemaRelationshipEvent>(session, (AddSchemaRelationshipEvent)ev)); } else { _customEvents.OnNext(new EventContext <IEvent>(session, ev)); } } catch (Exception ex) { NotifyEventError(log, ex); } } } try { _sessionCompleted.OnNext(session); } catch (Exception ex) { NotifyEventError(log, ex); } }
void IEventNotifier.NotifyEvent(ISessionInformation session, ISessionContext log, IEvent ev) { DebugContract.Requires(session, "session"); DebugContract.Requires(log, "log"); DebugContract.Requires(ev, "ev"); if (String.Compare(ev.Domain, _domainModel.Name, StringComparison.OrdinalIgnoreCase) != 0) { return; } // Event for extendee domain will be raised to its extension if (ev.ExtensionName != null && ev.ExtensionName != _domainModel.ExtensionName) { return; } try { if (ev is ChangePropertyValueEvent) { _attributeChanging.OnNext(new EventContext <ChangePropertyValueEvent>(session, (ChangePropertyValueEvent)ev)); } else if (ev is AddEntityEvent) { _elementAdding.OnNext(new EventContext <AddEntityEvent>(session, (AddEntityEvent)ev)); } else if (ev is AddRelationshipEvent) { _relationshipAdding.OnNext(new EventContext <AddRelationshipEvent>(session, (AddRelationshipEvent)ev)); } else if (ev is RemoveRelationshipEvent) { _relationshipRemoving.OnNext(new EventContext <RemoveRelationshipEvent>(session, (RemoveRelationshipEvent)ev)); } else if (ev is RemoveEntityEvent) { _elementRemoving.OnNext(new EventContext <RemoveEntityEvent>(session, (RemoveEntityEvent)ev)); } else if (ev is RemovePropertyEvent) { _attributeRemoving.OnNext(new EventContext <RemovePropertyEvent>(session, (RemovePropertyEvent)ev)); } else if (ev is AddSchemaEntityEvent) { _metadataAdding.OnNext(new EventContext <AddSchemaEntityEvent>(session, (AddSchemaEntityEvent)ev)); } else if (ev is AddSchemaRelationshipEvent) { _relationshipMetadataAdding.OnNext(new EventContext <AddSchemaRelationshipEvent>(session, (AddSchemaRelationshipEvent)ev)); } else { _customEventRaising.OnNext(new EventContext <IEvent>(session, ev)); } } catch (Exception ex) { NotifyEventError(log, ex); } }