internal HierarchicalRtStatementCreator(EntityCacheItem entityCacheItem, IDatabaseContext databaseContext, string language, ObjectId rtId, GraphDirections graphDirections, string targetCkId) : base(entityCacheItem, databaseContext, language) { _databaseContext = databaseContext; _rtId = rtId; _graphDirections = graphDirections; _targetCkId = targetCkId; }
private void BuildAssociationGraph(CkTypeAggregations ckTypeAggregations, IDictionary <string, List <AssociationCacheItem> > associations, string ckId, GraphDirections graphDirections) { Logger.Debug($"BuildAssociationGraph for '{ckId}' ({graphDirections})"); var groupFunc = new Func <CkEntityAssociation, string>(association => association.InboundName); if (graphDirections == GraphDirections.Outbound) { groupFunc = association => association.OutboundName; } var ckEntityAssociationList = new List <CkEntityAssociation>(); if (ckTypeAggregations.Owned != null) { ckEntityAssociationList.AddRange(ckTypeAggregations.Owned); } if (ckTypeAggregations.Inherited != null) { ckEntityAssociationList.AddRange(ckTypeAggregations.Inherited); } foreach (var entityAssociations in ckEntityAssociationList.GroupBy(groupFunc)) { var roleAssociationItems = new List <AssociationCacheItem>(); foreach (var entityAssociationByRole in entityAssociations.GroupBy(x => x.RoleId)) { List <EntityCacheItem> baseTypesChain = new List <EntityCacheItem>(); foreach (var entityAssociation in entityAssociationByRole) { var targetEntityId = graphDirections == GraphDirections.Inbound ? entityAssociation.OriginCkId : entityAssociation.TargetCkId; var targetInfo = _metaCache[targetEntityId]; baseTypesChain.AddRange(targetInfo.GetAllDerivedTypes(true)); } roleAssociationItems.Add(new AssociationCacheItem { RoleId = entityAssociationByRole.Key, Name = graphDirections == GraphDirections.Inbound ? entityAssociationByRole.First().InboundName : entityAssociationByRole.First().OutboundName, InboundMultiplicity = entityAssociationByRole.First().InboundMultiplicity, OutboundMultiplicity = entityAssociationByRole.First().OutboundMultiplicity, AllowedTypes = baseTypesChain.Where(x => !x.IsAbstract).ToList() }); } associations.Add(entityAssociations.Key, roleAssociationItems); } }
public Arguments(TValue initialValue, IVertexBase target, bool raycasting, IDrawClient raycastClient, GraphDirections directions, int depthMax, int viewDepthMax) { Value = initialValue; Target = target; Raycasting = raycasting; Directions = directions; DepthMax = depthMax; ViewDepthMax = viewDepthMax; RaycastClient = raycastClient; TransformerPath = new Stack <ITransformer>(); ViewDepths = new Dictionary <ViewVertex, int>(); }
public async Task <IReadOnlyList <RtAssociation> > GetRtAssociationsAsync(IOspSession session, ObjectId rtId, GraphDirections graphDirections) { List <RtAssociation> associations = new List <RtAssociation>(); if (graphDirections == GraphDirections.Any || graphDirections == GraphDirections.Inbound) { associations.AddRange(await _databaseContext.RtAssociations.FindManyAsync(session, x => x.TargetRtId == rtId)); } if (graphDirections == GraphDirections.Any || graphDirections == GraphDirections.Outbound) { associations.AddRange(await _databaseContext.RtAssociations.FindManyAsync(session, x => x.OriginRtId == rtId)); } return(associations); }
public HeuristicComparerManhattanOriented(Graph graph) : base(graph) { XPosLeft = graph.EndNode.NodeConnections[GraphDirections.GetDirectionOrder(GraphDirections.LEFT.CharCode)] == -1 ? graph.EndNode.NodeCode % graph.RowSize + 2 : graph.EndNode.NodeCode % graph.RowSize; XPosRight = graph.EndNode.NodeConnections[GraphDirections.GetDirectionOrder(GraphDirections.RIGHT.CharCode)] == -1 ? graph.EndNode.NodeCode % graph.RowSize + 2 : graph.EndNode.NodeCode % graph.RowSize; YPosTop = graph.EndNode.NodeConnections[GraphDirections.GetDirectionOrder(GraphDirections.UP.CharCode)] == -1 ? graph.EndNode.NodeCode / graph.RowSize + 2 : graph.EndNode.NodeCode / graph.RowSize; YPosBottom = graph.EndNode.NodeConnections[GraphDirections.GetDirectionOrder(GraphDirections.DOWN.CharCode)] == -1 ? graph.EndNode.NodeCode / graph.RowSize + 2 : graph.EndNode.NodeCode / graph.RowSize; }
public async Task <ResultSet <RtEntity> > GetRtAssociationTargetsAsync(IOspSession session, ObjectId rtId, string roleId, string targetCkId, GraphDirections graphDirection, DataQueryOperation dataQueryOperation, int?skip = null, int?take = null) { ArgumentValidation.Validate(nameof(rtId), rtId); ArgumentValidation.ValidateString(nameof(roleId), roleId); ArgumentValidation.ValidateString(nameof(targetCkId), targetCkId); ArgumentValidation.Validate(nameof(dataQueryOperation), dataQueryOperation); var entityCacheItem = GetEntityCacheItem(targetCkId); var hierarchicalRtStatementCreator = new HierarchicalRtStatementCreator(entityCacheItem, _databaseContext, dataQueryOperation.Language, rtId, graphDirection, targetCkId); hierarchicalRtStatementCreator.AddFieldFilters(dataQueryOperation.FieldFilters); hierarchicalRtStatementCreator.AddTextSearchFilter(dataQueryOperation.TextSearchFilter); hierarchicalRtStatementCreator.AddAttributeSearchFilter(dataQueryOperation.AttributeSearchFilter); hierarchicalRtStatementCreator.AddSort(dataQueryOperation.SortOrders); return(await hierarchicalRtStatementCreator.ExecuteQuery(session, skip, take)); }
public async Task <IReadOnlyList <RtAssociation> > GetRtAssociationsAsync(IOspSession session, string rtId, GraphDirections graphDirections) { return(await GetRtAssociationsAsync(session, ObjectId.Parse(rtId), graphDirections)); }
public async Task <CurrentMultiplicity> GetCurrentRtAssociationMultiplicityAsync(IOspSession session, RtEntityId rtEntityId, string roleId, GraphDirections graphDirections) { long counter = 0; if (graphDirections == GraphDirections.Inbound || graphDirections == GraphDirections.Any) { var filterDefinition = Builders <RtAssociation> .Filter.And( Builders <RtAssociation> .Filter.Eq(x => x.TargetRtId, rtEntityId.RtId.ToObjectId()), Builders <RtAssociation> .Filter.Eq(x => x.TargetCkId, rtEntityId.CkId), Builders <RtAssociation> .Filter.Eq(x => x.AssociationRoleId, roleId) ); var r = await _databaseContext.RtAssociations.GetTotalCountAsync(session, filterDefinition); counter = Math.Max(r, counter); } if (graphDirections == GraphDirections.Outbound || graphDirections == GraphDirections.Any) { var filterDefinition = Builders <RtAssociation> .Filter.And( Builders <RtAssociation> .Filter.Eq(x => x.OriginRtId, rtEntityId.RtId.ToObjectId()), Builders <RtAssociation> .Filter.Eq(x => x.TargetCkId, rtEntityId.CkId), Builders <RtAssociation> .Filter.Eq(x => x.AssociationRoleId, roleId) ); var r = await _databaseContext.RtAssociations.GetTotalCountAsync(session, filterDefinition); counter = Math.Max(r, counter); } if (counter >= 2) { return(CurrentMultiplicity.Many); } if (counter == 1) { return(CurrentMultiplicity.One); } return(CurrentMultiplicity.Zero); }
public static FieldType AssociationField <TSourceType>( this ComplexGraphType <TSourceType> _this, IGraphTypesCache graphTypesCache, string name, IReadOnlyList <string> allowedTypes, string roleId, GraphDirections graphDirection) { var graphTypes = allowedTypes.Select(ckId => graphTypesCache.GetOrCreate(ckId)); var unionType = new RtEntityAssociationType( $"{_this.Name}_{name}{CommonConstants.GraphQlUnionSuffix}", $"Association {roleId} ({graphDirection}) of entity type {_this.Name}", graphTypesCache, graphTypes, roleId, graphDirection); return(_this.Field(name, null, unionType, resolve: context => context.Source)); }
IOptionsController <TValue> IOptionsController <TValue> .InDirections(GraphDirections directions) { Directions = directions; return(this); }
public RtEntityAssociationType(string name, string description, IGraphTypesCache entityDtoCache, IEnumerable <RtEntityDtoType> rtEntityDtoTypes, string roleId, GraphDirections graphDirection) { ArgumentValidation.ValidateString(nameof(name), name); ArgumentValidation.ValidateString(nameof(description), description); Name = name; Description = description; foreach (var rtEntityDtoType in rtEntityDtoTypes) { this.Connection <object, IGraphType, RtEntityDto>(entityDtoCache, rtEntityDtoType, rtEntityDtoType.Name) .AddMetadata(Statics.CkId, rtEntityDtoType.CkId) .AddMetadata(Statics.RoleId, roleId) .AddMetadata(Statics.GraphDirection, graphDirection) .Argument <OspObjectIdType>(Statics.RtIdArg, "Returns the entity with the given rtId.") .Argument <ListGraphType <OspObjectIdType> >(Statics.RtIdsArg, "Returns entities with the given rtIds.") .Argument <SearchFilterDtoType>(Statics.SearchFilterArg, "Filters items based on text search") .Argument <ListGraphType <SortDtoType> >(Statics.SortOrderArg, "Sort order for items") .Argument <ListGraphType <FieldFilterDtoType> >(Statics.FieldFilterArg, "Filters items based on field compare") .ResolveAsync(ResolveRtEntitiesQuery); } }
public override PathFinderResult FindPath() { GraphNodeHeuristic tempX, tempY; bool updateDist; int i, conn, distTemp; var numberOfSteps = 0; Distances[Graph.StartNode.NodeCode] = 0; // distance in firts node is zero OpenSet.Add(new GraphNodeHeuristic(Graph.StartNode, 0, 0)); //O(log n) while (OpenSet.Count > 0) //O(1) { numberOfSteps++; tempX = OpenSet.ExtractMin(); // get first suitable key and remove it (O(log n)) if (tempX.GraphNode.Equals(Graph.EndNode)) { return new PathFinderResult { Path = Path, PathDirections = PathDirections, Distances = Distances } } ; ClosedSet[tempX.NodeCode] = true; for (i = 0; i < 4; i++) // four directions { conn = tempX.NodeConnections[i]; if (conn == int.MaxValue || ClosedSet[conn]) { continue; //skip value, no connections } distTemp = Distances[tempX.NodeCode] + Graph.GraphBody[conn].NodeValue; tempY = new GraphNodeHeuristic(Graph.GraphBody[conn], distTemp, HeuristicComparer.ComputeHeuristic(Graph.GraphBody[conn])); if (!OpenSet.Contains(tempY)) //O(log 1) { OpenSet.Add(tempY); //O(log n) updateDist = true; } else if (distTemp < Distances[tempY.NodeCode]) { updateDist = true; } else { updateDist = false; } if (updateDist) { OpenSet.UpdateDistance(tempY); // O(log n) Path[tempY.NodeCode] = tempX.GraphNode; PathDirections[tempY.NodeCode] = GraphDirections.GetDirectionCharCode((byte)i); Distances[tempY.NodeCode] = distTemp; } } } // no path found return(new PathFinderResult { Path = null, PathDirections = null, Distances = null }); } }