Ejemplo n.º 1
0
        public async Task <IEnumerable> ExecuteQuery(EntityQuery query)
        {
            if (query.ElementType == null)
            {
                throw new Exception("Cannot execute a query with a null TargetType");
            }
            var fetchStrategy = query.QueryOptions.FetchStrategy ?? this.DefaultQueryOptions.FetchStrategy ?? QueryOptions.Default.FetchStrategy;

            if (fetchStrategy == FetchStrategy.FromLocalCache)
            {
                return(query.ExecuteLocally(query.EntityManager ?? this));
                //var tcs = new TaskCompletionSource<IEnumerable>();
                //tcs.SetResult(query.ExecuteLocally());
                //return tcs.Task;
            }
            var dataService = query.DataService != null ? query.DataService : this.DefaultDataService;

            await FetchMetadata(dataService);

            var resourcePath = query.GetResourcePath();

            // HACK
            resourcePath = resourcePath.Replace("/*", "");
            var result = await dataService.GetAsync(resourcePath);

            var mergeStrategy = query.QueryOptions.MergeStrategy ?? this.DefaultQueryOptions.MergeStrategy ?? QueryOptions.Default.MergeStrategy;

            // cannot reuse a jsonConverter - internal refMap is one instance/query
            var  jsonConverter = new JsonEntityConverter(this, mergeStrategy.Value);
            Type rType;

            if (resourcePath.Contains("inlinecount"))
            {
                rType = typeof(QueryResult <>).MakeGenericType(query.ElementType);
            }
            else
            {
                rType = typeof(IEnumerable <>).MakeGenericType(query.ElementType);
            }
            using (NewIsLoadingBlock()) {
                return((IEnumerable)JsonConvert.DeserializeObject(result, rType, jsonConverter));
            }
        }
Ejemplo n.º 2
0
 public IEnumerable ExecuteQueryLocally(EntityQuery query)
 {
     return(query.ExecuteLocally(query.EntityManager ?? this));
 }