public EquipmentServiceQuery(IRouteNetworkState routeNetwork)
        {
            Description = "GraphQL API for querying OpenFTTH data";

            Field <StringGraphType>("apiVersion", resolve: context => VersionInfo.VersionString());

            Field <ListGraphType <RouteNodeType> >(
                "routeNodes",
                resolve: context =>
            {
                return(routeNetwork.GetAllRouteNodes());
            }
                );

            Field <RouteNodeType>(
                "routeNode",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "Id"
            }),
                resolve: context =>
            {
                Guid id;
                if (!Guid.TryParse(context.GetArgument <string>("id"), out id))
                {
                    context.Errors.Add(new ExecutionError("Wrong value for guid"));
                    return(null);
                }

                return(routeNetwork.GetRouteNodeInfo(id));
            }
                );


            Field <ListGraphType <RouteSegmentType> >(
                "routeSegments",
                resolve: context => {
                return(routeNetwork.GetAllRouteSegments());
            }
                );

            Field <RouteSegmentType>(
                "routeSegment",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "Id"
            }),
                resolve: context =>
            {
                Guid id;
                if (!Guid.TryParse(context.GetArgument <string>("id"), out id))
                {
                    context.Errors.Add(new ExecutionError("Wrong value for guid"));
                    return(null);
                }
                return(routeNetwork.GetRouteSegmentInfo(id));
            }
                );

            Field <ConduitServiceQuery>("conduitService", resolve: context => new { });
            Field <DiagramServiceQuery>("diagramService", resolve: context => new { });
        }
Exemple #2
0
        private static void PlaceCable(IRouteNetworkState routeNetworkQueryService, IMediator commandBus, Guid cableId, int nFibers, Guid startNodeParam, Guid endNodeId)
        {
            var startNode = routeNetworkQueryService.GetRouteNodeInfo(startNodeParam);

            List <Guid> result = new List <Guid>();

            List <IGraphElement> graphElements = new List <IGraphElement>();

            graphElements.AddRange(routeNetworkQueryService.GetAllRouteNodes());
            graphElements.AddRange(routeNetworkQueryService.GetAllRouteSegments());

            // remove element, so it has to be routed left through the pf and junctions
            var elementToRemove = graphElements.Find(g => g.Id == Guid.Parse("b95000fb-425d-4cd3-9f45-66e8c5000050"));

            graphElements.Remove(elementToRemove);

            var graph = new Graph(graphElements);

            var shortestPathResult = graph.ShortestPath(startNode.Id.ToString(), endNodeId.ToString()).ToList();

            var cableWalkOfInterest = new List <Guid>();

            foreach (var item in shortestPathResult)
            {
                cableWalkOfInterest.Add(item.Id);
            }

            // Walk of interest for cable
            var registerMultiConduitWalk = new RegisterWalkOfInterestCommand()
            {
                WalkOfInterestId = Guid.NewGuid(),
                RouteElementIds  = cableWalkOfInterest
            };

            commandBus.Send(registerMultiConduitWalk).Wait();

            // Place cable
            var placeCable1 = new PlaceFiberCableCommand()
            {
                FiberCableId     = cableId,
                WalkOfInterestId = registerMultiConduitWalk.WalkOfInterestId,
                NumberOfFibers   = nFibers
            };

            commandBus.Send(placeCable1).Wait();
        }
Exemple #3
0
        public RouteNodeGraphFunctions(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IDataLoaderContextAccessor dataLoader)
        {
            this.routeNetworkQueryService = routeNetworkQueryService;
            this.conduitNetworkEqueryService = conduitNetworkEqueryService;
            this.conduitClosureRepository = conduitClosureRepository;

            Description = "Route node graph functions";

            Field<ListGraphType<IdGraphType>>(
              "shortestPath",
              arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "ToNodeId" }),
              resolve: context =>
              {
                  var startNode = context.Source as RouteNodeInfo;

                  Guid endNodeId = context.GetArgument<Guid>("toNodeId");

                  List<Guid> result = new List<Guid>();

                  List<IGraphElement> graphElements = new List<IGraphElement>();

                  graphElements.AddRange(routeNetworkQueryService.GetAllRouteNodes());
                  graphElements.AddRange(routeNetworkQueryService.GetAllRouteSegments());

                  var graph = new Graph(graphElements);


                  var shortestPathResult = graph.ShortestPath(startNode.Id.ToString(), endNodeId.ToString()).Select(s => s.Id);

                  return shortestPathResult;
              });


            Field<ListGraphType<RouteNodeType>>(
               "neighborNodes",
               resolve: context =>
               {
                   List<RouteNodeInfo> result = new List<RouteNodeInfo>();

                   var routeNode = context.Source as RouteNodeInfo;

                   foreach (var neighbor in routeNode.NeighborElements)
                   {
                       var neighborNeighbors = neighbor.NeighborElements;

                       foreach (var neighborNeighbor in neighborNeighbors)
                       {
                           if (neighborNeighbor != routeNode)
                               result.Add((RouteNodeInfo)neighborNeighbor);
                       }
                       
                   }

                   return result;

               });


            Field<ListGraphType<RouteSegmentType>>(
              "neighborSegments",
              resolve: context =>
              {
                  List<RouteSegmentInfo> result = new List<RouteSegmentInfo>();

                  var routeNode = context.Source as RouteNodeInfo;

                  foreach (var neighbor in routeNode.NeighborElements)
                  {
                    result.Add((RouteSegmentInfo)neighbor);
                  }

                  return result;
              });

        }