/// <summary>
        /// Send information about a request handled by the application.
        /// </summary>
        /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
        /// <param name="name">The request name.</param>
        /// <param name="token">The token with user identifiable information.</param>
        /// <param name="startTime">The time when the page was requested.</param>
        /// <param name="duration">The time taken by the application to handle the request.</param>
        /// <param name="responseCode">The response status code.</param>
        /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
        /// <param name="properties">Named string values you can use to search and classify events.</param>
        public static void TrackRequest(this ITelemetryHelper telemetryHelper, string name, string token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary <string, string> properties = null)
        {
            Uri url;

            try
            {
                url = new Uri(string.Format("cqrs://{0}", name));
            }
            catch
            {
                url = null;
            }

            string sessionId;

            try
            {
                sessionId = string.Format("{0}::{1}", properties["CorrelationId"], token);
            }
            catch
            {
                sessionId = null;
            }

            telemetryHelper.TrackRequest(name, url, token, startTime, duration, responseCode, wasSuccessfull, properties, sessionId);
        }
 public PublishTimeZonesCommandHandler(ILogger logger, ITelemetryHelper telemetryHelper, IConfigurationManager configurationManager, IEventPublisher <Guid> eventPublisher)
 {
     Logger               = logger;
     TelemetryHelper      = telemetryHelper;
     ConfigurationManager = configurationManager;
     EventPublisher       = eventPublisher;
 }
Esempio n. 3
0
 /// <summary>
 /// Instantiates a new instance of <see cref="AzureServiceBus{TAuthenticationToken}"/>
 /// </summary>
 protected AzureServiceBus(IConfigurationManager configurationManager, IMessageSerialiser <TAuthenticationToken> messageSerialiser, IAuthenticationTokenHelper <TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, ILogger logger, IAzureBusHelper <TAuthenticationToken> azureBusHelper, IBusHelper busHelper, bool isAPublisher)
     : base(configurationManager, messageSerialiser, authenticationTokenHelper, correlationIdHelper, logger, isAPublisher)
 {
     AzureBusHelper             = azureBusHelper;
     BusHelper                  = busHelper;
     TelemetryHelper            = new NullTelemetryHelper();
     PrivateServiceBusReceivers = new Dictionary <int, SubscriptionClient>();
     PublicServiceBusReceivers  = new Dictionary <int, SubscriptionClient>();
 }
Esempio n. 4
0
 public InProcessBus(IAuthenticationTokenHelper <TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, IDependencyResolver dependencyResolver, ILogger logger, IConfigurationManager configurationManager, IBusHelper busHelper)
 {
     AuthenticationTokenHelper = authenticationTokenHelper;
     CorrelationIdHelper       = correlationIdHelper;
     DependencyResolver        = dependencyResolver;
     Logger = logger;
     ConfigurationManager = configurationManager;
     BusHelper            = busHelper;
     EventWaits           = new ConcurrentDictionary <Guid, IList <IEvent <TAuthenticationToken> > >();
     TelemetryHelper      = configurationManager.CreateTelemetryHelper("Cqrs.InProcessBus.UseApplicationInsightTelemetryHelper", correlationIdHelper);
 }
Esempio n. 5
0
        /// <summary>
        /// Register an event handler that will listen and respond to all events.
        /// </summary>
        public void RegisterGlobalEventHandler <TMessage>(ITelemetryHelper telemetryHelper, RouteManager routeManger, Action <TMessage> handler,
                                                          bool holdMessageLock = true) where TMessage : IMessage
        {
            Action <TMessage> registerableHandler = BusHelper.BuildActionHandler(handler, holdMessageLock);

            routeManger.RegisterGlobalEventHandler(registerableHandler);

            telemetryHelper.TrackEvent(string.Format("Cqrs/RegisterGlobalEventHandler/{0}", typeof(TMessage).FullName), new Dictionary <string, string> {
                { "Type", "Azure/Bus" }
            });
            telemetryHelper.Flush();
        }
Esempio n. 6
0
        public virtual void RegisterHandler <TMessage>(ITelemetryHelper telemetryHelper, RouteManager routeManger, Action <TMessage> handler, Type targetedType, bool holdMessageLock = true)
            where TMessage : IMessage
        {
            Action <TMessage> registerableHandler = BusHelper.BuildTelemeteredActionHandler <TMessage, TAuthenticationToken>(telemetryHelper, handler, holdMessageLock, "Azure/Bus");

            routeManger.RegisterHandler(registerableHandler, targetedType);

            telemetryHelper.TrackEvent(string.Format("Cqrs/RegisterHandler/{0}", typeof(TMessage).FullName), new Dictionary <string, string> {
                { "Type", "Azure/Bus" }
            });
            telemetryHelper.Flush();
        }
Esempio n. 7
0
        /// <summary>
        /// Send information about a request handled by the application.
        /// </summary>
        /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
        /// <param name="name">The request name.</param>
        /// <param name="token">The token with user identifiable information.</param>
        /// <param name="startTime">The time when the page was requested.</param>
        /// <param name="duration">The time taken by the application to handle the request.</param>
        /// <param name="responseCode">The response status code.</param>
        /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
        /// <param name="properties">Named string values you can use to search and classify events.</param>
        public static void TrackRequest <TAuthenticationToken>(this ITelemetryHelper telemetryHelper, string name, TAuthenticationToken token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary <string, string> properties = null)
            where TAuthenticationToken : ISingleSignOnToken
        {
            Uri url;

            try
            {
                url = new Uri(string.Format("cqrs://{0}", name));
            }
            catch
            {
                url = null;
            }

            telemetryHelper.TrackRequest(name, url, token == null ? null : token.Serialise(), startTime, duration, responseCode, wasSuccessfull, properties);
        }
Esempio n. 8
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="StringLogger"/> class.
 /// </summary>
 protected VeryPrimitiveLogger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper)
 {
     LoggerSettings      = loggerSettings;
     CorrelationIdHelper = correlationIdHelper;
     TelemetryHelper     = telemetryHelper;
     if (TelemetryHelper == null)
     {
         if (loggerSettings.UseApplicationInsightTelemetryHelper)
         {
             TelemetryHelper = (ITelemetryHelper)Activator.CreateInstanceFrom("cdmdotnet.Logging.Azure.ApplicationInsights.dll", "cdmdotnet.Logging.Azure.ApplicationInsights.TelemetryHelper").Unwrap();
         }
         else
         {
             TelemetryHelper = new NullTelemetryHelper();
         }
     }
     ExclusionNamespaces = new SynchronizedCollection <string> {
         "cdmdotnet.Logging"
     };
     InprogressThreads = new SynchronizedCollection <Guid>();
 }
Esempio n. 9
0
        /// <summary>
        /// Build a message handler that implements telemetry capturing as well as off thread handling.
        /// </summary>
        public virtual Action <TMessage> BuildTelemeteredActionHandler <TMessage, TAuthenticationToken>(ITelemetryHelper telemetryHelper, Action <TMessage> handler, bool holdMessageLock, string source)
            where TMessage : IMessage
        {
            Action <TMessage> registerableMessageHandler = message =>
            {
                DateTimeOffset startedAt      = DateTimeOffset.UtcNow;
                Stopwatch      mainStopWatch  = Stopwatch.StartNew();
                string         responseCode   = "200";
                bool           wasSuccessfull = true;

                string telemetryName       = message.GetType().FullName;
                var    telemeteredMessage  = message as ITelemeteredMessage;
                string messagePrefix       = null;
                object authenticationToken = null;
                var    @event = message as IEvent <TAuthenticationToken>;
                if (@event != null)
                {
                    messagePrefix       = "Event/";
                    telemetryName       = string.Format("{0}/{1}/{2}", telemetryName, @event.GetIdentity(), @event.Id);
                    authenticationToken = @event.AuthenticationToken;
                }
                else
                {
                    var command = message as ICommand <TAuthenticationToken>;
                    if (command != null)
                    {
                        messagePrefix       = "Command/";
                        telemetryName       = string.Format("{0}/{1}/{2}", telemetryName, command.GetIdentity(), command.Id);
                        authenticationToken = command.AuthenticationToken;
                    }
                }

                if (telemeteredMessage != null)
                {
                    telemetryName = telemeteredMessage.TelemetryName;
                }

                telemetryHelper.TrackEvent(string.Format("Cqrs/Handle/{0}{1}/Started", messagePrefix, telemetryName));

                try
                {
                    handler(message);
                }
                catch (Exception exception)
                {
                    telemetryHelper.TrackException(exception);
                    wasSuccessfull = false;
                    responseCode   = "500";
                    throw;
                }
                finally
                {
                    telemetryHelper.TrackEvent(string.Format("Cqrs/Handle/{0}{1}/Finished", messagePrefix, telemetryName));

                    mainStopWatch.Stop();
                    if (authenticationToken is ISingleSignOnToken)
                    {
                        telemetryHelper.TrackRequest
                        (
                            string.Format("Cqrs/Handle/{0}{1}", messagePrefix, telemetryName),
                            (ISingleSignOnToken)authenticationToken,
                            startedAt,
                            mainStopWatch.Elapsed,
                            responseCode,
                            wasSuccessfull,
                            new Dictionary <string, string> {
                            { "Type", source }
                        }
                        );
                    }
                    else if (authenticationToken is Guid)
                    {
                        telemetryHelper.TrackRequest
                        (
                            string.Format("Cqrs/Handle/{0}{1}", messagePrefix, telemetryName),
                            (Guid?)authenticationToken,
                            startedAt,
                            mainStopWatch.Elapsed,
                            responseCode,
                            wasSuccessfull,
                            new Dictionary <string, string> {
                            { "Type", source }
                        }
                        );
                    }
                    else if (authenticationToken is int)
                    {
                        telemetryHelper.TrackRequest
                        (
                            string.Format("Cqrs/Handle/{0}{1}", messagePrefix, telemetryName),
                            (int?)authenticationToken,
                            startedAt,
                            mainStopWatch.Elapsed,
                            responseCode,
                            wasSuccessfull,
                            new Dictionary <string, string> {
                            { "Type", source }
                        }
                        );
                    }
                    else
                    {
                        string token = authenticationToken == null ? null : authenticationToken.ToString();
                        telemetryHelper.TrackRequest
                        (
                            string.Format("Cqrs/Handle/{0}{1}", messagePrefix, telemetryName),
                            token,
                            startedAt,
                            mainStopWatch.Elapsed,
                            responseCode,
                            wasSuccessfull,
                            new Dictionary <string, string> {
                            { "Type", source }
                        }
                        );
                    }

                    telemetryHelper.Flush();
                }
            };

            return(BuildActionHandler(registerableMessageHandler, holdMessageLock));
        }
 /// <summary>
 /// Send information about a request handled by the application.
 /// </summary>
 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
 /// <param name="name">The request name.</param>
 /// <param name="token">The token with user identifiable information.</param>
 /// <param name="startTime">The time when the page was requested.</param>
 /// <param name="duration">The time taken by the application to handle the request.</param>
 /// <param name="responseCode">The response status code.</param>
 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
 /// <param name="properties">Named string values you can use to search and classify events.</param>
 public static void TrackRequest(this ITelemetryHelper telemetryHelper, string name, int?token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary <string, string> properties = null)
 {
     TrackRequest(telemetryHelper, name, token == null ? null : token.Value.ToString(), startTime, duration, responseCode, wasSuccessfull, properties);
 }
Esempio n. 11
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="DatabaseLogger"/> class calling the constructor on <see cref="DatabaseLogger"/>.
 /// </summary>
 public SqlLogger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper = null)
     : base(loggerSettings, correlationIdHelper, telemetryHelper)
 {
 }
Esempio n. 12
0
 public AzureEventBusReceiver(IConfigurationManager configurationManager, IMessageSerialiser <TAuthenticationToken> messageSerialiser, IAuthenticationTokenHelper <TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, ILogger logger, IAzureBusHelper <TAuthenticationToken> azureBusHelper)
     : base(configurationManager, messageSerialiser, authenticationTokenHelper, correlationIdHelper, logger, azureBusHelper, false)
 {
     TelemetryHelper = configurationManager.CreateTelemetryHelper("Cqrs.Azure.EventHub.EventBus.Receiver.UseApplicationInsightTelemetryHelper", correlationIdHelper);
 }
Esempio n. 13
0
 /// <summary>
 /// Instantiates a new instance of <see cref="Repository{TQueryStrategy,TQueryBuilder,TData}"/>
 /// </summary>
 protected Repository(Func <IDataStore <TData> > createDataStoreFunction, TQueryBuilder queryBuilder)
 {
     CreateDataStoreFunction = createDataStoreFunction;
     QueryBuilder            = queryBuilder;
     TelemetryHelper         = new NullTelemetryHelper();
 }
Esempio n. 14
0
        /// <summary>
        /// Build a message handler that implements telemetry capturing as well as off thread handling.
        /// </summary>
        public virtual Action <TMessage> BuildTelemeteredActionHandler <TMessage, TAuthenticationToken>(ITelemetryHelper telemetryHelper, Action <TMessage> handler, bool holdMessageLock, string source)
            where TMessage : IMessage
        {
            Action <TMessage> registerableMessageHandler = message =>
            {
                DateTimeOffset startedAt      = DateTimeOffset.UtcNow;
                Stopwatch      mainStopWatch  = Stopwatch.StartNew();
                string         responseCode   = "200";
                bool           wasSuccessfull = true;

                string telemetryName      = message.GetType().FullName;
                var    telemeteredMessage = message as ITelemeteredMessage;
                string messagePrefix      = null;
                var    @event             = message as IEvent <TAuthenticationToken>;
                if (@event != null)
                {
                    messagePrefix = "Event/";
                    telemetryName = string.Format("{0}/{1}", telemetryName, @event.Id);
                }
                else
                {
                    var command = message as ICommand <TAuthenticationToken>;
                    if (command != null)
                    {
                        messagePrefix = "Command/";
                        telemetryName = string.Format("{0}/{1}", telemetryName, command.Id);
                    }
                }

                if (telemeteredMessage != null)
                {
                    telemetryName = telemeteredMessage.TelemetryName;
                }

                telemetryHelper.TrackEvent(string.Format("Cqrs/Handle/{0}{1}/Started", messagePrefix, telemetryName));

                try
                {
                    handler(message);
                }
                catch (Exception exception)
                {
                    telemetryHelper.TrackException(exception);
                    wasSuccessfull = false;
                    responseCode   = "500";
                    throw;
                }
                finally
                {
                    telemetryHelper.TrackEvent(string.Format("Cqrs/Handle/{0}{1}/Finished", messagePrefix, telemetryName));

                    mainStopWatch.Stop();
                    telemetryHelper.TrackRequest
                    (
                        string.Format("Cqrs/Handle/{0}{1}", messagePrefix, telemetryName),
                        startedAt,
                        mainStopWatch.Elapsed,
                        responseCode,
                        wasSuccessfull,
                        new Dictionary <string, string> {
                        { "Type", source }
                    }
                    );

                    telemetryHelper.Flush();
                }
            };

            Action <TMessage> registerableHandler = registerableMessageHandler;

            if (!holdMessageLock)
            {
                registerableHandler = message =>
                {
                    Task.Factory.StartNewSafely(() =>
                    {
                        registerableMessageHandler(message);
                    });
                };
            }

            return(registerableHandler);
        }
Esempio n. 15
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="Logger"/> class preparing the required thread pool polling if <see cref="ILoggerSettings.EnableThreadedLogging"/> is set to true.
 /// </summary>
 protected Logger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper)
     : base(loggerSettings, correlationIdHelper, telemetryHelper)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Instantiates a new instance of <see cref="AzureEventHub{TAuthenticationToken}"/>
 /// </summary>
 protected AzureEventHub(IConfigurationManager configurationManager, IMessageSerialiser <TAuthenticationToken> messageSerialiser, IAuthenticationTokenHelper <TAuthenticationToken> authenticationTokenHelper, ICorrelationIdHelper correlationIdHelper, ILogger logger, bool isAPublisher)
     : base(configurationManager, messageSerialiser, authenticationTokenHelper, correlationIdHelper, logger, isAPublisher)
 {
     TelemetryHelper = new NullTelemetryHelper();
 }
 /// <summary>
 /// Send information about a request handled by the application.
 /// </summary>
 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
 /// <param name="name">The request name.</param>
 /// <param name="token">The token with user identifiable information.</param>
 /// <param name="startTime">The time when the page was requested.</param>
 /// <param name="duration">The time taken by the application to handle the request.</param>
 /// <param name="responseCode">The response status code.</param>
 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
 /// <param name="properties">Named string values you can use to search and classify events.</param>
 public static void TrackRequest <TAuthenticationToken>(this ITelemetryHelper telemetryHelper, string name, TAuthenticationToken token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary <string, string> properties = null)
     where TAuthenticationToken : ISingleSignOnToken
 {
     TrackRequest(telemetryHelper, name, token == null ? null : token.Serialise(), startTime, duration, responseCode, wasSuccessfull, properties);
 }