SenseNet.ContentRepository.RepositoryInstance.SendWaitForLockErrorMail C# (CSharp) Method

SendWaitForLockErrorMail() private static method

private static SendWaitForLockErrorMail ( ) : void
return void
        private static void SendWaitForLockErrorMail()
        {
            if (!string.IsNullOrEmpty(RepositoryConfiguration.NotificationSender) && !string.IsNullOrEmpty(RepositoryConfiguration.IndexLockFileRemovedNotificationEmail))
            {
                try
                {
                    var smtpClient = new System.Net.Mail.SmtpClient();
                    var msgstr = string.Format(WRITELOCKREMOVEERRORTEMPLATESTR,
                        RepositoryConfiguration.IndexLockFileWaitForRemovedTimeout,
                        AppDomain.CurrentDomain.FriendlyName,
                        AppDomain.CurrentDomain.BaseDirectory);
                    var msg = new System.Net.Mail.MailMessage(
                        RepositoryConfiguration.NotificationSender,
                        RepositoryConfiguration.IndexLockFileRemovedNotificationEmail,
                        WRITELOCKREMOVEERRORSUBJECTSTR,
                        msgstr);
                    smtpClient.Send(msg);
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex);
                }
            }
            else
            {
                Logger.WriteError(string.Format(WRITELOCKREMOVEEMAILERRORSTR,
                    RepositoryConfiguration.NotificationSenderKey,
                    RepositoryConfiguration.IndexLockFileRemovedNotificationEmailKey));
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Waits for write.lock to disappear for a configured time interval. Timeout: configured with IndexLockFileWaitForRemovedTimeout key.
        /// If timeout is exceeded an error is logged and execution continues. For errors at OnStart an email is also sent to a configured address.
        /// </summary>
        /// <param name="waitType">A parameter that influences the logged error message and email template only.</param>
        public static void WaitForWriterLockFileIsReleased(WaitForLockFileType waitType)
        {
            // check if writer.lock is still there -> if yes, wait for other appdomain to quit or lock to disappear - until a given timeout.
            // after timeout is passed, Repository.Start will deliberately attempt to remove lock file on following startup

            if (!WaitForWriterLockFileIsReleased())
            {
                // lock file was not removed by other or current appdomain for the given time interval (onstart: other appdomain might use it, onend: current appdomain did not release it yet)
                // onstart -> notify operator and start repository anyway
                // onend -> log error, and continue
                var template = waitType == WaitForLockFileType.OnEnd ? WRITELOCKREMOVEERRORONENDTEMPLATESTR : WRITELOCKREMOVEERRORTEMPLATESTR;
                SnLog.WriteError(string.Format(template, Indexing.IndexLockFileWaitForRemovedTimeout,
                                               AppDomain.CurrentDomain.FriendlyName, AppDomain.CurrentDomain.BaseDirectory));

                if (waitType == WaitForLockFileType.OnStart)
                {
                    RepositoryInstance.SendWaitForLockErrorMail();
                }
            }
        }