Exemplo n.º 1
0
        private static void ReadMessage(ConsoleCommand command)
        {
            string messageId = command.Current;

            ConsoleWriter.WriteInGreen($"Reading message {messageId}..");

            Message message = _messageProvider.GetMessage(TraceId.New(), messageId);

            ConsoleWriter.WriteInGreen(message.Body);
        }
Exemplo n.º 2
0
        private static void DownloadWithMessageId(ConsoleCommand command)
        {
            string messageId = command.Current;
            string dir       = command.Advance().Current;

            Directory.CreateDirectory(dir);

            ConsoleWriter.WriteInGreen($"Downloading message {messageId} to {dir}..");
            Message message = _messageProvider.GetMessage(TraceId.New(), messageId);

            SaveMessage(message, dir);
        }
Exemplo n.º 3
0
        private static void PrintMessages(ConsoleCommand command)
        {
            string labelId = command.Current;

            ConsoleWriter.WriteInGreen($"Fetching messages with label {labelId}..");

            var messages = _messageProvider.GetMessagesWithLabel(TraceId.New(), labelId);

            if (!messages.Any())
            {
                ConsoleWriter.WriteInGreen($"No messages found for label {labelId}");
                return;
            }

            foreach (var message in messages.OrderBy(m => m.Id))
            {
                ConsoleWriter.WriteInGreen($"{message.Id}\t{message.Date}\t{message.Subject}");
            }
        }
Exemplo n.º 4
0
        public static IServiceCollection AddTraceId(this IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient <TraceId>(o =>
            {
                var httpContextAccessor = o.GetRequiredService <IHttpContextAccessor>();
                var traceId             = httpContextAccessor.HttpContext.Items["TRACE_ID"];
                if (traceId == null)
                {
                    throw new NullReferenceException(nameof(traceId));
                }

                if (!Guid.TryParse(traceId.ToString(), out var guid))
                {
                    throw new ArgumentNullException(nameof(guid));
                }

                return(TraceId.New(guid));
            });
            return(serviceCollection);
        }
Exemplo n.º 5
0
        private static void DownloadWithLabel(ConsoleCommand command)
        {
            string labelId = command.Current;
            string dir     = command.Advance().Current;

            Directory.CreateDirectory(dir);

            ConsoleWriter.WriteInGreen($"Downloading messages with label {labelId} to {dir}..");
            var messages = _messageProvider.GetMessagesWithLabel(TraceId.New(), labelId);

            if (!messages.Any())
            {
                ConsoleWriter.WriteInGreen($"No messages found for label {labelId}");
                return;
            }

            foreach (var message in messages)
            {
                SaveMessage(message, dir);
            }
        }
        public async Task Invoke(HttpContext context)
        {
            context.Items["TRACE_ID"] = TraceId.New();

            await _next(context);
        }