示例#1
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);
            }
        }
示例#2
0
        public async Task CanGetServerInfo(string rootUrl)
        {
            var gateway = new PortalGateway(rootUrl);

            var response = await IntegrationTestFixture.TestPolicy.ExecuteAsync(() =>
            {
                return(gateway.Info());
            });

            Assert.Null(response.Error);
            Assert.True(response.CurrentVersion > 9.0);
            Assert.NotNull(response.AuthenticationInfo);
        }
        public async Task CanUseServerInfoToGenerateToken(string rootUrl, string username, string password)
        {
            var gateway    = new PortalGateway(rootUrl);
            var serverInfo = await IntegrationTestFixture.TestPolicy.Execute(() =>
            {
                return(gateway.Info());
            });

            var tokenProvider = new TokenProvider(serverInfo.AuthenticationInfo.TokenServicesUrl, username, password);
            var token         = await IntegrationTestFixture.TestPolicy.Execute(() =>
            {
                return(tokenProvider.CheckGenerateToken(CancellationToken.None));
            });

            Assert.NotNull(token);
            Assert.NotNull(token.Value);
            Assert.False(token.IsExpired);
            Assert.Null(token.Error);
        }