Пример #1
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="ev" /> to all users who are configured to receive event
        /// notifications in the gallery identified by <see cref="IEvent.GalleryId" />. If the event is not associated with a particular
        /// gallery (that is, <see cref="IEvent.GalleryId" /> is the ID of the template gallery, then e-mails are sent to users in all
        /// galleries who are configured to receive e-mailed event reports. The property <see cref="IGallerySettings.UsersToNotifyWhenErrorOccurs" />
        /// defines this list of users.
        /// </summary>
        /// <param name="ev">The application event to be sent to users.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="gallerySettingsCollection">The settings for all galleries. If the <paramref name="ev" /> is associated with
        /// a particular gallery, then only the settings for that gallery are used by this function; otherwise users in all galleries are
        /// notified.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ev" />, <paramref name="appSettings" /> or
        /// <paramref name="gallerySettingsCollection" /> is null.</exception>
        private static void SendEmail(IEvent ev, IAppSetting appSettings, IGallerySettingsCollection gallerySettingsCollection)
        {
            #region Validation

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

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

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

            // We only want to send en email for INFO events.
            if (ev.EventType == EventType.Info || ev.EventType == EventType.Warning)
            {
                return;
            }

            #endregion

            if (gallerySettingsCollection.FindByGalleryId(ev.GalleryId).IsTemplate)
            {
                // This is an application-wide event, so loop through every gallery and notify all users, making sure we don't notify anyone more than once.
                var notifiedUsers = new List <string>();

                foreach (var gallerySettings in gallerySettingsCollection)
                {
                    notifiedUsers.AddRange(SendMail(ev, appSettings, gallerySettings, notifiedUsers));
                }
            }
            else
            {
                // Use settings from the gallery associated with the event.
                var gallerySettings = gallerySettingsCollection.FindByGalleryId(ev.GalleryId);

                if (gallerySettings != null)
                {
                    SendMail(ev, appSettings, gallerySettingsCollection.FindByGalleryId(ev.GalleryId), null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="appError" /> to all users who are configured to receive error
        /// notifications in the gallery identified by <see cref="IAppError.GalleryId" />. If the error is not associated with a particular
        /// gallery (that is, <see cref="IAppError.GalleryId" /> == <see cref="Int32.MinValue" />, then e-mails are sent to users in all
        /// galleries who are configured to receive e-mailed error reports. The property <see cref="IGallerySettings.UsersToNotifyWhenErrorOccurs" />
        /// defines this list of users.
        /// </summary>
        /// <param name="appError">The application error to be sent to users.</param>
        /// <param name="gallerySettingsCollection">The settings for all galleries. If the <paramref name="appError" /> is associated with
        /// a particular gallery, then only the settings for that gallery are used by this function; otherwise users in all galleries are
        /// notified.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="appError" /> or <paramref name="gallerySettingsCollection" />
        /// is null.</exception>
        private static void SendEmail(IAppError appError, IGallerySettingsCollection gallerySettingsCollection)
        {
            #region Validation

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

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

            // HACK: We don't want to send en email for INFO events. Until this logging API can be properly refactored to handle non-error
            // types, we just check the message here and skip the email if necessary.
            if (appError.Message.StartsWith("INFO (not an error):", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            #endregion

            if (appError.GalleryId > int.MinValue)
            {
                // Use settings from the gallery associated with the error.
                IGallerySettings gallerySettings = gallerySettingsCollection.FindByGalleryId(appError.GalleryId);

                if (gallerySettings != null)
                {
                    SendMail(appError, gallerySettingsCollection.FindByGalleryId(appError.GalleryId), null);
                }
            }
            else
            {
                // This is an application-wide error, so loop through every gallery and notify all users, making sure we don't notify anyone more than once.
                List <String> notifiedUsers = new List <string>();

                foreach (IGallerySettings gallerySettings in gallerySettingsCollection)
                {
                    notifiedUsers.AddRange(SendMail(appError, gallerySettings, notifiedUsers));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="appError" /> to all users who are configured to receive error
        /// notifications in the gallery identified by <see cref="IAppError.GalleryId" />. If the error is not associated with a particular
        /// gallery (that is, <see cref="IAppError.GalleryId" /> == <see cref="Int32.MinValue" />, then e-mails are sent to users in all
        /// galleries who are configured to receive e-mailed error reports. The property <see cref="IGallerySettings.UsersToNotifyWhenErrorOccurs" />
        /// defines this list of users.
        /// </summary>
        /// <param name="appError">The application error to be sent to users.</param>
        /// <param name="gallerySettingsCollection">The settings for all galleries. If the <paramref name="appError" /> is associated with
        /// a particular gallery, then only the settings for that gallery are used by this function; otherwise users in all galleries are
        /// notified.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="appError" /> or <paramref name="gallerySettingsCollection" />
        /// is null.</exception>
        private static void SendEmail(IAppError appError, IGallerySettingsCollection gallerySettingsCollection)
        {
            #region Validation

            if (appError == null)
                throw new ArgumentNullException("appError");

            if (gallerySettingsCollection == null)
                throw new ArgumentNullException("gallerySettingsCollection");

            // HACK: We don't want to send en email for INFO events. Until this logging API can be properly refactored to handle non-error
            // types, we just check the message here and skip the email if necessary.
            if (appError.Message.StartsWith("INFO (not an error):", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            #endregion

            if (appError.GalleryId > int.MinValue)
            {
                // Use settings from the gallery associated with the error.
                IGallerySettings gallerySettings = gallerySettingsCollection.FindByGalleryId(appError.GalleryId);

                if (gallerySettings != null)
                {
                    SendMail(appError, gallerySettingsCollection.FindByGalleryId(appError.GalleryId), null);
                }
            }
            else
            {
                // This is an application-wide error, so loop through every gallery and notify all users, making sure we don't notify anyone more than once.
                List<String> notifiedUsers = new List<string>();

                foreach (IGallerySettings gallerySettings in gallerySettingsCollection)
                {
                    notifiedUsers.AddRange(SendMail(appError, gallerySettings, notifiedUsers));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="ev" /> to all users who are configured to receive event
        /// notifications in the gallery identified by <see cref="IEvent.GalleryId" />. If the event is not associated with a particular
        /// gallery (that is, <see cref="IEvent.GalleryId" /> is the ID of the template gallery, then e-mails are sent to users in all
        /// galleries who are configured to receive e-mailed event reports. The property <see cref="IGallerySettings.UsersToNotifyWhenErrorOccurs" />
        /// defines this list of users.
        /// </summary>
        /// <param name="ev">The application event to be sent to users.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="gallerySettingsCollection">The settings for all galleries. If the <paramref name="ev" /> is associated with
        /// a particular gallery, then only the settings for that gallery are used by this function; otherwise users in all galleries are
        /// notified.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ev" />, <paramref name="appSettings" /> or 
        /// <paramref name="gallerySettingsCollection" /> is null.</exception>
        private static void SendEmail(IEvent ev, IAppSetting appSettings, IGallerySettingsCollection gallerySettingsCollection)
        {
            #region Validation

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

            if (appSettings == null)
                throw new ArgumentNullException("appSettings");

            if (gallerySettingsCollection == null)
                throw new ArgumentNullException("gallerySettingsCollection");

            // We only want to send en email for INFO events.
            if (ev.EventType == EventType.Info || ev.EventType == EventType.Warning)
            {
                return;
            }

            #endregion

            if (gallerySettingsCollection.FindByGalleryId(ev.GalleryId).IsTemplate)
            {
                // This is an application-wide event, so loop through every gallery and notify all users, making sure we don't notify anyone more than once.
                var notifiedUsers = new List<string>();

                foreach (var gallerySettings in gallerySettingsCollection)
                {
                    notifiedUsers.AddRange(SendMail(ev, appSettings, gallerySettings, notifiedUsers));
                }
            }
            else
            {
                // Use settings from the gallery associated with the event.
                var gallerySettings = gallerySettingsCollection.FindByGalleryId(ev.GalleryId);

                if (gallerySettings != null)
                {
                    SendMail(ev, appSettings, gallerySettingsCollection.FindByGalleryId(ev.GalleryId), null);
                }
            }
        }