Exemple #1
0
        public async Task CanQueryForIds()
        {
            var gateway = new PortalGateway("http://services.arcgisonline.com/arcgis/");

            var query  = new QueryForIds(@"/Specialty/Soil_Survey_Map/MapServer/2");
            var result = await IntegrationTestFixture.TestPolicy.ExecuteAsync(() =>
            {
                return(gateway.QueryForIds(query));
            });

            Assert.NotNull(result);
            Assert.Null(result.Error);
            Assert.NotNull(result.ObjectIds);
            Assert.True(result.ObjectIds.Any());

            var queryFiltered = new QueryForIds(@"/Specialty/Soil_Survey_Map/MapServer/2".AsEndpoint())
            {
                ObjectIds = result.ObjectIds.Take(100).ToList()
            };
            var resultFiltered = await IntegrationTestFixture.TestPolicy.ExecuteAsync(() =>
            {
                return(gateway.QueryForIds(queryFiltered));
            });

            Assert.NotNull(resultFiltered);
            Assert.Null(resultFiltered.Error);
            Assert.NotNull(resultFiltered.ObjectIds);
            Assert.True(resultFiltered.ObjectIds.Any());
            Assert.True(resultFiltered.ObjectIds.Count() == queryFiltered.ObjectIds.Count);
        }
Exemple #2
0
        public static async Task Run([TimerTrigger("0 */15 * * * *")] TimerInfo timer, ILogger log)
        {
#if DEBUG
            log.LogInformation("Update traffic layer . . .");
#endif
            var trafficUrl = Environment.GetEnvironmentVariable(@"traffic.url");
#if DEBUG
            log.LogInformation($"Connecting to {trafficUrl}");
#endif

            var portalUrl      = Environment.GetEnvironmentVariable(@"portal.url");
            var appId          = Environment.GetEnvironmentVariable(@"portal.appid");
            var clientId       = Environment.GetEnvironmentVariable(@"portal.clientid");
            var featureService = Environment.GetEnvironmentVariable(@"portal.featureservice");

            try
            {
                var roadFeatureCollection = await TrafficServiceInstance.Query(trafficUrl);

                var wgs84 = new Crs {
                    Type = @"EPSG", Properties = new CrsProperties {
                        Wkid = 4326
                    }
                };
                roadFeatureCollection.CoordinateReferenceSystem = wgs84;
                var roadFeatures = roadFeatureCollection.ToFeatures();

                using (var gateway = new PortalGateway(portalUrl, tokenProvider: new ArcGISOnlineAppLoginOAuthProvider(appId, clientId)))
                {
#if DEBUG
                    var info = await gateway.Info();

                    log.LogInformation($"Connecting to {info.FullVersion}");
#endif
                    var featureServiceEndpoint = featureService.AsEndpoint();
                    var queryAllIds            = new QueryForIds(featureServiceEndpoint);
                    queryAllIds.Where = @"1=1";
                    var queryAllIdsResult = await gateway.QueryForIds(queryAllIds);

                    var deleteAll = new ApplyEdits <IGeometry>(featureServiceEndpoint);
                    deleteAll.Deletes.AddRange(queryAllIdsResult.ObjectIds);
                    var deleteAllResult = await gateway.ApplyEdits(deleteAll);

                    var addRoads = new ApplyEdits <IGeometry>(featureServiceEndpoint);
                    foreach (var roadFeature in roadFeatures)
                    {
                        roadFeature.Geometry.SpatialReference = SpatialReference.WGS84;
                        var serviceDateTime = (DateTime)roadFeature.Attributes[@"auswertezeit"];
                        roadFeature.Attributes[@"auswertezeit"] = DateTimeUtils.ConvertServiceTimeToUniversalTime(serviceDateTime);
                        addRoads.Adds.Add(roadFeature);
                    }
                    var addRoadsResult = await gateway.ApplyEdits(addRoads);
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
            }
        }