Пример #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, RemoveEntityEvent @event)
        {
            Contract.Requires(domainModel, "domainModel");
            Contract.Requires(@event, "@event");

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

            if (mel != null)
            {
                yield return(new RemoveEntityCommand(mel));
            }
        }
Пример #2
0
        private void ReadEntities()
        {
            if (_reader.LocalName == "entities")
            {
                string elem = ReadNextElement();
                while (elem == "entity")
                {
                    var id      = ReadId("id");
                    var deleted = ReadAttribute("deleted", false);
                    if (deleted == "true")
                    {
                        var cmd = new Hyperstore.Modeling.Commands.RemoveEntityCommand(_domain, id, false);
                        Session.Current.Execute(cmd);
                        elem = ReadNextElement();
                        continue;
                    }
                    var metadata = ReadAttribute("schema");
                    var schema   = GetSchemaFromMoniker(metadata) as ISchemaEntity;
                    if (schema == null)
                    {
                        throw new MetadataNotFoundException(String.Format("Invalid metadata {0} for entity {1}", metadata, id));
                    }
                    IModelEntity entity = null;
                    if (_allowElementOverriding)
                    {
                        entity = _domain.GetEntity(id);
                    }

                    if (entity == null)
                    {
                        entity = _domain.CreateEntity(schema, id);
                    }

                    elem = ReadProperties(entity, schema);
                }
            }
        }