/// <summary>
        /// Submits the event to be sent to the server.
        /// </summary>
        /// <param name="ev">The event data.</param>
        /// <param name="enrichmentContextData">
        /// Any contextual data objects to be used by Exceptionless enrichments to gather default
        /// information for inclusion in the report information.
        /// </param>
        public void SubmitEvent(Event ev, ContextData enrichmentContextData = null)
        {
            if (!Configuration.Enabled)
            {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The error will not be submitted.");
                return;
            }

            if (ev == null)
            {
                throw new ArgumentNullException("ev");
            }

            Configuration.LockConfig();
            if (!Configuration.Validate().IsValid)
            {
                Configuration.Enabled = false;
                _log.Value.FormattedError(typeof(ExceptionlessClient), "Disabling client due to invalid configuration: {0}", String.Join(", ", Configuration.Validate().Messages));
                return;
            }

            var context = new EventEnrichmentContext(this, enrichmentContextData);

            EventEnrichmentManager.Enrich(context, ev);

            if (_duplicateChecker.Value.IsDuplicate(ev))
            {
                return;
            }

            // ensure all required data
            if (String.IsNullOrEmpty(ev.Type))
            {
                ev.Type = Event.KnownTypes.Log;
            }
            if (ev.Date == DateTimeOffset.MinValue)
            {
                ev.Date = DateTimeOffset.Now;
            }

            if (!OnSubmittingEvent(ev, enrichmentContextData))
            {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event handler: id={0} type={1}", ev.ReferenceId, ev.Type);
                return;
            }

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Submitting event: type={0}{1}", ev.Type, !String.IsNullOrEmpty(ev.ReferenceId) ? " refid=" + ev.ReferenceId : String.Empty);
            _queue.Value.Enqueue(ev);

            if (String.IsNullOrEmpty(ev.ReferenceId))
            {
                return;
            }

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Setting last reference id '{0}'", ev.ReferenceId);
            _lastReferenceIdManager.Value.SetLast(ev.ReferenceId);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the user's email address and description of an event for the specified reference id.
        /// </summary>
        /// <param name="referenceId">The reference id of the event to update.</param>
        /// <param name="email">The user's email address to set on the event.</param>
        /// <param name="description">The user's description of the event.</param>
        /// <returns></returns>
        public bool UpdateUserEmailAndDescription(string referenceId, string email, string description)
        {
            if (String.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException("referenceId");
            }

            if (String.IsNullOrEmpty(email) && String.IsNullOrEmpty(description))
            {
                return(true);
            }

            if (!Configuration.Enabled)
            {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The event will not be updated with the user email and description.");
                return(false);
            }

            if (!Configuration.IsLocked)
            {
                Configuration.LockConfig();
                if (!Configuration.Validate().IsValid)
                {
                    _log.Value.FormattedError(typeof(ExceptionlessClient), "Disabling client due to invalid configuration: {0}", String.Join(", ", Configuration.Validate().Messages));
                    return(false);
                }
            }

            try {
                var response = _submissionClient.Value.PostUserDescription(referenceId, new UserDescription(email, description), Configuration, Configuration.Resolver.GetJsonSerializer());
                if (!response.Success)
                {
                    _log.Value.FormattedError(typeof(ExceptionlessClient), "Failed to submit user email and description for event: {0} {1}", response.StatusCode, response.Message);
                }

                return(response.Success);
            } catch (Exception ex) {
                _log.Value.FormattedError(typeof(ExceptionlessClient), ex, "An error occurred while updating the user email and description for event: {0}.", referenceId);
                return(false);
            }
        }