Beispiel #1
0
        public DiagramServiceQuery(IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkEqueryService, IConduitClosureRepository conduitClosureRepository, IFiberNetworkQueryService fiberNetworkService, IDataLoaderContextAccessor dataLoader)
        {
            Description = "GraphQL API for generating fiber equiment diagrams.";

            Field <DiagramType>(
                "buildRouteNodeDiagram",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNodeId"
            },
                    new QueryArgument <StringGraphType> {
                Name = "exportGeojsonFileName"
            }
                    ),
                resolve: context =>
            {
                var routeNodeId  = context.GetArgument <Guid>("routeNodeId");
                var jsonFilename = context.GetArgument <string>("exportGeojsonFileName");

                var diagram = new ConduitClosureBuilder().Build(routeNodeId, routeNetworkQueryService, conduitNetworkEqueryService, fiberNetworkService, conduitClosureRepository);

                if (jsonFilename != null)
                {
                    var export = new GeoJsonExporter(diagram);
                    export.Export(jsonFilename);
                }

                return(diagram);
            }
                );
        }
        public SchematicQueries(ILogger <SchematicQueries> logger, IQueryDispatcher queryDispatcher)
        {
            Description = "GraphQL API for generating schematic diagrams";

            FieldAsync <DiagramType>(
                "buildDiagram",
                arguments:
                new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "routeNetworkElementId"
            },
                                   new QueryArgument <StringGraphType> {
                Name = "exportToGeoJsonFilename"
            }
                                   ),
                resolve: async context =>
            {
                if (!Guid.TryParse(context.GetArgument <string>("routeNetworkElementId"), out Guid routeNetworkElementId))
                {
                    context.Errors.Add(new ExecutionError("Wrong value for guid"));
                    return(null);
                }

                var getDiagramQueryResult = await queryDispatcher.HandleAsync <GetDiagram, Result <GetDiagramResult> >(new GetDiagram(routeNetworkElementId));

                if (getDiagramQueryResult.IsFailed)
                {
                    foreach (var error in getDiagramQueryResult.Errors)
                    {
                        context.Errors.Add(new ExecutionError(error.Message));
                    }

                    return(null);
                }

                // Export to geojson file (for checking in QGIS etc.) if such filename is specified
                var jsonFilename = context.GetArgument <string>("exportToGeoJsonFilename");

                if (jsonFilename != null)
                {
                    var export = new GeoJsonExporter(getDiagramQueryResult.Value.Diagram);
                    export.Export(jsonFilename);
                }

                return(getDiagramQueryResult.Value.Diagram);
            }
                );
        }