Пример #1
0
        public async override Task <PropertyGraphModel> Execute(GraphQuery graphQuery)
        {
            if (graphQuery.NetworkId == null)
            {
                throw new ArgumentNullException(nameof(graphQuery.NetworkId));
            }

            _log.Debug("starting GraphQuery");
            var graph = (await _queryService.Execute(new InternalGraphQuery()
            {
                NetworkId = graphQuery.NetworkId,
            }, this))
                        .Snapshot();

            _log.Debug("compiling query");
            var queryList = _compiler.Compile(graphQuery.QueryText);

            _log.Debug("transforming graph");
            foreach (var query in queryList)
            {
                graph = query.Transform(graph);
            }

            _log.Debug("done GraphQuery");
            return(graph);
        }
Пример #2
0
        public async override Task <SigmaGraphModel> Execute(SigmaQuery query)
        {
            if (Guid.Empty.Equals(query.NetworkId))
            {
                throw new ArgumentNullException(nameof(query.NetworkId));
            }

            var setttings = await _queryService.Execute(new NetworkSettingsQuery()
            {
                NetworkId = query.NetworkId,
            }, this);

            var graph = (await _queryService.Execute(new InternalGraphQuery()
            {
                NetworkId = query.NetworkId,
            }, this))
                        .Snapshot();

            graph = _privacyFilter.ApplyFilter(graph, setttings);

            var queryList = _compiler.Compile(query.QueryText);

            foreach (var graphQuery in queryList)
            {
                // add default props
                graphQuery.SelectPropsClause?.VertexProps.Insert(0, new NameProp()
                {
                    Name = setttings.ProfileCard.LabelProp, Alias = "label"
                });
                graphQuery.SelectPropsClause?.VertexProps.Insert(0, new NameProp()
                {
                    Name = setttings.ProfileCard.DetailsProp, Alias = "details"
                });
                graphQuery.SelectPropsClause?.VertexProps.Insert(0, new NameProp()
                {
                    Name = setttings.ProfileCard.PhotoProp, Alias = "photo"
                });

                graph = graphQuery.Transform(graph);
            }

            var sigmaGraph = new SigmaGraphModel()
            {
                Nodes = graph.Vertices?.Select(TransformVertex).ToList(),
                Edges = graph.Edges?.Select(TransformEdge).ToList(),
                Data  = graph.Data
            };

            if (query.DoLayout)
            {
                var layoutClause = queryList.Last().LayoutClause;
                query.LayoutKey = query.LayoutKey ?? layoutClause?.LayoutKey;
                var task = new LayoutTask()
                {
                    Query    = query,
                    Settings = layoutClause?.Settings,
                };
                if (layoutClause?.Modify != null)
                {
                    task.ModifyLayout = (bool)layoutClause?.Modify.Value;
                }

                _layoutService.Auth = this.Auth;
                TimeSpan?duration = null;
                if (query.DurationMs.HasValue)
                {
                    duration = TimeSpan.FromMilliseconds(query.DurationMs.Value);
                }
                await _layoutService.LayoutGraph(sigmaGraph, task, duration);
            }

            return(sigmaGraph);
        }