示例#1
0
        public JObject Query(string storeId, JObject query, string[] expand, int level)
        {
            using (var op = _storeOperationFactory.Write(storeId)) {
                try {
                    var(data, _, _) = GetSetGraphs(storeId);
                    ObjectQueryModel queryModel;
                    try {
                        queryModel = query.ToObject <ObjectQueryModel>();
                    } catch (Exception e) {
                        throw new StoreException(e.Message, _storeErrors.UnableToParseQuery);
                    }

                    var     result   = new ObjectQueryExecutor().Query(queryModel, data);
                    dynamic response = new
                    {
                        values = result.Values?.Select(x =>
                        {
                            var expanded = GraphOperator.Expand(data, x.Subject, level, expand);
                            var rspGraph = new MemoryGraph();
                            rspGraph.Assert(expanded).ToList();
                            return(TripleConverter.ToJson(x.Subject, rspGraph));
                        }),
                        continuation = result.Continuation,
                        aggregates   = result.Aggregates
                    };
                    return(JObject.FromObject(response));
                } catch (Exception e) {
                    _logger.LogError("Query failed. {Message}\n {StackTrace}", e.Message, e.StackTrace);
                    throw e;
                }
            }
        }