Esempio n. 1
0
        public void UserInfoProperty()
        {
            RaygunIdentifierMessage user = new RaygunIdentifierMessage("Robbie Robot");

            _client.UserInfo = user;
            Assert.AreSame(user, _client.UserInfo);
        }
Esempio n. 2
0
        public RaygunMessage BuildMessage(OwinEnvironment environment, Exception exception, IList <string> tags = null, IDictionary <string, object> userCustomData = null)
        {
            exception = StripWrapperExceptions(exception);

            RaygunIdentifierMessage userInfo = null;

            if (_settings.LoadUserDetails != null)
            {
                userInfo = _settings.LoadUserDetails(environment);
            }

            var mergedTags = _settings.Tags
                             .Union(tags ?? Enumerable.Empty <string>())
                             .ToList();

            var message = RaygunMessageBuilder.New
                          .SetHttpDetails(environment)
                          .SetEnvironmentDetails()
                          .SetMachineName(Environment.MachineName)
                          .SetExceptionDetails(exception)
                          .SetClientDetails()
                          .SetVersion(_settings.ApplicationVersion)
                          .SetTags(mergedTags)
                          .SetUserCustomData(userCustomData)
                          .SetUser(userInfo)
                          .Build();

            return(message);
        }
Esempio n. 3
0
        public void IsAnonymousDefault()
        {
            RaygunIdentifierMessage user = new RaygunIdentifierMessage("Robbie Robot");

            Assert.IsFalse(user.IsAnonymous);

            _client.User = "******";
            RaygunMessage message = _client.ExposeBuildMessage(_exception);

            Assert.IsFalse(message.Details.User.IsAnonymous);
        }
        public void Should_set_user_details()
        {
            // Given
            var userDetails = new RaygunIdentifierMessage("testUser");
            var sut         = SutFactory();

            // When
            var result = sut.SetUser(userDetails).Build();

            // Then
            result.Details.User.ShouldBe(userDetails);
        }
        public void WhenLoggingEventContainsAffectedUserInformationThenRaygunMessageIsBuiltWithRaygunIdentifier()
        {
            var loggingEventWithProperties = new LoggingEvent(new LoggingEventData {
                Properties = new PropertiesDictionary()
            });
            var affectedUserInfo = new RaygunIdentifierMessage("I am an affected user");

            loggingEventWithProperties.Properties[RaygunAppenderBase.PropertyKeys.AffectedUser] = affectedUserInfo;

            _appender.DoAppend(loggingEventWithProperties);

            Assert.That(_fakeRaygunClient.LastMessageSent.Details.User, Is.EqualTo(affectedUserInfo));
        }
Esempio n. 6
0
        public void MessageWithUserInfo()
        {
            RaygunIdentifierMessage user = new RaygunIdentifierMessage("Robbie Robot")
            {
                IsAnonymous = true
            };

            _client.UserInfo = user;

            RaygunMessage message = _client.ExposeBuildMessage(_exception);

            Assert.AreEqual("Robbie Robot", message.Details.User.Identifier);
            Assert.IsTrue(message.Details.User.IsAnonymous);
        }
Esempio n. 7
0
        public void UserInfoFromBuildTrumpsAll()
        {
            RaygunIdentifierMessage user = new RaygunIdentifierMessage("Not Robbie Robot")
            {
                IsAnonymous = true
            };

            _client.UserInfo = user;
            _client.User     = "******";

            RaygunMessage message = _client.ExposeBuildMessage(_exception, null, null, new RaygunIdentifierMessage("Robbie Robot"));

            Assert.AreEqual("Robbie Robot", message.Details.User.Identifier);
            Assert.IsFalse(message.Details.User.IsAnonymous);
        }
Esempio n. 8
0
        private static RaygunIdentifierMessage ParseUserInformation(string userInfo)
        {
            RaygunIdentifierMessage userIdentifier = null;

            // This is a parse of the ToString implementation of RaygunIdentifierMessage which uses the format:
            // [RaygunIdentifierMessage: Identifier=X, IsAnonymous=X, Email=X, FullName=X, FirstName=X, UUID=X]
            string[] properties = userInfo.Split(new[] { ',', ']' }, StringSplitOptions.RemoveEmptyEntries);
            if (properties.Length == 6)
            {
                string[] identifierSplit = properties[0].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                if (identifierSplit.Length == 2)
                {
                    userIdentifier = new RaygunIdentifierMessage(identifierSplit[1]);

                    string[] isAnonymousSplit = properties[1].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (isAnonymousSplit.Length == 2)
                    {
                        userIdentifier.IsAnonymous = "True".Equals(isAnonymousSplit[1]);
                    }

                    string[] emailSplit = properties[2].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (emailSplit.Length == 2)
                    {
                        userIdentifier.Email = emailSplit[1];
                    }

                    string[] fullNameSplit = properties[3].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (fullNameSplit.Length == 2)
                    {
                        userIdentifier.FullName = fullNameSplit[1];
                    }

                    string[] firstNameSplit = properties[4].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (firstNameSplit.Length == 2)
                    {
                        userIdentifier.FirstName = firstNameSplit[1];
                    }

                    string[] uuidSplit = properties[5].Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (uuidSplit.Length == 2)
                    {
                        userIdentifier.UUID = uuidSplit[1];
                    }
                }
            }

            return(userIdentifier);
        }
Esempio n. 9
0
        private RaygunIdentifierMessage GetRaygunIdentifierForClaimsPrincipal(OwinRequest request)
        {
            var result = new RaygunIdentifierMessage(null)
            {
                IsAnonymous = true
            };

            var principal = request.User as ClaimsPrincipal;

            if (principal != null && principal.Identity != null)
            {
                result.Identifier = principal.Identity.Name;

                if (principal.Identity.IsAuthenticated)
                {
                    result.IsAnonymous = false;
                }
            }

            return(result);
        }
Esempio n. 10
0
        private static RaygunIdentifierMessage BuildUserInformationFromStructureValue(StructureValue userStructure)
        {
            RaygunIdentifierMessage userIdentifier = new RaygunIdentifierMessage(null);

            foreach (var property in userStructure.Properties)
            {
                switch (property.Name)
                {
                case nameof(RaygunIdentifierMessage.Identifier):
                    userIdentifier.Identifier = property.AsString();
                    break;

                case nameof(RaygunIdentifierMessage.IsAnonymous):
                    userIdentifier.IsAnonymous = "True".Equals(property.Value.ToString());
                    break;

                case nameof(RaygunIdentifierMessage.Email):
                    userIdentifier.Email = property.AsString();
                    break;

                case nameof(RaygunIdentifierMessage.FullName):
                    userIdentifier.FullName = property.AsString();
                    break;

                case nameof(RaygunIdentifierMessage.FirstName):
                    userIdentifier.FirstName = property.AsString();
                    break;

                case nameof(RaygunIdentifierMessage.UUID):
                    userIdentifier.UUID = property.AsString();
                    break;
                }
            }

            return(userIdentifier);
        }
Esempio n. 11
0
        public RaygunMessage ExposeBuildMessage(Exception exception, [Optional] IList <string> tags, [Optional] IDictionary userCustomData, [Optional] RaygunIdentifierMessage user)
        {
            var task = BuildMessage(exception, tags, userCustomData, user);

            task.Wait();

            return(task.Result);
        }
Esempio n. 12
0
        protected override async Task <RaygunMessage> BuildMessage(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfoMessage)
        {
            var message = RaygunMessageBuilder.New(GetSettings())
                          .SetResponseDetails(_currentResponseMessage.Value)
                          .SetRequestDetails(_currentRequestMessage.Value)
                          .SetEnvironmentDetails()
                          .SetMachineName(Environment.MachineName)
                          .SetExceptionDetails(exception)
                          .SetClientDetails()
                          .SetVersion(ApplicationVersion)
                          .SetTags(tags)
                          .SetUserCustomData(userCustomData)
                          .SetUser(userInfoMessage ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null))
                          .Build();

            var customGroupingKey = await OnCustomGroupingKey(exception, message);

            if (string.IsNullOrEmpty(customGroupingKey) == false)
            {
                message.Details.GroupingKey = customGroupingKey;
            }

            return(message);
        }
Esempio n. 13
0
        /// <summary>
        /// Asynchronously transmits an exception to Raygun.
        /// </summary>
        /// <param name="exception">The exception to deliver.</param>
        /// <param name="tags">A list of strings associated with the message.</param>
        /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param>
        /// <param name="userInfo">Information about the user including the identity string.</param>
        public override async Task SendInBackground(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo)
        {
            if (CanSend(exception))
            {
                // We need to process the Request on the current thread,
                // otherwise it will be disposed while we are using it on the other thread.
                RaygunRequestMessage currentRequestMessage = await BuildRequestMessage();

                RaygunResponseMessage currentResponseMessage = BuildResponseMessage();

                var task = Task.Run(async() =>
                {
                    _currentRequestMessage.Value  = currentRequestMessage;
                    _currentResponseMessage.Value = currentResponseMessage;
                    await StripAndSend(exception, tags, userCustomData, userInfo);
                });
                FlagAsSent(exception);
                await task;
            }
        }
Esempio n. 14
0
 public RaygunMessage ExposeBuildMessage(Exception exception, [Optional] IList <string> tags, [Optional] IDictionary userCustomData, [Optional] RaygunIdentifierMessage userIdentifierMessage)
 {
     return(BuildMessage(exception, tags, userCustomData, userIdentifierMessage));
 }
Esempio n. 15
0
 public IRaygunMessageBuilder SetUser(RaygunIdentifierMessage user)
 {
     _raygunMessage.Details.User = user;
     return(this);
 }
Esempio n. 16
0
 public IRaygunMessageBuilder SetUser(RaygunIdentifierMessage user)
 {
     throw new NotImplementedException();
 }