/// <inheritdoc cref="IEventObserver.EventReceived" />
        public virtual async Task EventReceived(EventSourceEvent @event, CancellationToken cancellationToken = default)
        {
            Logger.LogDebug("Projector {projector} processing event: {eventType}", GetType().Name,
                            @event.GetType().Name);

            await ProcessEvent(@event, cancellationToken).ConfigureAwait(false);
            await SetCheckpoint(@event.Position, cancellationToken).ConfigureAwait(false);
        }
Пример #2
0
        private static string FormatMessage(EventSourceEvent eventSourceEvent, Exception exception)
        {
            var eventData = eventSourceEvent.EventData;

            if (eventData.Message != null)
            {
                return(string.Format(eventData.Message, eventData.Payload));
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.Append(eventData.EventName).Append(" ");

            foreach (var pair in eventSourceEvent)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append(pair.Key).Append(" = ").Append(pair.Value);
            }

            return(stringBuilder.ToString());
        }
 public Task EventReceived(EventSourceEvent evt, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }
        private LoggerTemplateModel[] CompileAndEvaluateInterface(ProjectItem projectItem, IEnumerable <ProjectItem> referenceItems)
        {
            LogMessage($"Compiling possible logger file {projectItem.Include}");

            var loggers = new List <EventSourceLoggerTemplate>();

            try
            {
                var parameters = new CompilerParameters();

                foreach (var referenceItem in referenceItems)
                {
                    parameters.ReferencedAssemblies.Add(referenceItem.Name);
                }

                //parameters.ReferencedAssemblies.Add("System.dll");
                parameters.GenerateExecutable = false;
                parameters.GenerateInMemory   = true;

                parameters.IncludeDebugInformation = false;
                var cSharpCodeProvider = new CSharpCodeProvider();
                //var cSharpCodeProvider = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider();
                var compilerResults = cSharpCodeProvider.CompileAssemblyFromFile(parameters, projectItem.Name);
                foreach (CompilerError compilerResultsError in compilerResults.Errors)
                {
                    LogMessage(compilerResultsError.ToString());
                }

                var types = compilerResults.CompiledAssembly.GetTypes();
                foreach (
                    var type in
                    types.Where(t => t.IsInterface && t.Name.Matches(@"^I[^\\]*Logger", StringComparison.InvariantCultureIgnoreCase, useWildcards: false)))
                {
                    var include           = projectItem.Include.Replace(projectItem.Name, type.Name);
                    var eventSourceLogger = new EventSourceLoggerTemplate()
                    {
                        Name      = type.Name,
                        Namespace = type.Namespace,
                        Include   = include
                    };
                    var eventSourceEvents = new List <EventModel>();
                    foreach (var methodInfo in type.GetMethods())
                    {
                        var eventSourceEventArguments = new List <EventSourceEventArgument>();
                        var eventSourceEvent          = new EventSourceEvent()
                        {
                            Name = methodInfo.Name,
                        };
                        foreach (var parameterInfo in methodInfo.GetParameters())
                        {
                            var typeString = parameterInfo.ParameterType.GetFriendlyName();
                            eventSourceEventArguments.Add(new EventSourceEventArgument()
                            {
                                Name = parameterInfo.Name,
                                Type = typeString,
                            });
                        }
                        eventSourceEvent.Arguments = eventSourceEventArguments.ToArray();
                        eventSourceEvents.Add(eventSourceEvent);
                    }

                    eventSourceLogger.Events = eventSourceEvents.ToArray();
                    loggers.Add(eventSourceLogger);
                }
            }
            catch (Exception ex)
            {
                LogMessage($"Failed to compile/evaluate {projectItem.Include} - {ex.Message}\r\n{ex.StackTrace}");
            }
            return(loggers.ToArray());
        }
Пример #5
0
 private static string FormatMessage(EventSourceEvent eventSourceEvent, Exception exception)
 {
     return(EventSourceEventFormatting.Format(eventSourceEvent.EventData));
 }
 public override Task ProcessEvent(EventSourceEvent @event, CancellationToken cancellationToken = default)
     => Task.CompletedTask;
 /// <summary>
 /// Processes the <see cref="EventSourceEvent" />
 /// </summary>
 /// <param name="event">The <see cref="EventSourceEvent" /> to process</param>
 /// <param name="cancellationToken">Any <see cref="CancellationToken" /> used to marshall the operation</param>
 public abstract Task ProcessEvent(EventSourceEvent @event, CancellationToken cancellationToken);
 public Task EventReceived(EventSourceEvent evt, CancellationToken cancellationToken = default)
 {
     _outcome(evt);
     return(Task.CompletedTask);
 }