/// <summary>
 /// Recupera o enumerador das entidade com base no resultado preparado.
 /// </summary>
 /// <param name="prepareResult"></param>
 /// <param name="sourceContext"></param>
 /// <returns></returns>
 private IEnumerator <IEntity> GetEnumerator(PrepareNestedQueriesResult prepareResult, Colosoft.Query.ISourceContext sourceContext)
 {
     if (prepareResult.Exceptions.Count > 0)
     {
         throw new AggregateException(prepareResult.Exceptions.FirstOrDefault().Message, prepareResult.Exceptions);
     }
     foreach (var i in prepareResult.ParentResult)
     {
         IEntity       entity        = null;
         LazyDataState lazyDataState = new LazyDataState();
         prepareResult.EntityLoader.GetLazyData(i, lazyDataState, sourceContext, prepareResult.UiContext, prepareResult.EntityTypeManager, prepareResult.Exceptions);
         using (var args = new EntityLoaderCreatorArgs <Model>((Model)i.DataModel, i.RecordKey, i.Children, i.Links, i.References, prepareResult.UiContext, prepareResult.EntityTypeManager))
         {
             entity = ((EntityLoader <TEntity1, Model>)prepareResult.EntityLoader).EntityCreator(args);
             lazyDataState.Entity = entity;
             if (entity is IConnectedEntity)
             {
                 ((IConnectedEntity)entity).Connect(sourceContext);
             }
             if (entity is IEntityRecordObserver)
             {
                 ((IEntityRecordObserver)entity).RegisterObserver(i.RecordKey);
             }
             if (entity is ILoadableEntity)
             {
                 ((ILoadableEntity)entity).NotifyLoaded();
             }
         }
         i.Dispose();
         yield return(entity);
     }
 }
            /// <summary>
            /// Processo o resultado da consulta.
            /// </summary>
            /// <param name="prepareResult"></param>
            /// <param name="queryableResult"></param>
            private static void ProcessQueryResult(PrepareNestedQueriesResult prepareResult, Query.IQueryResult queryableResult)
            {
                var bindStrategy      = prepareResult.EntityLoader.GetBindStrategy();
                var objectCreator     = prepareResult.EntityLoader.GetObjectCreator();
                var recordKeyFactory  = prepareResult.EntityLoader.GetRecordKeyFactory();
                var dataModelTypeName = Colosoft.Reflection.TypeName.Get(prepareResult.EntityLoader.DataModelType);

                Colosoft.Query.IQueryResultBindStrategySession bindStrategySession = null;
                foreach (var record in queryableResult)
                {
                    var data = objectCreator.Create();
                    if (bindStrategySession == null)
                    {
                        bindStrategySession = bindStrategy.CreateSession(record.Descriptor);
                    }
                    var bindResult = bindStrategySession.Bind(record, Query.BindStrategyMode.All, ref data);
                    if (!bindResult.Any())
                    {
                        throw new Exception(string.Format("Not found scheme for bind record data to type '{0}'", data.GetType().FullName));
                    }
                    var recordKey = recordKeyFactory.Create(dataModelTypeName, record);
                    EntityLoaderCreatorArgs creatorArgs = null;
                    creatorArgs = new EntityLoaderCreatorArgs((Model)data, recordKey, new EntityLoaderChildContainer(), new EntityLoaderLinksContainer(), new EntityLoaderReferenceContainer(), prepareResult.UiContext, prepareResult.EntityTypeManager);
                    prepareResult.ParentResult.Add(creatorArgs);
                }
            }
 /// <summary>
 /// Recupera o enumerador do resultad.
 /// </summary>
 /// <returns></returns>
 public override IEnumerator <IEntity> GetEnumerator()
 {
     if (PrepareResult == null)
     {
         var result     = new List <EntityLoaderCreatorArgs>();
         var exceptions = new Queue <Exception>();
         EntityLoader.CreateNestedQueries(Queryable, UiContext, EntityTypeManager, result, exceptions);
         var prepareResult = new PrepareNestedQueriesResult(Queryable, EntityLoader, UiContext, EntityTypeManager, result, exceptions);
         ExecuteQuery(prepareResult);
         return(GetEnumerator(prepareResult, SourceContext));
     }
     else
     {
         if (QueryResult != null)
         {
             ProcessQueryResult(PrepareResult, QueryResult);
         }
         else
         {
             ExecuteQuery(PrepareResult);
         }
         return(GetEnumerator(PrepareResult, SourceContext));
     }
 }
 /// <summary>
 /// Construtor usado para carregar as entidades com base no resulta da consulta.
 /// </summary>
 /// <param name="prepareResult"></param>
 /// <param name="sourceContext"></param>
 /// <param name="queryResult"></param>
 public GetFullEntitiesEnumerable(PrepareNestedQueriesResult prepareResult, Colosoft.Query.ISourceContext sourceContext, Query.IQueryResult queryResult) : this(prepareResult, sourceContext)
 {
     _queryResult = queryResult;
 }
 /// <summary>
 /// Construtor usado para carregar as entidade com base no resultado preparado.
 /// </summary>
 /// <param name="prepareResult"></param>
 /// <param name="sourceContext"></param>
 public GetFullEntitiesEnumerable(PrepareNestedQueriesResult prepareResult, Colosoft.Query.ISourceContext sourceContext) : base((EntityLoader <TEntity1, Model>)prepareResult.EntityLoader, prepareResult.Queryable, sourceContext, prepareResult.UiContext, prepareResult.EntityTypeManager)
 {
     _prepareResult = prepareResult;
 }
 /// <summary>
 /// Executa a consulta.
 /// </summary>
 /// <param name="prepareResult"></param>
 private void ExecuteQuery(PrepareNestedQueriesResult prepareResult)
 {
     using (var queryableResult = prepareResult.Queryable.Execute(prepareResult.Queryable.DataSource))
         ProcessQueryResult(prepareResult, queryableResult);
 }
예제 #7
0
 /// <summary>
 /// Recupera as entidades completas com bas na preparação da consulta.
 /// </summary>
 /// <param name="prepareResult">Resultado da preparação da consulta.</param>
 /// <param name="sourceContext">Contexto de origem dos dados.</param>
 /// <param name="queryResult">Resultado da consulta.</param>
 /// <returns></returns>
 public abstract IEnumerable <IEntity> GetFullEntities(PrepareNestedQueriesResult prepareResult, Colosoft.Query.ISourceContext sourceContext, Query.IQueryResult queryResult);