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(SaveVertexCompletedEvent e, ICommandExecutionContext context)
        {
            _log.Debug("Invalidate cache (modify) for vertex " + e.Command.VertexId);

            var networkId =
                _repo.Db.Vertices.Where(v => v.Id == e.Command.VertexId).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 vertexInternal = await _queryService.Execute(new InternalGraphVerticesQuery()
                {
                    NetworkId = networkId,
                    VertexId  = e.Command.VertexId
                }, context);

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

                // generate property vertex objects
                var vertices = _graphBuilder.GenerateConcurrentVertexModel(schema, vertexInternal);

                // update vertex
                foreach (var vertex in vertices)
                {
                    cachedGraph.Vertices.AddOrUpdate(vertex.Key, vertex.Value, (k, oldVertex) => vertex.Value);
                }
            }
        }