コード例 #1
0
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and optionally notify
        /// zero or more users via e-mail. The users to be notified are specified in the <see cref="IGallerySettings.UsersToNotifyWhenErrorOccurs"/>
        /// property of the gallery settings object associated with <paramref name="galleryId" />.
        /// </summary>
        /// <param name="ex">The exception to record.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify <see cref="Int32.MinValue"/>.</param>
        /// <returns>
        /// Returns an integer that uniquely identifies this application error (<see cref="IAppError.AppErrorId"/>).
        /// </returns>
        public static int LogError(Exception ex, int galleryId)
        {
            IGallerySettingsCollection gallerySettings = Factory.LoadGallerySettings();

            int errorId = Error.Record(ex, galleryId, gallerySettings, AppSetting.Instance);

            HelperFunctions.PurgeCache();

            return(errorId);
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
ファイル: Error.cs プロジェクト: zbw911/GalleryServerProWeb
        /// <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
ファイル: Error.cs プロジェクト: zbw911/GalleryServerProWeb
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
        /// the ID that is assigned to it. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="ex">The exception to be recorded to the data store.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify <see cref="Int32.MinValue"/>.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known. This value must be specified for e-mail notification to occur.</param>
        /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
        /// <returns>
        /// Returns an integer that uniquely identifies this application error (<see cref="IAppError.AppErrorId"/>).
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
        public static int Record(Exception ex, int galleryId, IGallerySettingsCollection gallerySettingsCollection, IAppSetting appSettings)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            IAppError appError = new AppError(ex, galleryId);

            int appErrorId = DataProviderManager.Provider.AppError_Save(appError);

            if (gallerySettingsCollection != null)
            {
                SendEmail(appError, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return(appErrorId);
        }
コード例 #5
0
        /// <summary>
        /// Persist information about the specified <paramref name="msg" /> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="msg">The message to be recorded to the data store.</param>
        /// <param name="eventType">Type of the event. Defaults to <see cref="EventType.Info" /> if not specified.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="msg" /> is associated with.
        /// If the message is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
        /// <param name="data">Additional optional data to record. May be null.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">galleryId</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="galleryId" /> is <see cref="Int32.MinValue" />.</exception>
        public static IEvent RecordEvent(string msg, EventType eventType = EventType.Info, int?galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null, IAppSetting appSettings = null, Dictionary <string, string> data = null)
        {
            if (galleryId == Int32.MinValue)
            {
                throw new ArgumentOutOfRangeException("galleryId", String.Format("The galleryId parameter must represent an existing gallery. Instead, it was {0}", galleryId));
            }

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(msg, galleryId.Value, eventType, data);

            Save(ev);

            if (appSettings != null && gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return(ev);
        }
コード例 #6
0
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="ex">The exception to be recorded to the data store.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
        public static IEvent RecordError(Exception ex, IAppSetting appSettings, int?galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null)
        {
            if (ex == null)
            {
                throw new ArgumentNullException("ex");
            }

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(ex, galleryId.Value);

            Save(ev);

            if (gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return(ev);
        }
コード例 #7
0
ファイル: Error.cs プロジェクト: raquelsa/GalleryServerProWeb
 /// <summary>
 /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
 /// the ID that is assigned to it.
 /// </summary>
 /// <param name="ex">The exception to be recorded to the data store.</param>
 /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
 /// null if the value is not known. This value must be specified for e-mail notification to occur.</param>
 /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
 /// <returns>
 /// Returns an integer that uniquely identifies this application error (<see cref="IAppError.AppErrorId"/>).
 /// </returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
 public static int Record(Exception ex, IGallerySettingsCollection gallerySettingsCollection, IAppSetting appSettings)
 {
     return Record(ex, int.MinValue, gallerySettingsCollection, appSettings);
 }
コード例 #8
0
ファイル: Error.cs プロジェクト: raquelsa/GalleryServerProWeb
        /// <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));
                }
            }
        }
コード例 #9
0
ファイル: Error.cs プロジェクト: raquelsa/GalleryServerProWeb
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
        /// the ID that is assigned to it. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="ex">The exception to be recorded to the data store.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify <see cref="Int32.MinValue"/>.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known. This value must be specified for e-mail notification to occur.</param>
        /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
        /// <returns>
        /// Returns an integer that uniquely identifies this application error (<see cref="IAppError.AppErrorId"/>).
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
        public static int Record(Exception ex, int galleryId, IGallerySettingsCollection gallerySettingsCollection, IAppSetting appSettings)
        {
            if (ex == null)
                throw new ArgumentNullException("ex");

            IAppError appError = new AppError(ex, galleryId);

            int appErrorId = DataProviderManager.Provider.AppError_Save(appError);

            if (gallerySettingsCollection != null)
            {
                SendEmail(appError, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return appErrorId;
        }
コード例 #10
0
ファイル: Error.cs プロジェクト: zbw911/GalleryServerProWeb
 /// <summary>
 /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
 /// the ID that is assigned to it.
 /// </summary>
 /// <param name="ex">The exception to be recorded to the data store.</param>
 /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
 /// null if the value is not known. This value must be specified for e-mail notification to occur.</param>
 /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
 /// <returns>
 /// Returns an integer that uniquely identifies this application error (<see cref="IAppError.AppErrorId"/>).
 /// </returns>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
 public static int Record(Exception ex, IGallerySettingsCollection gallerySettingsCollection, IAppSetting appSettings)
 {
     return(Record(ex, int.MinValue, gallerySettingsCollection, appSettings));
 }
コード例 #11
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);
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Persist information about the specified <paramref name="msg" /> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="msg">The message to be recorded to the data store.</param>
        /// <param name="eventType">Type of the event. Defaults to <see cref="EventType.Info" /> if not specified.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="msg" /> is associated with.
        /// If the message is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <param name="appSettings">The application settings. You may specify null if the value is not known.</param>
        /// <param name="data">Additional optional data to record. May be null.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">galleryId</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="galleryId" /> is <see cref="Int32.MinValue" />.</exception>
        public static IEvent RecordEvent(string msg, EventType eventType = EventType.Info, int? galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null, IAppSetting appSettings = null, Dictionary<string, string> data = null)
        {
            if (galleryId == Int32.MinValue)
                throw new ArgumentOutOfRangeException("galleryId", String.Format("The galleryId parameter must represent an existing gallery. Instead, it was {0}", galleryId));

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(msg, galleryId.Value, eventType, data);

            Save(ev);

            if (appSettings != null && gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return ev;
        }
コード例 #13
0
        /// <summary>
        /// Persist information about the specified <paramref name="ex">exception</paramref> to the data store and return
        /// the instance. Send an e-mail notification if that option is enabled.
        /// </summary>
        /// <param name="ex">The exception to be recorded to the data store.</param>
        /// <param name="appSettings">The application settings containing the e-mail configuration data.</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="ex">exception</paramref> is associated with.
        /// If the exception is not specific to a particular gallery, specify null.</param>
        /// <param name="gallerySettingsCollection">The collection of gallery settings for all galleries. You may specify
        /// null if the value is not known; however, this value must be specified for e-mail notification to occur.</param>
        /// <returns>An instance of <see cref="IEvent" />.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="ex"/> is null.</exception>
        public static IEvent RecordError(Exception ex, IAppSetting appSettings, int? galleryId = null, IGallerySettingsCollection gallerySettingsCollection = null)
        {
            if (ex == null)
                throw new ArgumentNullException("ex");

            if (galleryId == null)
            {
                using (var repo = new GalleryRepository())
                {
                    galleryId = repo.Where(g => g.IsTemplate).First().GalleryId;
                }
            }

            var ev = new Event(ex, galleryId.Value);

            Save(ev);

            if (gallerySettingsCollection != null)
            {
                SendEmail(ev, appSettings, gallerySettingsCollection);
            }

            if (appSettings != null)
            {
                ValidateLogSize(appSettings.MaxNumberErrorItems);
            }

            return ev;
        }