Exemplo n.º 1
0
        public async Task Run(object o, object context)
        {
            var request = o.GetConvertedObject <T>();

            if (context is PerformContext performContext)
            {
                jobContext = performContext;
            }

            //Validate the parameters
            request.Validate();

            if (configStore.GetValueBool("SCHEDULER_ENABLE_DXF_TILE_GENERATION").HasValue&&
                configStore.GetValueBool("SCHEDULER_ENABLE_DXF_TILE_GENERATION").Value)
            {
                log.LogInformation($"Tile generation with Pegasus enabled: {JsonConvert.SerializeObject(request)}");

                var result = await GenerateTiles(request);

                log.LogInformation($"Received Pegasus response for tile generation, filename: {request.FileName}, result: `{JsonConvert.SerializeObject(result)}`");

                var notifyParams = new RasterTileNotificationParameters
                {
                    FileUid      = request.ImportedFileUid,
                    MinZoomLevel = result.MinZoom,
                    MaxZoomLevel = result.MaxZoom
                };

                await notificationHubClient.Notify(new ProjectFileRasterTilesGeneratedNotification(notifyParams));
            }
            else
            {
                log.LogInformation($"Tile generation with Pegasus disabled (Bug 83657) - ignoring request: {JsonConvert.SerializeObject(request)}");
            }
        }
Exemplo n.º 2
0
        public async Task <FilterDescriptorSingleResult> PutFilter(
            //[FromServices] IGeofenceProxy geofenceProxy,
            [FromServices] IFileImportProxy fileImportProxy,
            [FromServices] INotificationHubClient notificationHubClient,
            string projectUid,
            [FromBody] FilterRequest request)
        {
            Log.LogInformation($"{nameof(PutFilter)}: CustomerUID={CustomerUid} FilterRequest: {JsonConvert.SerializeObject(request)}");

            var filterExecutor = RequestExecutorContainer.Build <UpsertFilterExecutor>(ConfigStore, Logger, ServiceExceptionHandler, filterRepo, geofenceRepository, ProjectProxy,
                                                                                       productivity3dV2ProxyNotification: Productivity3dV2ProxyNotification, productivity3dV2ProxyCompaction: Productivity3dV2ProxyCompaction,
                                                                                       fileImportProxy: fileImportProxy /*, geofenceProxy: geofenceProxy */);
            var upsertFilterResult = await UpsertFilter(filterExecutor, await GetProject(projectUid), request);

            if (upsertFilterResult.FilterDescriptor.FilterType == FilterType.Persistent)
            {
                await notificationHubClient.Notify(new ProjectChangedNotification(Guid.Parse(projectUid)));
            }

            return(upsertFilterResult);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SnsNotification()
        {
            // https://forums.aws.amazon.com/thread.jspa?threadID=69413
            // AWS SNS is in text/plain, not application/json - so need to parse manually
            var payloadMs = new MemoryStream();
            await Request.Body.CopyToAsync(payloadMs);

            var payload = Message.ParseMessage(Encoding.UTF8.GetString(payloadMs.ToArray()));

            bool isValid;

            try
            {
                isValid = payload.IsMessageSignatureValid();
            }
            catch (AmazonClientException e)
            {
                _logger.LogWarning($"Failed to validate SNS Message. Error: {e.Message}");
                return(BadRequest(e.Message));
            }

            if (!isValid)
            {
                return(BadRequest());
            }

            _logger.LogInformation($"Received SNS Message: {payload.MessageId}. Topic: {payload.TopicArn} Type: {payload.Type} Valid: {payload.IsMessageSignatureValid()}");
            if (payload.IsSubscriptionType)
            {
                _logger.LogInformation($"SNS SUBSCRIPTION REQUEST: {payload.MessageText}, Subscription URL: '{payload.SubscribeURL}'");
            }
            else if (payload.IsNotificationType)
            {
                // Got a valid message
                var notification = JsonConvert.DeserializeObject <CwsTrnUpdate>(payload.MessageText);
                if (notification != null)
                {
                    // Iterate all
                    var trns = notification.UpdatedTrns ?? new List <string>();
                    trns.Add(notification.AccountTrn);
                    trns.Add(notification.ProjectTrn);
                    var tasks = new List <Task>(trns.Count);
                    foreach (var t in trns)
                    {
                        if (string.IsNullOrEmpty(t))
                        {
                            continue;
                        }
                        var guid = TRNHelper.ExtractGuid(t);
                        if (guid.HasValue)
                        {
                            tasks.Add(_notificationHubClient.Notify(new ProjectChangedNotification(guid.Value)));
                        }
                        else
                        {
                            _logger.LogWarning($"Failed to extra GUID from TRN: {t}");
                        }
                    }

                    await Task.WhenAll(tasks);

                    _logger.LogInformation($"Processed notifications. Total TRNS: {trns.Count}");
                }
                else
                {
                    _logger.LogWarning($"Failed to parse notification message with content: {payload.MessageText}");
                }
            }

            return(Ok());
        }