Ejemplo n.º 1
0
        public static LoggerConfiguration FromServiceContext(this LoggerEnrichmentConfiguration enrichmentConfiguration, ServiceContext context)
        {
            if (enrichmentConfiguration == null)
            {
                throw new ArgumentNullException(nameof(enrichmentConfiguration));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var propertyEnrichers = new PropertyEnricher[]
            {
                new PropertyEnricher(nameof(context.ServiceName), context.ServiceName),
                new PropertyEnricher(nameof(context.ServiceTypeName), context.ServiceTypeName),
                new PropertyEnricher(nameof(context.ReplicaOrInstanceId), context.ReplicaOrInstanceId.ToString()),
                new PropertyEnricher(nameof(context.PartitionId), context.PartitionId.ToString()),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.ApplicationName), context.CodePackageActivationContext.ApplicationName),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.ApplicationTypeName), context.CodePackageActivationContext.ApplicationTypeName),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.CodePackageName), context.CodePackageActivationContext.CodePackageName),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.CodePackageVersion), context.CodePackageActivationContext.CodePackageVersion),
                new PropertyEnricher(nameof(context.NodeContext.NodeName), context.NodeContext.NodeName),
                new PropertyEnricher(nameof(context.TraceId), context.TraceId),
            };

            return(enrichmentConfiguration.With(propertyEnrichers));
        }
Ejemplo n.º 2
0
        public async Task Consume(ConsumeContext <IDownloadPackage> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.ArchiveRecordId), context.Message.ArchiveRecordId);
            var packageIdEnricher       = new PropertyEnricher(nameof(context.Message.PackageId), context.Message.PackageId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher, packageIdEnricher))
            {
                Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(IDownloadPackage),
                                context.ConversationId);

                // Get the package from the repository
                // We are not waiting for it to end, because we want to free the consumer as early as possible
                var packageId       = context.Message.PackageId;
                var archiveRecordId = context.Message.ArchiveRecordId;
                var result          = await repositoryManager.GetPackage(packageId, archiveRecordId, context.Message.PrimaerdatenAuftragId);

                // Do we have a valid package?
                if (result.Success && result.Valid)
                {
                    // Forward the downloaded package to the asset manager for transformation
                    var endpoint = await context.GetSendEndpoint(new Uri(bus.Address, BusConstants.AssetManagerPrepareForTransformation));

                    await endpoint.Send(new PrepareForTransformationMessage
                    {
                        AssetType             = AssetType.Gebrauchskopie,
                        CallerId              = context.Message.CallerId,
                        RetentionCategory     = context.Message.RetentionCategory,
                        Recipient             = context.Message.Recipient,
                        Language              = context.Message.Language,
                        ProtectWithPassword   = context.Message.RetentionCategory != CacheRetentionCategory.UsageCopyPublic,
                        PrimaerdatenAuftragId = context.Message.PrimaerdatenAuftragId,
                        RepositoryPackage     = result.PackageDetails
                    });

                    // also publish the event, that the package is downloaded
                    await context.Publish <IPackageDownloaded>(
                        new
                    {
                        PackageInfo = result
                    });
                }
                else
                {
                    // Publish the download asset failure event
                    await context.Publish <IAssetReady>(new AssetReady
                    {
                        Valid                 = false,
                        ErrorMessage          = result.ErrorMessage,
                        AssetType             = AssetType.Gebrauchskopie,
                        CallerId              = context.Message.CallerId,
                        ArchiveRecordId       = context.Message.ArchiveRecordId,
                        RetentionCategory     = context.Message.RetentionCategory,
                        Recipient             = context.Message.Recipient,
                        PrimaerdatenAuftragId = context.Message.PrimaerdatenAuftragId
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public void BeginScope(string name, object value)
        {
            var propEnricher = new PropertyEnricher(name, value);

            _loggerStack.Push(_loggerStack.TryPeek(out var recentLogger)
        ? recentLogger.ForContext(propEnricher)
        : Log.ForContext(propEnricher));
        }
        public Task Consume(ConsumeContext <IUpdatePrimaerdatenAuftragStatus> context)
        {
            var conversationEnricher = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);

            using (LogContext.Push(conversationEnricher))
            {
                assetManager.UpdatePrimaerdatenAuftragStatus(context.Message);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 5
0
        public async Task Consume(ConsumeContext <IArchiveRecordAppendPackageMetadata> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.ArchiveRecord.ArchiveRecordId),
                                                               context.Message.ArchiveRecord?.ArchiveRecordId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher))
            {
                Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus",
                                nameof(IArchiveRecordAppendPackage), context.ConversationId);

                if (context.Message.ArchiveRecord != null)
                {
                    // Get the package from the repository
                    var result = repositoryManager.ReadPackageMetadata(context.Message.ArchiveRecord.Metadata.PrimaryDataLink,
                                                                       context.Message.ArchiveRecord.ArchiveRecordId);

                    // Inform the world about the created package
                    if (result != null && result.Success && result.Valid)
                    {
                        // Add the metadata to the archive record.
                        context.Message.ArchiveRecord.PrimaryData.Add(result.PackageDetails);
                        Log.Information("Package metadata extraction was successful for packageId {packageId}", result.PackageDetails.PackageId);

                        var endpoint = await context.GetSendEndpoint(new Uri(context.SourceAddress,
                                                                             BusConstants.AssetManagerSchdeduleForPackageSyncMessageQueue));

                        await endpoint.Send <IScheduleForPackageSync>(new
                        {
                            Workload = new ArchiveRecordAppendPackage
                            {
                                MutationId    = context.Message.MutationId,
                                ArchiveRecord = context.Message.ArchiveRecord,
                                ElasticRecord = context.Message.ElasticRecord
                            }
                        });
                    }
                    else
                    {
                        // If package creation was not successful, stop syncing here and return failure.
                        Log.Error(
                            "Failed to extract primary metadata from repository for archiveRecord with conversationId {ConversationId} with message {ErrorMessage}",
                            context.ConversationId, result?.ErrorMessage);
                        await context.Publish <IArchiveRecordUpdated>(new
                        {
                            context.Message.MutationId,
                            context.Message.ArchiveRecord.ArchiveRecordId,
                            ActionSuccessful = false,
                            result?.ErrorMessage
                        });
                    }
                }
            }
        }
        public ILoggingAdapter SetContextProperty(string name, object value, bool destructureObjects = false)
        {
            var contextProperty = new PropertyEnricher(name, value, destructureObjects);

            var contextNode = new ContextNode
            {
                Enricher = contextProperty,
                Next     = _enricherNode
            };

            return(new SerilogExtendedLoggingAdapter(_adapter, contextNode));
        }
        public async Task Consume(ConsumeContext <PrepareForTransformationMessage> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.RepositoryPackage.ArchiveRecordId), context.Message.RepositoryPackage.ArchiveRecordId);
            var packageIdEnricher       = new PropertyEnricher(nameof(context.Message.RepositoryPackage.PackageId), context.Message.RepositoryPackage.PackageId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher, packageIdEnricher))
            {
                Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(PrepareForTransformationMessage), context.ConversationId);

                // 1. Step: Extract Zip file(s)
                preparationSteps.Add(ExtractRepositoryPackage);
                // 2. Step: ConvertAreldaXml
                preparationSteps.Add(ConvertAreldaMetadataXml);
                // 3. Step: ConvertJp2ToPdf
                preparationSteps.Add(ConvertSingleJp2ToPdf);
                // 4. Step: Detect and mark files with large dimensions
                preparationSteps.Add(DetectAndFlagLargeDimensions);
                // 5. Step: Detect and optimize pdf files that need optimization
                preparationSteps.Add(DetectAndOptimizePdf);


                foreach (var step in preparationSteps)
                {
                    var result = await step(context.Message);

                    // In case any step was not successful, fail the sync
                    if (!result.Success)
                    {
                        await PublishAssetReadyFailed(context, result.ErrorMessage);

                        return;
                    }
                }

                // Forward the prepared data to the next processing point
                var endpoint = await context.GetSendEndpoint(new Uri(context.SourceAddress, BusConstants.AssetManagerTransformAssetMessageQueue));

                await endpoint.Send(new TransformAsset
                {
                    AssetType             = context.Message.AssetType,
                    OrderItemId           = context.Message.OrderItemId,
                    CallerId              = context.Message.CallerId,
                    RetentionCategory     = context.Message.RetentionCategory,
                    Recipient             = context.Message.Recipient,
                    Language              = context.Message.Language,
                    ProtectWithPassword   = context.Message.ProtectWithPassword,
                    PrimaerdatenAuftragId = context.Message.PrimaerdatenAuftragId,
                    RepositoryPackage     = context.Message.RepositoryPackage
                });
            }
        }
Ejemplo n.º 8
0
        public async Task Consume(ConsumeContext <IArchiveRecordAppendPackage> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.ArchiveRecord.ArchiveRecordId),
                                                               context.Message.ArchiveRecord?.ArchiveRecordId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher))
            {
                Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus",
                                nameof(IArchiveRecordAppendPackage), context.ConversationId);

                // Need to clear the existing primary data that just contain the metadata.
                // Required because the append Package is adding the same information again.
                context.Message.ArchiveRecord?.PrimaryData.Clear();

                // Get the package from the repository
                var result = await repositoryManager.AppendPackageToArchiveRecord(context.Message.ArchiveRecord, context.Message.MutationId,
                                                                                  context.Message.PrimaerdatenAuftragId);

                // Inform the world about the created package
                if (result != null && result.Success && result.Valid)
                {
                    Log.Information("Package creation was successful for packageId {packageId}", result.PackageDetails.PackageId);
                    Debug.Assert(result.PackageDetails.PackageFileName != null);
                    var endpoint = await context.GetSendEndpoint(new Uri(context.SourceAddress,
                                                                         BusConstants.AssetManagerPrepareForRecognition));

                    await endpoint.Send <PrepareForRecognitionMessage>(new
                    {
                        context.Message.MutationId,
                        context.Message.ArchiveRecord,
                        context.Message.PrimaerdatenAuftragId
                    });
                }
                else
                {
                    // If package creation was not successful, stop syncing here and return failure.
                    Log.Error(
                        "Failed to extract primary data from repository for archiveRecord with conversationId {ConversationId} with message {ErrorMessage}",
                        context.ConversationId, result?.ErrorMessage);
                    await context.Publish <IArchiveRecordUpdated>(new
                    {
                        context.Message.MutationId,
                        context.Message.ArchiveRecord?.ArchiveRecordId,
                        context.Message.PrimaerdatenAuftragId,
                        ActionSuccessful = false,
                        result?.ErrorMessage
                    });
                }
            }
        }
        public async Task Consume(ConsumeContext <PrepareForRecognitionMessage> context)
        {
            var conversationEnricher          = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var mutationIdEnricher            = new PropertyEnricher(nameof(context.Message.MutationId), context.Message.MutationId);
            var primaerdatenAuftragIdEnricher = new PropertyEnricher(nameof(context.Message.PrimaerdatenAuftragId), context.Message.PrimaerdatenAuftragId);

            using (LogContext.Push(conversationEnricher, mutationIdEnricher, primaerdatenAuftragIdEnricher))
            {
                Log.Information("Received {CommandName} command with conversationId {ConversationId} from the bus", nameof(PrepareForRecognitionMessage), context.ConversationId);


                // 1. Step: Extract Zip file(s)
                preparationSteps.Add(ExtractRepositoryPackage);
                // 2. Step: Detect and mark files with large dimensions
                preparationSteps.Add(DetectAndFlagLargeDimensions);
                // 3. Step: Detect and optimize pdf files that need optimization
                preparationSteps.Add(DetectAndOptimizePdf);

                foreach (var step in preparationSteps)
                {
                    var result = await step(context.Message);

                    // In case any step was not successful, fail the sync
                    if (!result.Success)
                    {
                        await SendFailSync(context, result.ErrorMessage);

                        return;
                    }
                }

                await assetManager.UpdatePrimaerdatenAuftragStatus(new UpdatePrimaerdatenAuftragStatus
                {
                    PrimaerdatenAuftragId = context.Message.PrimaerdatenAuftragId,
                    Service = AufbereitungsServices.AssetService,
                    Status  = AufbereitungsStatusEnum.PreprocessingAbgeschlossen
                });

                // Forward the prepared data to the next processing point
                var endpoint = await context.GetSendEndpoint(new Uri(context.SourceAddress, BusConstants.AssetManagerExtractFulltextMessageQueue));

                await endpoint.Send <IArchiveRecordExtractFulltextFromPackage>(new ArchiveRecordExtractFulltextFromPackage
                {
                    MutationId            = context.Message.MutationId,
                    ArchiveRecord         = context.Message.ArchiveRecord,
                    PrimaerdatenAuftragId = context.Message.PrimaerdatenAuftragId
                });
            }
        }
Ejemplo n.º 10
0
        public Gateway(StatelessServiceContext context, ILogger logger)
            : base(context)
        {
            PropertyEnricher[] properties = new PropertyEnricher[]
            {
                new PropertyEnricher("ServiceTypeName", context.ServiceTypeName),
                new PropertyEnricher("ServiceName", context.ServiceName),
                new PropertyEnricher("PartitionId", context.PartitionId),
                new PropertyEnricher("InstanceId", context.ReplicaOrInstanceId),
            };

            logger.ForContext(properties);

            Logger = new LoggerFactory().AddSerilog(logger.ForContext(properties)).CreateLogger <Gateway>();
        }
        public async Task Consume(ConsumeContext <IScheduleForPackageSync> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.Workload.ArchiveRecord.ArchiveRecordId),
                                                               context.Message.Workload.ArchiveRecord.ArchiveRecordId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher))
            {
                Log.Information("Received {CommandName} command.", nameof(IScheduleForPackageSync));

                var archiveRecord = context.Message.Workload.ArchiveRecord;
                await assetManager.RegisterJobInPreparationQueue(archiveRecord.ArchiveRecordId, archiveRecord.Metadata.PrimaryDataLink,
                                                                 AufbereitungsArtEnum.Sync, AufbereitungsServices.AssetService,
                                                                 archiveRecord.PrimaryData.ToElasticArchiveRecordPackage(), context.Message.Workload);
            }
        }
Ejemplo n.º 12
0
        public async Task Consume(ConsumeContext <IAssetReady> context)
        {
            var conversationEnricher    = new PropertyEnricher(nameof(context.ConversationId), context.ConversationId);
            var archiveRecordIdEnricher = new PropertyEnricher(nameof(context.Message.ArchiveRecordId), context.Message.ArchiveRecordId);

            using (LogContext.Push(conversationEnricher, archiveRecordIdEnricher))
            {
                Log.Information("Received {CommandName} command.", nameof(IAssetReady));

                switch (context.Message.AssetType)
                {
                case AssetType.Gebrauchskopie:

                    await assetManager.UnregisterJobFromPreparationQueue(context.Message.PrimaerdatenAuftragId);

                    if (context.Message.Valid)
                    {
                        await SendMailGebrauchskopieOk(context);
                    }
                    else
                    {
                        await SendMailGebrauchskopieProblem(context);
                    }

                    break;

                case AssetType.Benutzungskopie:

                    if (context.Message.Valid)
                    {
                        await SendMailBenutzungskopieOk(context);
                    }
                    else
                    {
                        await SendMailBenutzungskopieProblem(context);
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
        public async Task InvokeAsync(HttpContext context)
        {
            var enrichers        = new Stack <ILogEventEnricher>();
            var clientIpEnricher = new PropertyEnricher("ClientIP", context.Connection.RemoteIpAddress);

            enrichers.Push(clientIpEnricher);

            var userAgent = context.Request.Headers[HeaderNames.UserAgent].ToString();

            if (!string.IsNullOrEmpty(userAgent))
            {
                var userAgentEnricher = new PropertyEnricher("UserAgent", userAgent);
                enrichers.Push(userAgentEnricher);
            }

            using (Library.Log.Logger.PushEnrichers(enrichers.ToArray()))
            {
                await _next(context);
            }

            //DEBUG
            //await _next(context);
        }
Ejemplo n.º 14
0
        public static ILogger Enrich(this ILogger logger, StatelessServiceContext context)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var properties = new PropertyEnricher[]
            {
                new PropertyEnricher(nameof(context.ServiceName), context.ServiceName.ToString()),
                new PropertyEnricher(nameof(context.ServiceTypeName), context.ServiceTypeName),
                new PropertyEnricher(nameof(context.ReplicaOrInstanceId), context.ReplicaOrInstanceId.ToString()),
                new PropertyEnricher(nameof(context.PartitionId), context.PartitionId),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.ApplicationName), context.CodePackageActivationContext.ApplicationName),
                new PropertyEnricher(nameof(context.CodePackageActivationContext.ApplicationTypeName), context.CodePackageActivationContext.ApplicationTypeName),
                new PropertyEnricher(nameof(context.NodeContext.NodeName), context.NodeContext.NodeName),
                new PropertyEnricher(nameof(context.TraceId), context.TraceId),
            };

            return(logger.ForContext(properties));
        }
 public void AddEnricher(PropertyEnricher enricher)
 {
     PropertyEnrichers.Add(enricher);
 }