Ejemplo n.º 1
0
        public async override Task <ConcurrentGraphModel> Execute(InternalGraphQuery query)
        {
            if (query.NetworkId == null)
            {
                throw new ArgumentNullException(nameof(query.NetworkId));
            }

            var network = await _repo.Db.Networks.FirstAsync(n => n.Id == query.NetworkId.Value);

            if (network.Deleted != null)
            {
                throw new SecurityException("Network not found");
            }

            _log.Debug("querying db");

            var schemaTask = _queryService.Execute(new SchemaQuery()
            {
                NetworkId = query.NetworkId.Value
            }, this);

            var verticesTask = _queryService.Execute(new InternalGraphVerticesQuery()
            {
                NetworkId = query.NetworkId.Value
            }, this);

            var edgesTask = _queryService.Execute(new InternalGraphEdgesQuery()
            {
                NetworkId = query.NetworkId.Value
            }, this);

            // paralelize tasks
            await Task.WhenAll(verticesTask, edgesTask, schemaTask);

            _log.Debug("transforming db results");

            var schema   = schemaTask.Result;
            var vertices = verticesTask.Result;
            var edges    = edgesTask.Result;

            var concurrentVertexModels = _graphBuilder.GenerateConcurrentVertexModel(schema, vertices);

            // link it up
            var concurrentEdgeModels = _graphBuilder.GenerateConcurrentEdgeModel(schema, edges);

            var result = new ConcurrentGraphModel(
                new ConcurrentDictionary <Guid, ConcurrentVertexModel>(concurrentVertexModels),
                new ConcurrentDictionary <Tuple <Guid, Guid, string>, ConcurrentEdgeModel>(concurrentEdgeModels));

            _log.Debug("finished internal graph query");
            return(result);
        }
Ejemplo n.º 2
0
        public async Task Handle(SaveEdgeCompletedEvent e, ICommandExecutionContext context)
        {
            _log.Debug("Invalidate cache (modify) for edge " + e.Command.SourceVertexId + " => " + e.Command.TargetVertexId);

            var networkId =
                _repo.Db.Vertices.Where(v => v.Id == e.Command.SourceVertexId).Select(v => v.NetworkId).FirstOrDefault();

            var locales = await _queryService.Execute(new NetworkLanguagesQuery()
            {
                NetworkId = networkId
            }, context);

            foreach (var locale in locales)
            {
                var cachedGraph = CachedGraph(networkId, locale);
                if (cachedGraph == null)
                {
                    continue;                      // graph not cached... continue
                }
                // reload the edge
                var edgesInternal = await _queryService.Execute(new InternalGraphEdgesQuery()
                {
                    NetworkId           = networkId,
                    SourceIdTargetIdUri =
                        new Tuple <Guid, Guid, string>(e.Command.SourceVertexId, e.Command.TargetVertexId,
                                                       e.Command.SchemaUri)
                }, context);

                // load graph schema
                var schema = await _queryService.Execute(new SchemaQuery()
                {
                    NetworkId = networkId,
                }, context);

                // generate property edge objects
                var edges = _graphBuilder.GenerateConcurrentEdgeModel(schema, edgesInternal);

                // update edge and source and target vertices
                foreach (var edge in edges)
                {
                    cachedGraph.Edges.AddOrUpdate(edge.Key, edge.Value, (k, oldEdge) => edge.Value);
                }
            }
        }