Example #1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Enumerates handle in this collection.
        /// </summary>
        /// <param name="domainModel">
        ///  The domain model.
        /// </param>
        /// <param name="event">
        ///  The event.
        /// </param>
        /// <returns>
        ///  An enumerator that allows foreach to be used to process handle in this collection.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEnumerable <IDomainCommand> Handle(IDomainModel domainModel, AddSchemaPropertyEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

            var metadata = domainModel.Store.GetSchemaEntity(@event.SchemaId);

            if (domainModel.GetElement(@event.Id) == null)
            {
                yield return(new AddSchemaPropertyCommand(domainModel as ISchema, @event.Id, metadata));
            }
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Enumerates handle in this collection.
        /// </summary>
        /// <param name="domainModel">
        ///  The domain model.
        /// </param>
        /// <param name="event">
        ///  The event.
        /// </param>
        /// <returns>
        ///  An enumerator that allows foreach to be used to process handle in this collection.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEnumerable <IDomainCommand> Handle(IDomainModel domainModel, ChangePropertyValueEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

            var mel = domainModel.GetElement(@event.Id);

            if (mel == null)
            {
                yield break;
            }

            var metadata = domainModel.Store.GetSchemaEntity(@event.SchemaId);
            var prop     = metadata.GetProperty(@event.PropertyName);

            if (prop != null)
            {
                yield return(new ChangePropertyValueCommand(mel, prop, prop.Deserialize(new SerializationContext(prop, @event.Value)), @event.Version));
            }
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Enumerates handle in this collection.
        /// </summary>
        /// <exception cref="InvalidElementException">
        ///  Thrown when an Invalid Element error condition occurs.
        /// </exception>
        /// <param name="domainModel">
        ///  The domain model.
        /// </param>
        /// <param name="event">
        ///  The event.
        /// </param>
        /// <returns>
        ///  An enumerator that allows foreach to be used to process handle in this collection.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public IEnumerable <IDomainCommand> Handle(IDomainModel domainModel, AddRelationshipEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

            var start = domainModel.GetElement(@event.StartId);

            if (start == null)
            {
                throw new InvalidElementException(@event.StartId);
            }

            var end = domainModel.Store.GetElement(@event.EndId);

            if (end == null)
            {
                throw new InvalidElementException(@event.EndId);
            }

            var metadata = domainModel.Store.GetSchemaRelationship(@event.SchemaId);

            yield return(new AddRelationshipCommand(metadata, start, end, @event.Id));
        }
Example #4
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  An IDomainModel extension method that creates a relationship.
        /// </summary>
        /// <exception cref="SessionRequiredException">
        ///  Thrown when a Session Required error condition occurs.
        /// </exception>
        /// <param name="domain">
        ///  the domain model.
        /// </param>
        /// <param name="schema">
        ///  The schema.
        /// </param>
        /// <param name="startId">
        ///  The start identifier.
        /// </param>
        /// <param name="endId">
        ///  The end identifier.
        /// </param>
        /// <param name="id">
        ///  (Optional) the identifier.
        /// </param>
        /// <returns>
        ///  The new relationship.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public static IModelRelationship CreateRelationship(this IDomainModel domain, ISchemaRelationship schema, Identity startId, Identity endId, Identity id = null)
        {
            Contract.Requires(domain != null, "domain");
            Contract.Requires(schema != null, "schema");
            Contract.Requires(startId != null, "startId");
            Contract.Requires(endId != null, "endId");

            if (Session.Current == null)
            {
                throw new SessionRequiredException();
            }

            var start = domain.GetElement(startId);

            if (start == null)
            {
                throw new InvalidElementException(startId);
            }

            var cmd = new AddRelationshipCommand(schema, start, endId, id);

            Session.Current.Execute(cmd);
            return(cmd.Relationship);
        }