///-------------------------------------------------------------------------------------------------
        /// <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, RemoveRelationshipEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

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

            if (mel != null)
            {
                yield return(new RemoveRelationshipCommand(mel));
            }
        }
Esempio n. 2
0
        private void ReadRelationships()
        {
            if (_reader.LocalName == "relationships")
            {
                string elem = ReadNextElement();
                while (elem == "relationship")
                {
                    var id      = ReadId("id");
                    var deleted = ReadAttribute("deleted", false);
                    if (deleted == "true")
                    {
                        var cmd = new Hyperstore.Modeling.Commands.RemoveRelationshipCommand(_domain, id, false);
                        Session.Current.Execute(cmd);
                        elem = ReadNextElement();
                        continue;
                    }
                    var metadata = ReadAttribute("schema");
                    var schema   = GetSchemaFromMoniker(metadata) as ISchemaRelationship;
                    if (schema == null)
                    {
                        throw new MetadataNotFoundException(String.Format("Invalid metadata {0} for relationship {1}", metadata, id));
                    }

                    var startId = ReadId("start");
                    var endId   = ReadId("end");
                    IModelRelationship entity = null;
                    if (_allowElementOverriding)
                    {
                        entity = _domain.GetRelationship(id);
                    }

                    if (entity == null)
                    {
                        entity = _domain.CreateRelationship(schema, startId, endId, id);
                    }

                    elem = ReadProperties(entity, schema);
                }
            }
        }
Esempio n. 3
0
        ///-------------------------------------------------------------------------------------------------
        /// <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, AddSchemaRelationshipEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

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

            if (domainModel.GetRelationship(@event.Id) == null)
            {
                var start = domainModel.Store.GetSchemaElement(@event.StartId);
                if (start == null)
                {
                    throw new InvalidElementException(@event.StartId);
                }
                var end = domainModel.Store.GetSchemaElement(@event.EndId);
                if (end == null)
                {
                    throw new InvalidElementException(@event.EndId);
                }

                yield return(new AddSchemaRelationshipCommand(domainModel as ISchema, @event.Id, metadata, start, end));
            }
        }