Beispiel #1
0
        private void ImportRouteNodes(Wgs84GraphBuilder graphBuilder)
        {
            // Import node objects to database
            var nodesJsonText = File.ReadAllText(_routeNodeFilename);

            var nodesJson = JsonConvert.DeserializeObject(nodesJsonText) as JObject;

            var features = nodesJson["features"];

            bool firstNode = true;

            foreach (var feature in features)
            {
                var properties = feature["properties"] as JObject;

                var geometry = feature["geometry"];

                var geometryType        = geometry["type"].ToString();
                var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", "");

                var nodeId      = Guid.Parse(_nodeIdPrefix + properties["Id"].ToString().PadLeft(6, '0'));
                var nodeType    = properties["NodeType"].ToString();
                var nodeName    = properties["NodeName"].ToString();
                var assetStatus = properties["Status"].ToString();

                if (properties["BuildTestData"].ToString() != "")
                {
                    var buildCodes = properties["BuildTestData"].ToString().Split(';');
                    _nodeBuildCodes.Add(nodeId, buildCodes);
                }


                // Add node to graph
                var x = ((JArray)geometry["coordinates"])[0];
                var y = ((JArray)geometry["coordinates"])[1];


                // Derive node and function kind
                RouteNodeKindEnum?    nodeKind         = null;
                RouteNodeFunctionEnum?nodeFunctionKind = null;

                if (nodeType == "CO")
                {
                    nodeKind         = RouteNodeKindEnum.CentralOfficeSmall;
                    nodeFunctionKind = RouteNodeFunctionEnum.SecondaryNode;
                }
                else if (nodeType == "HH")
                {
                    nodeKind         = RouteNodeKindEnum.HandHole;
                    nodeFunctionKind = RouteNodeFunctionEnum.AccessibleConduitClosure;
                }
                else if (nodeType == "CC")
                {
                    nodeKind         = RouteNodeKindEnum.ConduitClosure;
                    nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure;
                }
                else if (nodeType == "CE")
                {
                    nodeKind         = RouteNodeKindEnum.ConduitEnd;
                    nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure;
                }
                else if (nodeType == "SJ")
                {
                    nodeKind         = RouteNodeKindEnum.ConduitSimpleJunction;
                    nodeFunctionKind = RouteNodeFunctionEnum.NonAccessibleConduitClosure;
                }
                else if (nodeType == "FP")
                {
                    nodeKind         = RouteNodeKindEnum.CabinetBig;
                    nodeFunctionKind = RouteNodeFunctionEnum.FlexPoint;
                }
                else if (nodeType == "SP")
                {
                    nodeKind         = RouteNodeKindEnum.CabinetSmall;
                    nodeFunctionKind = RouteNodeFunctionEnum.SplicePoint;
                }
                else if (nodeType == "A")
                {
                    nodeKind         = RouteNodeKindEnum.BuildingAccessPoint;
                    nodeFunctionKind = RouteNodeFunctionEnum.SplicePoint;
                }
                else if (nodeType == "MDU")
                {
                    nodeKind         = RouteNodeKindEnum.MultiDwellingUnit;
                    nodeFunctionKind = RouteNodeFunctionEnum.CustomerPremisesPoint;
                }
                else if (nodeType == "SDU")
                {
                    nodeKind         = RouteNodeKindEnum.SingleDwellingUnit;
                    nodeFunctionKind = RouteNodeFunctionEnum.CustomerPremisesPoint;
                }

                // On the first node, we set the start marker into applicaion info, and insert data into all the other propeties as well to test if every information is captured into the generated events
                if (firstNode)
                {
                    RouteNodeRecord routeNode = new RouteNodeRecord()
                    {
                        Id              = nodeId,
                        WorkTaskMrid    = _startMarker,
                        ApplicationName = _applicationName,
                        ApplicationInfo = _applicationName,
                        DeleteMe        = false,
                        MarkAsDeleted   = false,
                        Username        = _userName,
                        Geometry        = GeographicToProjectedCoordinateConverter.ConvertPoint(GeoJsonConversionHelper.ConvertFromPointGeoJson(geometryCoordinates)),
                        RouteNodeInfo   = new RouteNodeInfo(nodeKind, nodeFunctionKind),
                        LifecycleInfo   = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now),
                        MappingInfo     = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"),
                        NamingInfo      = new NamingInfo(nodeName, "Route node"),
                        SafetyInfo      = new SafetyInfo("no danger", "might contain rats"),
                        IsAutoCreated   = false
                    };

                    graphBuilder.AddNodeToGraph(routeNode, (double)x, (double)y);
                    _routeNetworkDatestore.InsertRouteNode(routeNode);
                }
                else
                {
                    RouteNodeRecord routeNode = new RouteNodeRecord()
                    {
                        Id = nodeId,
                        ApplicationName = _applicationName,
                        ApplicationInfo = _applicationName,
                        DeleteMe        = false,
                        MarkAsDeleted   = false,
                        Username        = _userName,
                        Geometry        = GeographicToProjectedCoordinateConverter.ConvertPoint(GeoJsonConversionHelper.ConvertFromPointGeoJson(geometryCoordinates)),
                        RouteNodeInfo   = new RouteNodeInfo(nodeKind, nodeFunctionKind),
                        NamingInfo      = new NamingInfo(nodeName, "Route node"),
                        IsAutoCreated   = false
                    };

                    graphBuilder.AddNodeToGraph(routeNode, (double)x, (double)y);
                    _routeNetworkDatestore.InsertRouteNode(routeNode);
                }


                firstNode = false;
            }
        }
        /// <summary>
        /// Returns true if test went well (no errors)
        /// </summary>
        /// <returns></returns>
        public bool Run()
        {
            Log.Information($"Scenario 1 test begun.");

            DateTime startTime = DateTime.UtcNow;

            Guid startMarker = Guid.NewGuid();

            bool allTestsWentOk = true;

            RouteSegmentRecord routeSegment = new RouteSegmentRecord()
            {
                Id               = Guid.NewGuid(),
                WorkTaskMrid     = startMarker,
                ApplicationName  = "ScenarioTester",
                ApplicationInfo  = "Scenario 1 happy case",
                DeleteMe         = false,
                MarkAsDeleted    = false,
                Username         = "******",
                Geometry         = GeoJsonConversionHelper.ConvertFromLineGeoJson("[[539632.709067166,6177928.15],[539718.634229065,6177984.82],[539816.442658036,6178004.93]]"),
                RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"),
                LifecycleInfo    = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now),
                MappingInfo      = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"),
                NamingInfo       = new NamingInfo("Route segment", "I'm an underground route segment"),
                SafetyInfo       = new SafetyInfo("No real danger, unless you're afraid of gophers", "Might contain gophers"),
            };

            _routeNetworkDatastore.InsertRouteSegment(routeSegment);

            var events = WaitForEvents(startMarker);

            if (events.Count != 3)
            {
                Log.Error($"Expected 3 events, but got {events.Count}");
                return(Fail());
            }

            // Snatch cmdId from the first event
            Guid cmdId = events.First().CmdId;

            if (allTestsWentOk)
            {
                // Event 1 must be route node added
                if (events[0] is RouteNodeAdded)
                {
                    var routeNodeAdded = events[0] as RouteNodeAdded;

                    // General route network event property checks
                    allTestsWentOk = CheckApplicationName(routeNodeAdded, "GDB_INTEGRATOR") ? allTestsWentOk : false;
                    allTestsWentOk = CheckCmdType(routeNodeAdded, "NewRouteSegmentDigitized") ? allTestsWentOk : false;
                    allTestsWentOk = CheckEventId(routeNodeAdded) ? allTestsWentOk : false;
                    allTestsWentOk = CheckEventType(routeNodeAdded, "RouteNodeAdded") ? allTestsWentOk : false;
                    allTestsWentOk = CheckEventTimestamp(routeNodeAdded, startTime) ? allTestsWentOk : false;
                    allTestsWentOk = CheckThatIsLastEventInCmdIsFalse(routeNodeAdded) ? allTestsWentOk : false;
                    allTestsWentOk = CheckThatWorkTaskMridIsTransferedToEvent(routeNodeAdded, routeSegment.WorkTaskMrid) ? allTestsWentOk : false;
                    allTestsWentOk = CheckThatUserNameIsTransferedToEvent(routeNodeAdded, routeSegment.Username) ? allTestsWentOk : false;

                    // Route node added specific tests
                    allTestsWentOk = CheckNodeId(routeNodeAdded) ? allTestsWentOk : false;
                }
                else
                {
                    return(Fail($"Expected that the first event was a route node added event, but got a: {events[0].GetType().Name}"));
                }
            }


            if (allTestsWentOk)
            {
                Log.Information($"Scenario 1 test ended with success.");
            }
            else
            {
                return(Fail());
            }

            return(allTestsWentOk);
        }
Beispiel #3
0
        private void ImportRouteSegments(Wgs84GraphBuilder graphBuilder)
        {
            // Import node objects to database
            var segmentJsonText = File.ReadAllText(_routeSegmentFilename);

            var segmentsJson = JsonConvert.DeserializeObject(segmentJsonText) as JObject;

            var features = segmentsJson["features"];

            bool firstSegment = true;
            bool lastSegment  = false;

            var numberOfSegmentFeatures = features.Count();

            var segmentCounter = 1;

            foreach (var feature in features)
            {
                var properties = feature["properties"] as JObject;

                var geometry = feature["geometry"];

                var geometryType        = geometry["type"].ToString();
                var geometryCoordinates = geometry["coordinates"].ToString().Replace("\r\n", "").Replace(" ", "");

                var segmentId   = Guid.Parse(_segmentIdPrefix + properties["Id"].ToString().PadLeft(6, '0'));
                var segmentKind = properties["RouteSegmentKind"].ToString();
                var assetStatus = properties["Status"].ToString();

                if (properties["BuildTestData"].ToString() != "")
                {
                    var buildCodes = properties["BuildTestData"].ToString().Split(';');
                    _segmentBuildCodes.Add(segmentId, buildCodes);
                }


                // Add link to graph
                var coordinates = geometry["coordinates"] as JArray;
                var startX      = coordinates.First[0];
                var startY      = coordinates.First[1];

                var endX = coordinates.Last[0];
                var endY = coordinates.Last[1];

                // Derive node and function kind
                RouteSegmentKindEnum?segmentKindCode = null;

                if (segmentKind == "buried")
                {
                    segmentKindCode = RouteSegmentKindEnum.Underground;
                }

                // On the first node, we set the start marker into applicaion info, and insert data into all the other propeties as well to test if every information is captured into the generated events
                if (firstSegment)
                {
                    RouteSegmentRecord routeSegment = new RouteSegmentRecord()
                    {
                        Id = segmentId,
                        ApplicationName  = _applicationName,
                        ApplicationInfo  = _applicationName,
                        DeleteMe         = false,
                        MarkAsDeleted    = false,
                        Username         = _userName,
                        Geometry         = GeographicToProjectedCoordinateConverter.ConvertLineString(GeoJsonConversionHelper.ConvertFromLineGeoJson(geometryCoordinates)),
                        RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"),
                        LifecycleInfo    = new LifecycleInfo(DeploymentStateEnum.InService, DateTime.Now, DateTime.Now),
                        MappingInfo      = new MappingInfo(MappingMethodEnum.LandSurveying, "10 cm", "20 cm", DateTime.Now, "Surveyed with GPS"),
                        NamingInfo       = new NamingInfo("Route segment", "I'm an underground route segment"),
                        SafetyInfo       = new SafetyInfo("no danger", "might contain gophers"),
                    };

                    graphBuilder.AddEdgeToGraph(routeSegment, (double)startX, (double)startY, (double)endX, (double)endY);
                    _routeNetworkDatestore.InsertRouteSegment(routeSegment);
                }
                else
                {
                    RouteSegmentRecord routeSegment = new RouteSegmentRecord()
                    {
                        Id = segmentId,
                        ApplicationName  = _applicationName,
                        ApplicationInfo  = _applicationName,
                        DeleteMe         = false,
                        MarkAsDeleted    = false,
                        Username         = _userName,
                        Geometry         = GeographicToProjectedCoordinateConverter.ConvertLineString(GeoJsonConversionHelper.ConvertFromLineGeoJson(geometryCoordinates)),
                        RouteSegmentInfo = new RouteSegmentInfo(RouteSegmentKindEnum.Underground, "50 cm", "90 cm"),
                    };

                    // Mark last segment
                    if (segmentCounter == numberOfSegmentFeatures)
                    {
                        routeSegment.WorkTaskMrid = _endMarker;
                    }

                    graphBuilder.AddEdgeToGraph(routeSegment, (double)startX, (double)startY, (double)endX, (double)endY);
                    _routeNetworkDatestore.InsertRouteSegment(routeSegment);
                }


                firstSegment = false;
                segmentCounter++;
            }
        }