Exemplo n.º 1
0
        /// <summary>
        /// Recupera o enumerador de resultados.
        /// </summary>
        /// <returns></returns>
        public IEnumerator <T> GetEnumerator()
        {
            var bindStrategy  = _entityLoader.GetEntityDescriptorBindStrategy();
            var objectCreator = _entityLoader.GetEntityDescriptorCreator();

            using (var queryResult = _queryable.Execute(_queryable.DataSource))
            {
                foreach (var item in bindStrategy.Bind(queryResult, Query.BindStrategyMode.All, objectCreator))
                {
                    if (item is IConnectedEntity)
                    {
                        ((IConnectedEntity)item).Connect(_sourceContext);
                    }
                    if (item is IEntityRecordObserver && item is BusinessEntityDescriptor)
                    {
                        ((IEntityRecordObserver)item).RegisterObserver(((BusinessEntityDescriptor)item).RecordKey);
                    }
                    if (item is ILoadableEntity)
                    {
                        ((ILoadableEntity)item).NotifyLoaded();
                    }
                    yield return((T)item);
                }
            }
        }
        /// <summary>
        /// Cria uma instancia do descritor.
        /// </summary>
        /// <returns></returns>
        private IEntityDescriptor CreateEntityDescriptor()
        {
            var creator = _entityLoader.GetEntityDescriptorCreator();

            if (creator != null)
            {
                return(creator.CreateEntityDescriptor());
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Cria um registro para a coleção com base no registro informado.
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        protected IEntityDescriptor CreateCollectionItem(Colosoft.Query.IRecord record)
        {
            var bindStrategy  = _entityLoader.GetEntityDescriptorBindStrategy();
            var objectCreator = _entityLoader.GetEntityDescriptorCreator();
            var instance      = objectCreator.Create();

            bindStrategy.Bind(record, Query.BindStrategyMode.All, ref instance);
            if (instance is IConnectedEntity)
            {
                ((IConnectedEntity)instance).Connect(_sourceContext);
            }
            if (instance is IEntityRecordObserver && instance is BusinessEntityDescriptor)
            {
                ((IEntityRecordObserver)instance).RegisterObserver(((BusinessEntityDescriptor)instance).RecordKey);
            }
            if (instance is ILoadableEntity)
            {
                ((ILoadableEntity)instance).NotifyLoaded();
            }
            return((IEntityDescriptor)instance);
        }